kaiser-ruby 0.2.1 → 0.2.2
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/TODO.md +5 -1
- data/lib/kaiser_ruby/cli.rb +25 -6
- data/lib/kaiser_ruby/rockstar_transform.rb +18 -8
- data/lib/kaiser_ruby/version.rb +1 -1
- data/lib/kaiser_ruby.rb +14 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cb628fa95145a8ff9f2c8fccbbbf17d879ee8e349b66166286a9f0b1a0d654e2
|
|
4
|
+
data.tar.gz: 10747f14ccbdc25d6b5e3d29b04ea8dbeb880cf0fc3deb890184e28211cefdfe
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7b417722ea526b3c98d6dac794a679bea64bc1513114e4724e6dddd12b9d1a945fe29c52196a2255fd11f00ed0fe69a54b63590653f9670df7d341816995b3a5
|
|
7
|
+
data.tar.gz: 9c12b3832c94be7812b5f052fa3e6d1240246f3fcb62812f5087252e0a9e9ab0c57da79222a077ae6e1512bb7f497f56f6594efbb05de6a226aafba0efd4a8cf
|
data/TODO.md
CHANGED
|
@@ -41,4 +41,8 @@
|
|
|
41
41
|
## Other stuff
|
|
42
42
|
|
|
43
43
|
- [x] Test if it handles metal umlauts (Ruby shouldn't care much, but tests should be made)
|
|
44
|
-
- [ ] Ignore comments in parentheses
|
|
44
|
+
- [ ] Ignore comments in parentheses
|
|
45
|
+
- [x] Nicely indent blocks
|
|
46
|
+
- [ ] Fix indenting of nested blocks that doesn't really work well
|
|
47
|
+
- [x] Working basic REPL
|
|
48
|
+
- [ ] Add code history to the REPL
|
data/lib/kaiser_ruby/cli.rb
CHANGED
|
@@ -10,19 +10,19 @@ module KaiserRuby
|
|
|
10
10
|
output = KaiserRuby.transpile(file)
|
|
11
11
|
|
|
12
12
|
if options['show-source'.to_sym]
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
say file
|
|
14
|
+
say "-" * 40, :green
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
if options[:save]
|
|
18
18
|
out = File.new(options[:save], 'w')
|
|
19
19
|
out.write output
|
|
20
20
|
out.close
|
|
21
|
-
|
|
21
|
+
say "Saved output in `#{options[:save]}`", :green
|
|
22
22
|
else
|
|
23
|
-
|
|
23
|
+
say output
|
|
24
24
|
end
|
|
25
|
-
|
|
25
|
+
say
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
desc "execute FILE", "transpiles and runs a .rock FILE"
|
|
@@ -31,7 +31,26 @@ module KaiserRuby
|
|
|
31
31
|
output = KaiserRuby.transpile(file)
|
|
32
32
|
|
|
33
33
|
eval output
|
|
34
|
-
|
|
34
|
+
say
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
desc "rock", "opens an interactive console that accepts and evaluates Rockstar code"
|
|
38
|
+
option :debug, type: :boolean, desc: "also shows transpiled code"
|
|
39
|
+
def rock
|
|
40
|
+
say "Type 'exit' to exit the console. Otherwise, rock on!"
|
|
41
|
+
|
|
42
|
+
b = binding
|
|
43
|
+
|
|
44
|
+
begin
|
|
45
|
+
input = ask('\m/>')
|
|
46
|
+
if input != 'exit'
|
|
47
|
+
code = KaiserRuby.transpile(input)
|
|
48
|
+
say "\\m/> #{code}", :blue if options[:debug]
|
|
49
|
+
output = b.eval(code)
|
|
50
|
+
output = 'nil' if output.nil?
|
|
51
|
+
say " => #{output}\n"
|
|
52
|
+
end
|
|
53
|
+
end until input == 'exit'
|
|
35
54
|
end
|
|
36
55
|
end
|
|
37
56
|
end
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
require 'pry'
|
|
1
2
|
module KaiserRuby
|
|
2
3
|
class RockstarTransform < Parslet::Transform
|
|
3
4
|
rule(variable_name: simple(:str)) { |c| parameterize(c[:str]) }
|
|
@@ -30,16 +31,25 @@ module KaiserRuby
|
|
|
30
31
|
|
|
31
32
|
rule(equals: { left: simple(:left), right: simple(:right) }) { "#{left} == #{right}" }
|
|
32
33
|
rule(if: { if_condition: simple(:if_condition), if_block: sequence(:if_block_lines), endif: simple(:_)} ) do
|
|
33
|
-
"if #{if_condition}\n"
|
|
34
|
-
|
|
35
|
-
"
|
|
34
|
+
output = "#{' ' * KaiserRuby.indent}if #{if_condition}\n"
|
|
35
|
+
KaiserRuby.up_indent
|
|
36
|
+
output += if_block_lines.map { |l| "#{' ' * KaiserRuby.indent}#{l}\n" }.join
|
|
37
|
+
KaiserRuby.down_indent
|
|
38
|
+
output += "#{' ' * KaiserRuby.indent}end"
|
|
39
|
+
output
|
|
36
40
|
end
|
|
41
|
+
|
|
37
42
|
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
|
-
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
"
|
|
43
|
+
output = "#{' ' * KaiserRuby.indent}if #{if_condition}\n"
|
|
44
|
+
KaiserRuby.up_indent
|
|
45
|
+
output += if_block_lines.map { |l| "#{' ' * KaiserRuby.indent}#{l}\n" }.join
|
|
46
|
+
KaiserRuby.down_indent
|
|
47
|
+
output += "#{' ' * KaiserRuby.indent}else\n"
|
|
48
|
+
KaiserRuby.up_indent
|
|
49
|
+
output += else_block_lines.map { |l| "#{' ' * KaiserRuby.indent}#{l}\n" }.join
|
|
50
|
+
KaiserRuby.down_indent
|
|
51
|
+
output += "#{' ' * KaiserRuby.indent}end"
|
|
52
|
+
output
|
|
43
53
|
end
|
|
44
54
|
|
|
45
55
|
rule(line: simple(:line)) { line == "\n" ? nil : line }
|
data/lib/kaiser_ruby/version.rb
CHANGED
data/lib/kaiser_ruby.rb
CHANGED
|
@@ -3,6 +3,20 @@ require 'kaiser_ruby/rockstar_parser'
|
|
|
3
3
|
require 'kaiser_ruby/rockstar_transform'
|
|
4
4
|
|
|
5
5
|
module KaiserRuby
|
|
6
|
+
def self.up_indent
|
|
7
|
+
@@indent ||= 0
|
|
8
|
+
@@indent += 2
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.down_indent
|
|
12
|
+
@@indent ||= 0
|
|
13
|
+
@@indent -= 2
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.indent
|
|
17
|
+
@@indent ||= 0
|
|
18
|
+
end
|
|
19
|
+
|
|
6
20
|
def self.parse(input)
|
|
7
21
|
if input.split("\n").size == 1
|
|
8
22
|
KaiserRuby::RockstarSingleLineParser.new.parse(input.chomp)
|