raabro 1.0.0 → 1.0.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.
- data/CHANGELOG.txt +7 -1
- data/lib/raabro.rb +33 -1
- data/spec/sample_xel_spec.rb +2 -10
- data/spec/spec_helper.rb +0 -12
- metadata +2 -2
data/CHANGELOG.txt
CHANGED
@@ -2,7 +2,13 @@
|
|
2
2
|
= raabro CHANGELOG.txt
|
3
3
|
|
4
4
|
|
5
|
-
== raabro 1.0.
|
5
|
+
== raabro 1.0.1 released 2015-09-23
|
6
|
+
|
7
|
+
- take last parser as default :root
|
8
|
+
- provide default .parse for modules including Raabro
|
9
|
+
|
10
|
+
|
11
|
+
== raabro 1.0.0 released 2015-09-23
|
6
12
|
|
7
13
|
- first complete (hopefully) release
|
8
14
|
|
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.1'
|
30
30
|
|
31
31
|
class Input
|
32
32
|
|
@@ -398,6 +398,38 @@ module Raabro
|
|
398
398
|
r
|
399
399
|
end
|
400
400
|
alias jseq eseq
|
401
|
+
|
402
|
+
def parse(input, opts={})
|
403
|
+
|
404
|
+
root = self.respond_to?(:root) ? :root : @last
|
405
|
+
|
406
|
+
t =
|
407
|
+
if opts[:all] == false
|
408
|
+
_parse(root, Raabro::Input.new(input, opts))
|
409
|
+
else
|
410
|
+
all(nil, Raabro::Input.new(input, opts), root)
|
411
|
+
end
|
412
|
+
|
413
|
+
return nil if t.result != 1
|
414
|
+
|
415
|
+
t = t.children.first if t.parter == :all
|
416
|
+
t = opts[:shrink] == false ? t : t.shrink!
|
417
|
+
|
418
|
+
return rewrite(t) if respond_to?(:rewrite)
|
419
|
+
|
420
|
+
t
|
421
|
+
end
|
422
|
+
|
423
|
+
attr_accessor :last
|
424
|
+
|
425
|
+
def method_added(name)
|
426
|
+
|
427
|
+
m = method(name)
|
428
|
+
return unless m.arity == 1
|
429
|
+
return unless m.parameters[0][1] == :i || m.parameters[0][1] == :input
|
430
|
+
|
431
|
+
@last = name.to_sym
|
432
|
+
end
|
401
433
|
end
|
402
434
|
extend ModuleMethods
|
403
435
|
|
data/spec/sample_xel_spec.rb
CHANGED
@@ -24,7 +24,8 @@ module Sample::Xel include Raabro
|
|
24
24
|
|
25
25
|
def exp(i); alt(:exp, i, :fun, :num); end
|
26
26
|
|
27
|
-
#
|
27
|
+
#alias root exp
|
28
|
+
# not necessary since Raabro takes the last defined parser as the root
|
28
29
|
|
29
30
|
def rewrite(tree)
|
30
31
|
|
@@ -40,15 +41,6 @@ module Sample::Xel include Raabro
|
|
40
41
|
fail ArgumentError.new("cannot rewrite #{tree.to_a.inspect}")
|
41
42
|
end
|
42
43
|
end
|
43
|
-
|
44
|
-
def parse(input)
|
45
|
-
|
46
|
-
t = all(nil, Raabro::Input.new(input, :prune => true), :exp)
|
47
|
-
|
48
|
-
return nil if t.result != 1
|
49
|
-
|
50
|
-
rewrite(t.children.first.shrink!)
|
51
|
-
end
|
52
44
|
end
|
53
45
|
|
54
46
|
|
data/spec/spec_helper.rb
CHANGED
@@ -44,13 +44,6 @@ module Sample::Cal include Raabro
|
|
44
44
|
def item(i); alt(:item, i, :num, :op); end
|
45
45
|
|
46
46
|
def suite(i); jseq(nil, i, :item, :sp); end
|
47
|
-
|
48
|
-
# entry point
|
49
|
-
|
50
|
-
def parse(input)
|
51
|
-
|
52
|
-
all(nil, Raabro::Input.new(input, :prune => true), :suite)
|
53
|
-
end
|
54
47
|
end
|
55
48
|
|
56
49
|
module Sample::Arith include Raabro
|
@@ -63,10 +56,5 @@ module Sample::Arith include Raabro
|
|
63
56
|
def substraction(i); seq(:substraction, i, :number, :minus, :op_or_num); end
|
64
57
|
|
65
58
|
def op_or_num(i); alt(nil, i, :addition, :substraction, :number); end
|
66
|
-
|
67
|
-
def parse(input)
|
68
|
-
|
69
|
-
all(nil, Raabro::Input.new(input, prune: true), :op_or_num)
|
70
|
-
end
|
71
59
|
end
|
72
60
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: raabro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-09-
|
12
|
+
date: 2015-09-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|