kaiseki 1.0.5 → 1.0.6
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/lib/grammar.rb +1 -1
- data/lib/grammar_stub.rb +11 -3
- data/lib/kaiseki.rb +1 -1
- data/lib/parser_choice.rb +3 -6
- data/lib/parser_repeat.rb +3 -6
- data/lib/parser_sequence.rb +2 -0
- data/lib/parser_symbol.rb +1 -1
- metadata +2 -2
data/lib/grammar.rb
CHANGED
data/lib/grammar_stub.rb
CHANGED
@@ -1,14 +1,22 @@
|
|
1
1
|
module Kaiseki
|
2
2
|
class GrammarStub < PackageParser
|
3
|
-
attr_reader :grammar
|
3
|
+
attr_reader :grammar, :rule
|
4
4
|
|
5
|
-
def initialize expected, grammar
|
5
|
+
def initialize expected, grammar, rule = 'main'
|
6
6
|
super expected
|
7
7
|
@grammar = grammar
|
8
|
+
@rule = rule
|
8
9
|
end
|
9
10
|
|
10
11
|
def parse! stream, options = {}
|
11
|
-
|
12
|
+
default_options = {
|
13
|
+
:grammar => @grammar,
|
14
|
+
:rule => @rule,
|
15
|
+
:skipping => @grammar.skipping_rule,
|
16
|
+
:simplify => @grammar.simplify,
|
17
|
+
:global => {}
|
18
|
+
}
|
19
|
+
@expected.parse stream, default_options.merge(options)
|
12
20
|
end
|
13
21
|
|
14
22
|
def eql? other
|
data/lib/kaiseki.rb
CHANGED
data/lib/parser_choice.rb
CHANGED
@@ -6,16 +6,13 @@ module Kaiseki
|
|
6
6
|
error = true
|
7
7
|
@expected.each do |n|
|
8
8
|
begin
|
9
|
-
|
9
|
+
catch :SkipSuccess do
|
10
10
|
return n.parse stream, options
|
11
11
|
end
|
12
|
-
if value == :NotImplemented
|
13
|
-
next
|
14
|
-
else
|
15
|
-
throw :SkipSuccess
|
16
|
-
end
|
17
12
|
rescue ParseError
|
18
13
|
next
|
14
|
+
rescue NotImplementedError
|
15
|
+
next
|
19
16
|
end
|
20
17
|
end
|
21
18
|
raise ParseError.new "no valid alternatives when parsing #{self}", options
|
data/lib/parser_repeat.rb
CHANGED
@@ -13,16 +13,11 @@ module Kaiseki
|
|
13
13
|
stream.must_be Stream
|
14
14
|
stream.lock do
|
15
15
|
result = []
|
16
|
-
|
17
|
-
while max.nil? or count < @max
|
16
|
+
while @max.nil? or result.length < @max
|
18
17
|
begin
|
19
18
|
catch :SkipSuccess do
|
20
19
|
result << @expected.parse(stream, options)
|
21
|
-
count += 1
|
22
|
-
next
|
23
20
|
end
|
24
|
-
count += 1
|
25
|
-
break if max.nil?
|
26
21
|
rescue ParseError
|
27
22
|
if options[:skipping]
|
28
23
|
begin
|
@@ -36,6 +31,8 @@ module Kaiseki
|
|
36
31
|
else
|
37
32
|
break
|
38
33
|
end
|
34
|
+
rescue NotImplementedError
|
35
|
+
break
|
39
36
|
end
|
40
37
|
end
|
41
38
|
if result.length < @min
|
data/lib/parser_sequence.rb
CHANGED
data/lib/parser_symbol.rb
CHANGED
@@ -6,7 +6,7 @@ module Kaiseki
|
|
6
6
|
options[:grammar].rules[@expected].parse stream, options.merge(:rule => @expected)
|
7
7
|
else
|
8
8
|
STDERR.puts "skipping #{self}: not implemented"
|
9
|
-
|
9
|
+
raise NotImplementedError
|
10
10
|
end
|
11
11
|
else
|
12
12
|
raise "can't use #{self} without a grammar"
|