kaiser-ruby 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -0
- data/Gemfile.lock +2 -2
- data/README.md +6 -4
- data/TODO.md +4 -9
- data/lib/kaiser_ruby.rb +8 -16
- data/lib/kaiser_ruby/cli.rb +13 -11
- data/lib/kaiser_ruby/rockstar_parser.rb +39 -33
- data/lib/kaiser_ruby/rockstar_transform.rb +94 -72
- data/lib/kaiser_ruby/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 692fa0cdec0bb22e125901704ddffd9bfb54d2d761779cec880f706b1ac1bfef
|
4
|
+
data.tar.gz: b48529cffefaa98132df6e0a3d9313df0e2b68c07b83c2b663b64a36993b237a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f3e3feae95830d93246828d6c1ef5783d544d57afb3bafaea168d18238469fda7972863804a65658e906d2c2934f98d251499a76c4e8dae328a0ab8c0bfba5e
|
7
|
+
data.tar.gz: 2aa9ba2f4f5d29aef2230797b0118e0199d4b9c03e7fcba52b123bf0b5c82e7d412ddcee71691f3e086a3526a17872c1cf82b89366f0335ae1f0299ff1ecaf37
|
data/CHANGELOG.md
CHANGED
@@ -30,3 +30,20 @@ Other stuff:
|
|
30
30
|
- [x] FizzBuzz example is working
|
31
31
|
- [x] Fibonacci example is working
|
32
32
|
- [x] Added comments to resulting ruby code flow control statements, so it's easier to see where what ends. This should help making the code more readable (and easier to figure out if it's actually correct), at least while the indentation feature is not fully working yet.
|
33
|
+
|
34
|
+
# 0.4
|
35
|
+
|
36
|
+
Language Implementation:
|
37
|
+
|
38
|
+
- [x] Handle non-alpha values in quoted strings
|
39
|
+
- [x] Ignore comments in parentheses
|
40
|
+
- [x] Handle input from STDIN
|
41
|
+
- [x] Handle contractions - "Janie's got a gun" should be expanded to "Janie is got a gun" and so it should transpile to "janie = 313"
|
42
|
+
- [x] Handle pronouns - he, she, it, and others should refer to the last used variable
|
43
|
+
|
44
|
+
Other stuff:
|
45
|
+
|
46
|
+
- [x] Updated the FizzBuzz example
|
47
|
+
- [x] Catch exceptions in the REPL
|
48
|
+
- [x] Suppressed warning about eval from Thor
|
49
|
+
- [x] Move nesting indentation from main module to transformer
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -8,7 +8,9 @@ This is still a work in progress, however most of the language implementation is
|
|
8
8
|
|
9
9
|
Install the gem by issuing the following command.
|
10
10
|
|
11
|
-
|
11
|
+
```
|
12
|
+
$ gem install kaiser-ruby
|
13
|
+
```
|
12
14
|
|
13
15
|
## Usage
|
14
16
|
|
@@ -16,7 +18,9 @@ The most common usage of this gem is to transpile (or transpile and run immediat
|
|
16
18
|
|
17
19
|
This gem provides a commandline tool for you to use:
|
18
20
|
|
19
|
-
|
21
|
+
```
|
22
|
+
$ kaiser-ruby
|
23
|
+
```
|
20
24
|
|
21
25
|
There are a few ways you can use it. First one will just output the result of the transpilation.
|
22
26
|
|
@@ -29,8 +33,6 @@ puts tommy
|
|
29
33
|
|
30
34
|
The `--show-source` flag will output the Rockstar code along with the resulting Ruby code like this:
|
31
35
|
|
32
|
-
This will have a following output:
|
33
|
-
|
34
36
|
```
|
35
37
|
$ kaiser-ruby transpile ./examples/assignment.rock --show-source
|
36
38
|
Tommy is a rebel
|
data/TODO.md
CHANGED
@@ -2,27 +2,22 @@
|
|
2
2
|
|
3
3
|
## Language Implementation
|
4
4
|
|
5
|
-
- [ ] Handle pronouns - he, she, it, and others should refer to the last used variable
|
6
|
-
- [ ] Handle "Janie's got a gun"
|
7
|
-
- [ ] Ignore comments in parentheses
|
8
|
-
- [ ] Handle object type
|
9
|
-
- [ ] Handle input from STDIN
|
10
5
|
- [ ] Function calls can be used as expressions in flow statements
|
11
6
|
- [ ] Handle ',' instead of 'and' in function calls
|
7
|
+
|
12
8
|
- [ ] Somehow handle function variable scope
|
9
|
+
- [ ] Handle object type
|
13
10
|
|
14
11
|
## Examples
|
15
12
|
|
16
13
|
- [ ] Should be able to run the [Cellular Rockomata](https://github.com/Rifhutch/cellular-rocktomata)
|
17
|
-
- [ ] Fibonacci example https://github.com/dylanbeattie/rockstar/issues/94#issuecomment-408217504
|
18
14
|
- [ ] Math module https://gist.github.com/wrenoud/6be6f7509c88a3d8f9867ae782fb768f
|
19
15
|
- [ ] Primality checker https://www.reddit.com/r/RockstarDevs/comments/92i6sm/primality_checker_in_rockstar/
|
20
16
|
- [ ] Make a demo command in the CLI that runs all examples (would that even work as a gem? it should be doable somehow)
|
21
17
|
|
22
18
|
## Other stuff
|
23
19
|
|
24
|
-
- [ ] Fix indenting of nested blocks that doesn't really work well
|
20
|
+
- [ ] Fix indenting of nested blocks that doesn't really work well (this should also help deeper nesting)
|
25
21
|
- [ ] Add code history to the REPL
|
26
22
|
- [ ] Make REPL work with multiline input also, not only singular lines
|
27
|
-
- [ ]
|
28
|
-
- [ ] Suppress warnign about eval from Thor
|
23
|
+
- [ ] Make a demo visitor that evals the code and waits a bit between commands, so it's more music video-ish. Maybe should change the console colors while at it?
|
data/lib/kaiser_ruby.rb
CHANGED
@@ -3,26 +3,18 @@ require 'kaiser_ruby/rockstar_parser'
|
|
3
3
|
require 'kaiser_ruby/rockstar_transform'
|
4
4
|
|
5
5
|
module KaiserRuby
|
6
|
-
def self.
|
7
|
-
|
8
|
-
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.down_indent
|
12
|
-
@@indent ||= 0
|
13
|
-
@@indent -= 2
|
14
|
-
end
|
6
|
+
def self.parse(input)
|
7
|
+
# eat comments since we don't care about them
|
8
|
+
input = input.gsub(/\(.*?\)/, '')
|
15
9
|
|
16
|
-
|
17
|
-
|
18
|
-
end
|
10
|
+
# expand contractions
|
11
|
+
input = input.gsub(/'s\W+/, ' is ')
|
19
12
|
|
20
|
-
def self.parse(input)
|
21
13
|
# strings without a line ending (or single lines) should be fed into the alternative parser
|
22
14
|
if input.split("\n").size == 1
|
23
|
-
KaiserRuby::RockstarSingleLineParser.new.parse(input.chomp)
|
15
|
+
KaiserRuby::RockstarSingleLineParser.new.parse(input.chomp, reporter: Parslet::ErrorReporter::Deepest.new)
|
24
16
|
else
|
25
|
-
KaiserRuby::RockstarParser.new.parse(input)
|
17
|
+
KaiserRuby::RockstarParser.new.parse(input, reporter: Parslet::ErrorReporter::Deepest.new)
|
26
18
|
end
|
27
19
|
rescue Parslet::ParseFailed => failure
|
28
20
|
puts input.inspect
|
@@ -36,4 +28,4 @@ module KaiserRuby
|
|
36
28
|
def self.transpile(input)
|
37
29
|
transform(parse(input))
|
38
30
|
end
|
39
|
-
end
|
31
|
+
end
|
data/lib/kaiser_ruby/cli.rb
CHANGED
@@ -30,7 +30,7 @@ module KaiserRuby
|
|
30
30
|
file = File.read filename
|
31
31
|
output = KaiserRuby.transpile(file)
|
32
32
|
|
33
|
-
|
33
|
+
instance_eval output
|
34
34
|
say
|
35
35
|
end
|
36
36
|
|
@@ -43,16 +43,18 @@ module KaiserRuby
|
|
43
43
|
# this makes it not lose local variables throughout the loop
|
44
44
|
b = binding
|
45
45
|
|
46
|
-
|
46
|
+
loop do
|
47
47
|
input = ask('\m/>')
|
48
|
-
if input
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
48
|
+
break if input == 'exit'
|
49
|
+
|
50
|
+
code = KaiserRuby.transpile(input)
|
51
|
+
say "\\m/> #{code}", :blue if options[:debug]
|
52
|
+
output = b.eval(code)
|
53
|
+
output = 'nil' if output.nil?
|
54
|
+
say " => #{output}\n"
|
55
|
+
rescue
|
56
|
+
say "THE STAGE IS ON FIRE!"
|
57
|
+
end
|
56
58
|
end
|
57
59
|
end
|
58
|
-
end
|
60
|
+
end
|
@@ -28,7 +28,9 @@ module KaiserRuby
|
|
28
28
|
rule(:assignment_keywords) { str('Put') | str('into') }
|
29
29
|
rule(:poetic_string_keywords) { str('says') }
|
30
30
|
rule(:comparison_keywords) { str("is") | not_keywords | gt_keywords | gte_keywords | lt_keywords | lte_keywords }
|
31
|
-
rule(:function_keywords) { str('Break it down') | str('Take it to the top') | str('Give back') | str('takes') | str('taking') }
|
31
|
+
rule(:function_keywords) { str('Break it down') | str('Take it to the top') | str('Give back') | str('takes') | str('taking') | str('Listen to') }
|
32
|
+
|
33
|
+
rule(:pronouns) { (str('he') | str('she') | str('it') | str('they') | str('them') | str('her') | str('him') | str('its')).as(:pronoun) }
|
32
34
|
|
33
35
|
# variable names
|
34
36
|
# using [[:upper:]] etc here allows for metal umlauts and other UTF characters
|
@@ -48,7 +50,7 @@ module KaiserRuby
|
|
48
50
|
end
|
49
51
|
|
50
52
|
rule(:variable_names) do
|
51
|
-
(common_variable_name | proper_variable_name).as(:variable_name)
|
53
|
+
(pronouns | common_variable_name | proper_variable_name).as(:variable_name)
|
52
54
|
end
|
53
55
|
|
54
56
|
# all the different value types (except Object for now)
|
@@ -57,7 +59,7 @@ module KaiserRuby
|
|
57
59
|
rule(:null_value) { null_value_keywords.as(:null_value) }
|
58
60
|
rule(:true_value) { true_value_keywords.as(:true_value) }
|
59
61
|
rule(:false_value) { false_value_keywords.as(:false_value) }
|
60
|
-
rule(:string_value) { (str('"') >> match['
|
62
|
+
rule(:string_value) { (str('"') >> match['^"'].repeat >> str('"')).as(:string_value) }
|
61
63
|
rule(:numeric_value) { match['0-9\.'].repeat.as(:numeric_value) }
|
62
64
|
rule(:unquoted_string) { match['^\n'].repeat.as(:unquoted_string) }
|
63
65
|
rule(:string_as_number) { reserved.absent? >> match['^\n'].repeat.as(:string_as_number) }
|
@@ -176,74 +178,79 @@ module KaiserRuby
|
|
176
178
|
str('Give back ') >> (math_operations | value_or_variable).as(:return_value)
|
177
179
|
end
|
178
180
|
|
181
|
+
rule(:input) do
|
182
|
+
str('Listen to ') >> variable_names.as(:input_variable)
|
183
|
+
end
|
184
|
+
|
179
185
|
# comparisons
|
180
186
|
|
187
|
+
rule(:gte_keywords) { str(' is as ') >> (str('high') | str('great') | str('big') | str('strong')) >> str(' as ') }
|
188
|
+
rule(:gte) do
|
189
|
+
(
|
190
|
+
value_or_variable.as(:left) >> gte_keywords >> (math_operations | value_or_variable).as(:right)
|
191
|
+
).as(:gte)
|
192
|
+
end
|
193
|
+
|
194
|
+
rule(:lte_keywords) { str(' is as ') >> (str('low') | str('little') | str('small') | str('weak')) >> str(' as ') }
|
195
|
+
rule(:lte) do
|
196
|
+
(
|
197
|
+
value_or_variable.as(:left) >> lte_keywords >> (math_operations | value_or_variable).as(:right)
|
198
|
+
).as(:lte)
|
199
|
+
end
|
200
|
+
|
181
201
|
rule(:equality) do
|
182
202
|
(
|
183
|
-
value_or_variable.as(:left) >> str(' is ') >> value_or_variable.as(:right)
|
203
|
+
value_or_variable.as(:left) >> str(' is ') >> (math_operations | value_or_variable).as(:right)
|
184
204
|
).as(:equals)
|
185
205
|
end
|
186
206
|
|
187
207
|
rule(:not_keywords) { str(' is not ') | str(" ain't ")}
|
188
208
|
rule(:inequality) do
|
189
209
|
(
|
190
|
-
value_or_variable.as(:left) >> not_keywords >> value_or_variable.as(:right)
|
210
|
+
value_or_variable.as(:left) >> not_keywords >> (math_operations | value_or_variable).as(:right)
|
191
211
|
).as(:not_equals)
|
192
212
|
end
|
193
213
|
|
194
214
|
rule(:gt_keywords) { str(' is ') >> (str('higher') | str('greater') | str('bigger') | str('stronger')) >> str(' than ') }
|
195
215
|
rule(:gt) do
|
196
216
|
(
|
197
|
-
value_or_variable.as(:left) >> gt_keywords >> value_or_variable.as(:right)
|
217
|
+
value_or_variable.as(:left) >> gt_keywords >> (math_operations | value_or_variable).as(:right)
|
198
218
|
).as(:gt)
|
199
219
|
end
|
200
220
|
|
201
221
|
rule(:lt_keywords) { str(' is ') >> (str('lower') | str('less') | str('smaller') | str('weaker')) >> str(' than ') }
|
202
222
|
rule(:lt) do
|
203
223
|
(
|
204
|
-
value_or_variable.as(:left) >> lt_keywords >> value_or_variable.as(:right)
|
224
|
+
value_or_variable.as(:left) >> lt_keywords >> (math_operations | value_or_variable).as(:right)
|
205
225
|
).as(:lt)
|
206
226
|
end
|
207
227
|
|
208
|
-
rule(:gte_keywords) { str(' is as ') >> (str('high') | str('great') | str('big') | str('strong')) >> str(' as ') }
|
209
|
-
rule(:gte) do
|
210
|
-
(
|
211
|
-
value_or_variable.as(:left) >> gte_keywords >> value_or_variable.as(:right)
|
212
|
-
).as(:gte)
|
213
|
-
end
|
214
228
|
|
215
|
-
rule(:lte_keywords) { str(' is as ') >> (str('low') | str('little') | str('small') | str('weak')) >> str(' as ') }
|
216
|
-
rule(:lte) do
|
217
|
-
(
|
218
|
-
value_or_variable.as(:left) >> lte_keywords >> value_or_variable.as(:right)
|
219
|
-
).as(:lte)
|
220
|
-
end
|
221
229
|
|
222
230
|
# flow control - if, else, while, until
|
223
231
|
|
224
|
-
rule(:
|
232
|
+
rule(:if_else_block) do
|
225
233
|
(
|
226
234
|
str('If ') >> comparisons.as(:if_condition) >>
|
227
235
|
(space >> (str('and') | str('or')).as(:and_or) >> space >> comparisons.as(:second_condition)).maybe >> eol >>
|
228
236
|
scope {
|
229
237
|
inner_block_line.repeat.as(:if_block)
|
238
|
+
} >>
|
239
|
+
str('Else') >> eol >>
|
240
|
+
scope {
|
241
|
+
inner_block_line.repeat.as(:else_block)
|
230
242
|
} >> (eol | eof).as(:endif)
|
231
|
-
).as(:
|
243
|
+
).as(:if_else)
|
232
244
|
end
|
233
245
|
|
234
|
-
rule(:
|
246
|
+
rule(:if_block) do
|
235
247
|
(
|
236
248
|
str('If ') >> comparisons.as(:if_condition) >>
|
237
249
|
(space >> (str('and') | str('or')).as(:and_or) >> space >> comparisons.as(:second_condition)).maybe >> eol >>
|
238
250
|
scope {
|
239
251
|
inner_block_line.repeat.as(:if_block)
|
240
|
-
} >>
|
241
|
-
|
242
|
-
scope {
|
243
|
-
inner_block_line.repeat.as(:else_block) >>
|
244
|
-
(eol | eof).as(:endif)
|
245
|
-
}
|
246
|
-
).as(:if_else)
|
252
|
+
} >> (eol | eof).as(:endif)
|
253
|
+
).as(:if)
|
247
254
|
end
|
248
255
|
|
249
256
|
rule(:while_block) do
|
@@ -251,9 +258,8 @@ module KaiserRuby
|
|
251
258
|
str('While ') >> comparisons.as(:while_condition) >>
|
252
259
|
(space >> (str('and') | str('or')).as(:and_or) >> space >> comparisons.as(:second_condition)).maybe >> eol >>
|
253
260
|
scope {
|
254
|
-
inner_block_line.repeat.as(:while_block)
|
255
|
-
|
256
|
-
}
|
261
|
+
inner_block_line.repeat.as(:while_block)
|
262
|
+
} >> (eol | eof).as(:endwhile)
|
257
263
|
).as(:while)
|
258
264
|
end
|
259
265
|
|
@@ -277,7 +283,7 @@ module KaiserRuby
|
|
277
283
|
rule(:comparisons) { gte | gt | lte | lt | inequality | equality }
|
278
284
|
rule(:flow_control) { if_block | if_else_block | while_block | until_block }
|
279
285
|
rule(:poetics) { poetic_type_literal | poetic_string_literal | poetic_number_literal }
|
280
|
-
rule(:functions) { function_call | function | print_function | break_function | continue_function | return_function }
|
286
|
+
rule(:functions) { function_call | function | print_function | break_function | continue_function | return_function | input }
|
281
287
|
rule(:line_elements) { flow_control | poetics | expressions | functions | eol }
|
282
288
|
|
283
289
|
# handle multiple lines in a file
|
@@ -1,7 +1,28 @@
|
|
1
1
|
require 'pry'
|
2
2
|
module KaiserRuby
|
3
3
|
class RockstarTransform < Parslet::Transform
|
4
|
-
|
4
|
+
@@last_variable = nil
|
5
|
+
@@indent = 0
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def last_variable=(value)
|
9
|
+
@@last_variable = value
|
10
|
+
end
|
11
|
+
|
12
|
+
def up_indent
|
13
|
+
@@indent += 2
|
14
|
+
end
|
15
|
+
|
16
|
+
def down_indent
|
17
|
+
@@indent -= 2
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
rule(variable_name: simple(:str)) do |context|
|
22
|
+
self.last_variable = parameterize(context[:str])
|
23
|
+
parameterize(context[:str])
|
24
|
+
end
|
25
|
+
rule(pronoun: simple(:_)) { @@last_variable }
|
5
26
|
|
6
27
|
rule(mysterious_value: simple(:_)) { 'nil' }
|
7
28
|
rule(null_value: simple(:_)) { '0' }
|
@@ -10,13 +31,13 @@ module KaiserRuby
|
|
10
31
|
rule(string_value: simple(:str)) { str }
|
11
32
|
rule(numeric_value: simple(:num)) { num }
|
12
33
|
rule(unquoted_string: simple(:str)) { "\"#{str}\"" }
|
13
|
-
rule(string_as_number: simple(:str)) do |
|
14
|
-
if
|
15
|
-
|
34
|
+
rule(string_as_number: simple(:str)) do |context|
|
35
|
+
if context[:str].to_s.include?('.')
|
36
|
+
context[:str].to_s.gsub(/[^A-Za-z\s\.]/, '').split('.').map do |sub|
|
16
37
|
str_to_num(sub)
|
17
38
|
end.join('.').to_f
|
18
39
|
else
|
19
|
-
str_to_num(
|
40
|
+
str_to_num(context[:str])
|
20
41
|
end
|
21
42
|
end
|
22
43
|
|
@@ -31,6 +52,7 @@ module KaiserRuby
|
|
31
52
|
rule(print: { output: simple(:output) }) { "puts #{output}" }
|
32
53
|
rule(continue: simple(:_)) { "next" }
|
33
54
|
rule(break: simple(:_)) { "break" }
|
55
|
+
rule(input_variable: simple(:var)) { "print '> '\n#{var} = STDIN.gets.chomp" }
|
34
56
|
|
35
57
|
rule(equals: { left: simple(:left), right: simple(:right) }) { "#{left} == #{right}" }
|
36
58
|
rule(not_equals: { left: simple(:left), right: simple(:right) }) { "#{left} != #{right}" }
|
@@ -43,12 +65,12 @@ module KaiserRuby
|
|
43
65
|
if_condition: simple(:if_condition),
|
44
66
|
if_block: sequence(:if_block_lines),
|
45
67
|
endif: simple(:_)
|
46
|
-
} ) do
|
47
|
-
output = "#{' ' *
|
48
|
-
|
49
|
-
output += if_block_lines.map { |l| "#{' ' *
|
50
|
-
|
51
|
-
output += "#{' ' *
|
68
|
+
} ) do |context|
|
69
|
+
output = "#{' ' * @@indent}if #{context[:if_condition]}\n"
|
70
|
+
self.up_indent
|
71
|
+
output += context[:if_block_lines].map { |l| "#{' ' * @@indent}#{l}\n" }.join
|
72
|
+
self.down_indent
|
73
|
+
output += "#{' ' * @@indent}end # endif"
|
52
74
|
output
|
53
75
|
end
|
54
76
|
|
@@ -58,13 +80,13 @@ module KaiserRuby
|
|
58
80
|
second_condition: simple(:second_condition),
|
59
81
|
if_block: sequence(:if_block_lines),
|
60
82
|
endif: simple(:_)
|
61
|
-
} ) do
|
62
|
-
proper_and_or = and_or == 'and' ? '&&' : '||'
|
63
|
-
output = "#{' ' *
|
64
|
-
|
65
|
-
output += if_block_lines.map { |l| "#{' ' *
|
66
|
-
|
67
|
-
output += "#{' ' *
|
83
|
+
} ) do |context|
|
84
|
+
proper_and_or = context[:and_or] == 'and' ? '&&' : '||'
|
85
|
+
output = "#{' ' * @@indent}if #{context[:if_condition]} #{proper_and_or} #{context[:second_condition]}\n"
|
86
|
+
self.up_indent
|
87
|
+
output += context[:if_block_lines].map { |l| "#{' ' * @@indent}#{l}\n" }.join
|
88
|
+
self.down_indent
|
89
|
+
output += "#{' ' * @@indent}end # endif"
|
68
90
|
output
|
69
91
|
end
|
70
92
|
|
@@ -73,16 +95,16 @@ module KaiserRuby
|
|
73
95
|
if_block: sequence(:if_block_lines),
|
74
96
|
else_block: sequence(:else_block_lines),
|
75
97
|
endif: simple(:_)
|
76
|
-
} ) do
|
77
|
-
output = "#{' ' *
|
78
|
-
|
79
|
-
output += if_block_lines.map { |l| "#{' ' *
|
80
|
-
|
81
|
-
output += "#{' ' *
|
82
|
-
|
83
|
-
output += else_block_lines.map { |l| "#{' ' *
|
84
|
-
|
85
|
-
output += "#{' ' *
|
98
|
+
} ) do |context|
|
99
|
+
output = "#{' ' * @@indent}if #{context[:if_condition]}\n"
|
100
|
+
self.up_indent
|
101
|
+
output += context[:if_block_lines].map { |l| "#{' ' * @@indent}#{l}\n" }.join
|
102
|
+
self.down_indent
|
103
|
+
output += "#{' ' * @@indent}else\n"
|
104
|
+
self.up_indent
|
105
|
+
output += context[:else_block_lines].map { |l| "#{' ' * @@indent}#{l}\n" }.join
|
106
|
+
self.down_indent
|
107
|
+
output += "#{' ' * @@indent}end # endifelse"
|
86
108
|
output
|
87
109
|
end
|
88
110
|
|
@@ -93,17 +115,17 @@ module KaiserRuby
|
|
93
115
|
if_block: sequence(:if_block_lines),
|
94
116
|
else_block: sequence(:else_block_lines),
|
95
117
|
endif: simple(:_)
|
96
|
-
} ) do
|
97
|
-
proper_and_or = and_or == 'and' ? '&&' : '||'
|
98
|
-
output = "#{' ' *
|
99
|
-
|
100
|
-
output += if_block_lines.map { |l| "#{' ' *
|
101
|
-
|
102
|
-
output += "#{' ' *
|
103
|
-
|
104
|
-
output += else_block_lines.map { |l| "#{' ' *
|
105
|
-
|
106
|
-
output += "#{' ' *
|
118
|
+
} ) do |context|
|
119
|
+
proper_and_or = context[:and_or] == 'and' ? '&&' : '||'
|
120
|
+
output = "#{' ' * @@indent}if #{context[:if_condition]} #{proper_and_or} #{context[:second_condition]}\n"
|
121
|
+
self.up_indent
|
122
|
+
output += context[:if_block_lines].map { |l| "#{' ' * @@indent}#{l}\n" }.join
|
123
|
+
self.down_indent
|
124
|
+
output += "#{' ' * @@indent}else\n"
|
125
|
+
self.up_indent
|
126
|
+
output += context[:else_block_lines].map { |l| "#{' ' * @@indent}#{l}\n" }.join
|
127
|
+
self.down_indent
|
128
|
+
output += "#{' ' * @@indent}end # endifelse"
|
107
129
|
output
|
108
130
|
end
|
109
131
|
|
@@ -111,12 +133,12 @@ module KaiserRuby
|
|
111
133
|
while_condition: simple(:while_condition),
|
112
134
|
while_block: sequence(:while_block_lines),
|
113
135
|
endwhile: simple(:_)
|
114
|
-
} ) do
|
115
|
-
output = "#{' ' *
|
116
|
-
|
117
|
-
output += while_block_lines.map { |l| "#{' ' *
|
118
|
-
|
119
|
-
output += "#{' ' *
|
136
|
+
} ) do |context|
|
137
|
+
output = "#{' ' * @@indent}while #{context[:while_condition]}\n"
|
138
|
+
self.up_indent
|
139
|
+
output += context[:while_block_lines].map { |l| "#{' ' * @@indent}#{l}\n" }.join
|
140
|
+
self.down_indent
|
141
|
+
output += "#{' ' * @@indent}end # endwhile"
|
120
142
|
output
|
121
143
|
end
|
122
144
|
|
@@ -126,13 +148,13 @@ module KaiserRuby
|
|
126
148
|
second_condition: simple(:second_condition),
|
127
149
|
while_block: sequence(:while_block_lines),
|
128
150
|
endwhile: simple(:_)
|
129
|
-
} ) do
|
130
|
-
proper_and_or = and_or == 'and' ? '&&' : '||'
|
131
|
-
output = "#{' ' *
|
132
|
-
|
133
|
-
output += while_block_lines.map { |l| "#{' ' *
|
134
|
-
|
135
|
-
output += "#{' ' *
|
151
|
+
} ) do |context|
|
152
|
+
proper_and_or = context[:and_or] == 'and' ? '&&' : '||'
|
153
|
+
output = "#{' ' * @@indent}while #{context[:while_condition]} #{proper_and_or} #{context[:second_condition]}\n"
|
154
|
+
self.up_indent
|
155
|
+
output += context[:while_block_lines].map { |l| "#{' ' * @@indent}#{l}\n" }.join
|
156
|
+
self.down_indent
|
157
|
+
output += "#{' ' * @@indent}end # endwhile"
|
136
158
|
output
|
137
159
|
end
|
138
160
|
|
@@ -140,12 +162,12 @@ module KaiserRuby
|
|
140
162
|
until_condition: simple(:until_condition),
|
141
163
|
until_block: sequence(:until_block_lines),
|
142
164
|
enduntil: simple(:_)
|
143
|
-
} ) do
|
144
|
-
output = "#{' ' *
|
145
|
-
|
146
|
-
output += until_block_lines.map { |l| "#{' ' *
|
147
|
-
|
148
|
-
output += "#{' ' *
|
165
|
+
} ) do |context|
|
166
|
+
output = "#{' ' * @@indent}until #{context[:until_condition]}\n"
|
167
|
+
self.up_indent
|
168
|
+
output += context[:until_block_lines].map { |l| "#{' ' * @@indent}#{l}\n" }.join
|
169
|
+
self.down_indent
|
170
|
+
output += "#{' ' * @@indent}end # enduntil"
|
149
171
|
output
|
150
172
|
end
|
151
173
|
|
@@ -155,13 +177,13 @@ module KaiserRuby
|
|
155
177
|
second_condition: simple(:second_condition),
|
156
178
|
until_block: sequence(:until_block_lines),
|
157
179
|
enduntil: simple(:_)
|
158
|
-
} ) do
|
159
|
-
proper_and_or = and_or == 'and' ? '&&' : '||'
|
160
|
-
output = "#{' ' *
|
161
|
-
|
162
|
-
output += until_block_lines.map { |l| "#{' ' *
|
163
|
-
|
164
|
-
output += "#{' ' *
|
180
|
+
} ) do |context|
|
181
|
+
proper_and_or = context[:and_or] == 'and' ? '&&' : '||'
|
182
|
+
output = "#{' ' * @@indent}until #{context[:until_condition]} #{proper_and_or} #{context[:second_condition]}\n"
|
183
|
+
self.up_indent
|
184
|
+
output += context[:until_block_lines].map { |l| "#{' ' * @@indent}#{l}\n" }.join
|
185
|
+
self.down_indent
|
186
|
+
output += "#{' ' * @@indent}end # enduntil"
|
165
187
|
output
|
166
188
|
end
|
167
189
|
|
@@ -173,12 +195,12 @@ module KaiserRuby
|
|
173
195
|
arguments: sequence(:arguments),
|
174
196
|
function_block: sequence(:function_block_lines),
|
175
197
|
enddef: simple(:_)
|
176
|
-
} ) do
|
177
|
-
output = "#{' ' *
|
178
|
-
|
179
|
-
output += function_block_lines.map { |l| "#{' ' *
|
180
|
-
|
181
|
-
output += "#{' ' *
|
198
|
+
} ) do |context|
|
199
|
+
output = "#{' ' * @@indent}def #{context[:function_name]}(#{context[:arguments].join(', ')})\n"
|
200
|
+
self.up_indent
|
201
|
+
output += context[:function_block_lines].map { |l| "#{' ' * @@indent}#{l}\n" }.join
|
202
|
+
self.down_indent
|
203
|
+
output += "#{' ' * @@indent}end # enddef"
|
182
204
|
output
|
183
205
|
end
|
184
206
|
|
@@ -200,4 +222,4 @@ module KaiserRuby
|
|
200
222
|
string.to_s.split(/\s+/).map { |e| e.length % 10 }.join.to_i
|
201
223
|
end
|
202
224
|
end
|
203
|
-
end
|
225
|
+
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.4.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-08-
|
11
|
+
date: 2018-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -141,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
141
|
version: '0'
|
142
142
|
requirements: []
|
143
143
|
rubyforge_project:
|
144
|
-
rubygems_version: 2.7.
|
144
|
+
rubygems_version: 2.7.6
|
145
145
|
signing_key:
|
146
146
|
specification_version: 4
|
147
147
|
summary: Transpiler of Rockstar language to Ruby
|