kaiser-ruby 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2a1985d728a64d673e6aa925260f338fff1bafb725e69573e9ef1927acfbbba3
4
- data.tar.gz: 2afb896bbb347197390f5291c340e56b3d314b164fe9ab4f003a2989a186e546
3
+ metadata.gz: cb628fa95145a8ff9f2c8fccbbbf17d879ee8e349b66166286a9f0b1a0d654e2
4
+ data.tar.gz: 10747f14ccbdc25d6b5e3d29b04ea8dbeb880cf0fc3deb890184e28211cefdfe
5
5
  SHA512:
6
- metadata.gz: 4487182e399e47821e3edbba6e1ad5cb505836c4f029296c4915896827ee013303e889a878fd5aeaa91e0b7c38072419b367f0c90c0c5ccba274c0a35032fa2e
7
- data.tar.gz: 494b8aed64be73611e43fbe7fa7326005407212c86ceea02d3ba818c5dfadbd983379a5bd31ad89143327c7a5c13ccac742161ed9653e012e8bd56b6ab1c43ad
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
@@ -10,19 +10,19 @@ module KaiserRuby
10
10
  output = KaiserRuby.transpile(file)
11
11
 
12
12
  if options['show-source'.to_sym]
13
- puts file
14
- puts "-" * 40
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
- puts "Saved output in `#{options[:save]}`"
21
+ say "Saved output in `#{options[:save]}`", :green
22
22
  else
23
- puts output
23
+ say output
24
24
  end
25
- puts
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
- puts
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
- if_block_lines.map { |l| "#{l}\n" }.join +
35
- "end"
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
- if_block_lines.map { |l| "#{l}\n" }.join +
40
- "else\n" +
41
- else_block_lines.map { |l| "#{l}\n" }.join +
42
- "end"
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 }
@@ -1,3 +1,3 @@
1
1
  module KaiserRuby
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
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)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kaiser-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcin Ruszkiewicz