fabulator-grammar 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +22 -0
- data/Rakefile +3 -1
- data/VERSION +1 -1
- data/features/grammar.feature +116 -12
- data/features/step_definitions/expression_steps.rb +2 -2
- data/features/step_definitions/grammar_steps.rb +46 -2
- data/features/step_definitions/xml_steps.rb +5 -16
- data/features/support/env.rb +1 -0
- data/lib/fabulator-grammar.rb +1 -0
- data/lib/fabulator/grammar.rb +12 -3
- data/lib/fabulator/grammar/actions.rb +17 -7
- data/lib/fabulator/grammar/actions/context.rb +18 -0
- data/lib/fabulator/grammar/actions/grammar.rb +76 -0
- data/lib/fabulator/grammar/actions/rule.rb +51 -0
- data/lib/fabulator/grammar/actions/token.rb +27 -0
- data/lib/fabulator/grammar/actions/when.rb +35 -0
- data/lib/fabulator/grammar/cursor.rb +118 -0
- data/lib/fabulator/grammar/expr/anchor.rb +28 -0
- data/lib/fabulator/grammar/expr/char_set.rb +67 -18
- data/lib/fabulator/grammar/expr/look_ahead.rb +44 -0
- data/lib/fabulator/grammar/expr/rule.rb +33 -28
- data/lib/fabulator/grammar/expr/rule_alternative.rb +45 -0
- data/lib/fabulator/grammar/expr/rule_mode.rb +16 -0
- data/lib/fabulator/grammar/expr/rule_ref.rb +15 -4
- data/lib/fabulator/grammar/expr/rule_sequence.rb +59 -0
- data/lib/fabulator/grammar/expr/sequence.rb +7 -1
- data/lib/fabulator/grammar/expr/set_skip.rb +16 -0
- data/lib/fabulator/grammar/expr/text.rb +8 -0
- data/lib/fabulator/grammar/expr/{rules.rb → token.rb} +12 -1
- data/lib/fabulator/grammar/expr/token_alternative.rb +42 -0
- data/lib/fabulator/grammar/rule_parser.rb +667 -0
- data/lib/fabulator/grammar/token_parser.rb +733 -0
- data/rules.racc +249 -0
- data/tokens.racc +257 -0
- metadata +29 -12
- data/lib/fabulator/grammar/parser.rb +0 -548
- data/regex.racc +0 -183
@@ -0,0 +1,45 @@
|
|
1
|
+
module Fabulator
|
2
|
+
module Grammar
|
3
|
+
module Expr
|
4
|
+
class RuleAlternative
|
5
|
+
def initialize
|
6
|
+
@sequences = [ ]
|
7
|
+
end
|
8
|
+
|
9
|
+
def add_sequence(s)
|
10
|
+
s = [ s ] unless s.is_a?(Array)
|
11
|
+
@sequences += s
|
12
|
+
end
|
13
|
+
|
14
|
+
def parse(source)
|
15
|
+
results = { }
|
16
|
+
@sequences.each do |sequence|
|
17
|
+
r = sequence.parse(source)
|
18
|
+
return nil if r.nil? # we fail
|
19
|
+
nom = (sequence.name rescue nil)
|
20
|
+
rr = { }
|
21
|
+
if nom.nil?
|
22
|
+
rr = r
|
23
|
+
elsif !r.nil?
|
24
|
+
if !(r.is_a?(Hash) || r.is_a?(Array)) || !r.empty?
|
25
|
+
rr[nom] = r
|
26
|
+
end
|
27
|
+
end
|
28
|
+
if rr.is_a?(Hash) && !rr.empty?
|
29
|
+
rr.each_pair do |k,v|
|
30
|
+
if results[k].nil?
|
31
|
+
results[k] = v
|
32
|
+
elsif results[k].is_a?(Array)
|
33
|
+
results[k] << v
|
34
|
+
else
|
35
|
+
results[k] = [ results[k], v ]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
results
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -2,12 +2,23 @@ module Fabulator::Grammar::Expr
|
|
2
2
|
class RuleRef
|
3
3
|
def initialize(qname)
|
4
4
|
bits = qname.split(/:/,2)
|
5
|
-
|
6
|
-
|
5
|
+
if bits.size > 1
|
6
|
+
@ns_prefix = bits[0]
|
7
|
+
@name = bits[1]
|
8
|
+
else
|
9
|
+
@name = qname
|
10
|
+
end
|
7
11
|
end
|
8
12
|
|
9
|
-
def
|
10
|
-
|
13
|
+
def name
|
14
|
+
@name
|
15
|
+
end
|
16
|
+
|
17
|
+
def parse(cursor)
|
18
|
+
rule = cursor.find_rule(@name)
|
19
|
+
return nil if rule.nil?
|
20
|
+
# we have @name as the path prefix for this part?
|
21
|
+
cursor.attempt { |c| rule.parse(c) }
|
11
22
|
end
|
12
23
|
end
|
13
24
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Fabulator
|
2
|
+
module Grammar
|
3
|
+
module Expr
|
4
|
+
class RuleSequence
|
5
|
+
def initialize(hypo, atom, quant = nil)
|
6
|
+
@name = hypo
|
7
|
+
@atom = atom
|
8
|
+
@quantifier = quant
|
9
|
+
end
|
10
|
+
|
11
|
+
# eventually, this can be the hypo name
|
12
|
+
def name
|
13
|
+
@name.nil? ? (@atom.name rescue nil) : @name
|
14
|
+
end
|
15
|
+
|
16
|
+
def parse(source)
|
17
|
+
if @quantifier.nil?
|
18
|
+
return @atom.parse(source)
|
19
|
+
end
|
20
|
+
|
21
|
+
case @quantifier.first
|
22
|
+
when '?'.to_sym: return @atom.parse(source) || { }
|
23
|
+
when :s:
|
24
|
+
ret = [ ]
|
25
|
+
r = @atom.parse(source)
|
26
|
+
while !r.nil?
|
27
|
+
ret << r
|
28
|
+
if @quantifier[1].nil?
|
29
|
+
r = @atom.parse(source)
|
30
|
+
else
|
31
|
+
r = @quantifier[1].parse(source)
|
32
|
+
if !r.nil?
|
33
|
+
r = @atom.parse(source)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
return ret.empty? ? nil : ret
|
38
|
+
when 's?'.to_sym:
|
39
|
+
ret = [ ]
|
40
|
+
r = @atom.parse(source)
|
41
|
+
while !r.nil?
|
42
|
+
ret << r
|
43
|
+
if @quantifier[1].nil?
|
44
|
+
r = @atom.parse(source)
|
45
|
+
else
|
46
|
+
r = @quantifier[1].parse(source)
|
47
|
+
if !r.nil?
|
48
|
+
r = @atom.parse(source)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
return ret.empty? ? {} : ret
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
@@ -1,8 +1,9 @@
|
|
1
1
|
module Fabulator::Grammar::Expr
|
2
2
|
class Sequence
|
3
|
-
def initialize(sub_seq, count = [ :one ])
|
3
|
+
def initialize(hypo, sub_seq, count = [ :one ])
|
4
4
|
@sub_sequence = sub_seq
|
5
5
|
@modifiers = ''
|
6
|
+
@hypothetical = hypo
|
6
7
|
case (count - [:min]).first
|
7
8
|
when :zero_or_one: @modifiers = '?'
|
8
9
|
when :one_or_more: @modifiers = '+'
|
@@ -20,7 +21,12 @@ module Fabulator::Grammar::Expr
|
|
20
21
|
end
|
21
22
|
|
22
23
|
def to_regex
|
24
|
+
# how do we handle setting the hypothetical?
|
23
25
|
s = %r{#{@sub_sequence.to_regex}#{@modifiers}}
|
24
26
|
end
|
27
|
+
|
28
|
+
def parse(cursor)
|
29
|
+
cursor.match(self.to_regex)
|
30
|
+
end
|
25
31
|
end
|
26
32
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module Fabulator::Grammar::Expr
|
2
|
-
class
|
2
|
+
class Token
|
3
|
+
attr_accessor :name
|
4
|
+
|
3
5
|
def initialize
|
4
6
|
@alternatives = [ ]
|
5
7
|
end
|
@@ -11,5 +13,14 @@ module Fabulator::Grammar::Expr
|
|
11
13
|
def to_regex
|
12
14
|
Regexp.union(@alternatives.collect{|a| a.to_regex })
|
13
15
|
end
|
16
|
+
|
17
|
+
def parse(cursor)
|
18
|
+
res = cursor.match_token(self.to_regex)
|
19
|
+
if res.nil?
|
20
|
+
return nil
|
21
|
+
else
|
22
|
+
return res
|
23
|
+
end
|
24
|
+
end
|
14
25
|
end
|
15
26
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Fabulator::Grammar::Expr
|
2
|
+
class TokenAlternative
|
3
|
+
def initialize
|
4
|
+
@sequences = [ ]
|
5
|
+
@anchor_start = false
|
6
|
+
@anchor_end = false
|
7
|
+
end
|
8
|
+
|
9
|
+
def anchor_start(t)
|
10
|
+
@anchor_start = case t
|
11
|
+
when '^': '^'
|
12
|
+
when '^^': '\A'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def anchor_end(t)
|
17
|
+
@anchor_end = case t
|
18
|
+
when '$': '$'
|
19
|
+
when '$$': '\Z'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def add_sequence(s)
|
24
|
+
@sequences << s
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_regex
|
28
|
+
r = %r{#{@sequences.collect{ |s| s.to_regex }}}
|
29
|
+
if @anchor_start
|
30
|
+
if @anchor_end
|
31
|
+
%r{#{@anchor_start}#{r}#{@anchor_end}}
|
32
|
+
else
|
33
|
+
%r{#{@anchor_start}#{r}}
|
34
|
+
end
|
35
|
+
elsif @anchor_end
|
36
|
+
%r{#{r}#{@anchor_end}}
|
37
|
+
else
|
38
|
+
r
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,667 @@
|
|
1
|
+
#
|
2
|
+
# DO NOT MODIFY!!!!
|
3
|
+
# This file is automatically generated by Racc 1.4.6
|
4
|
+
# from Racc grammer file "".
|
5
|
+
#
|
6
|
+
|
7
|
+
require 'racc/parser.rb'
|
8
|
+
module Fabulator
|
9
|
+
module Grammar
|
10
|
+
class RuleParser < Racc::Parser
|
11
|
+
|
12
|
+
module_eval(<<'...end rules.racc/module_eval...', 'rules.racc', 75)
|
13
|
+
require 'fabulator/grammar'
|
14
|
+
|
15
|
+
def parse(t)
|
16
|
+
@source = t
|
17
|
+
@curpos = 0
|
18
|
+
@line = 0
|
19
|
+
@col = 0
|
20
|
+
|
21
|
+
@in_quantifier = false
|
22
|
+
|
23
|
+
@yydebug = true
|
24
|
+
|
25
|
+
@last_token = nil
|
26
|
+
|
27
|
+
do_parse
|
28
|
+
end
|
29
|
+
|
30
|
+
def on_error(*args)
|
31
|
+
raise Fabulator::Grammar::ParserError.new("unable to parse '#{args[1]}' near line #{@line + 1}, column #{@col}")
|
32
|
+
end
|
33
|
+
|
34
|
+
@@ops = {
|
35
|
+
':=' => :COLON_EQUAL,
|
36
|
+
'[' => :LB,
|
37
|
+
']' => :RB,
|
38
|
+
'(' => :LP,
|
39
|
+
')' => :RP,
|
40
|
+
'{' => :LC,
|
41
|
+
'}' => :RC,
|
42
|
+
'?' => :QUESTION,
|
43
|
+
'.' => :DOT,
|
44
|
+
'..' => :DOT_DOT,
|
45
|
+
'...'=> :DOT_DOT_DOT,
|
46
|
+
'...!'=> :DOT_DOT_DOT_BANG,
|
47
|
+
'|' => :PIPE,
|
48
|
+
',' => :COMMA,
|
49
|
+
':' => :COLON,
|
50
|
+
'^' => :CARET,
|
51
|
+
'^^' => :CARET_CARET,
|
52
|
+
'$' => :DOLLAR,
|
53
|
+
'$$' => :DOLLAR_DOLLAR,
|
54
|
+
'/' => :SLASH,
|
55
|
+
}
|
56
|
+
|
57
|
+
@@regex = {
|
58
|
+
:simple_tokens => %r{^(#{Regexp.union(@@ops.keys.sort_by{|a| a.length}.reverse.collect{ |k| k })})},
|
59
|
+
:ncname => %r{(?:[a-zA-Z_][-a-zA-Z0-9_.]*)},
|
60
|
+
:integer => %r{(\d+)},
|
61
|
+
:literal => %r{((?:"(?:[^\\"]*(?:\\.[^\\"]*)*)")|(?:'(?:[^\\']*(?:\\.[^\\']*)*)'))},
|
62
|
+
}
|
63
|
+
|
64
|
+
@@regex[:general] = Regexp.compile(%{^(#{@@regex[:ncname]})|#{@@regex[:integer]}|#{@@regex[:literal]}})
|
65
|
+
|
66
|
+
def next_token
|
67
|
+
@token = nil
|
68
|
+
white_space = 0
|
69
|
+
new_line = 0
|
70
|
+
while @curpos < @source.length && @source[@curpos..@curpos] =~ /\s/ do
|
71
|
+
if @source[@curpos..@curpos] =~ /\n/
|
72
|
+
new_line = new_line + 1
|
73
|
+
@line = @line + 1
|
74
|
+
@col = 0
|
75
|
+
else
|
76
|
+
@col = @col + 1
|
77
|
+
end
|
78
|
+
@curpos = @curpos + 1
|
79
|
+
white_space = white_space + 1
|
80
|
+
end
|
81
|
+
|
82
|
+
# skip comments delimited by (: :)
|
83
|
+
# comments can be nested
|
84
|
+
# these are XPath 2.0 comments
|
85
|
+
#
|
86
|
+
|
87
|
+
if @curpos < @source.length && @source[@curpos..@curpos+1] == '(:'
|
88
|
+
comment_depth = 1
|
89
|
+
@curpos = @curpos + 2
|
90
|
+
@col = @col + 2
|
91
|
+
while comment_depth > 0 && @curpos < @source.length
|
92
|
+
if @source[@curpos..@curpos+1] == '(:'
|
93
|
+
comment_depth = comment_depth + 1
|
94
|
+
@curpos = @curpos + 1
|
95
|
+
@col = @col + 1
|
96
|
+
end
|
97
|
+
if @source[@curpos..@curpos+1] == ':)'
|
98
|
+
comment_depth = comment_depth - 1
|
99
|
+
@curpos = @curpos + 1
|
100
|
+
@col = @col + 1
|
101
|
+
end
|
102
|
+
@curpos = @curpos + 1
|
103
|
+
@col = @col + 1
|
104
|
+
end
|
105
|
+
white_space = white_space + 1
|
106
|
+
end
|
107
|
+
|
108
|
+
while @curpos < @source.length && @source[@curpos..@curpos] =~ /\s/ do
|
109
|
+
if @source[@curpos..@curpos] =~ /\n/
|
110
|
+
new_line = new_line + 1
|
111
|
+
@line = @line + 1
|
112
|
+
@col = 0
|
113
|
+
else
|
114
|
+
@col = @col + 1
|
115
|
+
end
|
116
|
+
@curpos = @curpos + 1
|
117
|
+
white_space = white_space + 1
|
118
|
+
end
|
119
|
+
|
120
|
+
if @curpos >= @source.length
|
121
|
+
@last_token = nil
|
122
|
+
return [ false, false ]
|
123
|
+
end
|
124
|
+
|
125
|
+
res = @@regex[:simple_tokens].match(@source[@curpos..@source.length-1])
|
126
|
+
if !res.nil?
|
127
|
+
if !res[1].nil?
|
128
|
+
@token = [ @@ops[res[1]], res[1] ]
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
if @token.nil?
|
133
|
+
res = @@regex[:general].match(@source[@curpos..@source.length-1])
|
134
|
+
if res.nil?
|
135
|
+
raise "Failed to parse '#{@source}' at #{@curpos}': #{@source[@curpos..@source.length-1]}"
|
136
|
+
end
|
137
|
+
#ncname, integer, literal
|
138
|
+
if !res[1].nil?
|
139
|
+
@token = [:NCNAME, res[1].to_s]
|
140
|
+
elsif !res[2].nil?
|
141
|
+
@token = [:INTEGER, res[2].to_s]
|
142
|
+
elsif !res[3].nil?
|
143
|
+
@token = [:LITERAL, res[3].to_s]
|
144
|
+
@token[1] = @token[1][1..@token[1].size-2]
|
145
|
+
@col += 2
|
146
|
+
@curpos += 2
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
|
151
|
+
if @token.nil?
|
152
|
+
puts "Uh oh... we don't know what to do: #{@source[@curpos .. @source.length-1]}"
|
153
|
+
return [ nil, nil ]
|
154
|
+
else
|
155
|
+
@curpos += @token[1].length
|
156
|
+
@col += @token[1].length
|
157
|
+
end
|
158
|
+
|
159
|
+
if !@token.nil? && @token[0] == :LP
|
160
|
+
# shorthand: if we see '(s[ )]', '(s?[ )]', '(?)', '(\d', then we have
|
161
|
+
if @curpos > 1 && ![' ', '('].include?(@source[@curpos-2 .. @curpos-2])
|
162
|
+
@token[0] = :LLP
|
163
|
+
@in_quantifier = true
|
164
|
+
end
|
165
|
+
elsif @in_quantifier
|
166
|
+
@in_quantifier = false
|
167
|
+
if @token[0] == :NCNAME
|
168
|
+
@token[0] = case @token[1]
|
169
|
+
when 's': :S
|
170
|
+
else :NCNAME
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
if !@token.nil? && @token[0] == :LB
|
176
|
+
if @curpos == 1 || @source[@curpos-2 .. @curpos - 2] == ' '
|
177
|
+
@token[0] = :LLB
|
178
|
+
@in_directive = true
|
179
|
+
end
|
180
|
+
elsif @in_directive && @token[0] == :NCNAME
|
181
|
+
@token[0] = @token[1].upcase.to_sym
|
182
|
+
@in_directive = false
|
183
|
+
end
|
184
|
+
|
185
|
+
# puts "token: #{@token.join(' => ')}"
|
186
|
+
return @token
|
187
|
+
end
|
188
|
+
...end rules.racc/module_eval...
|
189
|
+
##### State transition tables begin ###
|
190
|
+
|
191
|
+
racc_action_table = [
|
192
|
+
12, 57, 16, 64, 37, 58, 12, 62, 16, 6,
|
193
|
+
8, 11, 15, 18, 19, 6, 8, 11, 15, 18,
|
194
|
+
19, 38, 10, 14, 38, 63, 16, 61, 10, 14,
|
195
|
+
38, 3, 16, 4, 38, 59, 66, 38, 34, 33,
|
196
|
+
38, 10, 14, 38, 10, 14, 10, 14, 38, 48,
|
197
|
+
10, 14, 10, 14, 10, 14, 38, 10, 14, 67,
|
198
|
+
10, 14, 4, 10, 14, 34, 75, 45, 10, 14,
|
199
|
+
44, 69, 70, 12, 33, 71, 10, 14, 48, 73,
|
200
|
+
43, 47, 6, 8, 11, 15, 18, 19, 27, 42,
|
201
|
+
77, 28, 29, 30, 31, 26, 55, 37, 52, 53,
|
202
|
+
54, 79, 80, 21, 82, 83, 84 ]
|
203
|
+
|
204
|
+
racc_action_check = [
|
205
|
+
22, 40, 22, 50, 39, 42, 2, 49, 2, 22,
|
206
|
+
22, 22, 22, 22, 22, 2, 2, 2, 2, 2,
|
207
|
+
2, 52, 22, 22, 75, 50, 8, 49, 2, 2,
|
208
|
+
31, 1, 6, 1, 69, 46, 52, 20, 48, 38,
|
209
|
+
53, 52, 52, 26, 75, 75, 8, 8, 67, 33,
|
210
|
+
31, 31, 6, 6, 69, 69, 66, 20, 20, 53,
|
211
|
+
53, 53, 32, 26, 26, 16, 67, 30, 67, 67,
|
212
|
+
29, 54, 55, 7, 16, 62, 66, 66, 63, 65,
|
213
|
+
28, 32, 7, 7, 7, 7, 7, 7, 12, 27,
|
214
|
+
68, 12, 12, 12, 12, 12, 37, 17, 37, 37,
|
215
|
+
37, 71, 74, 3, 76, 78, 81 ]
|
216
|
+
|
217
|
+
racc_action_pointer = [
|
218
|
+
nil, 31, 3, 103, nil, nil, 27, 70, 21, nil,
|
219
|
+
nil, nil, 84, nil, nil, nil, 47, 78, nil, nil,
|
220
|
+
32, nil, -3, nil, nil, nil, 38, 84, 74, 64,
|
221
|
+
61, 25, 60, 44, nil, nil, nil, 76, 12, -15,
|
222
|
+
-5, nil, -1, nil, nil, nil, 29, nil, 20, 2,
|
223
|
+
-3, nil, 16, 35, 48, 51, nil, nil, nil, nil,
|
224
|
+
nil, nil, 46, 73, nil, 58, 51, 43, 69, 29,
|
225
|
+
nil, 96, nil, nil, 81, 19, 83, nil, 84, nil,
|
226
|
+
nil, 85, nil, nil, nil ]
|
227
|
+
|
228
|
+
racc_action_default = [
|
229
|
+
-3, -47, -1, -47, -3, -4, -47, -5, -47, -6,
|
230
|
+
-35, -17, -47, -7, -3, -18, -38, -22, -19, -20,
|
231
|
+
-47, 85, -2, -15, -8, -16, -33, -47, -47, -47,
|
232
|
+
-47, -33, -47, -47, -25, -37, -21, -47, -38, -24,
|
233
|
+
-47, -34, -47, -10, -11, -12, -47, -36, -47, -47,
|
234
|
+
-47, -40, -33, -33, -47, -47, -23, -14, -9, -13,
|
235
|
+
-43, -44, -45, -42, -39, -47, -33, -33, -47, -33,
|
236
|
+
-26, -47, -41, -27, -47, -33, -47, -29, -47, -46,
|
237
|
+
-28, -47, -32, -31, -30 ]
|
238
|
+
|
239
|
+
racc_goto_table = [
|
240
|
+
40, 51, 49, 36, 17, 46, 1, 23, 17, 25,
|
241
|
+
17, 50, 24, 22, 60, nil, nil, nil, nil, nil,
|
242
|
+
32, nil, 39, nil, 17, 56, 65, 68, nil, nil,
|
243
|
+
nil, 72, 49, nil, nil, nil, nil, nil, nil, nil,
|
244
|
+
74, 76, nil, 78, nil, nil, nil, nil, nil, 81 ]
|
245
|
+
|
246
|
+
racc_goto_check = [
|
247
|
+
7, 13, 10, 9, 8, 7, 1, 5, 8, 5,
|
248
|
+
8, 12, 6, 2, 14, nil, nil, nil, nil, nil,
|
249
|
+
1, nil, 8, nil, 8, 9, 7, 7, nil, nil,
|
250
|
+
nil, 13, 10, nil, nil, nil, nil, nil, nil, nil,
|
251
|
+
7, 7, nil, 7, nil, nil, nil, nil, nil, 7 ]
|
252
|
+
|
253
|
+
racc_goto_pointer = [
|
254
|
+
nil, 6, 9, nil, nil, 1, 5, -26, 2, -14,
|
255
|
+
-31, nil, -22, -32, -35 ]
|
256
|
+
|
257
|
+
racc_goto_default = [
|
258
|
+
nil, nil, 2, 5, 7, 9, 13, nil, 41, nil,
|
259
|
+
20, 35, nil, nil, nil ]
|
260
|
+
|
261
|
+
racc_reduce_table = [
|
262
|
+
0, 0, :racc_error,
|
263
|
+
1, 31, :_reduce_1,
|
264
|
+
3, 31, :_reduce_2,
|
265
|
+
0, 32, :_reduce_3,
|
266
|
+
2, 32, :_reduce_4,
|
267
|
+
1, 33, :_reduce_none,
|
268
|
+
1, 33, :_reduce_none,
|
269
|
+
1, 34, :_reduce_7,
|
270
|
+
2, 34, :_reduce_8,
|
271
|
+
4, 36, :_reduce_9,
|
272
|
+
3, 36, :_reduce_none,
|
273
|
+
3, 36, :_reduce_none,
|
274
|
+
3, 36, :_reduce_none,
|
275
|
+
4, 36, :_reduce_13,
|
276
|
+
4, 36, :_reduce_14,
|
277
|
+
2, 36, :_reduce_15,
|
278
|
+
2, 36, :_reduce_16,
|
279
|
+
1, 36, :_reduce_17,
|
280
|
+
1, 36, :_reduce_18,
|
281
|
+
1, 36, :_reduce_19,
|
282
|
+
1, 36, :_reduce_20,
|
283
|
+
2, 35, :_reduce_21,
|
284
|
+
1, 35, :_reduce_22,
|
285
|
+
3, 35, :_reduce_23,
|
286
|
+
2, 35, :_reduce_24,
|
287
|
+
2, 40, :_reduce_25,
|
288
|
+
3, 39, :_reduce_26,
|
289
|
+
4, 39, :_reduce_27,
|
290
|
+
5, 39, :_reduce_28,
|
291
|
+
4, 39, :_reduce_29,
|
292
|
+
6, 39, :_reduce_30,
|
293
|
+
5, 39, :_reduce_31,
|
294
|
+
5, 39, :_reduce_32,
|
295
|
+
0, 37, :_reduce_none,
|
296
|
+
1, 37, :_reduce_none,
|
297
|
+
1, 38, :_reduce_35,
|
298
|
+
3, 38, :_reduce_36,
|
299
|
+
2, 38, :_reduce_37,
|
300
|
+
0, 41, :_reduce_none,
|
301
|
+
3, 41, :_reduce_none,
|
302
|
+
1, 42, :_reduce_none,
|
303
|
+
3, 42, :_reduce_none,
|
304
|
+
2, 42, :_reduce_none,
|
305
|
+
2, 43, :_reduce_none,
|
306
|
+
2, 43, :_reduce_none,
|
307
|
+
1, 44, :_reduce_none,
|
308
|
+
3, 44, :_reduce_none ]
|
309
|
+
|
310
|
+
racc_reduce_n = 47
|
311
|
+
|
312
|
+
racc_shift_n = 85
|
313
|
+
|
314
|
+
racc_token_table = {
|
315
|
+
false => 0,
|
316
|
+
:error => 1,
|
317
|
+
:PIPE => 2,
|
318
|
+
:LLB => 3,
|
319
|
+
:MODE => 4,
|
320
|
+
:NCNAME => 5,
|
321
|
+
:RB => 6,
|
322
|
+
:COMMIT => 7,
|
323
|
+
:UNCOMMIT => 8,
|
324
|
+
:REJECT => 9,
|
325
|
+
:SKIP => 10,
|
326
|
+
:RESYNC => 11,
|
327
|
+
:DOT_DOT_DOT => 12,
|
328
|
+
:DOT_DOT_DOT_BANG => 13,
|
329
|
+
:CARET => 14,
|
330
|
+
:CARET_CARET => 15,
|
331
|
+
:DOLLAR => 16,
|
332
|
+
:DOLLAR_DOLLAR => 17,
|
333
|
+
:COLON_EQUAL => 18,
|
334
|
+
:LLP => 19,
|
335
|
+
:QUESTION => 20,
|
336
|
+
:RP => 21,
|
337
|
+
:S => 22,
|
338
|
+
:INTEGER => 23,
|
339
|
+
:DOT_DOT => 24,
|
340
|
+
:LITERAL => 25,
|
341
|
+
:LP => 26,
|
342
|
+
:LB => 27,
|
343
|
+
:COMMA => 28,
|
344
|
+
:SLASH => 29 }
|
345
|
+
|
346
|
+
racc_nt_base = 30
|
347
|
+
|
348
|
+
racc_use_result_var = true
|
349
|
+
|
350
|
+
Racc_arg = [
|
351
|
+
racc_action_table,
|
352
|
+
racc_action_check,
|
353
|
+
racc_action_default,
|
354
|
+
racc_action_pointer,
|
355
|
+
racc_goto_table,
|
356
|
+
racc_goto_check,
|
357
|
+
racc_goto_default,
|
358
|
+
racc_goto_pointer,
|
359
|
+
racc_nt_base,
|
360
|
+
racc_reduce_table,
|
361
|
+
racc_token_table,
|
362
|
+
racc_shift_n,
|
363
|
+
racc_reduce_n,
|
364
|
+
racc_use_result_var ]
|
365
|
+
|
366
|
+
Racc_token_to_s_table = [
|
367
|
+
"$end",
|
368
|
+
"error",
|
369
|
+
"PIPE",
|
370
|
+
"LLB",
|
371
|
+
"MODE",
|
372
|
+
"NCNAME",
|
373
|
+
"RB",
|
374
|
+
"COMMIT",
|
375
|
+
"UNCOMMIT",
|
376
|
+
"REJECT",
|
377
|
+
"SKIP",
|
378
|
+
"RESYNC",
|
379
|
+
"DOT_DOT_DOT",
|
380
|
+
"DOT_DOT_DOT_BANG",
|
381
|
+
"CARET",
|
382
|
+
"CARET_CARET",
|
383
|
+
"DOLLAR",
|
384
|
+
"DOLLAR_DOLLAR",
|
385
|
+
"COLON_EQUAL",
|
386
|
+
"LLP",
|
387
|
+
"QUESTION",
|
388
|
+
"RP",
|
389
|
+
"S",
|
390
|
+
"INTEGER",
|
391
|
+
"DOT_DOT",
|
392
|
+
"LITERAL",
|
393
|
+
"LP",
|
394
|
+
"LB",
|
395
|
+
"COMMA",
|
396
|
+
"SLASH",
|
397
|
+
"$start",
|
398
|
+
"rules",
|
399
|
+
"rule",
|
400
|
+
"rule_bit",
|
401
|
+
"directives",
|
402
|
+
"sequence",
|
403
|
+
"directive",
|
404
|
+
"opt_separator",
|
405
|
+
"atom",
|
406
|
+
"sequence_qualifiers",
|
407
|
+
"hypothetical",
|
408
|
+
"opt_params",
|
409
|
+
"params",
|
410
|
+
"param",
|
411
|
+
"relative_path" ]
|
412
|
+
|
413
|
+
Racc_debug_parser = false
|
414
|
+
|
415
|
+
##### State transition tables end #####
|
416
|
+
|
417
|
+
# reduce 0 omitted
|
418
|
+
|
419
|
+
module_eval(<<'.,.,', 'rules.racc', 6)
|
420
|
+
def _reduce_1(val, _values, result)
|
421
|
+
result = Fabulator::Grammar::Expr::Rule.new; result.add_alternative(val[0])
|
422
|
+
result
|
423
|
+
end
|
424
|
+
.,.,
|
425
|
+
|
426
|
+
module_eval(<<'.,.,', 'rules.racc', 7)
|
427
|
+
def _reduce_2(val, _values, result)
|
428
|
+
result = val[0]; result.add_alternative(val[2])
|
429
|
+
result
|
430
|
+
end
|
431
|
+
.,.,
|
432
|
+
|
433
|
+
module_eval(<<'.,.,', 'rules.racc', 9)
|
434
|
+
def _reduce_3(val, _values, result)
|
435
|
+
result = Fabulator::Grammar::Expr::RuleAlternative.new;
|
436
|
+
result
|
437
|
+
end
|
438
|
+
.,.,
|
439
|
+
|
440
|
+
module_eval(<<'.,.,', 'rules.racc', 10)
|
441
|
+
def _reduce_4(val, _values, result)
|
442
|
+
result = val[0]; result.add_sequence(val[1])
|
443
|
+
result
|
444
|
+
end
|
445
|
+
.,.,
|
446
|
+
|
447
|
+
# reduce 5 omitted
|
448
|
+
|
449
|
+
# reduce 6 omitted
|
450
|
+
|
451
|
+
module_eval(<<'.,.,', 'rules.racc', 15)
|
452
|
+
def _reduce_7(val, _values, result)
|
453
|
+
result = [ val[0] ]
|
454
|
+
result
|
455
|
+
end
|
456
|
+
.,.,
|
457
|
+
|
458
|
+
module_eval(<<'.,.,', 'rules.racc', 16)
|
459
|
+
def _reduce_8(val, _values, result)
|
460
|
+
result = val[0] + [ val[1] ]
|
461
|
+
result
|
462
|
+
end
|
463
|
+
.,.,
|
464
|
+
|
465
|
+
module_eval(<<'.,.,', 'rules.racc', 18)
|
466
|
+
def _reduce_9(val, _values, result)
|
467
|
+
result = Fabulator::Grammar::Expr::RuleMode.new(val[2])
|
468
|
+
result
|
469
|
+
end
|
470
|
+
.,.,
|
471
|
+
|
472
|
+
# reduce 10 omitted
|
473
|
+
|
474
|
+
# reduce 11 omitted
|
475
|
+
|
476
|
+
# reduce 12 omitted
|
477
|
+
|
478
|
+
module_eval(<<'.,.,', 'rules.racc', 22)
|
479
|
+
def _reduce_13(val, _values, result)
|
480
|
+
result = Fabulator::Grammar::Expr::SetSkip.new(val[2])
|
481
|
+
result
|
482
|
+
end
|
483
|
+
.,.,
|
484
|
+
|
485
|
+
module_eval(<<'.,.,', 'rules.racc', 23)
|
486
|
+
def _reduce_14(val, _values, result)
|
487
|
+
result = Fabulator::Grammar::Expr::Resync.new(val[2])
|
488
|
+
result
|
489
|
+
end
|
490
|
+
.,.,
|
491
|
+
|
492
|
+
module_eval(<<'.,.,', 'rules.racc', 24)
|
493
|
+
def _reduce_15(val, _values, result)
|
494
|
+
result = Fabulator::Grammar::Expr::LookAhead.new(val[1])
|
495
|
+
result
|
496
|
+
end
|
497
|
+
.,.,
|
498
|
+
|
499
|
+
module_eval(<<'.,.,', 'rules.racc', 25)
|
500
|
+
def _reduce_16(val, _values, result)
|
501
|
+
result = Fabulator::Grammar::Expr::NegLookAhead.new(val[1])
|
502
|
+
result
|
503
|
+
end
|
504
|
+
.,.,
|
505
|
+
|
506
|
+
module_eval(<<'.,.,', 'rules.racc', 26)
|
507
|
+
def _reduce_17(val, _values, result)
|
508
|
+
result = Fabulator::Grammar::Expr::Anchor.new(:start_of_line)
|
509
|
+
result
|
510
|
+
end
|
511
|
+
.,.,
|
512
|
+
|
513
|
+
module_eval(<<'.,.,', 'rules.racc', 27)
|
514
|
+
def _reduce_18(val, _values, result)
|
515
|
+
result = Fabulator::Grammar::Expr::Anchor.new(:start_of_string)
|
516
|
+
result
|
517
|
+
end
|
518
|
+
.,.,
|
519
|
+
|
520
|
+
module_eval(<<'.,.,', 'rules.racc', 28)
|
521
|
+
def _reduce_19(val, _values, result)
|
522
|
+
result = Fabulator::Grammar::Expr::Anchor.new(:end_of_line)
|
523
|
+
result
|
524
|
+
end
|
525
|
+
.,.,
|
526
|
+
|
527
|
+
module_eval(<<'.,.,', 'rules.racc', 29)
|
528
|
+
def _reduce_20(val, _values, result)
|
529
|
+
result = Fabulator::Grammar::Expr::Anchor.new(:end_of_string)
|
530
|
+
result
|
531
|
+
end
|
532
|
+
.,.,
|
533
|
+
|
534
|
+
module_eval(<<'.,.,', 'rules.racc', 31)
|
535
|
+
def _reduce_21(val, _values, result)
|
536
|
+
result = Fabulator::Grammar::Expr::RuleSequence.new(nil, val[0], val[1])
|
537
|
+
result
|
538
|
+
end
|
539
|
+
.,.,
|
540
|
+
|
541
|
+
module_eval(<<'.,.,', 'rules.racc', 32)
|
542
|
+
def _reduce_22(val, _values, result)
|
543
|
+
result = Fabulator::Grammar::Expr::RuleSequence.new(nil, val[0])
|
544
|
+
result
|
545
|
+
end
|
546
|
+
.,.,
|
547
|
+
|
548
|
+
module_eval(<<'.,.,', 'rules.racc', 33)
|
549
|
+
def _reduce_23(val, _values, result)
|
550
|
+
result = Fabulator::Grammar::Expr::RuleSequence.new(val[0], val[1], val[2])
|
551
|
+
result
|
552
|
+
end
|
553
|
+
.,.,
|
554
|
+
|
555
|
+
module_eval(<<'.,.,', 'rules.racc', 34)
|
556
|
+
def _reduce_24(val, _values, result)
|
557
|
+
result = Fabulator::Grammar::Expr::RuleSequence.new(val[0], val[1])
|
558
|
+
result
|
559
|
+
end
|
560
|
+
.,.,
|
561
|
+
|
562
|
+
module_eval(<<'.,.,', 'rules.racc', 36)
|
563
|
+
def _reduce_25(val, _values, result)
|
564
|
+
result = val[0]
|
565
|
+
result
|
566
|
+
end
|
567
|
+
.,.,
|
568
|
+
|
569
|
+
module_eval(<<'.,.,', 'rules.racc', 44)
|
570
|
+
def _reduce_26(val, _values, result)
|
571
|
+
result = [ '?'.to_sym ]
|
572
|
+
result
|
573
|
+
end
|
574
|
+
.,.,
|
575
|
+
|
576
|
+
module_eval(<<'.,.,', 'rules.racc', 45)
|
577
|
+
def _reduce_27(val, _values, result)
|
578
|
+
result = [ :s, val[2] ]
|
579
|
+
result
|
580
|
+
end
|
581
|
+
.,.,
|
582
|
+
|
583
|
+
module_eval(<<'.,.,', 'rules.racc', 46)
|
584
|
+
def _reduce_28(val, _values, result)
|
585
|
+
result = [ 's?'.to_sym, val[3] ]
|
586
|
+
result
|
587
|
+
end
|
588
|
+
.,.,
|
589
|
+
|
590
|
+
module_eval(<<'.,.,', 'rules.racc', 47)
|
591
|
+
def _reduce_29(val, _values, result)
|
592
|
+
result = [ :count, val[1], val[2] ]
|
593
|
+
result
|
594
|
+
end
|
595
|
+
.,.,
|
596
|
+
|
597
|
+
module_eval(<<'.,.,', 'rules.racc', 48)
|
598
|
+
def _reduce_30(val, _values, result)
|
599
|
+
result = [ :range, [ val[1], val[3] ], val[4] ]
|
600
|
+
result
|
601
|
+
end
|
602
|
+
.,.,
|
603
|
+
|
604
|
+
module_eval(<<'.,.,', 'rules.racc', 49)
|
605
|
+
def _reduce_31(val, _values, result)
|
606
|
+
result = [ :upto, val[2], val[3] ]
|
607
|
+
result
|
608
|
+
end
|
609
|
+
.,.,
|
610
|
+
|
611
|
+
module_eval(<<'.,.,', 'rules.racc', 50)
|
612
|
+
def _reduce_32(val, _values, result)
|
613
|
+
result = [ :atleast, val[1],val[3] ]
|
614
|
+
result
|
615
|
+
end
|
616
|
+
.,.,
|
617
|
+
|
618
|
+
# reduce 33 omitted
|
619
|
+
|
620
|
+
# reduce 34 omitted
|
621
|
+
|
622
|
+
module_eval(<<'.,.,', 'rules.racc', 55)
|
623
|
+
def _reduce_35(val, _values, result)
|
624
|
+
result = Fabulator::Grammar::Expr::Text.new(val[0])
|
625
|
+
result
|
626
|
+
end
|
627
|
+
.,.,
|
628
|
+
|
629
|
+
module_eval(<<'.,.,', 'rules.racc', 56)
|
630
|
+
def _reduce_36(val, _values, result)
|
631
|
+
result = val[1]
|
632
|
+
result
|
633
|
+
end
|
634
|
+
.,.,
|
635
|
+
|
636
|
+
module_eval(<<'.,.,', 'rules.racc', 57)
|
637
|
+
def _reduce_37(val, _values, result)
|
638
|
+
result = Fabulator::Grammar::Expr::RuleRef.new(val[0])
|
639
|
+
result
|
640
|
+
end
|
641
|
+
.,.,
|
642
|
+
|
643
|
+
# reduce 38 omitted
|
644
|
+
|
645
|
+
# reduce 39 omitted
|
646
|
+
|
647
|
+
# reduce 40 omitted
|
648
|
+
|
649
|
+
# reduce 41 omitted
|
650
|
+
|
651
|
+
# reduce 42 omitted
|
652
|
+
|
653
|
+
# reduce 43 omitted
|
654
|
+
|
655
|
+
# reduce 44 omitted
|
656
|
+
|
657
|
+
# reduce 45 omitted
|
658
|
+
|
659
|
+
# reduce 46 omitted
|
660
|
+
|
661
|
+
def _reduce_none(val, _values, result)
|
662
|
+
val[0]
|
663
|
+
end
|
664
|
+
|
665
|
+
end # class RuleParser
|
666
|
+
end # module Grammar
|
667
|
+
end # module Fabulator
|