kaiser-ruby 0.1.0 → 0.2.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 +4 -4
- data/.gitignore +2 -1
- data/Gemfile.lock +5 -3
- data/README.md +43 -16
- data/TODO.md +43 -0
- data/bin/console +1 -1
- data/exe/kaiser-ruby +7 -0
- data/kaiser-ruby.gemspec +5 -4
- data/lib/kaiser_ruby.rb +7 -1
- data/lib/kaiser_ruby/cli.rb +37 -0
- data/lib/kaiser_ruby/rockstar_parser.rb +174 -9
- data/lib/kaiser_ruby/rockstar_transform.rb +46 -3
- data/lib/kaiser_ruby/version.rb +1 -1
- metadata +29 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b5718545e9c7f76ee7424888738a48381168802086130192a15fee4d6c2f11a
|
4
|
+
data.tar.gz: a01209b2869ccbef8a0aa9824bba5b2cee0383e4a5cdb8044db5a0447d1805cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 535f03ccac46331c49ef62b7b22f529ad4a7248c35fefacb6d3c3ee77603eb4a85c6cbb50580aa20fe210f3a8dabd4fa8a1cb381a6fb2fb0d97dea728a474a07
|
7
|
+
data.tar.gz: 328d6528bb967ca27e7eea4e69df429f08ad7659b28bd3058e357f28113153933a75de32d0efbdb817a7e7a6afb62d54b2b3379df50cf7d44df77f40da633af2
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
kaiser-ruby (0.
|
5
|
-
parslet
|
4
|
+
kaiser-ruby (0.2.0)
|
5
|
+
parslet (~> 1.8)
|
6
|
+
thor (~> 0.20)
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
@@ -28,6 +29,7 @@ GEM
|
|
28
29
|
diff-lcs (>= 1.2.0, < 2.0)
|
29
30
|
rspec-support (~> 3.7.0)
|
30
31
|
rspec-support (3.7.1)
|
32
|
+
thor (0.20.0)
|
31
33
|
|
32
34
|
PLATFORMS
|
33
35
|
ruby
|
@@ -35,7 +37,7 @@ PLATFORMS
|
|
35
37
|
DEPENDENCIES
|
36
38
|
bundler (~> 1.16)
|
37
39
|
kaiser-ruby!
|
38
|
-
pry
|
40
|
+
pry (~> 0.11)
|
39
41
|
rake (~> 10.0)
|
40
42
|
rspec (~> 3.0)
|
41
43
|
|
data/README.md
CHANGED
@@ -1,38 +1,65 @@
|
|
1
|
-
#
|
1
|
+
# KaiserRuby - a Rockstar to Ruby transpiler
|
2
2
|
|
3
|
-
|
3
|
+
This tool translates a file containing a program written in the [Rockstar language](https://github.com/dylanbeattie/rockstar) to Ruby code.
|
4
4
|
|
5
|
-
|
5
|
+
This is still a work in progress. For details on that, see the TODO.md file.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
9
|
-
|
9
|
+
Install the gem by issuing the following command.
|
10
|
+
|
11
|
+
$ gem install kaiser-ruby
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
The most common usage of this gem is to transpile (or transpile and run immediately) Rockstar code into Ruby code.
|
16
|
+
|
17
|
+
This gem provides a commandline tool for you to use:
|
18
|
+
|
19
|
+
$ kaiser-ruby
|
20
|
+
|
21
|
+
There are a few ways you can use it. First one will just output the result of the transpilation.
|
10
22
|
|
11
|
-
```ruby
|
12
|
-
gem 'kaiser-ruby'
|
13
23
|
```
|
24
|
+
$ kaiser-ruby transpile ./examples/assignment.rock
|
25
|
+
tommy = 15
|
26
|
+
puts tommy
|
14
27
|
|
15
|
-
|
28
|
+
```
|
16
29
|
|
17
|
-
|
30
|
+
The `--show-source` flag will output the Rockstar code along with the resulting Ruby code like this:
|
18
31
|
|
19
|
-
|
32
|
+
This will have a following output:
|
20
33
|
|
21
|
-
|
34
|
+
```
|
35
|
+
$ kaiser-ruby transpile ./examples/assignment.rock --show-source
|
36
|
+
Tommy is a rebel
|
37
|
+
Shout Tommy
|
38
|
+
----------------------------------------
|
39
|
+
tommy = 15
|
40
|
+
puts tommy
|
22
41
|
|
23
|
-
|
42
|
+
```
|
24
43
|
|
25
|
-
|
44
|
+
You can also use the `--save=FILE` option to write the resulting transpiled code as a file instead of outputting it:
|
26
45
|
|
27
|
-
|
46
|
+
```
|
47
|
+
$ kaiser-ruby transpile ./examples/assignment.rock --save=a.rb
|
48
|
+
Saved output in `a.rb`
|
28
49
|
|
29
|
-
|
50
|
+
```
|
30
51
|
|
31
|
-
|
52
|
+
Finally, you can also transpile and immediately execute the code, like this:
|
53
|
+
|
54
|
+
```
|
55
|
+
$ kaiser-ruby execute ./examples/assignment.rock
|
56
|
+
15
|
57
|
+
|
58
|
+
```
|
32
59
|
|
33
60
|
## Contributing
|
34
61
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
62
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/marcinruszkiewicz/kaiser-ruby.
|
36
63
|
|
37
64
|
## License
|
38
65
|
|
data/TODO.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# TODO notes for KaiserRuby transpiler
|
2
|
+
|
3
|
+
## Variables
|
4
|
+
|
5
|
+
- [ ] Handle pronouns - he, she, it, and others should refer to the last used variable
|
6
|
+
|
7
|
+
## Types
|
8
|
+
|
9
|
+
- [ ] Handle null type differently - nil in Ruby isn't really comparable to 0
|
10
|
+
- [ ] Handle mysterious type - probably this should be nil and what is now nil should be 0 instead
|
11
|
+
- [ ] Handle object type
|
12
|
+
|
13
|
+
## Comparisons
|
14
|
+
|
15
|
+
- [ ] Handle gt, gte, lt, lte comparisons
|
16
|
+
- [ ] Handle negation
|
17
|
+
|
18
|
+
## Input
|
19
|
+
|
20
|
+
- [ ] Handle input from STDIN
|
21
|
+
|
22
|
+
## Flow Control
|
23
|
+
|
24
|
+
- [ ] While loop
|
25
|
+
- [ ] Until loop
|
26
|
+
- [ ] Break and continue
|
27
|
+
|
28
|
+
## Functions
|
29
|
+
|
30
|
+
- [ ] Define functions
|
31
|
+
- [ ] Handle function calls
|
32
|
+
|
33
|
+
## Examples
|
34
|
+
|
35
|
+
- [ ] FizzBuzz example (should also be in tests to check if it runs)
|
36
|
+
- [ ] Should be able to run the [Cellular Rockomata](https://github.com/Rifhutch/cellular-rocktomata)
|
37
|
+
- [ ] Fibonacci example https://github.com/dylanbeattie/rockstar/issues/94#issuecomment-408217504
|
38
|
+
- [ ] Math module https://gist.github.com/wrenoud/6be6f7509c88a3d8f9867ae782fb768f
|
39
|
+
|
40
|
+
## Other stuff
|
41
|
+
|
42
|
+
- [ ] Test if it handles metal umlauts (Ruby shouldn't care much, but tests should be made)
|
43
|
+
- [ ] Ignore comments in parentheses
|
data/bin/console
CHANGED
data/exe/kaiser-ruby
ADDED
data/kaiser-ruby.gemspec
CHANGED
@@ -14,15 +14,16 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
-
f.match(%r{^(
|
17
|
+
f.match(%r{^(spec|examples)/})
|
18
18
|
end
|
19
19
|
spec.bindir = "exe"
|
20
|
-
spec.executables =
|
20
|
+
spec.executables = ['kaiser-ruby']
|
21
21
|
spec.require_paths = ["lib"]
|
22
22
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.16"
|
24
24
|
spec.add_development_dependency "rake", "~> 10.0"
|
25
25
|
spec.add_development_dependency "rspec", "~> 3.0"
|
26
|
-
spec.add_development_dependency "pry"
|
27
|
-
spec.add_dependency "parslet"
|
26
|
+
spec.add_development_dependency "pry", "~> 0.11"
|
27
|
+
spec.add_dependency "parslet", "~> 1.8"
|
28
|
+
spec.add_dependency "thor", "~> 0.20"
|
28
29
|
end
|
data/lib/kaiser_ruby.rb
CHANGED
@@ -1,11 +1,17 @@
|
|
1
1
|
require 'parslet'
|
2
2
|
require 'kaiser_ruby/rockstar_parser'
|
3
3
|
require 'kaiser_ruby/rockstar_transform'
|
4
|
+
require 'pry'
|
4
5
|
|
5
6
|
module KaiserRuby
|
6
7
|
def self.parse(input)
|
7
|
-
|
8
|
+
if input.split("\n").size == 1
|
9
|
+
KaiserRuby::RockstarSingleLineParser.new.parse(input.chomp)
|
10
|
+
else
|
11
|
+
KaiserRuby::RockstarParser.new.parse(input)
|
12
|
+
end
|
8
13
|
rescue Parslet::ParseFailed => failure
|
14
|
+
puts input.inspect
|
9
15
|
puts failure.parse_failure_cause.ascii_tree
|
10
16
|
end
|
11
17
|
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
module KaiserRuby
|
4
|
+
class CLI < Thor
|
5
|
+
desc "transpile FILE", "transpile a .rock FILE and output the result"
|
6
|
+
option 'show-source'.to_sym, type: :boolean, desc: "prints out the source file along with the transpiled output"
|
7
|
+
option :save, desc: "saves the transpiled output in SAVE"
|
8
|
+
def transpile(filename)
|
9
|
+
file = File.read filename
|
10
|
+
output = KaiserRuby.transpile(file)
|
11
|
+
|
12
|
+
if options['show-source'.to_sym]
|
13
|
+
puts file
|
14
|
+
puts "-" * 40
|
15
|
+
end
|
16
|
+
|
17
|
+
if options[:save]
|
18
|
+
out = File.new(options[:save], 'w')
|
19
|
+
out.write output
|
20
|
+
out.close
|
21
|
+
puts "Saved output in `#{options[:save]}`"
|
22
|
+
else
|
23
|
+
puts output
|
24
|
+
end
|
25
|
+
puts
|
26
|
+
end
|
27
|
+
|
28
|
+
desc "execute FILE", "transpiles and runs a .rock FILE"
|
29
|
+
def execute(filename)
|
30
|
+
file = File.read filename
|
31
|
+
output = KaiserRuby.transpile(file)
|
32
|
+
|
33
|
+
eval output
|
34
|
+
puts
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -1,16 +1,181 @@
|
|
1
1
|
module KaiserRuby
|
2
2
|
class RockstarParser < Parslet::Parser
|
3
|
-
|
3
|
+
rule(:reserved) do
|
4
|
+
nil_value_keywords | true_value_keywords | false_value_keywords | plus_keywords | minus_keywords | times_keywords | over_keywords |
|
5
|
+
str('Knock') | str('Build') | str('Put') | str('into') | str('says') | poetic_number_keywords | say_keywords
|
6
|
+
end
|
4
7
|
|
5
|
-
|
6
|
-
rule(:
|
8
|
+
rule(:nil_value_keywords) { str('nothing') | str('nowhere') | str('nobody') | str('empty') | str('gone') }
|
9
|
+
rule(:false_value_keywords) { str('false') | str('wrong') | str('no') | str('lies') }
|
10
|
+
rule(:true_value_keywords) { str('true') | str('right') | str('yes') | str('ok') }
|
11
|
+
rule(:plus_keywords) { str('plus') | str('with') }
|
12
|
+
rule(:minus_keywords) { str('minus') | str('without') }
|
13
|
+
rule(:minus_keywords) { str('minus') | str('without') }
|
14
|
+
rule(:times_keywords) { str('times') | str('of') }
|
15
|
+
rule(:over_keywords) { str('over') }
|
16
|
+
rule(:poetic_number_keywords) { str('is') | str('was') | str('were') }
|
17
|
+
rule(:say_keywords) { str('Say') | str('Shout') | str('Scream') | str('Whisper') }
|
18
|
+
rule(:flow_keywords) { str('If') | str('Else') | str('While') | str('Until') }
|
7
19
|
|
8
|
-
|
9
|
-
rule(:
|
10
|
-
rule(:
|
11
|
-
|
20
|
+
rule(:proper_word) { reserved.absent? >> match['A-Z'] >> match['A-Za-z'].repeat }
|
21
|
+
rule(:common_word) { reserved.absent? >> match['A-Za-z'].repeat }
|
22
|
+
rule(:common_variable_name) do
|
23
|
+
(
|
24
|
+
str('A ') | str('a ') |
|
25
|
+
str('An ') | str('an ') |
|
26
|
+
str('The ') | str('the ') |
|
27
|
+
str('My ') | str('my ') |
|
28
|
+
str('Your ') | str('your ')
|
29
|
+
) >> reserved.absent? >> match['a-z'].repeat
|
30
|
+
end
|
31
|
+
rule(:proper_variable_name) do
|
32
|
+
(proper_word >> (space >> proper_word).repeat).repeat(1)
|
33
|
+
end
|
12
34
|
|
13
|
-
rule(:
|
14
|
-
|
35
|
+
rule(:variable_names) do
|
36
|
+
(common_variable_name | proper_variable_name).as(:variable_name)
|
37
|
+
end
|
38
|
+
|
39
|
+
rule(:nil_value) { nil_value_keywords.as(:nil_value) }
|
40
|
+
rule(:true_value) { true_value_keywords.as(:true_value) }
|
41
|
+
rule(:false_value) { false_value_keywords.as(:false_value) }
|
42
|
+
rule(:string_value) { (str('"') >> match['A-Za-z '].repeat >> str('"')).as(:string_value) }
|
43
|
+
rule(:numeric_value) { match['0-9\.'].repeat.as(:numeric_value) }
|
44
|
+
rule(:unquoted_string) { match['^\n'].repeat.as(:unquoted_string) }
|
45
|
+
rule(:string_as_number) { reserved.absent? >> match['^\n'].repeat.as(:string_as_number) }
|
46
|
+
|
47
|
+
rule(:basic_assignment_expression) do
|
48
|
+
match('Put ').present? >>
|
49
|
+
(
|
50
|
+
str('Put ') >> string_input.as(:right) >> str(' into ') >> variable_names.as(:left)
|
51
|
+
).as(:assignment)
|
52
|
+
end
|
53
|
+
|
54
|
+
rule(:increment) do
|
55
|
+
(
|
56
|
+
str('Build ') >> variable_names.as(:variable_name) >> str(' up')
|
57
|
+
).as(:increment)
|
58
|
+
end
|
59
|
+
|
60
|
+
rule(:decrement) do
|
61
|
+
(
|
62
|
+
str('Knock ') >> variable_names.as(:variable_name) >> str(' down')
|
63
|
+
).as(:decrement)
|
64
|
+
end
|
65
|
+
|
66
|
+
# math operations
|
67
|
+
|
68
|
+
rule(:addition) do
|
69
|
+
(match('.*? plus') | match('.*? with')).present? >>
|
70
|
+
(
|
71
|
+
value_or_variable.as(:left) >> space >> plus_keywords >> space >> value_or_variable.as(:right)
|
72
|
+
).as(:addition)
|
73
|
+
end
|
74
|
+
|
75
|
+
rule(:subtraction) do
|
76
|
+
(match('.*? minus') | match('.*? without')).present? >>
|
77
|
+
(
|
78
|
+
value_or_variable.as(:left) >> space >> minus_keywords >> space >> value_or_variable.as(:right)
|
79
|
+
).as(:subtraction)
|
80
|
+
end
|
81
|
+
|
82
|
+
rule(:division) do
|
83
|
+
match('.*? over').present? >>
|
84
|
+
(
|
85
|
+
value_or_variable.as(:left) >> space >> over_keywords >> space >> value_or_variable.as(:right)
|
86
|
+
).as(:division)
|
87
|
+
end
|
88
|
+
|
89
|
+
rule(:multiplication) do
|
90
|
+
(match('.*? times') | match('.*? of')).present? >>
|
91
|
+
(
|
92
|
+
value_or_variable.as(:left) >> space >> times_keywords >> space >> value_or_variable.as(:right)
|
93
|
+
).as(:multiplication)
|
94
|
+
end
|
95
|
+
|
96
|
+
# poetic assignments
|
97
|
+
|
98
|
+
rule(:poetic_type_literal) do
|
99
|
+
(flow_keywords.absent?) >>
|
100
|
+
(
|
101
|
+
variable_names.as(:left) >> str(' is ') >> (nil_value | false_value | true_value).as(:right)
|
102
|
+
).as(:assignment)
|
103
|
+
end
|
104
|
+
|
105
|
+
rule(:poetic_string_literal) do
|
106
|
+
(
|
107
|
+
variable_names.as(:left) >> str(' says ') >> unquoted_string.as(:right)
|
108
|
+
).as(:assignment)
|
109
|
+
end
|
110
|
+
|
111
|
+
rule(:poetic_number_literal) do
|
112
|
+
(flow_keywords.absent?) >>
|
113
|
+
(
|
114
|
+
variable_names.as(:left) >> space >> poetic_number_keywords >> space >> string_as_number.as(:right)
|
115
|
+
).as(:assignment)
|
116
|
+
end
|
117
|
+
|
118
|
+
rule(:print_function) do
|
119
|
+
(
|
120
|
+
say_keywords >> space >> value_or_variable.as(:output)
|
121
|
+
).as(:print)
|
122
|
+
end
|
123
|
+
|
124
|
+
# comparisons
|
125
|
+
|
126
|
+
rule(:equality) do
|
127
|
+
(
|
128
|
+
value_or_variable.as(:left) >> str(' is ') >> (string_as_number | value_or_variable).as(:right)
|
129
|
+
).as(:equals)
|
130
|
+
end
|
131
|
+
|
132
|
+
# flow control
|
133
|
+
|
134
|
+
rule(:if_block) do
|
135
|
+
(
|
136
|
+
str('If ') >> comparisons.as(:if_condition) >> eol >>
|
137
|
+
scope {
|
138
|
+
inner_block_line.repeat.as(:if_block) >>
|
139
|
+
(eol | eof).as(:endif)
|
140
|
+
}
|
141
|
+
).as(:if)
|
142
|
+
end
|
143
|
+
|
144
|
+
rule(:if_else_block) do
|
145
|
+
(
|
146
|
+
str('If ') >> comparisons.as(:if_condition) >> eol >>
|
147
|
+
scope {
|
148
|
+
inner_block_line.repeat.as(:if_block)
|
149
|
+
} >>
|
150
|
+
str('Else') >> eol >>
|
151
|
+
scope {
|
152
|
+
inner_block_line.repeat.as(:else_block) >>
|
153
|
+
(eol | eof).as(:endif)
|
154
|
+
}
|
155
|
+
).as(:if_else)
|
156
|
+
end
|
157
|
+
|
158
|
+
rule(:simple_values) { nil_value | false_value | true_value | string_value | numeric_value }
|
159
|
+
rule(:value_or_variable) { variable_names | simple_values }
|
160
|
+
rule(:expressions) { basic_assignment_expression | increment | decrement | addition | subtraction | multiplication | division }
|
161
|
+
rule(:comparisons) { equality }
|
162
|
+
rule(:flow_control) { if_block | if_else_block }
|
163
|
+
rule(:poetics) { poetic_type_literal | poetic_string_literal | poetic_number_literal }
|
164
|
+
rule(:functions) { print_function }
|
165
|
+
rule(:line_elements) { flow_control | poetics | expressions | functions | eol }
|
166
|
+
|
167
|
+
rule(:string_input) { line_elements | value_or_variable }
|
168
|
+
rule(:line) { (line_elements >> eol.maybe).as(:line) }
|
169
|
+
rule(:inner_block_line) { ( (flow_control | poetics | expressions | functions) >> eol.maybe).as(:line) }
|
170
|
+
rule(:lyrics) { line.repeat.as(:lyrics) }
|
171
|
+
root(:lyrics)
|
172
|
+
|
173
|
+
rule(:eol) { match["\n"] }
|
174
|
+
rule(:eof) { any.absent? }
|
175
|
+
rule(:space) { match[' \t'].repeat(1) }
|
176
|
+
end
|
177
|
+
|
178
|
+
class RockstarSingleLineParser < KaiserRuby::RockstarParser
|
179
|
+
root(:string_input)
|
15
180
|
end
|
16
181
|
end
|
@@ -1,13 +1,56 @@
|
|
1
1
|
module KaiserRuby
|
2
2
|
class RockstarTransform < Parslet::Transform
|
3
|
-
rule(:
|
3
|
+
rule(variable_name: simple(:str)) { |c| parameterize(c[:str]) }
|
4
4
|
|
5
|
-
rule(:
|
6
|
-
|
5
|
+
rule(nil_value: simple(:_)) { 'nil' }
|
6
|
+
rule(true_value: simple(:_)) { 'true' }
|
7
|
+
rule(false_value: simple(:_)) { 'false' }
|
8
|
+
rule(string_value: simple(:str)) { str }
|
9
|
+
rule(numeric_value: simple(:num)) { num }
|
10
|
+
rule(unquoted_string: simple(:str)) { "\"#{str}\"" }
|
11
|
+
rule(string_as_number: simple(:str)) do |c|
|
12
|
+
if c[:str].to_s.include?('.')
|
13
|
+
c[:str].to_s.gsub(/[^A-Za-z\s\.]/, '').split('.').map do |sub|
|
14
|
+
str_to_num(sub)
|
15
|
+
end.join('.').to_f
|
16
|
+
else
|
17
|
+
str_to_num(c[:str])
|
18
|
+
end
|
7
19
|
end
|
8
20
|
|
21
|
+
rule(assignment: { left: simple(:left), right: simple(:right) }) { "#{left} = #{right}" }
|
22
|
+
rule(increment: simple(:str)) { "#{str} += 1" }
|
23
|
+
rule(decrement: simple(:str)) { "#{str} -= 1" }
|
24
|
+
rule(addition: { left: simple(:left), right: simple(:right) }) { "#{left} + #{right}" }
|
25
|
+
rule(subtraction: { left: simple(:left), right: simple(:right) }) { "#{left} - #{right}" }
|
26
|
+
rule(multiplication: { left: simple(:left), right: simple(:right) }) { "#{left} * #{right}" }
|
27
|
+
rule(division: { left: simple(:left), right: simple(:right) }) { "#{left} / #{right}" }
|
28
|
+
|
29
|
+
rule(print: { output: simple(:output) }) { "puts #{output}" }
|
30
|
+
|
31
|
+
rule(equals: { left: simple(:left), right: simple(:right) }) { "#{left} == #{right}" }
|
32
|
+
rule(if: { if_condition: simple(:if_condition), if_block: sequence(:if_block_lines), endif: simple(:_)} ) do
|
33
|
+
"if #{if_condition}\n" +
|
34
|
+
if_block_lines.map { |l| "#{l}\n" }.join +
|
35
|
+
"end"
|
36
|
+
end
|
37
|
+
rule(if_else: { if_condition: simple(:if_condition), if_block: sequence(:if_block_lines), else_block: sequence(:else_block_lines), endif: simple(:_)} ) do
|
38
|
+
"if #{if_condition}\n" +
|
39
|
+
if_block_lines.map { |l| "#{l}\n" }.join +
|
40
|
+
"else\n" +
|
41
|
+
else_block_lines.map { |l| "#{l}\n" }.join +
|
42
|
+
"end"
|
43
|
+
end
|
44
|
+
|
45
|
+
rule(line: simple(:line)) { line == "\n" ? nil : line }
|
46
|
+
rule(lyrics: sequence(:lines)) { lines.join("\n") + "\n" }
|
47
|
+
|
9
48
|
def self.parameterize(string)
|
10
49
|
string.to_s.downcase.gsub(/\s+/, '_')
|
11
50
|
end
|
51
|
+
|
52
|
+
def self.str_to_num(string)
|
53
|
+
string.to_s.split(/\s+/).map { |e| e.length % 10 }.join.to_i
|
54
|
+
end
|
12
55
|
end
|
13
56
|
end
|
data/lib/kaiser_ruby/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kaiser-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcin Ruszkiewicz
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -56,34 +56,49 @@ dependencies:
|
|
56
56
|
name: pry
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
61
|
+
version: '0.11'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
68
|
+
version: '0.11'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: parslet
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '1.8'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.8'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: thor
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.20'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
81
95
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
96
|
+
version: '0.20'
|
83
97
|
description:
|
84
98
|
email:
|
85
99
|
- marcin.ruszkiewicz@polcode.net
|
86
|
-
executables:
|
100
|
+
executables:
|
101
|
+
- kaiser-ruby
|
87
102
|
extensions: []
|
88
103
|
extra_rdoc_files: []
|
89
104
|
files:
|
@@ -95,10 +110,13 @@ files:
|
|
95
110
|
- LICENSE.txt
|
96
111
|
- README.md
|
97
112
|
- Rakefile
|
113
|
+
- TODO.md
|
98
114
|
- bin/console
|
99
115
|
- bin/setup
|
116
|
+
- exe/kaiser-ruby
|
100
117
|
- kaiser-ruby.gemspec
|
101
118
|
- lib/kaiser_ruby.rb
|
119
|
+
- lib/kaiser_ruby/cli.rb
|
102
120
|
- lib/kaiser_ruby/rockstar_parser.rb
|
103
121
|
- lib/kaiser_ruby/rockstar_transform.rb
|
104
122
|
- lib/kaiser_ruby/version.rb
|