raheui 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/.gitignore +19 -0
- data/.rspec +1 -0
- data/.rubocop.yml +14 -0
- data/.rubocop_todo.yml +24 -0
- data/.travis.yml +17 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +64 -0
- data/Rakefile +16 -0
- data/bin/raheui +8 -0
- data/lib/raheui/cli.rb +27 -0
- data/lib/raheui/code.rb +106 -0
- data/lib/raheui/io.rb +60 -0
- data/lib/raheui/option.rb +44 -0
- data/lib/raheui/port.rb +14 -0
- data/lib/raheui/queue.rb +18 -0
- data/lib/raheui/runner.rb +212 -0
- data/lib/raheui/stack.rb +13 -0
- data/lib/raheui/store.rb +41 -0
- data/lib/raheui/version.rb +7 -0
- data/lib/raheui.rb +16 -0
- data/raheui.gemspec +26 -0
- data/spec/raheui/cli_spec.rb +39 -0
- data/spec/raheui/code_spec.rb +119 -0
- data/spec/raheui/io_spec.rb +94 -0
- data/spec/raheui/option_spec.rb +43 -0
- data/spec/raheui/port_spec.rb +6 -0
- data/spec/raheui/queue_spec.rb +148 -0
- data/spec/raheui/runner_spec.rb +516 -0
- data/spec/raheui/stack_spec.rb +145 -0
- data/spec/raheui/store_spec.rb +93 -0
- data/spec/raheui/version_spec.rb +8 -0
- data/spec/spec_helper.rb +75 -0
- data/spec/support/exit_code_matchers.rb +27 -0
- data/spec/support/file_helper.rb +38 -0
- data/spec/support/isolated_environment.rb +13 -0
- data/spec/support/shared_store.rb +47 -0
- metadata +168 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZDU3ZTkwN2FmMzdiN2UyMDhhYzMzODAzZDk5M2QyNjBiY2ZlYzA4Yg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MmUwMzM0MmFjZjM1YWE3OGY0ZjZmMzQ3YzY4MWQxY2E4NTQ2ZTUyNw==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YWE3M2EzNzgwZGZhY2M3YTViZTk1NDM2NGJjN2Q3NDI3YzMxZGFlODE4Njk4
|
10
|
+
MzhmY2MxZWMwNzM4OWUxY2I0OTZiNmI5MDU3NzcxMzFlOGRmNTI3ODlhZTE2
|
11
|
+
ZDE2N2JmNGFhMTg3OTAyZWNlY2FlMWU2YzE0NTg3ZjBkMjdiOGU=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ODFiMGFiM2JkOWFhM2U3MTgwZTc0MDdkNTA0NjQ5YjZlMTkzOGVmZmJiYmZl
|
14
|
+
YThhYjcwNzcxOTU1YjJjODAyMDc4NGMwNzA3MjA1ZDg4ZGY3YzZhOGQ3NDBk
|
15
|
+
ZDYzYzc5N2EzZDU4OTNmNDAwYzQxZjFlZjc1MjJjNjY4MWM3MjI=
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
Include:
|
5
|
+
- '**/*.gemspec'
|
6
|
+
- '**/Gemfile'
|
7
|
+
- '**/Rakefile'
|
8
|
+
|
9
|
+
Style/AsciiComments:
|
10
|
+
Exclude:
|
11
|
+
- 'lib/raheui/io.rb'
|
12
|
+
- 'lib/raheui/code.rb'
|
13
|
+
- 'lib/raheui/runner.rb'
|
14
|
+
- 'spec/raheui/code_spec.rb'
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# This configuration was generated by `rubocop --auto-gen-config`
|
2
|
+
# on 2014-08-25 21:02:20 +0900 using RuboCop version 0.25.0.
|
3
|
+
# The point is for the user to remove these configuration records
|
4
|
+
# one by one as the offenses are removed from the code base.
|
5
|
+
# Note that changes in the inspected code, or installation of new
|
6
|
+
# versions of RuboCop, may require this file to be generated again.
|
7
|
+
|
8
|
+
# Offense count: 1
|
9
|
+
# Configuration parameters: CountComments.
|
10
|
+
Metrics/ClassLength:
|
11
|
+
Max: 132
|
12
|
+
|
13
|
+
# Offense count: 1
|
14
|
+
Metrics/CyclomaticComplexity:
|
15
|
+
Max: 21
|
16
|
+
|
17
|
+
# Offense count: 3
|
18
|
+
# Configuration parameters: CountComments.
|
19
|
+
Metrics/MethodLength:
|
20
|
+
Max: 46
|
21
|
+
|
22
|
+
# Offense count: 1
|
23
|
+
Metrics/PerceivedComplexity:
|
24
|
+
Max: 13
|
data/.travis.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 1.9.3
|
4
|
+
- 2.0.0
|
5
|
+
- 2.1
|
6
|
+
- ruby-head
|
7
|
+
- jruby-19mode
|
8
|
+
- jruby-head
|
9
|
+
- rbx-2
|
10
|
+
matrix:
|
11
|
+
allow_failures:
|
12
|
+
- rvm: ruby-head
|
13
|
+
- rvm: jruby-19mode
|
14
|
+
- rvm: jruby-head
|
15
|
+
- rvm: rbx-2
|
16
|
+
before_install:
|
17
|
+
- gem update --system
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 ChaYoung You
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# Raheui
|
2
|
+
|
3
|
+
[](https://travis-ci.org/yous/raheui)
|
4
|
+
[](https://gemnasium.com/yous/raheui)
|
5
|
+
[](https://codeclimate.com/github/yous/raheui)
|
6
|
+
[](https://coveralls.io/r/yous/raheui)
|
7
|
+
[](http://inch-ci.org/github/yous/raheui)
|
8
|
+
|
9
|
+
[Aheui][] interpreter in Ruby.
|
10
|
+
|
11
|
+
[Aheui]: http://aheui.github.io
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
``` sh
|
16
|
+
gem install raheui
|
17
|
+
```
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Pass `raheui` a file to execute:
|
22
|
+
|
23
|
+
``` sh
|
24
|
+
raheui helloworld.aheui
|
25
|
+
```
|
26
|
+
|
27
|
+
Alternatively you can run `raheui` with no arguments to pass aheui code through terminal input.
|
28
|
+
|
29
|
+
``` sh
|
30
|
+
raheui
|
31
|
+
```
|
32
|
+
|
33
|
+
For additional command-line options:
|
34
|
+
|
35
|
+
``` sh
|
36
|
+
raheui -h
|
37
|
+
```
|
38
|
+
|
39
|
+
Command flag | Description
|
40
|
+
-------------------------------------
|
41
|
+
`-h, --help` | Print this message.
|
42
|
+
`-v, --version` | Print version.
|
43
|
+
|
44
|
+
## Commit message in Aheui
|
45
|
+
|
46
|
+
Why don't you just try:
|
47
|
+
|
48
|
+
``` sh
|
49
|
+
git log --format=%b -n 1 | raheui
|
50
|
+
```
|
51
|
+
|
52
|
+
Also it works for every commit hash:
|
53
|
+
|
54
|
+
``` sh
|
55
|
+
git log --format=%b -n 1 <commit> | raheui
|
56
|
+
```
|
57
|
+
|
58
|
+
## Changelog
|
59
|
+
|
60
|
+
See [CHANGELOG.md](CHANGELOG.md).
|
61
|
+
|
62
|
+
## License
|
63
|
+
|
64
|
+
Copyright (c) 2014 ChaYoung You. See [LICENSE.txt](LICENSE.txt) for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
|
7
|
+
require 'rubocop/rake_task'
|
8
|
+
RuboCop::RakeTask.new(:rubocop)
|
9
|
+
|
10
|
+
desc 'Run RSpec with code coverage'
|
11
|
+
task :coverage do
|
12
|
+
ENV['COVERAGE'] = 'true'
|
13
|
+
Rake::Task[:spec].execute
|
14
|
+
end
|
15
|
+
|
16
|
+
task default: [:spec, :rubocop]
|
data/bin/raheui
ADDED
data/lib/raheui/cli.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Raheui
|
3
|
+
# Handle command line interfaces logic.
|
4
|
+
class CLI
|
5
|
+
# Initialize a CLI.
|
6
|
+
def initialize
|
7
|
+
@options = {}
|
8
|
+
end
|
9
|
+
|
10
|
+
# Entry point for the applicaiton logic. Process command line arguments and
|
11
|
+
# run the Aheui code.
|
12
|
+
#
|
13
|
+
# args - An Array of Strings user passed.
|
14
|
+
#
|
15
|
+
# Returns an Integer UNIX exit code.
|
16
|
+
def run(args = ARGV)
|
17
|
+
@options, paths = Option.new.parse(args)
|
18
|
+
source = if paths.empty?
|
19
|
+
$stdin.read
|
20
|
+
else
|
21
|
+
File.read(paths[0])
|
22
|
+
end
|
23
|
+
runner = Runner.new(Code.new(source))
|
24
|
+
runner.run
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/raheui/code.rb
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Raheui
|
3
|
+
# Store code object.
|
4
|
+
class Code
|
5
|
+
extend Forwardable
|
6
|
+
|
7
|
+
# Count of initial, medial and final consonant of Korean alphabet.
|
8
|
+
INITIAL_CONSONANTS = 19
|
9
|
+
MEDIAL_CONSONANTS = 21
|
10
|
+
FINAL_CONSONANTS = 28
|
11
|
+
|
12
|
+
# Returns the Integer width of code.
|
13
|
+
attr_reader :width
|
14
|
+
|
15
|
+
# Returns the Integer height of code.
|
16
|
+
attr_reader :height
|
17
|
+
|
18
|
+
# Initialize a Code. Separate Korean alphabet into consonants. Calculate the
|
19
|
+
# width and height of code.
|
20
|
+
#
|
21
|
+
# str - The String raw text of code.
|
22
|
+
#
|
23
|
+
# Examples
|
24
|
+
#
|
25
|
+
# Code.new('아희')
|
26
|
+
#
|
27
|
+
# Code.new(
|
28
|
+
# <<-CODE
|
29
|
+
# 밤밣따빠밣밟따뿌
|
30
|
+
# 빠맣파빨받밤뚜뭏
|
31
|
+
# 돋밬탕빠맣붏두붇
|
32
|
+
# 볻뫃박발뚷투뭏붖
|
33
|
+
# 뫃도뫃희멓뭏뭏붘
|
34
|
+
# 뫃봌토범더벌뿌뚜
|
35
|
+
# 뽑뽀멓멓더벓뻐뚠
|
36
|
+
# 뽀덩벐멓뻐덕더벅
|
37
|
+
# CODE
|
38
|
+
# )
|
39
|
+
def initialize(str)
|
40
|
+
@matrix = str.lines.map do |line|
|
41
|
+
line.chomp.chars.map { |ch| consonants(ch) }
|
42
|
+
end
|
43
|
+
@height = @matrix.size
|
44
|
+
if @height.zero?
|
45
|
+
@width = 1
|
46
|
+
@height = 1
|
47
|
+
else
|
48
|
+
@width = @matrix.map(&:size).max
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Get consonants of the given position.
|
53
|
+
#
|
54
|
+
# x - The Integer position of x coordinate.
|
55
|
+
# y - The Integer position of y coordinate.
|
56
|
+
#
|
57
|
+
# Examples
|
58
|
+
#
|
59
|
+
# code = Code.new('아희')
|
60
|
+
# code[0, 0]
|
61
|
+
# # => [11, 0, 0]
|
62
|
+
# code[1, 0]
|
63
|
+
# # => [18, 19, 0]
|
64
|
+
# code[0, 1]
|
65
|
+
# # => []
|
66
|
+
# code[1, 1]
|
67
|
+
# # => []
|
68
|
+
#
|
69
|
+
# Returns an Array consists of consonants or an empty Array when there is no
|
70
|
+
# element in the position.
|
71
|
+
def [](x, y)
|
72
|
+
@matrix.fetch(y, []).fetch(x, [])
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
# Separate Korean alphabet into consonants.
|
78
|
+
#
|
79
|
+
# ch - The String character to separate.
|
80
|
+
#
|
81
|
+
# Examples
|
82
|
+
#
|
83
|
+
# consonants('가')
|
84
|
+
# # => [0, 0, 0]
|
85
|
+
#
|
86
|
+
# consonants('힣')
|
87
|
+
# # => [18, 20, 27]
|
88
|
+
#
|
89
|
+
# consonants('a')
|
90
|
+
# # => []
|
91
|
+
#
|
92
|
+
# Returns an Array of index of consonants or empty Array if the character is
|
93
|
+
# not an Korean alphabet.
|
94
|
+
def consonants(ch)
|
95
|
+
case ch
|
96
|
+
when '가'..'힣'
|
97
|
+
index = ch.ord - '가'.ord
|
98
|
+
[index / (MEDIAL_CONSONANTS * FINAL_CONSONANTS),
|
99
|
+
(index / FINAL_CONSONANTS) % MEDIAL_CONSONANTS,
|
100
|
+
index % FINAL_CONSONANTS]
|
101
|
+
else
|
102
|
+
[]
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
data/lib/raheui/io.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Raheui
|
3
|
+
# IO methods for user input and output.
|
4
|
+
module IO
|
5
|
+
# Read an Integer from user input.
|
6
|
+
#
|
7
|
+
# Returns the Integer user entered.
|
8
|
+
def self.read_int
|
9
|
+
$stdin.gets.to_i
|
10
|
+
end
|
11
|
+
|
12
|
+
# Read an character from user input.
|
13
|
+
#
|
14
|
+
# Returns the Integer character code of the character user entered.
|
15
|
+
def self.read_chr
|
16
|
+
$stdin.getc.ord
|
17
|
+
end
|
18
|
+
|
19
|
+
# Print an Integer.
|
20
|
+
#
|
21
|
+
# value - The Integer to print.
|
22
|
+
#
|
23
|
+
# Examples
|
24
|
+
#
|
25
|
+
# IO.print_int(42)
|
26
|
+
# # 42=> nil
|
27
|
+
#
|
28
|
+
# Returns nothing.
|
29
|
+
def self.print_int(value)
|
30
|
+
$stdout.print value
|
31
|
+
end
|
32
|
+
|
33
|
+
# Print an character from character code.
|
34
|
+
#
|
35
|
+
# value - The Integer character code to print.
|
36
|
+
#
|
37
|
+
# Examples
|
38
|
+
#
|
39
|
+
# IO.print_chr(97)
|
40
|
+
# # a=> nil
|
41
|
+
#
|
42
|
+
# IO.print_chr(0xAC00)
|
43
|
+
# # 가=> nil
|
44
|
+
#
|
45
|
+
# # Rescue RangeError
|
46
|
+
# IO.print_chr(-1)
|
47
|
+
# # [U+..FF]=> nil
|
48
|
+
#
|
49
|
+
# # Rescue RangeError
|
50
|
+
# IO.print_chr(0x110000)
|
51
|
+
# # [U+110000]=> nil
|
52
|
+
#
|
53
|
+
# Returns nothing.
|
54
|
+
def self.print_chr(value)
|
55
|
+
$stdout.print value.chr(Encoding::UTF_8)
|
56
|
+
rescue RangeError
|
57
|
+
$stdout.print format('[U+%04X]', value)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Raheui
|
3
|
+
# Handle command line options.
|
4
|
+
class Option
|
5
|
+
# Initialize a Option.
|
6
|
+
def initialize
|
7
|
+
@options = {}
|
8
|
+
end
|
9
|
+
|
10
|
+
# Parse the passed arguments to a Hash.
|
11
|
+
#
|
12
|
+
# args - An Array of Strings containing options.
|
13
|
+
#
|
14
|
+
# Returns an Array consists of a Hash options and an Array of String
|
15
|
+
# remaining arguments.
|
16
|
+
def parse(args)
|
17
|
+
OptionParser.new do |opts|
|
18
|
+
opts.banner = 'Usage: raheui [options] [file]'
|
19
|
+
|
20
|
+
add_options(opts)
|
21
|
+
end.parse!(args)
|
22
|
+
[@options, args]
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
# Add command line options to OptionParser.
|
28
|
+
#
|
29
|
+
# opts - An OptionParser object to add options.
|
30
|
+
#
|
31
|
+
# Returns nothing.
|
32
|
+
def add_options(opts)
|
33
|
+
opts.on('-h', '--help', 'Print this message.') do
|
34
|
+
puts opts
|
35
|
+
exit 0
|
36
|
+
end
|
37
|
+
|
38
|
+
opts.on('-v', '--version', 'Print version.') do
|
39
|
+
puts Version::STRING
|
40
|
+
exit 0
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/raheui/port.rb
ADDED
data/lib/raheui/queue.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Raheui
|
3
|
+
# Queue class for Aheui.
|
4
|
+
class Queue < Store
|
5
|
+
# Delegates push to @store.
|
6
|
+
def_delegator :@store, :push
|
7
|
+
|
8
|
+
# Dequeue from the Queue.
|
9
|
+
def pop
|
10
|
+
@store.shift
|
11
|
+
end
|
12
|
+
|
13
|
+
# Swap the first two elements of Queue.
|
14
|
+
def swap
|
15
|
+
@store[0], @store[1] = @store[1], @store[0] if size > 1
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|