abnftt 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +7 -0
  2. data/abnftt.gemspec +14 -0
  3. data/bin/abnftt +136 -0
  4. data/bin/abnftt~ +135 -0
  5. data/lib/abnf.rb +2586 -0
  6. metadata +48 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3bc3e072613b51decf47f31c6ccbff2af79e403131d889ce6bbc075d097d5af2
4
+ data.tar.gz: 0d17df7192ac612129632e001e348f531f2c483041b961d447837a4dd3755b6f
5
+ SHA512:
6
+ metadata.gz: 729b268fe2df5265d44560cd6dd07dc3a01de87a9d3fca4570953bf920566f35aadd64ba752f83560bf4b47d1404a6146500a0621d95e35416627ef8df5b115a
7
+ data.tar.gz: e319d947ef1f7ce20ece128b8b993d3b7931c4a3985b54ef8d7849ee79420a4d23b071cf6baa784062b92fec0ca74f4aea42d8e81829ba83f3911b71ede587fa
@@ -0,0 +1,14 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "abnftt"
3
+ s.version = "0.1.1"
4
+ s.summary = "RFC 5234+7405 ABNF to Treetop"
5
+ s.description = %q{Less shifty support for tools based on IETF's ABNF}
6
+ s.author = "Carsten Bormann"
7
+ s.email = "cabo@tzi.org"
8
+ s.license = "MIT"
9
+ s.homepage = "http://github.com/cabo/abnftt"
10
+ s.files = Dir['lib/**/*.rb'] + %w(abnftt.gemspec) + Dir['bin/*']
11
+ s.executables = Dir['bin/*'].map {|x| File.basename(x)}
12
+ s.required_ruby_version = '>= 2.3'
13
+ s.require_paths = ["lib"]
14
+ end
@@ -0,0 +1,136 @@
1
+ #!/usr/bin/env ruby -Ku
2
+
3
+ require 'pp'
4
+ require 'yaml'
5
+ require 'treetop'
6
+
7
+ Encoding.default_external = Encoding::UTF_8
8
+
9
+ require 'abnf'
10
+
11
+ class Treetop::Runtime::SyntaxNode
12
+ def clean_abnf
13
+ if elements
14
+ elements.map {|el| el.clean_abnf}.join
15
+ else
16
+ text_value
17
+ end
18
+ end
19
+ def ast
20
+ fail "undefined_ast #{inspect}"
21
+ end
22
+ def ast_from_percent(base, first, second)
23
+ c1 = first.to_i(base).chr(Encoding::UTF_8)
24
+ case second[0]
25
+ when nil
26
+ ["cs", c1]
27
+ when "-"
28
+ c2 = second[1..-1].to_i(base).chr(Encoding::UTF_8)
29
+ ["char-range", c1, c2]
30
+ when "."
31
+ el = second.split(".")
32
+ el[0] = first
33
+ ["cs", el.map {|c| c.to_i(base).chr(Encoding::UTF_8)}.join]
34
+ else
35
+ fail "ast_from_percent"
36
+ end
37
+ end
38
+ end
39
+
40
+ def to_treetop(ast, ofn)
41
+ modname = File.basename(ofn).sub("-", "_").sub(/[^_a-zA-Z]/, "").upcase
42
+ <<~EOS
43
+ # Encoding: UTF-8
44
+ grammar #{modname}
45
+ #{ast.map {|x| to_treetop0(x)}.join}
46
+ end
47
+ EOS
48
+ end
49
+ def to_treetop0(ast)
50
+ fail ast.inspect unless ast[0] == "="
51
+ <<~EOS
52
+ rule #{to_treetop1(ast[1])}
53
+ #{to_treetop1(ast[2])}
54
+ end
55
+ EOS
56
+ end
57
+ FIXUP_NAMES = Hash.new {|h, k| k}
58
+ FIXUP_NAMES.merge!({
59
+ "rule" => "r__rule",
60
+ })
61
+ def to_treetop1(ast)
62
+ case ast
63
+ when String
64
+ FIXUP_NAMES[ast].gsub("-", "_")
65
+ when Array
66
+ case ast[0]
67
+ when "alt" # ["alt", *a]
68
+ "(#{ast[1..-1].map {|x| to_treetop1(x)}.join(" / ")})"
69
+ when "seq" # ["seq", *a]
70
+ "(#{ast[1..-1].map {|x| to_treetop1(x)}.join(" ")})"
71
+ when "rep" # ["rep", s, e, a]
72
+ t = to_treetop1(ast[3]) || "@@@"
73
+ case [ast[1], ast[2]]
74
+ when [0, 1]
75
+ t + "?"
76
+ when [0, true]
77
+ t + "*"
78
+ when [1, true]
79
+ t + "+"
80
+ else
81
+ t + " #{ast[1]}..#{ast[2] == true ? '' : ast[2]}"
82
+ end
83
+ when "prose" # ["prose", text]
84
+ fail "prose not implemented #{ast.inspect}"
85
+ when "ci" # ["ci", text]
86
+ s = ast[1]
87
+ if s =~ /\A[^A-Za-z]*\z/
88
+ s.inspect
89
+ else
90
+ s.inspect << "i" # could do this always, but reduce noise
91
+ end
92
+ when "cs" # ["cs", text]
93
+ ast[1].inspect
94
+ when "char-range" # ["char-range", c1, c2]
95
+ c1 = Regexp.quote(ast[1])
96
+ c2 = Regexp.quote(ast[2])
97
+ "[#{c1}-#{c2}]" # XXX does that always work
98
+ when "im" # ["im", a, text]
99
+ to_treetop1(ast[1]) + " " + ast[2]
100
+ else
101
+ fail "to_treetop(#{ast.inspect})"
102
+ end
103
+ else
104
+ fail "to_treetop(#{ast.inspect})"
105
+ end
106
+ end
107
+
108
+ unless fn = ARGV[0]
109
+ warn "Usage: abnftt grammar.abnftt"
110
+ exit 1
111
+ end
112
+ outfn = fn.sub(/\.abnftt\z/, "")
113
+
114
+ parser = ABNFParser.new
115
+ abnf_file = File.read(fn)
116
+ ast = parser.parse abnf_file
117
+ if ast
118
+ # p ast
119
+ File.open("#{outfn}.yaml", "w") do |f|
120
+ f.puts ast.ast.to_yaml
121
+ end
122
+ # pp ast.ast
123
+ File.open("#{outfn}.treetop", "w") do |f|
124
+ f.puts to_treetop(ast.ast, outfn)
125
+ end
126
+ File.open("#{outfn}.abnf", "w") do |f|
127
+ f.puts ast.clean_abnf.lines.map(&:rstrip).join("\n")
128
+ end
129
+ else
130
+
131
+ puts parser.failure_reason
132
+ parser.failure_reason =~ /^(Expected .+) after/m
133
+ puts "#{$1.gsub("\n", '<<<NEWLINE>>>')}:"
134
+ puts abnf_file.lines.to_a[parser.failure_line - 1]
135
+ puts "#{'~' * (parser.failure_column - 1)}^"
136
+ end
@@ -0,0 +1,135 @@
1
+ #!/usr/bin/env ruby -Ku
2
+
3
+ require 'pp'
4
+ require 'yaml'
5
+ require 'treetop'
6
+
7
+ Encoding.default_external = Encoding::UTF_8
8
+
9
+ require 'abnf'
10
+
11
+ class Treetop::Runtime::SyntaxNode
12
+ def clean_abnf
13
+ if elements
14
+ elements.map {|el| el.clean_abnf}.join
15
+ else
16
+ text_value
17
+ end
18
+ end
19
+ def ast
20
+ fail "undefined_ast #{inspect}"
21
+ end
22
+ def ast_from_percent(base, first, second)
23
+ c1 = first.to_i(base).chr(Encoding::UTF_8)
24
+ case second[0]
25
+ when nil
26
+ ["cs", c1]
27
+ when "-"
28
+ c2 = second[1..-1].to_i(base).chr(Encoding::UTF_8)
29
+ ["char-range", c1, c2]
30
+ when "."
31
+ el = second.split(".")
32
+ el[0] = first
33
+ ["cs", el.map {|c| c.to_i(base).chr(Encoding::UTF_8)}.join]
34
+ else
35
+ fail "ast_from_percent"
36
+ end
37
+ end
38
+ end
39
+
40
+ def to_treetop(ast)
41
+ <<~EOS
42
+ # Encoding: UTF-8
43
+ grammar TESTME
44
+ #{ast.map {|x| to_treetop0(x)}.join}
45
+ end
46
+ EOS
47
+ end
48
+ def to_treetop0(ast)
49
+ fail ast.inspect unless ast[0] == "="
50
+ <<~EOS
51
+ rule #{to_treetop1(ast[1])}
52
+ #{to_treetop1(ast[2])}
53
+ end
54
+ EOS
55
+ end
56
+ FIXUP_NAMES = Hash.new {|h, k| k}
57
+ FIXUP_NAMES.merge!({
58
+ "rule" => "r__rule",
59
+ })
60
+ def to_treetop1(ast)
61
+ case ast
62
+ when String
63
+ FIXUP_NAMES[ast].gsub("-", "_")
64
+ when Array
65
+ case ast[0]
66
+ when "alt" # ["alt", *a]
67
+ "(#{ast[1..-1].map {|x| to_treetop1(x)}.join(" / ")})"
68
+ when "seq" # ["seq", *a]
69
+ "(#{ast[1..-1].map {|x| to_treetop1(x)}.join(" ")})"
70
+ when "rep" # ["rep", s, e, a]
71
+ t = to_treetop1(ast[3]) || "@@@"
72
+ case [ast[1], ast[2]]
73
+ when [0, 1]
74
+ t + "?"
75
+ when [0, true]
76
+ t + "*"
77
+ when [1, true]
78
+ t + "+"
79
+ else
80
+ t + " #{ast[1]}..#{ast[2] == true ? '' : ast[2]}"
81
+ end
82
+ when "prose" # ["prose", text]
83
+ fail "prose not implemented #{ast.inspect}"
84
+ when "ci" # ["ci", text]
85
+ s = ast[1]
86
+ if s =~ /\A[^A-Za-z]*\z/
87
+ s.inspect
88
+ else
89
+ s.inspect << "i" # could do this always, but reduce noise
90
+ end
91
+ when "cs" # ["cs", text]
92
+ ast[1].inspect
93
+ when "char-range" # ["char-range", c1, c2]
94
+ c1 = Regexp.quote(ast[1])
95
+ c2 = Regexp.quote(ast[2])
96
+ "[#{c1}-#{c2}]" # XXX does that always work
97
+ when "im" # ["im", a, text]
98
+ to_treetop1(ast[1]) + " " + ast[2]
99
+ else
100
+ fail "to_treetop(#{ast.inspect})"
101
+ end
102
+ else
103
+ fail "to_treetop(#{ast.inspect})"
104
+ end
105
+ end
106
+
107
+ unless fn = ARGV[0]
108
+ warn "Usage: abnftt grammar.abnftt"
109
+ exit 1
110
+ end
111
+ outfn = fn.sub(/\.abnftt\z/, "")
112
+
113
+ parser = ABNFParser.new
114
+ abnf_file = File.read(fn)
115
+ ast = parser.parse abnf_file
116
+ if ast
117
+ # p ast
118
+ File.open("#{outfn}.yaml", "w") do |f|
119
+ f.puts ast.ast.to_yaml
120
+ end
121
+ # pp ast.ast
122
+ File.open("#{outfn}.treetop", "w") do |f|
123
+ f.puts to_treetop(ast.ast)
124
+ end
125
+ File.open("#{outfn}.abnf", "w") do |f|
126
+ f.puts ast.clean_abnf
127
+ end
128
+ else
129
+
130
+ puts parser.failure_reason
131
+ parser.failure_reason =~ /^(Expected .+) after/m
132
+ puts "#{$1.gsub("\n", '<<<NEWLINE>>>')}:"
133
+ puts abnf_file.lines.to_a[parser.failure_line - 1]
134
+ puts "#{'~' * (parser.failure_column - 1)}^"
135
+ end
@@ -0,0 +1,2586 @@
1
+ # Autogenerated from a Treetop grammar. Edits may be lost.
2
+
3
+
4
+ module ABNF
5
+ include Treetop::Runtime
6
+
7
+ def root
8
+ @root ||= :rulelist
9
+ end
10
+
11
+ module Rulelist0
12
+ def ast() elements.map {|e| e.ast }.compact end
13
+ end
14
+
15
+ def _nt_rulelist
16
+ start_index = index
17
+ if node_cache[:rulelist].has_key?(index)
18
+ cached = node_cache[:rulelist][index]
19
+ if cached
20
+ node_cache[:rulelist][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
21
+ @index = cached.interval.end
22
+ end
23
+ return cached
24
+ end
25
+
26
+ s0, i0 = [], index
27
+ loop do
28
+ i1 = index
29
+ r2 = _nt_abnf_rule
30
+ if r2
31
+ r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
32
+ r1 = r2
33
+ else
34
+ r3 = _nt_empty_line
35
+ if r3
36
+ r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
37
+ r1 = r3
38
+ else
39
+ @index = i1
40
+ r1 = nil
41
+ end
42
+ end
43
+ if r1
44
+ s0 << r1
45
+ else
46
+ break
47
+ end
48
+ end
49
+ if s0.empty?
50
+ @index = i0
51
+ r0 = nil
52
+ else
53
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
54
+ r0.extend(Rulelist0)
55
+ r0.extend(Rulelist0)
56
+ end
57
+
58
+ node_cache[:rulelist][start_index] = r0
59
+
60
+ r0
61
+ end
62
+
63
+ module EmptyLine0
64
+ def c_nl
65
+ elements[1]
66
+ end
67
+ end
68
+
69
+ module EmptyLine1
70
+ def ast() nil end
71
+ end
72
+
73
+ def _nt_empty_line
74
+ start_index = index
75
+ if node_cache[:empty_line].has_key?(index)
76
+ cached = node_cache[:empty_line][index]
77
+ if cached
78
+ node_cache[:empty_line][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
79
+ @index = cached.interval.end
80
+ end
81
+ return cached
82
+ end
83
+
84
+ i0, s0 = index, []
85
+ s1, i1 = [], index
86
+ loop do
87
+ r2 = _nt_c_wsp
88
+ if r2
89
+ s1 << r2
90
+ else
91
+ break
92
+ end
93
+ end
94
+ r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
95
+ s0 << r1
96
+ if r1
97
+ r3 = _nt_c_nl
98
+ s0 << r3
99
+ end
100
+ if s0.last
101
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
102
+ r0.extend(EmptyLine0)
103
+ r0.extend(EmptyLine1)
104
+ else
105
+ @index = i0
106
+ r0 = nil
107
+ end
108
+
109
+ node_cache[:empty_line][start_index] = r0
110
+
111
+ r0
112
+ end
113
+
114
+ module AbnfRule0
115
+ def rulename
116
+ elements[0]
117
+ end
118
+
119
+ def defined_as
120
+ elements[1]
121
+ end
122
+
123
+ def alternation
124
+ elements[2]
125
+ end
126
+
127
+ def c_nl
128
+ elements[3]
129
+ end
130
+ end
131
+
132
+ module AbnfRule1
133
+ def ast() [defined_as.ast, rulename.ast, alternation.ast] end
134
+ end
135
+
136
+ def _nt_abnf_rule
137
+ start_index = index
138
+ if node_cache[:abnf_rule].has_key?(index)
139
+ cached = node_cache[:abnf_rule][index]
140
+ if cached
141
+ node_cache[:abnf_rule][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
142
+ @index = cached.interval.end
143
+ end
144
+ return cached
145
+ end
146
+
147
+ i0, s0 = index, []
148
+ r1 = _nt_rulename
149
+ s0 << r1
150
+ if r1
151
+ r2 = _nt_defined_as
152
+ s0 << r2
153
+ if r2
154
+ r3 = _nt_alternation
155
+ s0 << r3
156
+ if r3
157
+ r4 = _nt_c_nl
158
+ s0 << r4
159
+ end
160
+ end
161
+ end
162
+ if s0.last
163
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
164
+ r0.extend(AbnfRule0)
165
+ r0.extend(AbnfRule1)
166
+ else
167
+ @index = i0
168
+ r0 = nil
169
+ end
170
+
171
+ node_cache[:abnf_rule][start_index] = r0
172
+
173
+ r0
174
+ end
175
+
176
+ module Rulename0
177
+ def ALPHA
178
+ elements[0]
179
+ end
180
+
181
+ end
182
+
183
+ module Rulename1
184
+ def ast() text_value end
185
+ end
186
+
187
+ def _nt_rulename
188
+ start_index = index
189
+ if node_cache[:rulename].has_key?(index)
190
+ cached = node_cache[:rulename][index]
191
+ if cached
192
+ node_cache[:rulename][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
193
+ @index = cached.interval.end
194
+ end
195
+ return cached
196
+ end
197
+
198
+ i0, s0 = index, []
199
+ r1 = _nt_ALPHA
200
+ s0 << r1
201
+ if r1
202
+ s2, i2 = [], index
203
+ loop do
204
+ i3 = index
205
+ r4 = _nt_ALPHA
206
+ if r4
207
+ r4 = SyntaxNode.new(input, (index-1)...index) if r4 == true
208
+ r3 = r4
209
+ else
210
+ r5 = _nt_DIGIT
211
+ if r5
212
+ r5 = SyntaxNode.new(input, (index-1)...index) if r5 == true
213
+ r3 = r5
214
+ else
215
+ if (match_len = has_terminal?("-", false, index))
216
+ r6 = true
217
+ @index += match_len
218
+ else
219
+ terminal_parse_failure('"-"')
220
+ r6 = nil
221
+ end
222
+ if r6
223
+ r6 = SyntaxNode.new(input, (index-1)...index) if r6 == true
224
+ r3 = r6
225
+ else
226
+ @index = i3
227
+ r3 = nil
228
+ end
229
+ end
230
+ end
231
+ if r3
232
+ s2 << r3
233
+ else
234
+ break
235
+ end
236
+ end
237
+ r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
238
+ s0 << r2
239
+ end
240
+ if s0.last
241
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
242
+ r0.extend(Rulename0)
243
+ r0.extend(Rulename1)
244
+ else
245
+ @index = i0
246
+ r0 = nil
247
+ end
248
+
249
+ node_cache[:rulename][start_index] = r0
250
+
251
+ r0
252
+ end
253
+
254
+ module DefinedAs0
255
+ end
256
+
257
+ module DefinedAs1
258
+ def ast() elements[1].text_value end
259
+ end
260
+
261
+ def _nt_defined_as
262
+ start_index = index
263
+ if node_cache[:defined_as].has_key?(index)
264
+ cached = node_cache[:defined_as][index]
265
+ if cached
266
+ node_cache[:defined_as][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
267
+ @index = cached.interval.end
268
+ end
269
+ return cached
270
+ end
271
+
272
+ i0, s0 = index, []
273
+ s1, i1 = [], index
274
+ loop do
275
+ r2 = _nt_c_wsp
276
+ if r2
277
+ s1 << r2
278
+ else
279
+ break
280
+ end
281
+ end
282
+ r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
283
+ s0 << r1
284
+ if r1
285
+ i3 = index
286
+ if (match_len = has_terminal?("=", false, index))
287
+ r4 = true
288
+ @index += match_len
289
+ else
290
+ terminal_parse_failure('"="')
291
+ r4 = nil
292
+ end
293
+ if r4
294
+ r4 = SyntaxNode.new(input, (index-1)...index) if r4 == true
295
+ r3 = r4
296
+ else
297
+ if (match_len = has_terminal?("=/", false, index))
298
+ r5 = instantiate_node(SyntaxNode,input, index...(index + match_len))
299
+ @index += match_len
300
+ else
301
+ terminal_parse_failure('"=/"')
302
+ r5 = nil
303
+ end
304
+ if r5
305
+ r5 = SyntaxNode.new(input, (index-1)...index) if r5 == true
306
+ r3 = r5
307
+ else
308
+ @index = i3
309
+ r3 = nil
310
+ end
311
+ end
312
+ s0 << r3
313
+ if r3
314
+ s6, i6 = [], index
315
+ loop do
316
+ r7 = _nt_c_wsp
317
+ if r7
318
+ s6 << r7
319
+ else
320
+ break
321
+ end
322
+ end
323
+ r6 = instantiate_node(SyntaxNode,input, i6...index, s6)
324
+ s0 << r6
325
+ end
326
+ end
327
+ if s0.last
328
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
329
+ r0.extend(DefinedAs0)
330
+ r0.extend(DefinedAs1)
331
+ else
332
+ @index = i0
333
+ r0 = nil
334
+ end
335
+
336
+ node_cache[:defined_as][start_index] = r0
337
+
338
+ r0
339
+ end
340
+
341
+ module CWsp0
342
+ def c_nl
343
+ elements[0]
344
+ end
345
+
346
+ def WSP
347
+ elements[1]
348
+ end
349
+ end
350
+
351
+ module CWsp1
352
+ def ast() nil end
353
+ end
354
+
355
+ def _nt_c_wsp
356
+ start_index = index
357
+ if node_cache[:c_wsp].has_key?(index)
358
+ cached = node_cache[:c_wsp][index]
359
+ if cached
360
+ node_cache[:c_wsp][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
361
+ @index = cached.interval.end
362
+ end
363
+ return cached
364
+ end
365
+
366
+ i0 = index
367
+ r1 = _nt_WSP
368
+ if r1
369
+ r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
370
+ r0 = r1
371
+ r0.extend(CWsp1)
372
+ r0.extend(CWsp1)
373
+ else
374
+ i2, s2 = index, []
375
+ r3 = _nt_c_nl
376
+ s2 << r3
377
+ if r3
378
+ r4 = _nt_WSP
379
+ s2 << r4
380
+ end
381
+ if s2.last
382
+ r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
383
+ r2.extend(CWsp0)
384
+ else
385
+ @index = i2
386
+ r2 = nil
387
+ end
388
+ if r2
389
+ r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
390
+ r0 = r2
391
+ r0.extend(CWsp1)
392
+ r0.extend(CWsp1)
393
+ else
394
+ @index = i0
395
+ r0 = nil
396
+ end
397
+ end
398
+
399
+ node_cache[:c_wsp][start_index] = r0
400
+
401
+ r0
402
+ end
403
+
404
+ module CNl0
405
+ def ast() nil end
406
+ end
407
+
408
+ def _nt_c_nl
409
+ start_index = index
410
+ if node_cache[:c_nl].has_key?(index)
411
+ cached = node_cache[:c_nl][index]
412
+ if cached
413
+ node_cache[:c_nl][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
414
+ @index = cached.interval.end
415
+ end
416
+ return cached
417
+ end
418
+
419
+ i0 = index
420
+ r1 = _nt_comment
421
+ if r1
422
+ r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
423
+ r0 = r1
424
+ r0.extend(CNl0)
425
+ r0.extend(CNl0)
426
+ else
427
+ r2 = _nt_CRLF
428
+ if r2
429
+ r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
430
+ r0 = r2
431
+ r0.extend(CNl0)
432
+ r0.extend(CNl0)
433
+ else
434
+ @index = i0
435
+ r0 = nil
436
+ end
437
+ end
438
+
439
+ node_cache[:c_nl][start_index] = r0
440
+
441
+ r0
442
+ end
443
+
444
+ module Comment0
445
+ def CRLF
446
+ elements[2]
447
+ end
448
+ end
449
+
450
+ module Comment1
451
+ def ast() nil end
452
+ end
453
+
454
+ def _nt_comment
455
+ start_index = index
456
+ if node_cache[:comment].has_key?(index)
457
+ cached = node_cache[:comment][index]
458
+ if cached
459
+ node_cache[:comment][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
460
+ @index = cached.interval.end
461
+ end
462
+ return cached
463
+ end
464
+
465
+ i0, s0 = index, []
466
+ if (match_len = has_terminal?(";", false, index))
467
+ r1 = true
468
+ @index += match_len
469
+ else
470
+ terminal_parse_failure('";"')
471
+ r1 = nil
472
+ end
473
+ s0 << r1
474
+ if r1
475
+ s2, i2 = [], index
476
+ loop do
477
+ i3 = index
478
+ r4 = _nt_WSP
479
+ if r4
480
+ r4 = SyntaxNode.new(input, (index-1)...index) if r4 == true
481
+ r3 = r4
482
+ else
483
+ r5 = _nt_VCHAR
484
+ if r5
485
+ r5 = SyntaxNode.new(input, (index-1)...index) if r5 == true
486
+ r3 = r5
487
+ else
488
+ @index = i3
489
+ r3 = nil
490
+ end
491
+ end
492
+ if r3
493
+ s2 << r3
494
+ else
495
+ break
496
+ end
497
+ end
498
+ r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
499
+ s0 << r2
500
+ if r2
501
+ r6 = _nt_CRLF
502
+ s0 << r6
503
+ end
504
+ end
505
+ if s0.last
506
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
507
+ r0.extend(Comment0)
508
+ r0.extend(Comment1)
509
+ else
510
+ @index = i0
511
+ r0 = nil
512
+ end
513
+
514
+ node_cache[:comment][start_index] = r0
515
+
516
+ r0
517
+ end
518
+
519
+ module Alternation0
520
+ def concatenation
521
+ elements[2]
522
+ end
523
+ end
524
+
525
+ module Alternation1
526
+ def concatenation
527
+ elements[0]
528
+ end
529
+
530
+ end
531
+
532
+ module Alternation2
533
+ def ast
534
+ conc2 = elements[1].elements.map {|x| x.concatenation}
535
+ # warn ["alt!!!", concatenation, conc2].inspect
536
+ e = [elements[0], *conc2].map {|e| e.ast}.compact
537
+ e.size == 1 ? e[0] : ["alt", *e]
538
+ end
539
+ end
540
+
541
+ def _nt_alternation
542
+ start_index = index
543
+ if node_cache[:alternation].has_key?(index)
544
+ cached = node_cache[:alternation][index]
545
+ if cached
546
+ node_cache[:alternation][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
547
+ @index = cached.interval.end
548
+ end
549
+ return cached
550
+ end
551
+
552
+ i0, s0 = index, []
553
+ r1 = _nt_concatenation
554
+ s0 << r1
555
+ if r1
556
+ s2, i2 = [], index
557
+ loop do
558
+ i3, s3 = index, []
559
+ if (match_len = has_terminal?("/", false, index))
560
+ r4 = true
561
+ @index += match_len
562
+ else
563
+ terminal_parse_failure('"/"')
564
+ r4 = nil
565
+ end
566
+ s3 << r4
567
+ if r4
568
+ s5, i5 = [], index
569
+ loop do
570
+ r6 = _nt_c_wsp
571
+ if r6
572
+ s5 << r6
573
+ else
574
+ break
575
+ end
576
+ end
577
+ r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
578
+ s3 << r5
579
+ if r5
580
+ r7 = _nt_concatenation
581
+ s3 << r7
582
+ end
583
+ end
584
+ if s3.last
585
+ r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
586
+ r3.extend(Alternation0)
587
+ else
588
+ @index = i3
589
+ r3 = nil
590
+ end
591
+ if r3
592
+ s2 << r3
593
+ else
594
+ break
595
+ end
596
+ end
597
+ r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
598
+ s0 << r2
599
+ end
600
+ if s0.last
601
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
602
+ r0.extend(Alternation1)
603
+ r0.extend(Alternation2)
604
+ else
605
+ @index = i0
606
+ r0 = nil
607
+ end
608
+
609
+ node_cache[:alternation][start_index] = r0
610
+
611
+ r0
612
+ end
613
+
614
+ module Concatenation0
615
+ def repetition
616
+ elements[1]
617
+ end
618
+ end
619
+
620
+ module Concatenation1
621
+ def repetition
622
+ elements[0]
623
+ end
624
+
625
+ end
626
+
627
+ module Concatenation2
628
+ def inline_module
629
+ elements[1]
630
+ end
631
+
632
+ end
633
+
634
+ module Concatenation3
635
+ def ast
636
+ rep2 = elements[0].elements[1].elements.map {|x| x.repetition}
637
+ # warn ["seq!!!", elements.size, elements[0], "bar", elements[1].elements].inspect
638
+ e = [elements[0].elements[0], *rep2].map {|e| e.ast}.compact
639
+ inline_module.ast_wrap(e.size == 1 ? e[0] : ["seq", *e])
640
+ end
641
+ def clean_abnf
642
+ elements[0].clean_abnf + elements[2].text_value
643
+ end
644
+ end
645
+
646
+ def _nt_concatenation
647
+ start_index = index
648
+ if node_cache[:concatenation].has_key?(index)
649
+ cached = node_cache[:concatenation][index]
650
+ if cached
651
+ node_cache[:concatenation][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
652
+ @index = cached.interval.end
653
+ end
654
+ return cached
655
+ end
656
+
657
+ i0, s0 = index, []
658
+ i1, s1 = index, []
659
+ r2 = _nt_repetition
660
+ s1 << r2
661
+ if r2
662
+ s3, i3 = [], index
663
+ loop do
664
+ i4, s4 = index, []
665
+ s5, i5 = [], index
666
+ loop do
667
+ r6 = _nt_c_wsp
668
+ if r6
669
+ s5 << r6
670
+ else
671
+ break
672
+ end
673
+ end
674
+ if s5.empty?
675
+ @index = i5
676
+ r5 = nil
677
+ else
678
+ r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
679
+ end
680
+ s4 << r5
681
+ if r5
682
+ r7 = _nt_repetition
683
+ s4 << r7
684
+ end
685
+ if s4.last
686
+ r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
687
+ r4.extend(Concatenation0)
688
+ else
689
+ @index = i4
690
+ r4 = nil
691
+ end
692
+ if r4
693
+ s3 << r4
694
+ else
695
+ break
696
+ end
697
+ end
698
+ r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
699
+ s1 << r3
700
+ if r3
701
+ s8, i8 = [], index
702
+ loop do
703
+ r9 = _nt_c_wsp
704
+ if r9
705
+ s8 << r9
706
+ else
707
+ break
708
+ end
709
+ end
710
+ r8 = instantiate_node(SyntaxNode,input, i8...index, s8)
711
+ s1 << r8
712
+ end
713
+ end
714
+ if s1.last
715
+ r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
716
+ r1.extend(Concatenation1)
717
+ else
718
+ @index = i1
719
+ r1 = nil
720
+ end
721
+ s0 << r1
722
+ if r1
723
+ r10 = _nt_inline_module
724
+ s0 << r10
725
+ if r10
726
+ s11, i11 = [], index
727
+ loop do
728
+ r12 = _nt_c_wsp
729
+ if r12
730
+ s11 << r12
731
+ else
732
+ break
733
+ end
734
+ end
735
+ r11 = instantiate_node(SyntaxNode,input, i11...index, s11)
736
+ s0 << r11
737
+ end
738
+ end
739
+ if s0.last
740
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
741
+ r0.extend(Concatenation2)
742
+ r0.extend(Concatenation3)
743
+ else
744
+ @index = i0
745
+ r0 = nil
746
+ end
747
+
748
+ node_cache[:concatenation][start_index] = r0
749
+
750
+ r0
751
+ end
752
+
753
+ module Repetition0
754
+ def repeat_c
755
+ elements[0]
756
+ end
757
+
758
+ def element
759
+ elements[1]
760
+ end
761
+ end
762
+
763
+ module Repetition1
764
+ def ast
765
+ elements[0].ast_wrap(element.ast)
766
+ end
767
+ end
768
+
769
+ def _nt_repetition
770
+ start_index = index
771
+ if node_cache[:repetition].has_key?(index)
772
+ cached = node_cache[:repetition][index]
773
+ if cached
774
+ node_cache[:repetition][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
775
+ @index = cached.interval.end
776
+ end
777
+ return cached
778
+ end
779
+
780
+ i0, s0 = index, []
781
+ r1 = _nt_repeat_c
782
+ s0 << r1
783
+ if r1
784
+ r2 = _nt_element
785
+ s0 << r2
786
+ end
787
+ if s0.last
788
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
789
+ r0.extend(Repetition0)
790
+ r0.extend(Repetition1)
791
+ else
792
+ @index = i0
793
+ r0 = nil
794
+ end
795
+
796
+ node_cache[:repetition][start_index] = r0
797
+
798
+ r0
799
+ end
800
+
801
+ module RepeatC0
802
+ end
803
+
804
+ module RepeatC1
805
+ def ast_wrap(a)
806
+ s = 1
807
+ e = 1
808
+ el = elements.map {|e| e.text_value}
809
+ if el[1] == "*"
810
+ if el[0] != ""
811
+ s = el[0].to_i
812
+ else
813
+ s = 0
814
+ end
815
+ if el[2] != ""
816
+ e = el[2].to_i
817
+ else
818
+ e = true
819
+ end
820
+ end
821
+ occ = [s, e]
822
+ if occ == [1, 1]
823
+ a
824
+ else
825
+ ["rep", s, e, a]
826
+ end
827
+ end
828
+ end
829
+
830
+ def _nt_repeat_c
831
+ start_index = index
832
+ if node_cache[:repeat_c].has_key?(index)
833
+ cached = node_cache[:repeat_c][index]
834
+ if cached
835
+ node_cache[:repeat_c][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
836
+ @index = cached.interval.end
837
+ end
838
+ return cached
839
+ end
840
+
841
+ i0 = index
842
+ i1, s1 = index, []
843
+ s2, i2 = [], index
844
+ loop do
845
+ r3 = _nt_DIGIT
846
+ if r3
847
+ s2 << r3
848
+ else
849
+ break
850
+ end
851
+ end
852
+ r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
853
+ s1 << r2
854
+ if r2
855
+ if (match_len = has_terminal?("*", false, index))
856
+ r4 = true
857
+ @index += match_len
858
+ else
859
+ terminal_parse_failure('"*"')
860
+ r4 = nil
861
+ end
862
+ s1 << r4
863
+ if r4
864
+ s5, i5 = [], index
865
+ loop do
866
+ r6 = _nt_DIGIT
867
+ if r6
868
+ s5 << r6
869
+ else
870
+ break
871
+ end
872
+ end
873
+ r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
874
+ s1 << r5
875
+ end
876
+ end
877
+ if s1.last
878
+ r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
879
+ r1.extend(RepeatC0)
880
+ else
881
+ @index = i1
882
+ r1 = nil
883
+ end
884
+ if r1
885
+ r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
886
+ r0 = r1
887
+ r0.extend(RepeatC1)
888
+ r0.extend(RepeatC1)
889
+ else
890
+ s7, i7 = [], index
891
+ loop do
892
+ r8 = _nt_DIGIT
893
+ if r8
894
+ s7 << r8
895
+ else
896
+ break
897
+ end
898
+ end
899
+ r7 = instantiate_node(SyntaxNode,input, i7...index, s7)
900
+ if r7
901
+ r7 = SyntaxNode.new(input, (index-1)...index) if r7 == true
902
+ r0 = r7
903
+ r0.extend(RepeatC1)
904
+ r0.extend(RepeatC1)
905
+ else
906
+ @index = i0
907
+ r0 = nil
908
+ end
909
+ end
910
+
911
+ node_cache[:repeat_c][start_index] = r0
912
+
913
+ r0
914
+ end
915
+
916
+ module Element0
917
+ def ast() elements[0].ast end
918
+ end
919
+
920
+ def _nt_element
921
+ start_index = index
922
+ if node_cache[:element].has_key?(index)
923
+ cached = node_cache[:element][index]
924
+ if cached
925
+ node_cache[:element][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
926
+ @index = cached.interval.end
927
+ end
928
+ return cached
929
+ end
930
+
931
+ i0 = index
932
+ r1 = _nt_rulename
933
+ if r1
934
+ r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
935
+ r0 = r1
936
+ else
937
+ r2 = _nt_group
938
+ if r2
939
+ r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
940
+ r0 = r2
941
+ else
942
+ r3 = _nt_option
943
+ if r3
944
+ r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
945
+ r0 = r3
946
+ else
947
+ r4 = _nt_char_val
948
+ if r4
949
+ r4 = SyntaxNode.new(input, (index-1)...index) if r4 == true
950
+ r0 = r4
951
+ else
952
+ r5 = _nt_num_val
953
+ if r5
954
+ r5 = SyntaxNode.new(input, (index-1)...index) if r5 == true
955
+ r0 = r5
956
+ else
957
+ r6 = _nt_prose_val
958
+ r6.extend(Element0)
959
+ r6.extend(Element0)
960
+ if r6
961
+ r6 = SyntaxNode.new(input, (index-1)...index) if r6 == true
962
+ r0 = r6
963
+ else
964
+ @index = i0
965
+ r0 = nil
966
+ end
967
+ end
968
+ end
969
+ end
970
+ end
971
+ end
972
+
973
+ node_cache[:element][start_index] = r0
974
+
975
+ r0
976
+ end
977
+
978
+ module Group0
979
+ def alternation
980
+ elements[2]
981
+ end
982
+
983
+ end
984
+
985
+ module Group1
986
+ def ast() alternation.ast end
987
+ end
988
+
989
+ def _nt_group
990
+ start_index = index
991
+ if node_cache[:group].has_key?(index)
992
+ cached = node_cache[:group][index]
993
+ if cached
994
+ node_cache[:group][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
995
+ @index = cached.interval.end
996
+ end
997
+ return cached
998
+ end
999
+
1000
+ i0, s0 = index, []
1001
+ if (match_len = has_terminal?("(", false, index))
1002
+ r1 = true
1003
+ @index += match_len
1004
+ else
1005
+ terminal_parse_failure('"("')
1006
+ r1 = nil
1007
+ end
1008
+ s0 << r1
1009
+ if r1
1010
+ s2, i2 = [], index
1011
+ loop do
1012
+ r3 = _nt_c_wsp
1013
+ if r3
1014
+ s2 << r3
1015
+ else
1016
+ break
1017
+ end
1018
+ end
1019
+ r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
1020
+ s0 << r2
1021
+ if r2
1022
+ r4 = _nt_alternation
1023
+ s0 << r4
1024
+ if r4
1025
+ if (match_len = has_terminal?(")", false, index))
1026
+ r5 = true
1027
+ @index += match_len
1028
+ else
1029
+ terminal_parse_failure('")"')
1030
+ r5 = nil
1031
+ end
1032
+ s0 << r5
1033
+ end
1034
+ end
1035
+ end
1036
+ if s0.last
1037
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
1038
+ r0.extend(Group0)
1039
+ r0.extend(Group1)
1040
+ else
1041
+ @index = i0
1042
+ r0 = nil
1043
+ end
1044
+
1045
+ node_cache[:group][start_index] = r0
1046
+
1047
+ r0
1048
+ end
1049
+
1050
+ module Option0
1051
+ def alternation
1052
+ elements[2]
1053
+ end
1054
+
1055
+ end
1056
+
1057
+ module Option1
1058
+ def ast() ["rep", 0, 1, alternation.ast] end
1059
+ end
1060
+
1061
+ def _nt_option
1062
+ start_index = index
1063
+ if node_cache[:option].has_key?(index)
1064
+ cached = node_cache[:option][index]
1065
+ if cached
1066
+ node_cache[:option][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
1067
+ @index = cached.interval.end
1068
+ end
1069
+ return cached
1070
+ end
1071
+
1072
+ i0, s0 = index, []
1073
+ if (match_len = has_terminal?("[", false, index))
1074
+ r1 = true
1075
+ @index += match_len
1076
+ else
1077
+ terminal_parse_failure('"["')
1078
+ r1 = nil
1079
+ end
1080
+ s0 << r1
1081
+ if r1
1082
+ s2, i2 = [], index
1083
+ loop do
1084
+ r3 = _nt_c_wsp
1085
+ if r3
1086
+ s2 << r3
1087
+ else
1088
+ break
1089
+ end
1090
+ end
1091
+ r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
1092
+ s0 << r2
1093
+ if r2
1094
+ r4 = _nt_alternation
1095
+ s0 << r4
1096
+ if r4
1097
+ if (match_len = has_terminal?("]", false, index))
1098
+ r5 = true
1099
+ @index += match_len
1100
+ else
1101
+ terminal_parse_failure('"]"')
1102
+ r5 = nil
1103
+ end
1104
+ s0 << r5
1105
+ end
1106
+ end
1107
+ end
1108
+ if s0.last
1109
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
1110
+ r0.extend(Option0)
1111
+ r0.extend(Option1)
1112
+ else
1113
+ @index = i0
1114
+ r0 = nil
1115
+ end
1116
+
1117
+ node_cache[:option][start_index] = r0
1118
+
1119
+ r0
1120
+ end
1121
+
1122
+ module NumVal0
1123
+ def a
1124
+ elements[1]
1125
+ end
1126
+ end
1127
+
1128
+ module NumVal1
1129
+ def ast() a.ast end
1130
+ end
1131
+
1132
+ def _nt_num_val
1133
+ start_index = index
1134
+ if node_cache[:num_val].has_key?(index)
1135
+ cached = node_cache[:num_val][index]
1136
+ if cached
1137
+ node_cache[:num_val][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
1138
+ @index = cached.interval.end
1139
+ end
1140
+ return cached
1141
+ end
1142
+
1143
+ i0, s0 = index, []
1144
+ if (match_len = has_terminal?("%", false, index))
1145
+ r1 = true
1146
+ @index += match_len
1147
+ else
1148
+ terminal_parse_failure('"%"')
1149
+ r1 = nil
1150
+ end
1151
+ s0 << r1
1152
+ if r1
1153
+ i2 = index
1154
+ r3 = _nt_bin_val
1155
+ if r3
1156
+ r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
1157
+ r2 = r3
1158
+ else
1159
+ r4 = _nt_dec_val
1160
+ if r4
1161
+ r4 = SyntaxNode.new(input, (index-1)...index) if r4 == true
1162
+ r2 = r4
1163
+ else
1164
+ r5 = _nt_hex_val
1165
+ if r5
1166
+ r5 = SyntaxNode.new(input, (index-1)...index) if r5 == true
1167
+ r2 = r5
1168
+ else
1169
+ @index = i2
1170
+ r2 = nil
1171
+ end
1172
+ end
1173
+ end
1174
+ s0 << r2
1175
+ end
1176
+ if s0.last
1177
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
1178
+ r0.extend(NumVal0)
1179
+ r0.extend(NumVal1)
1180
+ else
1181
+ @index = i0
1182
+ r0 = nil
1183
+ end
1184
+
1185
+ node_cache[:num_val][start_index] = r0
1186
+
1187
+ r0
1188
+ end
1189
+
1190
+ module BinVal0
1191
+ end
1192
+
1193
+ module BinVal1
1194
+ def b
1195
+ elements[0]
1196
+ end
1197
+ end
1198
+
1199
+ module BinVal2
1200
+ end
1201
+
1202
+ module BinVal3
1203
+ def c
1204
+ elements[0]
1205
+ end
1206
+ end
1207
+
1208
+ module BinVal4
1209
+ def a
1210
+ elements[1]
1211
+ end
1212
+
1213
+ end
1214
+
1215
+ module BinVal5
1216
+ def ast() ast_from_percent(2, elements[1].text_value, elements[2].text_value) end
1217
+ end
1218
+
1219
+ def _nt_bin_val
1220
+ start_index = index
1221
+ if node_cache[:bin_val].has_key?(index)
1222
+ cached = node_cache[:bin_val][index]
1223
+ if cached
1224
+ node_cache[:bin_val][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
1225
+ @index = cached.interval.end
1226
+ end
1227
+ return cached
1228
+ end
1229
+
1230
+ i0, s0 = index, []
1231
+ if (match_len = has_terminal?("b", false, index))
1232
+ r1 = true
1233
+ @index += match_len
1234
+ else
1235
+ terminal_parse_failure('"b"')
1236
+ r1 = nil
1237
+ end
1238
+ s0 << r1
1239
+ if r1
1240
+ s2, i2 = [], index
1241
+ loop do
1242
+ r3 = _nt_BIT
1243
+ if r3
1244
+ s2 << r3
1245
+ else
1246
+ break
1247
+ end
1248
+ end
1249
+ if s2.empty?
1250
+ @index = i2
1251
+ r2 = nil
1252
+ else
1253
+ r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
1254
+ end
1255
+ s0 << r2
1256
+ if r2
1257
+ i5 = index
1258
+ i6, s6 = index, []
1259
+ s7, i7 = [], index
1260
+ loop do
1261
+ i8, s8 = index, []
1262
+ if (match_len = has_terminal?(".", false, index))
1263
+ r9 = true
1264
+ @index += match_len
1265
+ else
1266
+ terminal_parse_failure('"."')
1267
+ r9 = nil
1268
+ end
1269
+ s8 << r9
1270
+ if r9
1271
+ s10, i10 = [], index
1272
+ loop do
1273
+ r11 = _nt_BIT
1274
+ if r11
1275
+ s10 << r11
1276
+ else
1277
+ break
1278
+ end
1279
+ end
1280
+ if s10.empty?
1281
+ @index = i10
1282
+ r10 = nil
1283
+ else
1284
+ r10 = instantiate_node(SyntaxNode,input, i10...index, s10)
1285
+ end
1286
+ s8 << r10
1287
+ end
1288
+ if s8.last
1289
+ r8 = instantiate_node(SyntaxNode,input, i8...index, s8)
1290
+ r8.extend(BinVal0)
1291
+ else
1292
+ @index = i8
1293
+ r8 = nil
1294
+ end
1295
+ if r8
1296
+ s7 << r8
1297
+ else
1298
+ break
1299
+ end
1300
+ end
1301
+ if s7.empty?
1302
+ @index = i7
1303
+ r7 = nil
1304
+ else
1305
+ r7 = instantiate_node(SyntaxNode,input, i7...index, s7)
1306
+ end
1307
+ s6 << r7
1308
+ if s6.last
1309
+ r6 = instantiate_node(SyntaxNode,input, i6...index, s6)
1310
+ r6.extend(BinVal1)
1311
+ else
1312
+ @index = i6
1313
+ r6 = nil
1314
+ end
1315
+ if r6
1316
+ r6 = SyntaxNode.new(input, (index-1)...index) if r6 == true
1317
+ r5 = r6
1318
+ else
1319
+ i12, s12 = index, []
1320
+ i13, s13 = index, []
1321
+ if (match_len = has_terminal?("-", false, index))
1322
+ r14 = true
1323
+ @index += match_len
1324
+ else
1325
+ terminal_parse_failure('"-"')
1326
+ r14 = nil
1327
+ end
1328
+ s13 << r14
1329
+ if r14
1330
+ s15, i15 = [], index
1331
+ loop do
1332
+ r16 = _nt_BIT
1333
+ if r16
1334
+ s15 << r16
1335
+ else
1336
+ break
1337
+ end
1338
+ end
1339
+ if s15.empty?
1340
+ @index = i15
1341
+ r15 = nil
1342
+ else
1343
+ r15 = instantiate_node(SyntaxNode,input, i15...index, s15)
1344
+ end
1345
+ s13 << r15
1346
+ end
1347
+ if s13.last
1348
+ r13 = instantiate_node(SyntaxNode,input, i13...index, s13)
1349
+ r13.extend(BinVal2)
1350
+ else
1351
+ @index = i13
1352
+ r13 = nil
1353
+ end
1354
+ s12 << r13
1355
+ if s12.last
1356
+ r12 = instantiate_node(SyntaxNode,input, i12...index, s12)
1357
+ r12.extend(BinVal3)
1358
+ else
1359
+ @index = i12
1360
+ r12 = nil
1361
+ end
1362
+ if r12
1363
+ r12 = SyntaxNode.new(input, (index-1)...index) if r12 == true
1364
+ r5 = r12
1365
+ else
1366
+ @index = i5
1367
+ r5 = nil
1368
+ end
1369
+ end
1370
+ if r5
1371
+ r4 = r5
1372
+ else
1373
+ r4 = instantiate_node(SyntaxNode,input, index...index)
1374
+ end
1375
+ s0 << r4
1376
+ end
1377
+ end
1378
+ if s0.last
1379
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
1380
+ r0.extend(BinVal4)
1381
+ r0.extend(BinVal5)
1382
+ else
1383
+ @index = i0
1384
+ r0 = nil
1385
+ end
1386
+
1387
+ node_cache[:bin_val][start_index] = r0
1388
+
1389
+ r0
1390
+ end
1391
+
1392
+ module DecVal0
1393
+ end
1394
+
1395
+ module DecVal1
1396
+ def b
1397
+ elements[0]
1398
+ end
1399
+ end
1400
+
1401
+ module DecVal2
1402
+ end
1403
+
1404
+ module DecVal3
1405
+ def c
1406
+ elements[0]
1407
+ end
1408
+ end
1409
+
1410
+ module DecVal4
1411
+ def a
1412
+ elements[1]
1413
+ end
1414
+
1415
+ end
1416
+
1417
+ module DecVal5
1418
+ def ast() ast_from_percent(10, elements[1].text_value, elements[2].text_value) end
1419
+ end
1420
+
1421
+ def _nt_dec_val
1422
+ start_index = index
1423
+ if node_cache[:dec_val].has_key?(index)
1424
+ cached = node_cache[:dec_val][index]
1425
+ if cached
1426
+ node_cache[:dec_val][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
1427
+ @index = cached.interval.end
1428
+ end
1429
+ return cached
1430
+ end
1431
+
1432
+ i0, s0 = index, []
1433
+ if (match_len = has_terminal?("d", false, index))
1434
+ r1 = true
1435
+ @index += match_len
1436
+ else
1437
+ terminal_parse_failure('"d"')
1438
+ r1 = nil
1439
+ end
1440
+ s0 << r1
1441
+ if r1
1442
+ s2, i2 = [], index
1443
+ loop do
1444
+ r3 = _nt_DIGIT
1445
+ if r3
1446
+ s2 << r3
1447
+ else
1448
+ break
1449
+ end
1450
+ end
1451
+ if s2.empty?
1452
+ @index = i2
1453
+ r2 = nil
1454
+ else
1455
+ r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
1456
+ end
1457
+ s0 << r2
1458
+ if r2
1459
+ i5 = index
1460
+ i6, s6 = index, []
1461
+ s7, i7 = [], index
1462
+ loop do
1463
+ i8, s8 = index, []
1464
+ if (match_len = has_terminal?(".", false, index))
1465
+ r9 = true
1466
+ @index += match_len
1467
+ else
1468
+ terminal_parse_failure('"."')
1469
+ r9 = nil
1470
+ end
1471
+ s8 << r9
1472
+ if r9
1473
+ s10, i10 = [], index
1474
+ loop do
1475
+ r11 = _nt_DIGIT
1476
+ if r11
1477
+ s10 << r11
1478
+ else
1479
+ break
1480
+ end
1481
+ end
1482
+ if s10.empty?
1483
+ @index = i10
1484
+ r10 = nil
1485
+ else
1486
+ r10 = instantiate_node(SyntaxNode,input, i10...index, s10)
1487
+ end
1488
+ s8 << r10
1489
+ end
1490
+ if s8.last
1491
+ r8 = instantiate_node(SyntaxNode,input, i8...index, s8)
1492
+ r8.extend(DecVal0)
1493
+ else
1494
+ @index = i8
1495
+ r8 = nil
1496
+ end
1497
+ if r8
1498
+ s7 << r8
1499
+ else
1500
+ break
1501
+ end
1502
+ end
1503
+ if s7.empty?
1504
+ @index = i7
1505
+ r7 = nil
1506
+ else
1507
+ r7 = instantiate_node(SyntaxNode,input, i7...index, s7)
1508
+ end
1509
+ s6 << r7
1510
+ if s6.last
1511
+ r6 = instantiate_node(SyntaxNode,input, i6...index, s6)
1512
+ r6.extend(DecVal1)
1513
+ else
1514
+ @index = i6
1515
+ r6 = nil
1516
+ end
1517
+ if r6
1518
+ r6 = SyntaxNode.new(input, (index-1)...index) if r6 == true
1519
+ r5 = r6
1520
+ else
1521
+ i12, s12 = index, []
1522
+ i13, s13 = index, []
1523
+ if (match_len = has_terminal?("-", false, index))
1524
+ r14 = true
1525
+ @index += match_len
1526
+ else
1527
+ terminal_parse_failure('"-"')
1528
+ r14 = nil
1529
+ end
1530
+ s13 << r14
1531
+ if r14
1532
+ s15, i15 = [], index
1533
+ loop do
1534
+ r16 = _nt_DIGIT
1535
+ if r16
1536
+ s15 << r16
1537
+ else
1538
+ break
1539
+ end
1540
+ end
1541
+ if s15.empty?
1542
+ @index = i15
1543
+ r15 = nil
1544
+ else
1545
+ r15 = instantiate_node(SyntaxNode,input, i15...index, s15)
1546
+ end
1547
+ s13 << r15
1548
+ end
1549
+ if s13.last
1550
+ r13 = instantiate_node(SyntaxNode,input, i13...index, s13)
1551
+ r13.extend(DecVal2)
1552
+ else
1553
+ @index = i13
1554
+ r13 = nil
1555
+ end
1556
+ s12 << r13
1557
+ if s12.last
1558
+ r12 = instantiate_node(SyntaxNode,input, i12...index, s12)
1559
+ r12.extend(DecVal3)
1560
+ else
1561
+ @index = i12
1562
+ r12 = nil
1563
+ end
1564
+ if r12
1565
+ r12 = SyntaxNode.new(input, (index-1)...index) if r12 == true
1566
+ r5 = r12
1567
+ else
1568
+ @index = i5
1569
+ r5 = nil
1570
+ end
1571
+ end
1572
+ if r5
1573
+ r4 = r5
1574
+ else
1575
+ r4 = instantiate_node(SyntaxNode,input, index...index)
1576
+ end
1577
+ s0 << r4
1578
+ end
1579
+ end
1580
+ if s0.last
1581
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
1582
+ r0.extend(DecVal4)
1583
+ r0.extend(DecVal5)
1584
+ else
1585
+ @index = i0
1586
+ r0 = nil
1587
+ end
1588
+
1589
+ node_cache[:dec_val][start_index] = r0
1590
+
1591
+ r0
1592
+ end
1593
+
1594
+ module HexVal0
1595
+ end
1596
+
1597
+ module HexVal1
1598
+ def b
1599
+ elements[0]
1600
+ end
1601
+ end
1602
+
1603
+ module HexVal2
1604
+ end
1605
+
1606
+ module HexVal3
1607
+ def c
1608
+ elements[0]
1609
+ end
1610
+ end
1611
+
1612
+ module HexVal4
1613
+ def a
1614
+ elements[1]
1615
+ end
1616
+
1617
+ end
1618
+
1619
+ module HexVal5
1620
+ def ast() ast_from_percent(16, elements[1].text_value, elements[2].text_value) end
1621
+ end
1622
+
1623
+ def _nt_hex_val
1624
+ start_index = index
1625
+ if node_cache[:hex_val].has_key?(index)
1626
+ cached = node_cache[:hex_val][index]
1627
+ if cached
1628
+ node_cache[:hex_val][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
1629
+ @index = cached.interval.end
1630
+ end
1631
+ return cached
1632
+ end
1633
+
1634
+ i0, s0 = index, []
1635
+ if (match_len = has_terminal?("x", false, index))
1636
+ r1 = true
1637
+ @index += match_len
1638
+ else
1639
+ terminal_parse_failure('"x"')
1640
+ r1 = nil
1641
+ end
1642
+ s0 << r1
1643
+ if r1
1644
+ s2, i2 = [], index
1645
+ loop do
1646
+ r3 = _nt_HEXDIG
1647
+ if r3
1648
+ s2 << r3
1649
+ else
1650
+ break
1651
+ end
1652
+ end
1653
+ if s2.empty?
1654
+ @index = i2
1655
+ r2 = nil
1656
+ else
1657
+ r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
1658
+ end
1659
+ s0 << r2
1660
+ if r2
1661
+ i5 = index
1662
+ i6, s6 = index, []
1663
+ s7, i7 = [], index
1664
+ loop do
1665
+ i8, s8 = index, []
1666
+ if (match_len = has_terminal?(".", false, index))
1667
+ r9 = true
1668
+ @index += match_len
1669
+ else
1670
+ terminal_parse_failure('"."')
1671
+ r9 = nil
1672
+ end
1673
+ s8 << r9
1674
+ if r9
1675
+ s10, i10 = [], index
1676
+ loop do
1677
+ r11 = _nt_HEXDIG
1678
+ if r11
1679
+ s10 << r11
1680
+ else
1681
+ break
1682
+ end
1683
+ end
1684
+ if s10.empty?
1685
+ @index = i10
1686
+ r10 = nil
1687
+ else
1688
+ r10 = instantiate_node(SyntaxNode,input, i10...index, s10)
1689
+ end
1690
+ s8 << r10
1691
+ end
1692
+ if s8.last
1693
+ r8 = instantiate_node(SyntaxNode,input, i8...index, s8)
1694
+ r8.extend(HexVal0)
1695
+ else
1696
+ @index = i8
1697
+ r8 = nil
1698
+ end
1699
+ if r8
1700
+ s7 << r8
1701
+ else
1702
+ break
1703
+ end
1704
+ end
1705
+ if s7.empty?
1706
+ @index = i7
1707
+ r7 = nil
1708
+ else
1709
+ r7 = instantiate_node(SyntaxNode,input, i7...index, s7)
1710
+ end
1711
+ s6 << r7
1712
+ if s6.last
1713
+ r6 = instantiate_node(SyntaxNode,input, i6...index, s6)
1714
+ r6.extend(HexVal1)
1715
+ else
1716
+ @index = i6
1717
+ r6 = nil
1718
+ end
1719
+ if r6
1720
+ r6 = SyntaxNode.new(input, (index-1)...index) if r6 == true
1721
+ r5 = r6
1722
+ else
1723
+ i12, s12 = index, []
1724
+ i13, s13 = index, []
1725
+ if (match_len = has_terminal?("-", false, index))
1726
+ r14 = true
1727
+ @index += match_len
1728
+ else
1729
+ terminal_parse_failure('"-"')
1730
+ r14 = nil
1731
+ end
1732
+ s13 << r14
1733
+ if r14
1734
+ s15, i15 = [], index
1735
+ loop do
1736
+ r16 = _nt_HEXDIG
1737
+ if r16
1738
+ s15 << r16
1739
+ else
1740
+ break
1741
+ end
1742
+ end
1743
+ if s15.empty?
1744
+ @index = i15
1745
+ r15 = nil
1746
+ else
1747
+ r15 = instantiate_node(SyntaxNode,input, i15...index, s15)
1748
+ end
1749
+ s13 << r15
1750
+ end
1751
+ if s13.last
1752
+ r13 = instantiate_node(SyntaxNode,input, i13...index, s13)
1753
+ r13.extend(HexVal2)
1754
+ else
1755
+ @index = i13
1756
+ r13 = nil
1757
+ end
1758
+ s12 << r13
1759
+ if s12.last
1760
+ r12 = instantiate_node(SyntaxNode,input, i12...index, s12)
1761
+ r12.extend(HexVal3)
1762
+ else
1763
+ @index = i12
1764
+ r12 = nil
1765
+ end
1766
+ if r12
1767
+ r12 = SyntaxNode.new(input, (index-1)...index) if r12 == true
1768
+ r5 = r12
1769
+ else
1770
+ @index = i5
1771
+ r5 = nil
1772
+ end
1773
+ end
1774
+ if r5
1775
+ r4 = r5
1776
+ else
1777
+ r4 = instantiate_node(SyntaxNode,input, index...index)
1778
+ end
1779
+ s0 << r4
1780
+ end
1781
+ end
1782
+ if s0.last
1783
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
1784
+ r0.extend(HexVal4)
1785
+ r0.extend(HexVal5)
1786
+ else
1787
+ @index = i0
1788
+ r0 = nil
1789
+ end
1790
+
1791
+ node_cache[:hex_val][start_index] = r0
1792
+
1793
+ r0
1794
+ end
1795
+
1796
+ module ProseVal0
1797
+ def a
1798
+ elements[1]
1799
+ end
1800
+
1801
+ end
1802
+
1803
+ module ProseVal1
1804
+ def ast() ["prose", a.text_value] end
1805
+ end
1806
+
1807
+ def _nt_prose_val
1808
+ start_index = index
1809
+ if node_cache[:prose_val].has_key?(index)
1810
+ cached = node_cache[:prose_val][index]
1811
+ if cached
1812
+ node_cache[:prose_val][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
1813
+ @index = cached.interval.end
1814
+ end
1815
+ return cached
1816
+ end
1817
+
1818
+ i0, s0 = index, []
1819
+ if (match_len = has_terminal?("<", false, index))
1820
+ r1 = true
1821
+ @index += match_len
1822
+ else
1823
+ terminal_parse_failure('"<"')
1824
+ r1 = nil
1825
+ end
1826
+ s0 << r1
1827
+ if r1
1828
+ s2, i2 = [], index
1829
+ loop do
1830
+ if has_terminal?(@regexps[gr = '\A[ -=?-~]'] ||= Regexp.new(gr), :regexp, index)
1831
+ r3 = true
1832
+ @index += 1
1833
+ else
1834
+ terminal_parse_failure('[ -=?-~]')
1835
+ r3 = nil
1836
+ end
1837
+ if r3
1838
+ s2 << r3
1839
+ else
1840
+ break
1841
+ end
1842
+ end
1843
+ r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
1844
+ s0 << r2
1845
+ if r2
1846
+ if (match_len = has_terminal?(">", false, index))
1847
+ r4 = true
1848
+ @index += match_len
1849
+ else
1850
+ terminal_parse_failure('">"')
1851
+ r4 = nil
1852
+ end
1853
+ s0 << r4
1854
+ end
1855
+ end
1856
+ if s0.last
1857
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
1858
+ r0.extend(ProseVal0)
1859
+ r0.extend(ProseVal1)
1860
+ else
1861
+ @index = i0
1862
+ r0 = nil
1863
+ end
1864
+
1865
+ node_cache[:prose_val][start_index] = r0
1866
+
1867
+ r0
1868
+ end
1869
+
1870
+ def _nt_ALPHA
1871
+ start_index = index
1872
+ if node_cache[:ALPHA].has_key?(index)
1873
+ cached = node_cache[:ALPHA][index]
1874
+ if cached
1875
+ node_cache[:ALPHA][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
1876
+ @index = cached.interval.end
1877
+ end
1878
+ return cached
1879
+ end
1880
+
1881
+ if has_terminal?(@regexps[gr = '\A[A-Za-z]'] ||= Regexp.new(gr), :regexp, index)
1882
+ r0 = instantiate_node(SyntaxNode,input, index...(index + 1))
1883
+ @index += 1
1884
+ else
1885
+ terminal_parse_failure('[A-Za-z]')
1886
+ r0 = nil
1887
+ end
1888
+
1889
+ node_cache[:ALPHA][start_index] = r0
1890
+
1891
+ r0
1892
+ end
1893
+
1894
+ def _nt_BIT
1895
+ start_index = index
1896
+ if node_cache[:BIT].has_key?(index)
1897
+ cached = node_cache[:BIT][index]
1898
+ if cached
1899
+ node_cache[:BIT][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
1900
+ @index = cached.interval.end
1901
+ end
1902
+ return cached
1903
+ end
1904
+
1905
+ i0 = index
1906
+ if (match_len = has_terminal?("0", false, index))
1907
+ r1 = true
1908
+ @index += match_len
1909
+ else
1910
+ terminal_parse_failure('"0"')
1911
+ r1 = nil
1912
+ end
1913
+ if r1
1914
+ r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
1915
+ r0 = r1
1916
+ else
1917
+ if (match_len = has_terminal?("1", false, index))
1918
+ r2 = true
1919
+ @index += match_len
1920
+ else
1921
+ terminal_parse_failure('"1"')
1922
+ r2 = nil
1923
+ end
1924
+ if r2
1925
+ r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
1926
+ r0 = r2
1927
+ else
1928
+ @index = i0
1929
+ r0 = nil
1930
+ end
1931
+ end
1932
+
1933
+ node_cache[:BIT][start_index] = r0
1934
+
1935
+ r0
1936
+ end
1937
+
1938
+ module CRLF0
1939
+ def CR
1940
+ elements[0]
1941
+ end
1942
+
1943
+ def LF
1944
+ elements[1]
1945
+ end
1946
+ end
1947
+
1948
+ def _nt_CRLF
1949
+ start_index = index
1950
+ if node_cache[:CRLF].has_key?(index)
1951
+ cached = node_cache[:CRLF][index]
1952
+ if cached
1953
+ node_cache[:CRLF][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
1954
+ @index = cached.interval.end
1955
+ end
1956
+ return cached
1957
+ end
1958
+
1959
+ i0, s0 = index, []
1960
+ r1 = _nt_CR
1961
+ s0 << r1
1962
+ if r1
1963
+ r2 = _nt_LF
1964
+ s0 << r2
1965
+ end
1966
+ if s0.last
1967
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
1968
+ r0.extend(CRLF0)
1969
+ else
1970
+ @index = i0
1971
+ r0 = nil
1972
+ end
1973
+
1974
+ node_cache[:CRLF][start_index] = r0
1975
+
1976
+ r0
1977
+ end
1978
+
1979
+ def _nt_CR
1980
+ start_index = index
1981
+ if node_cache[:CR].has_key?(index)
1982
+ cached = node_cache[:CR][index]
1983
+ if cached
1984
+ node_cache[:CR][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
1985
+ @index = cached.interval.end
1986
+ end
1987
+ return cached
1988
+ end
1989
+
1990
+ if has_terminal?(@regexps[gr = '\A[\\r]'] ||= Regexp.new(gr), :regexp, index)
1991
+ r1 = true
1992
+ @index += 1
1993
+ else
1994
+ terminal_parse_failure('[\\r]')
1995
+ r1 = nil
1996
+ end
1997
+ if r1
1998
+ r0 = r1
1999
+ else
2000
+ r0 = instantiate_node(SyntaxNode,input, index...index)
2001
+ end
2002
+
2003
+ node_cache[:CR][start_index] = r0
2004
+
2005
+ r0
2006
+ end
2007
+
2008
+ def _nt_LF
2009
+ start_index = index
2010
+ if node_cache[:LF].has_key?(index)
2011
+ cached = node_cache[:LF][index]
2012
+ if cached
2013
+ node_cache[:LF][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
2014
+ @index = cached.interval.end
2015
+ end
2016
+ return cached
2017
+ end
2018
+
2019
+ if has_terminal?(@regexps[gr = '\A[\\n]'] ||= Regexp.new(gr), :regexp, index)
2020
+ r0 = instantiate_node(SyntaxNode,input, index...(index + 1))
2021
+ @index += 1
2022
+ else
2023
+ terminal_parse_failure('[\\n]')
2024
+ r0 = nil
2025
+ end
2026
+
2027
+ node_cache[:LF][start_index] = r0
2028
+
2029
+ r0
2030
+ end
2031
+
2032
+ def _nt_DIGIT
2033
+ start_index = index
2034
+ if node_cache[:DIGIT].has_key?(index)
2035
+ cached = node_cache[:DIGIT][index]
2036
+ if cached
2037
+ node_cache[:DIGIT][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
2038
+ @index = cached.interval.end
2039
+ end
2040
+ return cached
2041
+ end
2042
+
2043
+ if has_terminal?(@regexps[gr = '\A[0-9]'] ||= Regexp.new(gr), :regexp, index)
2044
+ r0 = instantiate_node(SyntaxNode,input, index...(index + 1))
2045
+ @index += 1
2046
+ else
2047
+ terminal_parse_failure('[0-9]')
2048
+ r0 = nil
2049
+ end
2050
+
2051
+ node_cache[:DIGIT][start_index] = r0
2052
+
2053
+ r0
2054
+ end
2055
+
2056
+ def _nt_DQUOTE
2057
+ start_index = index
2058
+ if node_cache[:DQUOTE].has_key?(index)
2059
+ cached = node_cache[:DQUOTE][index]
2060
+ if cached
2061
+ node_cache[:DQUOTE][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
2062
+ @index = cached.interval.end
2063
+ end
2064
+ return cached
2065
+ end
2066
+
2067
+ if has_terminal?(@regexps[gr = '\A["]'] ||= Regexp.new(gr), :regexp, index)
2068
+ r0 = instantiate_node(SyntaxNode,input, index...(index + 1))
2069
+ @index += 1
2070
+ else
2071
+ terminal_parse_failure('["]')
2072
+ r0 = nil
2073
+ end
2074
+
2075
+ node_cache[:DQUOTE][start_index] = r0
2076
+
2077
+ r0
2078
+ end
2079
+
2080
+ def _nt_HEXDIG
2081
+ start_index = index
2082
+ if node_cache[:HEXDIG].has_key?(index)
2083
+ cached = node_cache[:HEXDIG][index]
2084
+ if cached
2085
+ node_cache[:HEXDIG][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
2086
+ @index = cached.interval.end
2087
+ end
2088
+ return cached
2089
+ end
2090
+
2091
+ i0 = index
2092
+ r1 = _nt_DIGIT
2093
+ if r1
2094
+ r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
2095
+ r0 = r1
2096
+ else
2097
+ if has_terminal?(@regexps[gr = '\A[A-Fa-f]'] ||= Regexp.new(gr), :regexp, index)
2098
+ r2 = true
2099
+ @index += 1
2100
+ else
2101
+ terminal_parse_failure('[A-Fa-f]')
2102
+ r2 = nil
2103
+ end
2104
+ if r2
2105
+ r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
2106
+ r0 = r2
2107
+ else
2108
+ @index = i0
2109
+ r0 = nil
2110
+ end
2111
+ end
2112
+
2113
+ node_cache[:HEXDIG][start_index] = r0
2114
+
2115
+ r0
2116
+ end
2117
+
2118
+ def _nt_WSP
2119
+ start_index = index
2120
+ if node_cache[:WSP].has_key?(index)
2121
+ cached = node_cache[:WSP][index]
2122
+ if cached
2123
+ node_cache[:WSP][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
2124
+ @index = cached.interval.end
2125
+ end
2126
+ return cached
2127
+ end
2128
+
2129
+ i0 = index
2130
+ r1 = _nt_SP
2131
+ if r1
2132
+ r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
2133
+ r0 = r1
2134
+ else
2135
+ r2 = _nt_HTAB
2136
+ if r2
2137
+ r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
2138
+ r0 = r2
2139
+ else
2140
+ @index = i0
2141
+ r0 = nil
2142
+ end
2143
+ end
2144
+
2145
+ node_cache[:WSP][start_index] = r0
2146
+
2147
+ r0
2148
+ end
2149
+
2150
+ def _nt_HTAB
2151
+ start_index = index
2152
+ if node_cache[:HTAB].has_key?(index)
2153
+ cached = node_cache[:HTAB][index]
2154
+ if cached
2155
+ node_cache[:HTAB][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
2156
+ @index = cached.interval.end
2157
+ end
2158
+ return cached
2159
+ end
2160
+
2161
+ if has_terminal?(@regexps[gr = '\A[\\t]'] ||= Regexp.new(gr), :regexp, index)
2162
+ r0 = instantiate_node(SyntaxNode,input, index...(index + 1))
2163
+ @index += 1
2164
+ else
2165
+ terminal_parse_failure('[\\t]')
2166
+ r0 = nil
2167
+ end
2168
+
2169
+ node_cache[:HTAB][start_index] = r0
2170
+
2171
+ r0
2172
+ end
2173
+
2174
+ def _nt_SP
2175
+ start_index = index
2176
+ if node_cache[:SP].has_key?(index)
2177
+ cached = node_cache[:SP][index]
2178
+ if cached
2179
+ node_cache[:SP][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
2180
+ @index = cached.interval.end
2181
+ end
2182
+ return cached
2183
+ end
2184
+
2185
+ if (match_len = has_terminal?(" ", false, index))
2186
+ r0 = instantiate_node(SyntaxNode,input, index...(index + match_len))
2187
+ @index += match_len
2188
+ else
2189
+ terminal_parse_failure('" "')
2190
+ r0 = nil
2191
+ end
2192
+
2193
+ node_cache[:SP][start_index] = r0
2194
+
2195
+ r0
2196
+ end
2197
+
2198
+ def _nt_VCHAR
2199
+ start_index = index
2200
+ if node_cache[:VCHAR].has_key?(index)
2201
+ cached = node_cache[:VCHAR][index]
2202
+ if cached
2203
+ node_cache[:VCHAR][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
2204
+ @index = cached.interval.end
2205
+ end
2206
+ return cached
2207
+ end
2208
+
2209
+ if has_terminal?(@regexps[gr = '\A[!-~]'] ||= Regexp.new(gr), :regexp, index)
2210
+ r0 = instantiate_node(SyntaxNode,input, index...(index + 1))
2211
+ @index += 1
2212
+ else
2213
+ terminal_parse_failure('[!-~]')
2214
+ r0 = nil
2215
+ end
2216
+
2217
+ node_cache[:VCHAR][start_index] = r0
2218
+
2219
+ r0
2220
+ end
2221
+
2222
+ def _nt_char_val
2223
+ start_index = index
2224
+ if node_cache[:char_val].has_key?(index)
2225
+ cached = node_cache[:char_val][index]
2226
+ if cached
2227
+ node_cache[:char_val][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
2228
+ @index = cached.interval.end
2229
+ end
2230
+ return cached
2231
+ end
2232
+
2233
+ i0 = index
2234
+ r1 = _nt_case_insensitive_string
2235
+ if r1
2236
+ r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
2237
+ r0 = r1
2238
+ else
2239
+ r2 = _nt_case_sensitive_string
2240
+ if r2
2241
+ r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
2242
+ r0 = r2
2243
+ else
2244
+ @index = i0
2245
+ r0 = nil
2246
+ end
2247
+ end
2248
+
2249
+ node_cache[:char_val][start_index] = r0
2250
+
2251
+ r0
2252
+ end
2253
+
2254
+ module CaseInsensitiveString0
2255
+ def quoted_string
2256
+ elements[1]
2257
+ end
2258
+ end
2259
+
2260
+ module CaseInsensitiveString1
2261
+ def ast() ["ci", quoted_string.ast] end
2262
+ end
2263
+
2264
+ def _nt_case_insensitive_string
2265
+ start_index = index
2266
+ if node_cache[:case_insensitive_string].has_key?(index)
2267
+ cached = node_cache[:case_insensitive_string][index]
2268
+ if cached
2269
+ node_cache[:case_insensitive_string][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
2270
+ @index = cached.interval.end
2271
+ end
2272
+ return cached
2273
+ end
2274
+
2275
+ i0, s0 = index, []
2276
+ if (match_len = has_terminal?("%i", false, index))
2277
+ r2 = instantiate_node(SyntaxNode,input, index...(index + match_len))
2278
+ @index += match_len
2279
+ else
2280
+ terminal_parse_failure('"%i"')
2281
+ r2 = nil
2282
+ end
2283
+ if r2
2284
+ r1 = r2
2285
+ else
2286
+ r1 = instantiate_node(SyntaxNode,input, index...index)
2287
+ end
2288
+ s0 << r1
2289
+ if r1
2290
+ r3 = _nt_quoted_string
2291
+ s0 << r3
2292
+ end
2293
+ if s0.last
2294
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
2295
+ r0.extend(CaseInsensitiveString0)
2296
+ r0.extend(CaseInsensitiveString1)
2297
+ else
2298
+ @index = i0
2299
+ r0 = nil
2300
+ end
2301
+
2302
+ node_cache[:case_insensitive_string][start_index] = r0
2303
+
2304
+ r0
2305
+ end
2306
+
2307
+ module CaseSensitiveString0
2308
+ def quoted_string
2309
+ elements[1]
2310
+ end
2311
+ end
2312
+
2313
+ module CaseSensitiveString1
2314
+ def ast() ["cs", quoted_string.ast] end
2315
+ end
2316
+
2317
+ def _nt_case_sensitive_string
2318
+ start_index = index
2319
+ if node_cache[:case_sensitive_string].has_key?(index)
2320
+ cached = node_cache[:case_sensitive_string][index]
2321
+ if cached
2322
+ node_cache[:case_sensitive_string][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
2323
+ @index = cached.interval.end
2324
+ end
2325
+ return cached
2326
+ end
2327
+
2328
+ i0, s0 = index, []
2329
+ if (match_len = has_terminal?("%s", false, index))
2330
+ r1 = instantiate_node(SyntaxNode,input, index...(index + match_len))
2331
+ @index += match_len
2332
+ else
2333
+ terminal_parse_failure('"%s"')
2334
+ r1 = nil
2335
+ end
2336
+ s0 << r1
2337
+ if r1
2338
+ r2 = _nt_quoted_string
2339
+ s0 << r2
2340
+ end
2341
+ if s0.last
2342
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
2343
+ r0.extend(CaseSensitiveString0)
2344
+ r0.extend(CaseSensitiveString1)
2345
+ else
2346
+ @index = i0
2347
+ r0 = nil
2348
+ end
2349
+
2350
+ node_cache[:case_sensitive_string][start_index] = r0
2351
+
2352
+ r0
2353
+ end
2354
+
2355
+ module QuotedString0
2356
+ def DQUOTE1
2357
+ elements[0]
2358
+ end
2359
+
2360
+ def DQUOTE2
2361
+ elements[2]
2362
+ end
2363
+ end
2364
+
2365
+ module QuotedString1
2366
+ def ast() elements[1].text_value end
2367
+ end
2368
+
2369
+ def _nt_quoted_string
2370
+ start_index = index
2371
+ if node_cache[:quoted_string].has_key?(index)
2372
+ cached = node_cache[:quoted_string][index]
2373
+ if cached
2374
+ node_cache[:quoted_string][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
2375
+ @index = cached.interval.end
2376
+ end
2377
+ return cached
2378
+ end
2379
+
2380
+ i0, s0 = index, []
2381
+ r1 = _nt_DQUOTE
2382
+ s0 << r1
2383
+ if r1
2384
+ s2, i2 = [], index
2385
+ loop do
2386
+ if has_terminal?(@regexps[gr = '\A[ !#-~]'] ||= Regexp.new(gr), :regexp, index)
2387
+ r3 = true
2388
+ @index += 1
2389
+ else
2390
+ terminal_parse_failure('[ !#-~]')
2391
+ r3 = nil
2392
+ end
2393
+ if r3
2394
+ s2 << r3
2395
+ else
2396
+ break
2397
+ end
2398
+ end
2399
+ r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
2400
+ s0 << r2
2401
+ if r2
2402
+ r4 = _nt_DQUOTE
2403
+ s0 << r4
2404
+ end
2405
+ end
2406
+ if s0.last
2407
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
2408
+ r0.extend(QuotedString0)
2409
+ r0.extend(QuotedString1)
2410
+ else
2411
+ @index = i0
2412
+ r0 = nil
2413
+ end
2414
+
2415
+ node_cache[:quoted_string][start_index] = r0
2416
+
2417
+ r0
2418
+ end
2419
+
2420
+ module InlineModule10
2421
+ end
2422
+
2423
+ module InlineModule11
2424
+ end
2425
+
2426
+ def _nt_inline_module1
2427
+ start_index = index
2428
+ if node_cache[:inline_module1].has_key?(index)
2429
+ cached = node_cache[:inline_module1][index]
2430
+ if cached
2431
+ node_cache[:inline_module1][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
2432
+ @index = cached.interval.end
2433
+ end
2434
+ return cached
2435
+ end
2436
+
2437
+ i0, s0 = index, []
2438
+ if (match_len = has_terminal?('{', false, index))
2439
+ r1 = true
2440
+ @index += match_len
2441
+ else
2442
+ terminal_parse_failure('\'{\'')
2443
+ r1 = nil
2444
+ end
2445
+ s0 << r1
2446
+ if r1
2447
+ s2, i2 = [], index
2448
+ loop do
2449
+ i3 = index
2450
+ r4 = _nt_inline_module1
2451
+ if r4
2452
+ r4 = SyntaxNode.new(input, (index-1)...index) if r4 == true
2453
+ r3 = r4
2454
+ else
2455
+ i5, s5 = index, []
2456
+ i6 = index
2457
+ if has_terminal?(@regexps[gr = '\A[{}]'] ||= Regexp.new(gr), :regexp, index)
2458
+ r7 = true
2459
+ @index += 1
2460
+ else
2461
+ terminal_parse_failure('[{}]')
2462
+ r7 = nil
2463
+ end
2464
+ if r7
2465
+ @index = i6
2466
+ r6 = nil
2467
+ terminal_parse_failure('[{}]', true)
2468
+ else
2469
+ @terminal_failures.pop
2470
+ @index = i6
2471
+ r6 = instantiate_node(SyntaxNode,input, index...index)
2472
+ end
2473
+ s5 << r6
2474
+ if r6
2475
+ if index < input_length
2476
+ r8 = true
2477
+ @index += 1
2478
+ else
2479
+ terminal_parse_failure("any character")
2480
+ r8 = nil
2481
+ end
2482
+ s5 << r8
2483
+ end
2484
+ if s5.last
2485
+ r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
2486
+ r5.extend(InlineModule10)
2487
+ else
2488
+ @index = i5
2489
+ r5 = nil
2490
+ end
2491
+ if r5
2492
+ r5 = SyntaxNode.new(input, (index-1)...index) if r5 == true
2493
+ r3 = r5
2494
+ else
2495
+ @index = i3
2496
+ r3 = nil
2497
+ end
2498
+ end
2499
+ if r3
2500
+ s2 << r3
2501
+ else
2502
+ break
2503
+ end
2504
+ end
2505
+ r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
2506
+ s0 << r2
2507
+ if r2
2508
+ if (match_len = has_terminal?('}', false, index))
2509
+ r9 = true
2510
+ @index += match_len
2511
+ else
2512
+ terminal_parse_failure('\'}\'')
2513
+ r9 = nil
2514
+ end
2515
+ s0 << r9
2516
+ end
2517
+ end
2518
+ if s0.last
2519
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
2520
+ r0.extend(InlineModule11)
2521
+ else
2522
+ @index = i0
2523
+ r0 = nil
2524
+ end
2525
+
2526
+ node_cache[:inline_module1][start_index] = r0
2527
+
2528
+ r0
2529
+ end
2530
+
2531
+ module InlineModule0
2532
+ def ast_wrap(a) ["im", a, text_value] end
2533
+ end
2534
+
2535
+ module InlineModule1
2536
+ def ast_wrap(a) a end
2537
+ end
2538
+
2539
+ def _nt_inline_module
2540
+ start_index = index
2541
+ if node_cache[:inline_module].has_key?(index)
2542
+ cached = node_cache[:inline_module][index]
2543
+ if cached
2544
+ node_cache[:inline_module][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
2545
+ @index = cached.interval.end
2546
+ end
2547
+ return cached
2548
+ end
2549
+
2550
+ i0 = index
2551
+ r1 = _nt_inline_module1
2552
+ r1.extend(InlineModule0)
2553
+ r1.extend(InlineModule0)
2554
+ if r1
2555
+ r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
2556
+ r0 = r1
2557
+ else
2558
+ if (match_len = has_terminal?('', false, index))
2559
+ r2 = instantiate_node(SyntaxNode,input, index...(index + match_len))
2560
+ r2.extend(InlineModule1)
2561
+ @index += match_len
2562
+ else
2563
+ terminal_parse_failure('\'\'')
2564
+ r2 = nil
2565
+ end
2566
+ if r2
2567
+ r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
2568
+ r0 = r2
2569
+ else
2570
+ @index = i0
2571
+ r0 = nil
2572
+ end
2573
+ end
2574
+
2575
+ node_cache[:inline_module][start_index] = r0
2576
+
2577
+ r0
2578
+ end
2579
+
2580
+ end
2581
+
2582
+ class ABNFParser < Treetop::Runtime::CompiledParser
2583
+ include ABNF
2584
+ end
2585
+
2586
+