raabro 1.0.2 → 1.0.3
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.
- data/CHANGELOG.txt +5 -0
- data/lib/raabro.rb +3 -13
- data/spec/sample_xel_spec.rb +5 -2
- metadata +1 -1
data/CHANGELOG.txt
CHANGED
data/lib/raabro.rb
CHANGED
@@ -26,7 +26,7 @@
|
|
26
26
|
|
27
27
|
module Raabro
|
28
28
|
|
29
|
-
VERSION = '1.0.
|
29
|
+
VERSION = '1.0.3'
|
30
30
|
|
31
31
|
class Input
|
32
32
|
|
@@ -81,17 +81,6 @@ module Raabro
|
|
81
81
|
@children = successful_children
|
82
82
|
end
|
83
83
|
|
84
|
-
def shrink!
|
85
|
-
|
86
|
-
@children =
|
87
|
-
@children.inject([]) do |a, c|
|
88
|
-
a << c.shrink! if c.result == 1 && c.name
|
89
|
-
a
|
90
|
-
end
|
91
|
-
|
92
|
-
self
|
93
|
-
end
|
94
|
-
|
95
84
|
def string
|
96
85
|
|
97
86
|
@input.string[@offset, @length]
|
@@ -401,6 +390,8 @@ module Raabro
|
|
401
390
|
|
402
391
|
def parse(input, opts={})
|
403
392
|
|
393
|
+
opts[:prune] = true unless opts.has_key?(:prune)
|
394
|
+
|
404
395
|
root = self.respond_to?(:root) ? :root : @last
|
405
396
|
|
406
397
|
t =
|
@@ -413,7 +404,6 @@ module Raabro
|
|
413
404
|
return nil if opts[:prune] != false && t.result != 1
|
414
405
|
|
415
406
|
t = t.children.first if t.parter == :all
|
416
|
-
t = (opts[:prune] == false) || (opts[:shrink] == false) ? t : t.shrink!
|
417
407
|
|
418
408
|
return rewrite(t) if opts[:rewrite] != false && respond_to?(:rewrite)
|
419
409
|
|
data/spec/sample_xel_spec.rb
CHANGED
@@ -36,7 +36,7 @@ module Sample::Xel include Raabro
|
|
36
36
|
tree.string.to_i
|
37
37
|
when :fun
|
38
38
|
[ tree.children[0].string ] +
|
39
|
-
tree.children[1].children.collect { |e| rewrite(e) }
|
39
|
+
tree.children[1].children.select(&:name).collect { |e| rewrite(e) }
|
40
40
|
else
|
41
41
|
fail ArgumentError.new("cannot rewrite #{tree.to_a.inspect}")
|
42
42
|
end
|
@@ -73,7 +73,7 @@ describe Raabro do
|
|
73
73
|
expect(t.result).to eq(1)
|
74
74
|
|
75
75
|
expect(
|
76
|
-
Sample::Xel.rewrite(t
|
76
|
+
Sample::Xel.rewrite(t)
|
77
77
|
).to eq(
|
78
78
|
[ 'SUM', 1, [ 'MUL', 4, 5 ] ]
|
79
79
|
)
|
@@ -100,10 +100,13 @@ describe Raabro do
|
|
100
100
|
1 :fun 0,9
|
101
101
|
1 :funame 0,3 "MUL"
|
102
102
|
1 :args 3,6
|
103
|
+
1 nil 3,1 "("
|
103
104
|
1 :exp 4,1
|
104
105
|
1 :num 4,1 "7"
|
106
|
+
1 nil 5,1 ","
|
105
107
|
1 :exp 6,2
|
106
108
|
1 :num 6,2 "-3"
|
109
|
+
1 nil 8,1 ")"
|
107
110
|
}.strip)
|
108
111
|
end
|
109
112
|
|