kaiser-ruby 0.7 → 0.7.1
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/CHANGELOG.md +7 -0
- data/Gemfile.lock +1 -1
- data/README.md +2 -2
- data/TODO.md +0 -1
- data/lib/kaiser_ruby/cli.rb +3 -2
- data/lib/kaiser_ruby/parser.rb +12 -10
- data/lib/kaiser_ruby/transformer.rb +4 -4
- data/lib/kaiser_ruby/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d86f7b4d4eeb3c6c63aee4afd51fafb2e1676fe6d743a8df48a10a77b7e761e8
|
4
|
+
data.tar.gz: 1090782c7e4bb4684ffbc3162f4d5ae6529c0e4cfd3d29d227938f1a930d8519
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cf3a4423bc2d0da323ac5dcf575cdacf373eac7d3aaccee48c23781a85589342941a225a909b53f7e342baa611e0fe8ad8997c37386f44ffc306bff96160839
|
7
|
+
data.tar.gz: 100adddde94add35ad05b3a2d58d8a99993bc88b55f8d71a452f0356468d8f4a1be669a6bb3531d0ca596d8230b73098ee447b28b65d86bfefe40c245fb26d22
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -63,7 +63,7 @@ end
|
|
63
63
|
|
64
64
|
```
|
65
65
|
|
66
|
-
You can also use the `--save=FILE` option to write the resulting transpiled code as a file instead of outputting it.
|
66
|
+
You can also use the `--save=FILE` option to write the resulting transpiled code as a file instead of outputting it.
|
67
67
|
|
68
68
|
```
|
69
69
|
$ kaiser-ruby transpile ./examples/simple.rock --save=simple.rb
|
@@ -74,7 +74,7 @@ Saved output in `simple.rb`
|
|
74
74
|
The saved output will have a few additional lines at the start that include the language changes necessary for Rockstar to work correctly. You need the gem installed to run this file:
|
75
75
|
|
76
76
|
```
|
77
|
-
$ ruby simple.rb
|
77
|
+
$ ruby simple.rb
|
78
78
|
15.0
|
79
79
|
|
80
80
|
```
|
data/TODO.md
CHANGED
@@ -6,7 +6,6 @@
|
|
6
6
|
|
7
7
|
- [ ] Should be able to run the [Cellular Rockomata](https://github.com/Rifhutch/cellular-rocktomata)
|
8
8
|
- [ ] Math module https://gist.github.com/wrenoud/6be6f7509c88a3d8f9867ae782fb768f
|
9
|
-
- [ ] Primality checker https://www.reddit.com/r/RockstarDevs/comments/92i6sm/primality_checker_in_rockstar/
|
10
9
|
|
11
10
|
## Other stuff
|
12
11
|
|
data/lib/kaiser_ruby/cli.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
require 'thor'
|
2
|
+
require_relative 'version'
|
2
3
|
|
3
4
|
module KaiserRuby
|
4
5
|
class CLI < Thor
|
5
6
|
package_name "Kaiser-Ruby v#{KaiserRuby::VERSION}"
|
6
|
-
|
7
|
+
|
7
8
|
desc "transpile FILE", "transpile a .rock FILE and output the result"
|
8
9
|
option 'show-source'.to_sym, type: :boolean, desc: "prints out the source file along with the transpiled output"
|
9
10
|
option :save, desc: "saves the transpiled output in SAVE"
|
@@ -21,7 +22,7 @@ module KaiserRuby
|
|
21
22
|
out.write <<~REQ
|
22
23
|
require 'kaiser_ruby/refinements'
|
23
24
|
using KaiserRuby::Refinements
|
24
|
-
|
25
|
+
|
25
26
|
REQ
|
26
27
|
out.write output
|
27
28
|
out.close
|
data/lib/kaiser_ruby/parser.rb
CHANGED
@@ -94,7 +94,9 @@ module KaiserRuby
|
|
94
94
|
end
|
95
95
|
|
96
96
|
def parse_line(line)
|
97
|
-
|
97
|
+
line = line.strip
|
98
|
+
|
99
|
+
if line.empty?
|
98
100
|
if @nesting > 0
|
99
101
|
@nesting -= 1
|
100
102
|
@nesting_start_line = nil
|
@@ -158,7 +160,7 @@ module KaiserRuby
|
|
158
160
|
end
|
159
161
|
end
|
160
162
|
|
161
|
-
raise KaiserRuby::RockstarSyntaxError, "couldn't parse line: #{line}"
|
163
|
+
raise KaiserRuby::RockstarSyntaxError, "couldn't parse line: #{line}:#{@lnum+1}"
|
162
164
|
end
|
163
165
|
|
164
166
|
# statements
|
@@ -276,16 +278,16 @@ module KaiserRuby
|
|
276
278
|
words = string.split /\s/
|
277
279
|
|
278
280
|
if matches_first?(words, NIL_TYPE)
|
279
|
-
raise KaiserRuby::RockstarSyntaxError, "extra words are not allowed after literal type keyword" if words.count > 1
|
281
|
+
raise KaiserRuby::RockstarSyntaxError, "extra words are not allowed after literal type keyword: #{string}:#{@lnum+1}" if words.count > 1
|
280
282
|
{ type: 'nil' }
|
281
283
|
elsif matches_first?(words, NULL_TYPE)
|
282
|
-
raise KaiserRuby::RockstarSyntaxError, "extra words are not allowed after literal type keyword" if words.count > 1
|
284
|
+
raise KaiserRuby::RockstarSyntaxError, "extra words are not allowed after literal type keyword: #{string}:#{@lnum+1}" if words.count > 1
|
283
285
|
{ type: 'null' }
|
284
286
|
elsif matches_first?(words, TRUE_TYPE)
|
285
|
-
raise KaiserRuby::RockstarSyntaxError, "extra words are not allowed after literal type keyword" if words.count > 1
|
287
|
+
raise KaiserRuby::RockstarSyntaxError, "extra words are not allowed after literal type keyword: #{string}:#{@lnum+1}" if words.count > 1
|
286
288
|
{ type: 'true' }
|
287
289
|
elsif matches_first?(words, FALSE_TYPE)
|
288
|
-
raise KaiserRuby::RockstarSyntaxError, "extra words are not allowed after literal type keyword" if words.count > 1
|
290
|
+
raise KaiserRuby::RockstarSyntaxError, "extra words are not allowed after literal type keyword: #{string}:#{@lnum+1}" if words.count > 1
|
289
291
|
{ type: 'false' }
|
290
292
|
elsif string.strip.start_with?('"') && string.strip.end_with?('"')
|
291
293
|
parse_literal_string(string)
|
@@ -296,7 +298,7 @@ module KaiserRuby
|
|
296
298
|
|
297
299
|
def parse_type_literal(string)
|
298
300
|
words = string.split /\s/
|
299
|
-
raise SyntaxError, "too many words in poetic type literal: #{string}" if words.size > 1
|
301
|
+
raise SyntaxError, "too many words in poetic type literal: #{string}:#{@lnum+1}" if words.size > 1
|
300
302
|
|
301
303
|
if matches_first?(words, NIL_TYPE)
|
302
304
|
{ type: 'nil' }
|
@@ -307,7 +309,7 @@ module KaiserRuby
|
|
307
309
|
elsif matches_first?(words, FALSE_TYPE)
|
308
310
|
{ type: 'false' }
|
309
311
|
else
|
310
|
-
raise SyntaxError, "unknown poetic type literal: #{string}"
|
312
|
+
raise SyntaxError, "unknown poetic type literal: #{string}:#{@lnum+1}"
|
311
313
|
end
|
312
314
|
end
|
313
315
|
|
@@ -562,7 +564,7 @@ module KaiserRuby
|
|
562
564
|
copied = words.dup
|
563
565
|
copied.shift
|
564
566
|
copied.each do |w|
|
565
|
-
raise SyntaxError, "invalid common variable name: #{string}" if w =~ /[[:upper:]]/
|
567
|
+
raise SyntaxError, "invalid common variable name: #{string}:#{@lnum+1}" if w =~ /[[:upper:]]/
|
566
568
|
end
|
567
569
|
|
568
570
|
words = words.map { |e| e.chars.select { |c| c =~ /[[:alpha:]]/ }.join }
|
@@ -575,7 +577,7 @@ module KaiserRuby
|
|
575
577
|
copied = words.dup
|
576
578
|
copied.shift
|
577
579
|
copied.each do |w|
|
578
|
-
raise SyntaxError, "invalid proper variable name: #{string}" unless w =~ /\A[[:upper:]]/
|
580
|
+
raise SyntaxError, "invalid proper variable name: #{string}:#{@lnum+1}" unless w =~ /\A[[:upper:]]/
|
579
581
|
end
|
580
582
|
|
581
583
|
words = words.map { |e| e.chars.select { |c| c =~ /[[:alpha:]]/ }.join }
|
@@ -89,9 +89,9 @@ module KaiserRuby
|
|
89
89
|
else
|
90
90
|
@local_variables << varname
|
91
91
|
end
|
92
|
-
else
|
93
|
-
unless @local_variables.include?(varname)
|
94
|
-
varname = @method_names.include?(varname) ? varname : "@#{varname}"
|
92
|
+
else
|
93
|
+
unless @local_variables.include?(varname)
|
94
|
+
varname = @method_names.include?(varname) ? varname : "@#{varname}"
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
@@ -237,7 +237,7 @@ module KaiserRuby
|
|
237
237
|
end
|
238
238
|
|
239
239
|
def additional_argument_transformation(argument)
|
240
|
-
# testing function existence
|
240
|
+
# testing function existence
|
241
241
|
arg = @method_names.include?(argument) ? "defined?(#{argument})" : argument
|
242
242
|
|
243
243
|
# single variable without any operator needs to return a refined boolean
|
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:
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcin Ruszkiewicz
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|