kaiseki 1.0.7 → 1.0.8
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 +4 -3
- data/lib/grammar_stub.rb +2 -2
- data/lib/kaiseki.rb +4 -2
- data/lib/parse_error.rb +1 -1
- data/lib/parse_result.rb +3 -3
- data/lib/parseable.rb +10 -0
- data/lib/parser_choice.rb +4 -0
- data/lib/parser_custom.rb +4 -9
- data/lib/parser_repeat.rb +3 -3
- data/lib/parser_sequence.rb +13 -2
- data/lib/parser_symbol.rb +1 -1
- data/lib/rule.rb +3 -2
- data/lib/stream.rb +2 -2
- metadata +3 -3
data/lib/grammar.rb
CHANGED
@@ -28,7 +28,7 @@ module Kaiseki
|
|
28
28
|
stream.lock do
|
29
29
|
default_options = {
|
30
30
|
:grammar => self,
|
31
|
-
:rule => 'main',
|
31
|
+
:rule => '(main)',
|
32
32
|
:skipping => @skipping_rule,
|
33
33
|
:simplify => @simplify,
|
34
34
|
:global => {},
|
@@ -43,12 +43,13 @@ module Kaiseki
|
|
43
43
|
|
44
44
|
def starting parseable
|
45
45
|
raise "starting rule already defined" if @starting_rule
|
46
|
-
@starting_rule = parseable
|
46
|
+
@starting_rule = parseable.to_parseable
|
47
47
|
end
|
48
48
|
|
49
49
|
def skipping parseable
|
50
50
|
raise "skipping rule already defined" if @skipping_rule
|
51
|
-
|
51
|
+
raise "skipping rule must not be a predicate" if parseable.predicate?
|
52
|
+
@skipping_rule = parseable.to_parseable
|
52
53
|
end
|
53
54
|
|
54
55
|
def simplify bool = true
|
data/lib/grammar_stub.rb
CHANGED
@@ -2,7 +2,7 @@ module Kaiseki
|
|
2
2
|
class GrammarStub < PackageParser
|
3
3
|
attr_reader :grammar, :rule
|
4
4
|
|
5
|
-
def initialize expected, grammar, rule = 'main'
|
5
|
+
def initialize expected, grammar, rule = '(main)'
|
6
6
|
super expected
|
7
7
|
@grammar = grammar
|
8
8
|
@rule = rule
|
@@ -11,7 +11,7 @@ module Kaiseki
|
|
11
11
|
def parse! stream, options = {}
|
12
12
|
default_options = {
|
13
13
|
:grammar => @grammar,
|
14
|
-
:rule => @rule,
|
14
|
+
:rule => @rule.to_s,
|
15
15
|
:skipping => @grammar.skipping_rule,
|
16
16
|
:simplify => @grammar.simplify,
|
17
17
|
:global => {}
|
data/lib/kaiseki.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Kaiseki
|
2
|
-
VERSION = '1.0.
|
2
|
+
VERSION = '1.0.8'
|
3
3
|
file_path = File.dirname __FILE__
|
4
4
|
|
5
5
|
#load basic kaiseki classes
|
@@ -30,7 +30,6 @@ module Kaiseki
|
|
30
30
|
require file_path + '/parser_repeat'
|
31
31
|
|
32
32
|
require file_path + '/parser_package'
|
33
|
-
require file_path + '/parser_custom'
|
34
33
|
|
35
34
|
#load predicates
|
36
35
|
require file_path + '/predicate_and'
|
@@ -54,4 +53,7 @@ module Kaiseki
|
|
54
53
|
require file_path + '/var_set'
|
55
54
|
require file_path + '/var_get'
|
56
55
|
require file_path + '/var_insert'
|
56
|
+
|
57
|
+
#load others
|
58
|
+
require file_path + '/parser_custom'
|
57
59
|
end
|
data/lib/parse_error.rb
CHANGED
data/lib/parse_result.rb
CHANGED
data/lib/parseable.rb
CHANGED
@@ -12,6 +12,16 @@ module Kaiseki
|
|
12
12
|
false
|
13
13
|
end
|
14
14
|
|
15
|
+
def protect &block
|
16
|
+
catch :ParseSuccess do
|
17
|
+
catch :SkipSuccess do
|
18
|
+
block.call
|
19
|
+
throw :ParseSuccess
|
20
|
+
end
|
21
|
+
raise RuntimeError, "#{self.to_s} must not catch a SkipSuccess"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
15
25
|
def & other
|
16
26
|
SequenceParser.new self, other
|
17
27
|
end
|
data/lib/parser_choice.rb
CHANGED
data/lib/parser_custom.rb
CHANGED
@@ -1,26 +1,21 @@
|
|
1
1
|
module Kaiseki
|
2
|
-
attr_reader :name
|
3
|
-
|
4
2
|
class CustomParser < BasicParser
|
5
|
-
|
3
|
+
NODE = Node.subclass [:stream, :options]
|
4
|
+
|
5
|
+
def initialize is_predicate = false, &block
|
6
6
|
super block
|
7
|
-
@name = name
|
8
7
|
@is_predicate = is_predicate
|
9
8
|
end
|
10
9
|
|
11
10
|
def parse! stream, options = {}
|
12
11
|
stream.must_be Stream
|
13
12
|
stream.lock do
|
14
|
-
|
13
|
+
NODE.new([stream, options], options[:global]).eval options[:global], &@expected
|
15
14
|
end
|
16
15
|
end
|
17
16
|
|
18
17
|
def predicate?
|
19
18
|
@is_predicate
|
20
19
|
end
|
21
|
-
|
22
|
-
def to_s
|
23
|
-
@name || @expected.inspect
|
24
|
-
end
|
25
20
|
end
|
26
21
|
end
|
data/lib/parser_repeat.rb
CHANGED
@@ -4,7 +4,7 @@ module Kaiseki
|
|
4
4
|
attr_reader :expected, :min, :max
|
5
5
|
|
6
6
|
def initialize expected, min, max = nil
|
7
|
-
raise "
|
7
|
+
raise ArgumentError, "expected must not be a predicate" if expected.predicate?
|
8
8
|
@expected = expected.to_parseable
|
9
9
|
@min = min
|
10
10
|
@max = max
|
@@ -16,13 +16,13 @@ module Kaiseki
|
|
16
16
|
result = []
|
17
17
|
while @max.nil? or result.length < @max
|
18
18
|
begin
|
19
|
-
|
19
|
+
protect do
|
20
20
|
result << @expected.parse(stream, options)
|
21
21
|
end
|
22
22
|
rescue ParseError
|
23
23
|
if options[:skipping]
|
24
24
|
begin
|
25
|
-
|
25
|
+
protect do
|
26
26
|
options[:skipping].parse stream, options.merge(:skipping => nil)
|
27
27
|
end
|
28
28
|
redo
|
data/lib/parser_sequence.rb
CHANGED
@@ -12,7 +12,7 @@ module Kaiseki
|
|
12
12
|
rescue ParseError => e
|
13
13
|
if options[:skipping]
|
14
14
|
begin
|
15
|
-
|
15
|
+
protect do
|
16
16
|
options[:skipping].parse stream, options.merge(:skipping => nil)
|
17
17
|
end
|
18
18
|
redo
|
@@ -27,7 +27,14 @@ module Kaiseki
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
if options[:simplify]
|
30
|
-
result.length
|
30
|
+
case result.length
|
31
|
+
when 0
|
32
|
+
throw :SkipSuccess
|
33
|
+
when 1
|
34
|
+
result[0]
|
35
|
+
else
|
36
|
+
result
|
37
|
+
end
|
31
38
|
else
|
32
39
|
result
|
33
40
|
end
|
@@ -36,6 +43,10 @@ module Kaiseki
|
|
36
43
|
|
37
44
|
alias :& :append
|
38
45
|
|
46
|
+
def predicate?
|
47
|
+
@expected.find {|n| !n.predicate? } ? false : true
|
48
|
+
end
|
49
|
+
|
39
50
|
def delimiter
|
40
51
|
'&'
|
41
52
|
end
|
data/lib/parser_symbol.rb
CHANGED
@@ -3,7 +3,7 @@ module Kaiseki
|
|
3
3
|
def parse! stream, options = {}
|
4
4
|
if options[:grammar]
|
5
5
|
if options[:grammar].rules[@expected]
|
6
|
-
options[:grammar].rules[@expected].parse stream, options.merge(:rule => @expected)
|
6
|
+
options[:grammar].rules[@expected].parse stream, options.merge(:rule => @expected.to_s)
|
7
7
|
else
|
8
8
|
STDERR.puts "skipping #{self}: not implemented"
|
9
9
|
raise NotImplementedError
|
data/lib/rule.rb
CHANGED
@@ -18,11 +18,11 @@ module Kaiseki
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
def custom &block
|
21
|
+
def custom is_predicate = false, &block
|
22
22
|
if @parseable
|
23
23
|
raise "parseable for rule #{@name.inspect} already defined"
|
24
24
|
else
|
25
|
-
@parseable = CustomParser.new &block
|
25
|
+
@parseable = CustomParser.new is_predicate, &block
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -36,6 +36,7 @@ module Kaiseki
|
|
36
36
|
|
37
37
|
def skipping parseable
|
38
38
|
if @parseable
|
39
|
+
raise "skipping rule must not be a predicate" if parseable.predicate?
|
39
40
|
@parseable = @parseable.override :skipping => parseable.to_parseable
|
40
41
|
else
|
41
42
|
raise "parseable for rule #{@name.inspect} undefined"
|
data/lib/stream.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 1.0.
|
8
|
+
- 8
|
9
|
+
version: 1.0.8
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- William Hamilton-Levi
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-01-
|
17
|
+
date: 2011-01-11 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|