kaiseki 1.1.1 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/action.rb +1 -0
- data/lib/grammar.rb +14 -20
- data/lib/grammar_stub.rb +8 -7
- data/lib/kaiseki.rb +6 -1
- data/lib/mod_kernel.rb +0 -1
- data/lib/parse_result.rb +17 -12
- data/lib/parseable.rb +12 -1
- data/lib/parser_basic.rb +5 -4
- data/lib/parser_choice.rb +17 -19
- data/lib/parser_custom.rb +5 -7
- data/lib/parser_eof.rb +10 -12
- data/lib/parser_multi.rb +1 -4
- data/lib/parser_regexp.rb +8 -10
- data/lib/parser_repeat.rb +40 -42
- data/lib/parser_sequence.rb +11 -10
- data/lib/parser_string.rb +9 -10
- data/lib/parser_symbol.rb +4 -2
- data/lib/predicate_and.rb +10 -12
- data/lib/predicate_not.rb +10 -12
- data/lib/predicate_skip.rb +10 -12
- data/lib/result_action.rb +2 -0
- data/lib/result_cast.rb +7 -6
- data/lib/result_filter.rb +7 -6
- data/lib/result_merge.rb +2 -0
- data/lib/result_override.rb +5 -4
- data/lib/result_validate.rb +7 -6
- data/lib/rule.rb +32 -16
- data/lib/tag_basic.rb +16 -0
- data/lib/tag_error.rb +16 -0
- data/lib/tag_result.rb +13 -0
- data/lib/var_get.rb +11 -10
- data/lib/var_insert.rb +5 -4
- data/lib/var_set.rb +7 -6
- metadata +7 -12
data/lib/action.rb
CHANGED
data/lib/grammar.rb
CHANGED
@@ -18,26 +18,20 @@ module Kaiseki
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def parse stream, options = {}
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
}
|
36
|
-
if @starting_rule
|
37
|
-
@starting_rule.parse stream, default_options.merge(options)
|
38
|
-
else
|
39
|
-
raise "starting rule undefined"
|
40
|
-
end
|
21
|
+
raise 'starting rule undefined' unless @starting_rule
|
22
|
+
default_options = {
|
23
|
+
:grammar => self,
|
24
|
+
:result => ParseResult.new,
|
25
|
+
:global => {},
|
26
|
+
:rule => '(main)',
|
27
|
+
:skipping => @skipping_rule,
|
28
|
+
:simplify => @simplify
|
29
|
+
}
|
30
|
+
options = default_options.merge options
|
31
|
+
begin
|
32
|
+
options[:result].results[:main] = @starting_rule.parse stream.to_stream, options
|
33
|
+
rescue ParseError => e
|
34
|
+
options[:result].errors[:main] = e
|
41
35
|
end
|
42
36
|
end
|
43
37
|
|
data/lib/grammar_stub.rb
CHANGED
@@ -8,21 +8,22 @@ module Kaiseki
|
|
8
8
|
@rule = rule
|
9
9
|
end
|
10
10
|
|
11
|
+
def eql? other
|
12
|
+
other.is_a?(self.class) and other.expected == @expected and other.grammar == @grammar
|
13
|
+
end
|
14
|
+
|
15
|
+
alias :== :eql?
|
16
|
+
|
17
|
+
private
|
11
18
|
def parse! stream, options = {}
|
12
19
|
default_options = {
|
13
20
|
:grammar => @grammar,
|
21
|
+
:global => {},
|
14
22
|
:rule => @rule.to_s,
|
15
23
|
:skipping => @grammar.skipping_rule,
|
16
24
|
:simplify => @grammar.simplify,
|
17
|
-
:global => {}
|
18
25
|
}
|
19
26
|
@expected.parse stream, default_options.merge(options)
|
20
27
|
end
|
21
|
-
|
22
|
-
def eql? other
|
23
|
-
other.is_a?(self.class) and other.expected == @expected and other.grammar == @grammar
|
24
|
-
end
|
25
|
-
|
26
|
-
alias :== :eql?
|
27
28
|
end
|
28
29
|
end
|
data/lib/kaiseki.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Kaiseki
|
2
|
-
VERSION = '1.
|
2
|
+
VERSION = '1.2.1'
|
3
3
|
file_path = File.dirname __FILE__
|
4
4
|
|
5
5
|
#load basic kaiseki classes
|
@@ -56,6 +56,11 @@ module Kaiseki
|
|
56
56
|
require file_path + '/var_get'
|
57
57
|
require file_path + '/var_insert'
|
58
58
|
|
59
|
+
#load result tags
|
60
|
+
require file_path + '/tag_basic'
|
61
|
+
require file_path + '/tag_result'
|
62
|
+
require file_path + '/tag_error'
|
63
|
+
|
59
64
|
#load others
|
60
65
|
require file_path + '/parser_custom'
|
61
66
|
end
|
data/lib/mod_kernel.rb
CHANGED
data/lib/parse_result.rb
CHANGED
@@ -1,21 +1,26 @@
|
|
1
1
|
module Kaiseki
|
2
2
|
class ParseResult
|
3
|
-
attr_reader :
|
3
|
+
attr_reader :results, :errors
|
4
4
|
|
5
|
-
def initialize
|
6
|
-
|
7
|
-
|
8
|
-
@result = block.call
|
9
|
-
return
|
10
|
-
end
|
11
|
-
@result = '(skipped)'
|
12
|
-
rescue ParseError => e
|
13
|
-
@error = e.verbose
|
14
|
-
end
|
5
|
+
def initialize
|
6
|
+
@results = {}
|
7
|
+
@errors = {}
|
15
8
|
end
|
16
9
|
|
17
10
|
def parsed?
|
18
|
-
@
|
11
|
+
@errors.empty?
|
12
|
+
end
|
13
|
+
|
14
|
+
def result
|
15
|
+
@results[:main]
|
16
|
+
end
|
17
|
+
|
18
|
+
def error
|
19
|
+
@errors[:main]
|
20
|
+
end
|
21
|
+
|
22
|
+
def error_msg error = :main
|
23
|
+
@errors.key?(error) ? @errors[error].verbose : nil
|
19
24
|
end
|
20
25
|
end
|
21
26
|
end
|
data/lib/parseable.rb
CHANGED
@@ -5,7 +5,10 @@ module Kaiseki
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def parse stream, options = {}
|
8
|
-
|
8
|
+
stream = stream.to_parseable
|
9
|
+
stream.lock do
|
10
|
+
self.to_parseable.parse! stream, options
|
11
|
+
end
|
9
12
|
end
|
10
13
|
|
11
14
|
def predicate?
|
@@ -85,5 +88,13 @@ module Kaiseki
|
|
85
88
|
def set *vars
|
86
89
|
SetVar.new self, *vars
|
87
90
|
end
|
91
|
+
|
92
|
+
def tag_result name
|
93
|
+
ResultTag.new self, name
|
94
|
+
end
|
95
|
+
|
96
|
+
def tag_error name
|
97
|
+
ErrorTag.new self, name
|
98
|
+
end
|
88
99
|
end
|
89
100
|
end
|
data/lib/parser_basic.rb
CHANGED
@@ -7,10 +7,6 @@ module Kaiseki
|
|
7
7
|
@expected = expected
|
8
8
|
end
|
9
9
|
|
10
|
-
def parse! stream, options = {}
|
11
|
-
raise NotImplementedError
|
12
|
-
end
|
13
|
-
|
14
10
|
def eql? other
|
15
11
|
other.is_a?(self.class) and other.expected == @expected
|
16
12
|
end
|
@@ -20,5 +16,10 @@ module Kaiseki
|
|
20
16
|
def to_s
|
21
17
|
@expected.inspect
|
22
18
|
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def parse! stream, options = {}
|
22
|
+
raise NotImplementedError
|
23
|
+
end
|
23
24
|
end
|
24
25
|
end
|
data/lib/parser_choice.rb
CHANGED
@@ -1,24 +1,5 @@
|
|
1
1
|
module Kaiseki
|
2
2
|
class ChoiceParser < MultiParser
|
3
|
-
def parse! stream, options = {}
|
4
|
-
stream.must_be Stream
|
5
|
-
stream.lock do
|
6
|
-
error = true
|
7
|
-
@expected.each do |n|
|
8
|
-
begin
|
9
|
-
catch :SkipSuccess do
|
10
|
-
return n.parse stream, options
|
11
|
-
end
|
12
|
-
rescue ParseError
|
13
|
-
next
|
14
|
-
rescue NotImplementedError
|
15
|
-
next
|
16
|
-
end
|
17
|
-
end
|
18
|
-
raise ParseError.new "no valid alternatives when parsing #{self}", options
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
3
|
alias :| :append
|
23
4
|
|
24
5
|
def predicate?
|
@@ -28,5 +9,22 @@ module Kaiseki
|
|
28
9
|
def delimiter
|
29
10
|
'|'
|
30
11
|
end
|
12
|
+
|
13
|
+
private
|
14
|
+
def parse! stream, options = {}
|
15
|
+
error = true
|
16
|
+
@expected.each do |n|
|
17
|
+
begin
|
18
|
+
catch :SkipSuccess do
|
19
|
+
return n.parse stream, options
|
20
|
+
end
|
21
|
+
rescue ParseError
|
22
|
+
next
|
23
|
+
rescue NotImplementedError
|
24
|
+
next
|
25
|
+
end
|
26
|
+
end
|
27
|
+
raise ParseError.new "no valid alternatives when parsing #{self}", options
|
28
|
+
end
|
31
29
|
end
|
32
30
|
end
|
data/lib/parser_custom.rb
CHANGED
@@ -7,15 +7,13 @@ module Kaiseki
|
|
7
7
|
@is_predicate = is_predicate
|
8
8
|
end
|
9
9
|
|
10
|
-
def parse! stream, options = {}
|
11
|
-
stream.must_be Stream
|
12
|
-
stream.lock do
|
13
|
-
NODE.new([stream, options], options[:global]).eval options[:global], &@expected
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
10
|
def predicate?
|
18
11
|
@is_predicate
|
19
12
|
end
|
13
|
+
|
14
|
+
private
|
15
|
+
def parse! stream, options = {}
|
16
|
+
NODE.new([stream, options], options[:global]).eval options[:global], &@expected
|
17
|
+
end
|
20
18
|
end
|
21
19
|
end
|
data/lib/parser_eof.rb
CHANGED
@@ -2,18 +2,6 @@ module Kaiseki
|
|
2
2
|
class EOFParser
|
3
3
|
include Parseable
|
4
4
|
|
5
|
-
def parse! stream, options = {}
|
6
|
-
stream.must_be Stream
|
7
|
-
stream.lock do
|
8
|
-
actual = stream.getc
|
9
|
-
if actual
|
10
|
-
raise ParseError.new "unexpected character \"#{actual}\" (expected end-of-string) when parsing #{self}", options
|
11
|
-
else
|
12
|
-
true
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
5
|
def eql? other
|
18
6
|
other.is_a? self.class
|
19
7
|
end
|
@@ -23,5 +11,15 @@ module Kaiseki
|
|
23
11
|
def to_s
|
24
12
|
'EOF'
|
25
13
|
end
|
14
|
+
|
15
|
+
private
|
16
|
+
def parse! stream, options = {}
|
17
|
+
actual = stream.getc
|
18
|
+
if actual
|
19
|
+
raise ParseError.new "unexpected character \"#{actual}\" (expected end-of-string) when parsing #{self}", options
|
20
|
+
else
|
21
|
+
true
|
22
|
+
end
|
23
|
+
end
|
26
24
|
end
|
27
25
|
end
|
data/lib/parser_multi.rb
CHANGED
data/lib/parser_regexp.rb
CHANGED
@@ -1,18 +1,16 @@
|
|
1
1
|
module Kaiseki
|
2
2
|
class RegexpParser < BasicParser
|
3
|
+
private
|
3
4
|
def parse! stream, options = {}
|
4
|
-
stream.
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
if options[:simplify]
|
9
|
-
match.to_s
|
10
|
-
else
|
11
|
-
match
|
12
|
-
end
|
5
|
+
match = stream.match @expected
|
6
|
+
if match
|
7
|
+
if options[:simplify]
|
8
|
+
match.to_s
|
13
9
|
else
|
14
|
-
|
10
|
+
match
|
15
11
|
end
|
12
|
+
else
|
13
|
+
raise ParseError.new "non-matching characters when parsing #{self}", options
|
16
14
|
end
|
17
15
|
end
|
18
16
|
end
|
data/lib/parser_repeat.rb
CHANGED
@@ -10,48 +10,6 @@ module Kaiseki
|
|
10
10
|
@max = max
|
11
11
|
end
|
12
12
|
|
13
|
-
def parse! stream, options = {}
|
14
|
-
stream.must_be Stream
|
15
|
-
stream.lock do
|
16
|
-
result = []
|
17
|
-
while @max.nil? or result.length < @max
|
18
|
-
begin
|
19
|
-
protect do
|
20
|
-
result << @expected.parse(stream, options)
|
21
|
-
end
|
22
|
-
rescue ParseError
|
23
|
-
if options[:skipping]
|
24
|
-
begin
|
25
|
-
protect do
|
26
|
-
options[:skipping].parse stream, options.merge(:skipping => nil)
|
27
|
-
end
|
28
|
-
redo
|
29
|
-
rescue ParseError
|
30
|
-
break
|
31
|
-
end
|
32
|
-
else
|
33
|
-
break
|
34
|
-
end
|
35
|
-
rescue NotImplementedError
|
36
|
-
break
|
37
|
-
end
|
38
|
-
end
|
39
|
-
if result.length < @min
|
40
|
-
raise ParseError.new "expected #{@min} match#{'es' unless @min == 1} but obtained #{result.length} when parsing #{self}", options
|
41
|
-
else
|
42
|
-
if options[:simplify]
|
43
|
-
if @min == 0 and @max == 1
|
44
|
-
result.length == 0 ? nil : result[0]
|
45
|
-
else
|
46
|
-
result
|
47
|
-
end
|
48
|
-
else
|
49
|
-
result
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
13
|
def eql? other
|
56
14
|
other.is_a?(self.class) and other.expected == @expected and other.min == @min and other.max == @max
|
57
15
|
end
|
@@ -65,5 +23,45 @@ module Kaiseki
|
|
65
23
|
@expected.to_s + " [#{@min}+]"
|
66
24
|
end
|
67
25
|
end
|
26
|
+
|
27
|
+
private
|
28
|
+
def parse! stream, options = {}
|
29
|
+
result = []
|
30
|
+
while @max.nil? or result.length < @max
|
31
|
+
begin
|
32
|
+
protect do
|
33
|
+
result << @expected.parse(stream, options)
|
34
|
+
end
|
35
|
+
rescue ParseError
|
36
|
+
if options[:skipping]
|
37
|
+
begin
|
38
|
+
protect do
|
39
|
+
options[:skipping].parse stream, options.merge(:skipping => nil)
|
40
|
+
end
|
41
|
+
redo
|
42
|
+
rescue ParseError
|
43
|
+
break
|
44
|
+
end
|
45
|
+
else
|
46
|
+
break
|
47
|
+
end
|
48
|
+
rescue NotImplementedError
|
49
|
+
break
|
50
|
+
end
|
51
|
+
end
|
52
|
+
if result.length < @min
|
53
|
+
raise ParseError.new "expected #{@min} match#{'es' unless @min == 1} but obtained #{result.length} when parsing #{self}", options
|
54
|
+
else
|
55
|
+
if options[:simplify]
|
56
|
+
if @min == 0 and @max == 1
|
57
|
+
result.length == 0 ? nil : result[0]
|
58
|
+
else
|
59
|
+
result
|
60
|
+
end
|
61
|
+
else
|
62
|
+
result
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
68
66
|
end
|
69
67
|
end
|
data/lib/parser_sequence.rb
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
module Kaiseki
|
2
2
|
class SequenceParser < MultiParser
|
3
|
+
alias :& :append
|
4
|
+
|
5
|
+
def predicate?
|
6
|
+
@expected.find {|n| !n.predicate? } ? false : true
|
7
|
+
end
|
8
|
+
|
9
|
+
def delimiter
|
10
|
+
'&'
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
3
14
|
def parse! stream, options = {}
|
4
15
|
stream.must_be Stream
|
5
16
|
stream.lock do
|
@@ -40,15 +51,5 @@ module Kaiseki
|
|
40
51
|
end
|
41
52
|
end
|
42
53
|
end
|
43
|
-
|
44
|
-
alias :& :append
|
45
|
-
|
46
|
-
def predicate?
|
47
|
-
@expected.find {|n| !n.predicate? } ? false : true
|
48
|
-
end
|
49
|
-
|
50
|
-
def delimiter
|
51
|
-
'&'
|
52
|
-
end
|
53
54
|
end
|
54
55
|
end
|
data/lib/parser_string.rb
CHANGED
@@ -1,18 +1,17 @@
|
|
1
1
|
module Kaiseki
|
2
2
|
class StringParser < BasicParser
|
3
|
+
|
4
|
+
private
|
3
5
|
def parse! stream, options = {}
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
elsif actual != char
|
11
|
-
raise ParseError.new "unexpected character \"#{actual}\" (expected \"#{char}\") when parsing #{self}", options
|
12
|
-
end
|
6
|
+
@expected.each_char do |char|
|
7
|
+
actual = stream.getc
|
8
|
+
if actual.nil?
|
9
|
+
raise ParseError.new "unexpected end-of-string (expected \"#{char}\") when parsing #{self}", options
|
10
|
+
elsif actual != char
|
11
|
+
raise ParseError.new "unexpected character \"#{actual}\" (expected \"#{char}\") when parsing #{self}", options
|
13
12
|
end
|
14
|
-
@expected.dup
|
15
13
|
end
|
14
|
+
@expected.dup
|
16
15
|
end
|
17
16
|
end
|
18
17
|
end
|
data/lib/parser_symbol.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
module Kaiseki
|
2
2
|
class SymbolParser < BasicParser
|
3
|
+
|
4
|
+
private
|
3
5
|
def parse! stream, options = {}
|
4
|
-
if options
|
5
|
-
if options[:grammar].rules
|
6
|
+
if options.key? :grammar
|
7
|
+
if options[:grammar].rules.key? @expected
|
6
8
|
options[:grammar].rules[@expected].parse stream, options.merge(:rule => @expected.to_s)
|
7
9
|
else
|
8
10
|
STDERR.puts "skipping #{self}: not implemented"
|
data/lib/predicate_and.rb
CHANGED
@@ -1,17 +1,5 @@
|
|
1
1
|
module Kaiseki
|
2
2
|
class AndPredicate < PackageParser
|
3
|
-
def parse! stream, options = {}
|
4
|
-
stream.must_be Stream
|
5
|
-
stream.lock do
|
6
|
-
begin
|
7
|
-
@expected.parse stream, options
|
8
|
-
rescue ParseError => e
|
9
|
-
raise ParseError.new "predicate not satisfied when parsing #{self}: #{e.to_s}", options
|
10
|
-
end
|
11
|
-
throw :PredicateSuccess
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
3
|
def predicate?
|
16
4
|
true
|
17
5
|
end
|
@@ -19,5 +7,15 @@ module Kaiseki
|
|
19
7
|
def to_s
|
20
8
|
"#{@expected}.and?"
|
21
9
|
end
|
10
|
+
|
11
|
+
private
|
12
|
+
def parse! stream, options = {}
|
13
|
+
begin
|
14
|
+
@expected.parse stream, options
|
15
|
+
rescue ParseError => e
|
16
|
+
raise ParseError.new "predicate not satisfied when parsing #{self}: #{e.to_s}", options
|
17
|
+
end
|
18
|
+
throw :PredicateSuccess
|
19
|
+
end
|
22
20
|
end
|
23
21
|
end
|
data/lib/predicate_not.rb
CHANGED
@@ -1,17 +1,5 @@
|
|
1
1
|
module Kaiseki
|
2
2
|
class NotPredicate < PackageParser
|
3
|
-
def parse! stream, options = {}
|
4
|
-
stream.must_be Stream
|
5
|
-
stream.lock do
|
6
|
-
begin
|
7
|
-
result = @expected.parse stream, options
|
8
|
-
rescue ParseError
|
9
|
-
throw :PredicateSuccess
|
10
|
-
end
|
11
|
-
raise ParseError.new "predicate not satisfied when parsing #{self}: matched #{result}", options
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
3
|
def predicate?
|
16
4
|
true
|
17
5
|
end
|
@@ -19,5 +7,15 @@ module Kaiseki
|
|
19
7
|
def to_s
|
20
8
|
"#{@expected}.not!"
|
21
9
|
end
|
10
|
+
|
11
|
+
private
|
12
|
+
def parse! stream, options = {}
|
13
|
+
begin
|
14
|
+
result = @expected.parse stream, options
|
15
|
+
rescue ParseError
|
16
|
+
throw :PredicateSuccess
|
17
|
+
end
|
18
|
+
raise ParseError.new "predicate not satisfied when parsing #{self}: matched #{result}", options
|
19
|
+
end
|
22
20
|
end
|
23
21
|
end
|
data/lib/predicate_skip.rb
CHANGED
@@ -1,17 +1,5 @@
|
|
1
1
|
module Kaiseki
|
2
2
|
class SkipPredicate < PackageParser
|
3
|
-
def parse! stream, options = {}
|
4
|
-
stream.must_be Stream
|
5
|
-
stream.lock do
|
6
|
-
begin
|
7
|
-
@expected.parse stream, options
|
8
|
-
rescue ParseError => e
|
9
|
-
raise ParseError.new "predicate not satisfied when parsing #{self}: #{e.to_s}", options
|
10
|
-
end
|
11
|
-
throw :SkipSuccess
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
3
|
def predicate?
|
16
4
|
true
|
17
5
|
end
|
@@ -19,5 +7,15 @@ module Kaiseki
|
|
19
7
|
def to_s
|
20
8
|
"#{@expected}.skip"
|
21
9
|
end
|
10
|
+
|
11
|
+
private
|
12
|
+
def parse! stream, options = {}
|
13
|
+
begin
|
14
|
+
@expected.parse stream, options
|
15
|
+
rescue ParseError => e
|
16
|
+
raise ParseError.new "predicate not satisfied when parsing #{self}: #{e.to_s}", options
|
17
|
+
end
|
18
|
+
throw :SkipSuccess
|
19
|
+
end
|
22
20
|
end
|
23
21
|
end
|
data/lib/result_action.rb
CHANGED
data/lib/result_cast.rb
CHANGED
@@ -7,6 +7,13 @@ module Kaiseki
|
|
7
7
|
@to_class = to_class
|
8
8
|
end
|
9
9
|
|
10
|
+
def eql? other
|
11
|
+
other.is_a?(self.class) and other.expected == @expected and other.to_class == @to_class
|
12
|
+
end
|
13
|
+
|
14
|
+
alias :== :eql?
|
15
|
+
|
16
|
+
private
|
10
17
|
def parse! stream, options = {}
|
11
18
|
result = @expected.parse stream, options
|
12
19
|
if @to_class == Integer
|
@@ -23,11 +30,5 @@ module Kaiseki
|
|
23
30
|
raise "can't cast to #{@to_class}"
|
24
31
|
end
|
25
32
|
end
|
26
|
-
|
27
|
-
def eql? other
|
28
|
-
other.is_a?(self.class) and other.expected == @expected and other.to_class == @to_class
|
29
|
-
end
|
30
|
-
|
31
|
-
alias :== :eql?
|
32
33
|
end
|
33
34
|
end
|
data/lib/result_filter.rb
CHANGED
@@ -8,6 +8,13 @@ module Kaiseki
|
|
8
8
|
@block = block
|
9
9
|
end
|
10
10
|
|
11
|
+
def eql? other
|
12
|
+
other.is_a?(self.class) and other.expected == @expected and other.block == @block
|
13
|
+
end
|
14
|
+
|
15
|
+
alias :== :eql?
|
16
|
+
|
17
|
+
private
|
11
18
|
def parse! stream, options = {}
|
12
19
|
if @node.is_a? Class
|
13
20
|
node_class = @node
|
@@ -26,11 +33,5 @@ module Kaiseki
|
|
26
33
|
end
|
27
34
|
node.eval options[:global], &@block
|
28
35
|
end
|
29
|
-
|
30
|
-
def eql? other
|
31
|
-
other.is_a?(self.class) and other.expected == @expected and other.block == @block
|
32
|
-
end
|
33
|
-
|
34
|
-
alias :== :eql?
|
35
36
|
end
|
36
37
|
end
|
data/lib/result_merge.rb
CHANGED
data/lib/result_override.rb
CHANGED
@@ -7,14 +7,15 @@ module Kaiseki
|
|
7
7
|
@options = options
|
8
8
|
end
|
9
9
|
|
10
|
-
def parse! stream, options = {}
|
11
|
-
@expected.parse stream, options.merge(@options)
|
12
|
-
end
|
13
|
-
|
14
10
|
def eql? other
|
15
11
|
other.is_a?(self.class) and other.expected == @expected and other.options == @options
|
16
12
|
end
|
17
13
|
|
18
14
|
alias :== :eql?
|
15
|
+
|
16
|
+
private
|
17
|
+
def parse! stream, options = {}
|
18
|
+
@expected.parse stream, options.merge(@options)
|
19
|
+
end
|
19
20
|
end
|
20
21
|
end
|
data/lib/result_validate.rb
CHANGED
@@ -7,6 +7,13 @@ module Kaiseki
|
|
7
7
|
@validators = validators
|
8
8
|
end
|
9
9
|
|
10
|
+
def eql? other
|
11
|
+
other.is_a?(self.class) and other.expected == @expected and other.validators == @validators
|
12
|
+
end
|
13
|
+
|
14
|
+
alias :== :eql?
|
15
|
+
|
16
|
+
private
|
10
17
|
def parse! stream, options = {}
|
11
18
|
result = @expected.parse stream, options
|
12
19
|
passed = true
|
@@ -28,11 +35,5 @@ module Kaiseki
|
|
28
35
|
raise ParseError.new "`#{result}' does not pass validation", options
|
29
36
|
end
|
30
37
|
end
|
31
|
-
|
32
|
-
def eql? other
|
33
|
-
other.is_a?(self.class) and other.expected == @expected and other.validators == @validators
|
34
|
-
end
|
35
|
-
|
36
|
-
alias :== :eql?
|
37
38
|
end
|
38
39
|
end
|
data/lib/rule.rb
CHANGED
@@ -67,6 +67,38 @@ module Kaiseki
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
+
def validates validators
|
71
|
+
if @parseable
|
72
|
+
@parseable = @parseable.validate validators
|
73
|
+
else
|
74
|
+
raise "parseable for rule #{@name.inspect} undefined"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def set *vars
|
79
|
+
if @parseable
|
80
|
+
@parseable = @parseable.set *vars
|
81
|
+
else
|
82
|
+
raise "parseable for rule #{@name.inspect} undefined"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def tag_result name = @name
|
87
|
+
if @parseable
|
88
|
+
@parseable = @parseable.tag_result name
|
89
|
+
else
|
90
|
+
raise "parseable for rule #{@name.inspect} undefined"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def tag_error name = @name
|
95
|
+
if @parseable
|
96
|
+
@parseable = @parseable.tag_error name
|
97
|
+
else
|
98
|
+
raise "parseable for rule #{@name.inspect} undefined"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
70
102
|
def filter node = @name, &block
|
71
103
|
if @parseable
|
72
104
|
unless @grammar.nodes.key? @name
|
@@ -89,14 +121,6 @@ module Kaiseki
|
|
89
121
|
end
|
90
122
|
end
|
91
123
|
|
92
|
-
def validates validators
|
93
|
-
if @parseable
|
94
|
-
@parseable = @parseable.validate validators
|
95
|
-
else
|
96
|
-
raise "parseable for rule #{@name.inspect} undefined"
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
124
|
def node args, options = {}
|
101
125
|
args.must_be Array
|
102
126
|
if @grammar.nodes.key? @name
|
@@ -106,13 +130,5 @@ module Kaiseki
|
|
106
130
|
@grammar.nodes[@name] = parent.subclass args, options
|
107
131
|
end
|
108
132
|
end
|
109
|
-
|
110
|
-
def set *vars
|
111
|
-
if @parseable
|
112
|
-
@parseable = @parseable.set *vars
|
113
|
-
else
|
114
|
-
raise "parseable for rule #{@name.inspect} undefined"
|
115
|
-
end
|
116
|
-
end
|
117
133
|
end
|
118
134
|
end
|
data/lib/tag_basic.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
module Kaiseki
|
2
|
+
class BasicTag < PackageParser
|
3
|
+
attr_reader :name
|
4
|
+
|
5
|
+
def initialize expected, name
|
6
|
+
super expected
|
7
|
+
@name = name
|
8
|
+
end
|
9
|
+
|
10
|
+
def eql? other
|
11
|
+
other.is_a?(self.class) and other.expected == @expected and other.name == @name
|
12
|
+
end
|
13
|
+
|
14
|
+
alias :== :eql?
|
15
|
+
end
|
16
|
+
end
|
data/lib/tag_error.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
module Kaiseki
|
2
|
+
class ErrorTag < BasicTag
|
3
|
+
|
4
|
+
private
|
5
|
+
def parse! stream, options = {}
|
6
|
+
begin
|
7
|
+
@expected.parse stream, options
|
8
|
+
rescue ParseError => e
|
9
|
+
if options.key? :result
|
10
|
+
options[:result].errors[@name] = e
|
11
|
+
end
|
12
|
+
raise e
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/tag_result.rb
ADDED
data/lib/var_get.rb
CHANGED
@@ -7,6 +7,17 @@ module Kaiseki
|
|
7
7
|
@parser = parser.to_parseable
|
8
8
|
end
|
9
9
|
|
10
|
+
def eql? other
|
11
|
+
other.is_a?(self.class) and other.expected == @expected and other.parser == @parser
|
12
|
+
end
|
13
|
+
|
14
|
+
alias :== :eql?
|
15
|
+
|
16
|
+
def to_s
|
17
|
+
"#{@expected.is_a?(Symbol) ? "$#{@expected}" : @expected.inspect} (match)"
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
10
21
|
def parse! stream, options = {}
|
11
22
|
if @expected.is_a? Symbol
|
12
23
|
if options[:global] and options[:global].key?(@expected)
|
@@ -26,15 +37,5 @@ module Kaiseki
|
|
26
37
|
raise ParseError.new "unexpected result #{result.inspect} (expected #{source.inspect}) when parsing #{@parser}", options
|
27
38
|
end
|
28
39
|
end
|
29
|
-
|
30
|
-
def eql? other
|
31
|
-
other.is_a?(self.class) and other.expected == @expected and other.parser == @parser
|
32
|
-
end
|
33
|
-
|
34
|
-
alias :== :eql?
|
35
|
-
|
36
|
-
def to_s
|
37
|
-
"#{@expected.is_a?(Symbol) ? "$#{@expected}" : @expected.inspect} (match)"
|
38
|
-
end
|
39
40
|
end
|
40
41
|
end
|
data/lib/var_insert.rb
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
module Kaiseki
|
2
2
|
class InsertVar < BasicParser
|
3
|
+
def to_s
|
4
|
+
"#{@expected.is_a?(Symbol) ? "$#{@expected}" : @expected.inspect} (ins)"
|
5
|
+
end
|
6
|
+
|
7
|
+
private
|
3
8
|
def parse! stream, options = {}
|
4
9
|
if @expected.is_a? Symbol
|
5
10
|
if options[:global] and options[:global].key?(@expected)
|
@@ -11,9 +16,5 @@ module Kaiseki
|
|
11
16
|
@expected
|
12
17
|
end
|
13
18
|
end
|
14
|
-
|
15
|
-
def to_s
|
16
|
-
"#{@expected.is_a?(Symbol) ? "$#{@expected}" : @expected.inspect} (ins)"
|
17
|
-
end
|
18
19
|
end
|
19
20
|
end
|
data/lib/var_set.rb
CHANGED
@@ -8,17 +8,18 @@ module Kaiseki
|
|
8
8
|
vars.each {|n| @vars << n }
|
9
9
|
end
|
10
10
|
|
11
|
+
def eql? other
|
12
|
+
other.is_a?(self.class) and other.expected == @expected and other.vars == @vars
|
13
|
+
end
|
14
|
+
|
15
|
+
alias :== :eql?
|
16
|
+
|
17
|
+
private
|
11
18
|
def parse! stream, options = {}
|
12
19
|
result = @expected.parse stream, options
|
13
20
|
options[:global] ||= {}
|
14
21
|
@vars.each {|n| options[:global][n] = result }
|
15
22
|
result
|
16
23
|
end
|
17
|
-
|
18
|
-
def eql? other
|
19
|
-
other.is_a?(self.class) and other.expected == @expected and other.vars == @vars
|
20
|
-
end
|
21
|
-
|
22
|
-
alias :== :eql?
|
23
24
|
end
|
24
25
|
end
|
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kaiseki
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 1
|
7
|
-
- 1
|
8
|
-
- 1
|
9
|
-
version: 1.1.1
|
4
|
+
prerelease:
|
5
|
+
version: 1.2.1
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- William Hamilton-Levi
|
@@ -14,7 +10,7 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date: 2011-
|
13
|
+
date: 2011-02-28 00:00:00 -05:00
|
18
14
|
default_executable:
|
19
15
|
dependencies: []
|
20
16
|
|
@@ -45,6 +41,7 @@ files:
|
|
45
41
|
- lib/parseable.rb
|
46
42
|
- lib/parser_regexp.rb
|
47
43
|
- lib/result_filter.rb
|
44
|
+
- lib/tag_result.rb
|
48
45
|
- lib/kaiseki.rb
|
49
46
|
- lib/action.rb
|
50
47
|
- lib/stream.rb
|
@@ -53,6 +50,7 @@ files:
|
|
53
50
|
- lib/parser_sequence.rb
|
54
51
|
- lib/mod_symbol.rb
|
55
52
|
- lib/parser_custom.rb
|
53
|
+
- lib/tag_basic.rb
|
56
54
|
- lib/parser_eof.rb
|
57
55
|
- lib/result_validate.rb
|
58
56
|
- lib/parse_result.rb
|
@@ -64,6 +62,7 @@ files:
|
|
64
62
|
- lib/result_override.rb
|
65
63
|
- lib/mod_regexp.rb
|
66
64
|
- lib/parser_multi.rb
|
65
|
+
- lib/tag_error.rb
|
67
66
|
- lib/parse_error.rb
|
68
67
|
- lib/mod_file.rb
|
69
68
|
- lib/mod_string.rb
|
@@ -83,21 +82,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
83
82
|
requirements:
|
84
83
|
- - ">="
|
85
84
|
- !ruby/object:Gem::Version
|
86
|
-
segments:
|
87
|
-
- 0
|
88
85
|
version: "0"
|
89
86
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
87
|
none: false
|
91
88
|
requirements:
|
92
89
|
- - ">="
|
93
90
|
- !ruby/object:Gem::Version
|
94
|
-
segments:
|
95
|
-
- 0
|
96
91
|
version: "0"
|
97
92
|
requirements: []
|
98
93
|
|
99
94
|
rubyforge_project:
|
100
|
-
rubygems_version: 1.
|
95
|
+
rubygems_version: 1.5.2
|
101
96
|
signing_key:
|
102
97
|
specification_version: 3
|
103
98
|
summary: A parsing expression grammar generator
|