treetop 1.1.4 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/README +1 -1
  2. data/Rakefile +3 -2
  3. data/doc/contributing_and_planned_features.markdown +1 -1
  4. data/doc/using_in_ruby.markdown +2 -2
  5. data/examples/lambda_calculus/arithmetic.rb +551 -0
  6. data/examples/lambda_calculus/arithmetic_test.rb +1 -1
  7. data/examples/lambda_calculus/lambda_calculus.rb +39 -72
  8. data/examples/lambda_calculus/lambda_calculus_test.rb +2 -2
  9. data/examples/lambda_calculus/test_helper.rb +3 -3
  10. data/lib/treetop.rb +3 -0
  11. data/lib/treetop/bootstrap_gen_1_metagrammar.rb +22 -14
  12. data/lib/treetop/compiler.rb +1 -2
  13. data/lib/treetop/compiler/grammar_compiler.rb +12 -5
  14. data/lib/treetop/compiler/metagrammar.rb +931 -558
  15. data/lib/treetop/compiler/metagrammar.treetop +26 -6
  16. data/lib/treetop/compiler/node_classes/anything_symbol.rb +10 -2
  17. data/lib/treetop/compiler/node_classes/atomic_expression.rb +4 -0
  18. data/lib/treetop/compiler/node_classes/character_class.rb +10 -1
  19. data/lib/treetop/compiler/node_classes/choice.rb +2 -4
  20. data/lib/treetop/compiler/node_classes/parsing_expression.rb +8 -17
  21. data/lib/treetop/compiler/node_classes/parsing_rule.rb +3 -3
  22. data/lib/treetop/compiler/node_classes/predicate.rb +1 -1
  23. data/lib/treetop/compiler/node_classes/repetition.rb +3 -4
  24. data/lib/treetop/compiler/node_classes/sequence.rb +4 -4
  25. data/lib/treetop/compiler/node_classes/terminal.rb +11 -1
  26. data/lib/treetop/compiler/ruby_builder.rb +2 -2
  27. data/lib/treetop/ruby_extensions.rb +1 -1
  28. data/lib/treetop/runtime.rb +0 -3
  29. data/lib/treetop/runtime/compiled_parser.rb +42 -34
  30. data/lib/treetop/runtime/node_cache.rb +1 -1
  31. data/lib/treetop/runtime/syntax_node.rb +51 -32
  32. data/lib/treetop/runtime/terminal_parse_failure.rb +7 -24
  33. data/lib/treetop/runtime/terminal_syntax_node.rb +7 -2
  34. metadata +12 -7
  35. data/examples/TALK +0 -33
  36. data/lib/treetop/compiler/load_grammar.rb +0 -7
  37. data/lib/treetop/compiler/metagrammar. +0 -0
  38. data/lib/treetop/runtime/parse_failure.rb +0 -32
  39. data/lib/treetop/runtime/parse_result.rb +0 -30
@@ -2,6 +2,5 @@ dir = File.dirname(__FILE__)
2
2
  require File.join(dir, *%w[compiler lexical_address_space])
3
3
  require File.join(dir, *%w[compiler ruby_builder])
4
4
  require File.join(dir, *%w[compiler node_classes])
5
- require File.join(dir, *%w[compiler metagrammar])
5
+ require File.join(dir, *%w[compiler metagrammar]) unless $exclude_metagrammar
6
6
  require File.join(dir, *%w[compiler grammar_compiler])
7
- require File.join(dir, *%w[compiler load_grammar])
@@ -1,7 +1,7 @@
1
1
  module Treetop
2
2
  module Compiler
3
3
  class GrammarCompiler
4
- def compile(source_path, target_path = source_path.gsub(/treetop\Z/, 'rb'))
4
+ def compile(source_path, target_path = source_path.gsub(/\.(treetop|tt)\Z/, '.rb'))
5
5
  File.open(target_path, 'w') do |target_file|
6
6
  target_file.write(ruby_source(source_path))
7
7
  end
@@ -9,13 +9,20 @@ module Treetop
9
9
 
10
10
  def ruby_source(source_path)
11
11
  File.open(source_path) do |source_file|
12
- result = MetagrammarParser.new.parse(source_file.read)
13
- if result.failure?
14
- raise RuntimeError.new(result.nested_failures.map {|failure| failure.to_s}.join("\n"))
12
+ parser = MetagrammarParser.new
13
+ result = parser.parse(source_file.read)
14
+ unless result
15
+ raise RuntimeError.new(parser.failure_reason)
15
16
  end
16
17
  result.compile
17
18
  end
18
19
  end
19
20
  end
20
21
  end
21
- end
22
+
23
+ def self.load(path)
24
+ adjusted_path = path =~ /\.(treetop|tt)\Z/ ? path : path + '.treetop'
25
+ compiler = Treetop::Compiler::GrammarCompiler.new
26
+ Object.class_eval(compiler.ruby_source(adjusted_path))
27
+ end
28
+ end
@@ -35,50 +35,46 @@ module Treetop
35
35
  return cached
36
36
  end
37
37
 
38
- i0, s0, nr0 = index, [], []
38
+ i0, s0 = index, []
39
39
  r2 = _nt_space
40
- if r2.success?
40
+ if r2
41
41
  r1 = r2
42
42
  else
43
- r1 = SyntaxNode.new(input, index...index, r2.nested_failures)
43
+ r1 = SyntaxNode.new(input, index...index)
44
44
  end
45
45
  s0 << r1
46
- if r1.success?
47
- i3, nr3 = index, []
46
+ if r1
47
+ i3 = index
48
48
  r4 = _nt_module_declaration
49
- nr3 << r4
50
- if r4.success?
49
+ if r4
51
50
  r3 = r4
52
- r4.update_nested_results(nr3)
53
51
  else
54
52
  r5 = _nt_grammar
55
- nr3 << r5
56
- if r5.success?
53
+ if r5
57
54
  r3 = r5
58
- r5.update_nested_results(nr3)
59
55
  else
60
56
  self.index = i3
61
- r3 = ParseFailure.new(input, i3, nr3)
57
+ r3 = nil
62
58
  end
63
59
  end
64
60
  s0 << r3
65
- if r3.success?
61
+ if r3
66
62
  r7 = _nt_space
67
- if r7.success?
63
+ if r7
68
64
  r6 = r7
69
65
  else
70
- r6 = SyntaxNode.new(input, index...index, r7.nested_failures)
66
+ r6 = SyntaxNode.new(input, index...index)
71
67
  end
72
68
  s0 << r6
73
69
  end
74
70
  end
75
- if s0.last.success?
71
+ if s0.last
76
72
  r0 = (SyntaxNode).new(input, i0...index, s0)
77
73
  r0.extend(TreetopFile0)
78
74
  r0.extend(TreetopFile1)
79
75
  else
80
76
  self.index = i0
81
- r0 = ParseFailure.new(input, i0, s0)
77
+ r0 = nil
82
78
  end
83
79
 
84
80
  node_cache[:treetop_file][start_index] = r0
@@ -131,88 +127,100 @@ module Treetop
131
127
  return cached
132
128
  end
133
129
 
134
- i0, s0, nr0 = index, [], []
135
- i1, s1, nr1 = index, [], []
136
- r2 = parse_terminal('module', SyntaxNode)
130
+ i0, s0 = index, []
131
+ i1, s1 = index, []
132
+ if input.index('module', index) == index
133
+ r2 = (SyntaxNode).new(input, index...(index + 6))
134
+ @index += 6
135
+ else
136
+ terminal_parse_failure('module')
137
+ r2 = nil
138
+ end
137
139
  s1 << r2
138
- if r2.success?
140
+ if r2
139
141
  r3 = _nt_space
140
142
  s1 << r3
141
- if r3.success?
142
- r4 = parse_char_class(/[A-Z]/, 'A-Z', SyntaxNode)
143
+ if r3
144
+ if input.index(/[A-Z]/, index) == index
145
+ r4 = (SyntaxNode).new(input, index...(index + 1))
146
+ @index += 1
147
+ else
148
+ r4 = nil
149
+ end
143
150
  s1 << r4
144
- if r4.success?
145
- s5, nr5, i5 = [], [], index
151
+ if r4
152
+ s5, i5 = [], index
146
153
  loop do
147
154
  r6 = _nt_alphanumeric_char
148
- nr5 << r6
149
- if r6.success?
155
+ if r6
150
156
  s5 << r6
151
157
  else
152
158
  break
153
159
  end
154
160
  end
155
- r5 = SyntaxNode.new(input, i5...index, s5, nr5)
161
+ r5 = SyntaxNode.new(input, i5...index, s5)
156
162
  s1 << r5
157
- if r5.success?
163
+ if r5
158
164
  r7 = _nt_space
159
165
  s1 << r7
160
166
  end
161
167
  end
162
168
  end
163
169
  end
164
- if s1.last.success?
170
+ if s1.last
165
171
  r1 = (SyntaxNode).new(input, i1...index, s1)
166
172
  r1.extend(ModuleDeclaration0)
167
173
  else
168
174
  self.index = i1
169
- r1 = ParseFailure.new(input, i1, s1)
175
+ r1 = nil
170
176
  end
171
177
  s0 << r1
172
- if r1.success?
173
- i8, nr8 = index, []
178
+ if r1
179
+ i8 = index
174
180
  r9 = _nt_module_declaration
175
- nr8 << r9
176
- if r9.success?
181
+ if r9
177
182
  r8 = r9
178
- r9.update_nested_results(nr8)
179
183
  else
180
184
  r10 = _nt_grammar
181
- nr8 << r10
182
- if r10.success?
185
+ if r10
183
186
  r8 = r10
184
- r10.update_nested_results(nr8)
185
187
  else
186
188
  self.index = i8
187
- r8 = ParseFailure.new(input, i8, nr8)
189
+ r8 = nil
188
190
  end
189
191
  end
190
192
  s0 << r8
191
- if r8.success?
192
- i11, s11, nr11 = index, [], []
193
+ if r8
194
+ i11, s11 = index, []
193
195
  r12 = _nt_space
194
196
  s11 << r12
195
- if r12.success?
196
- r13 = parse_terminal('end', SyntaxNode)
197
+ if r12
198
+ if input.index('end', index) == index
199
+ r13 = (SyntaxNode).new(input, index...(index + 3))
200
+ @index += 3
201
+ else
202
+ terminal_parse_failure('end')
203
+ r13 = nil
204
+ end
197
205
  s11 << r13
198
206
  end
199
- if s11.last.success?
207
+ if s11.last
200
208
  r11 = (SyntaxNode).new(input, i11...index, s11)
201
209
  r11.extend(ModuleDeclaration1)
202
210
  else
203
211
  self.index = i11
204
- r11 = ParseFailure.new(input, i11, s11)
212
+ r11 = nil
205
213
  end
206
214
  s0 << r11
207
215
  end
208
216
  end
209
- if s0.last.success?
217
+ if s0.last
210
218
  r0 = (SyntaxNode).new(input, i0...index, s0)
211
219
  r0.extend(ModuleDeclaration2)
212
220
  r0.extend(ModuleDeclaration3)
213
221
  else
214
222
  self.index = i0
215
- r0 = ParseFailure.new(input, i0, s0)
223
+ r0 = nil
216
224
  end
217
225
 
218
226
  node_cache[:module_declaration][start_index] = r0
@@ -247,31 +255,43 @@ module Treetop
247
255
  return cached
248
256
  end
249
257
 
250
- i0, s0, nr0 = index, [], []
251
- r1 = parse_terminal('grammar', SyntaxNode)
258
+ i0, s0 = index, []
259
+ if input.index('grammar', index) == index
260
+ r1 = (SyntaxNode).new(input, index...(index + 7))
261
+ @index += 7
262
+ else
263
+ terminal_parse_failure('grammar')
264
+ r1 = nil
265
+ end
252
266
  s0 << r1
253
- if r1.success?
267
+ if r1
254
268
  r2 = _nt_space
255
269
  s0 << r2
256
- if r2.success?
270
+ if r2
257
271
  r3 = _nt_grammar_name
258
272
  s0 << r3
259
- if r3.success?
273
+ if r3
260
274
  r4 = _nt_space
261
275
  s0 << r4
262
- if r4.success?
276
+ if r4
263
277
  r5 = _nt_declaration_sequence
264
278
  s0 << r5
265
- if r5.success?
279
+ if r5
266
280
  r7 = _nt_space
267
- if r7.success?
281
+ if r7
268
282
  r6 = r7
269
283
  else
270
- r6 = SyntaxNode.new(input, index...index, r7.nested_failures)
284
+ r6 = SyntaxNode.new(input, index...index)
271
285
  end
272
286
  s0 << r6
273
- if r6.success?
274
- r8 = parse_terminal('end', SyntaxNode)
287
+ if r6
288
+ if input.index('end', index) == index
289
+ r8 = (SyntaxNode).new(input, index...(index + 3))
290
+ @index += 3
291
+ else
292
+ terminal_parse_failure('end')
293
+ r8 = nil
294
+ end
275
295
  s0 << r8
276
296
  end
277
297
  end
@@ -279,12 +299,12 @@ module Treetop
279
299
  end
280
300
  end
281
301
  end
282
- if s0.last.success?
302
+ if s0.last
283
303
  r0 = (Grammar).new(input, i0...index, s0)
284
304
  r0.extend(Grammar0)
285
305
  else
286
306
  self.index = i0
287
- r0 = ParseFailure.new(input, i0, s0)
307
+ r0 = nil
288
308
  end
289
309
 
290
310
  node_cache[:grammar][start_index] = r0
@@ -303,29 +323,33 @@ module Treetop
303
323
  return cached
304
324
  end
305
325
 
306
- i0, s0, nr0 = index, [], []
307
- r1 = parse_char_class(/[A-Z]/, 'A-Z', SyntaxNode)
326
+ i0, s0 = index, []
327
+ if input.index(/[A-Z]/, index) == index
328
+ r1 = (SyntaxNode).new(input, index...(index + 1))
329
+ @index += 1
330
+ else
331
+ r1 = nil
332
+ end
308
333
  s0 << r1
309
- if r1.success?
310
- s2, nr2, i2 = [], [], index
334
+ if r1
335
+ s2, i2 = [], index
311
336
  loop do
312
337
  r3 = _nt_alphanumeric_char
313
- nr2 << r3
314
- if r3.success?
338
+ if r3
315
339
  s2 << r3
316
340
  else
317
341
  break
318
342
  end
319
343
  end
320
- r2 = SyntaxNode.new(input, i2...index, s2, nr2)
344
+ r2 = SyntaxNode.new(input, i2...index, s2)
321
345
  s0 << r2
322
346
  end
323
- if s0.last.success?
347
+ if s0.last
324
348
  r0 = (SyntaxNode).new(input, i0...index, s0)
325
349
  r0.extend(GrammarName0)
326
350
  else
327
351
  self.index = i0
328
- r0 = ParseFailure.new(input, i0, s0)
352
+ r0 = nil
329
353
  end
330
354
 
331
355
  node_cache[:grammar_name][start_index] = r0
@@ -376,58 +400,60 @@ module Treetop
376
400
  return cached
377
401
  end
378
402
 
379
- i0, nr0 = index, []
380
- i1, s1, nr1 = index, [], []
403
+ i0 = index
404
+ i1, s1 = index, []
381
405
  r2 = _nt_declaration
382
406
  s1 << r2
383
- if r2.success?
384
- s3, nr3, i3 = [], [], index
407
+ if r2
408
+ s3, i3 = [], index
385
409
  loop do
386
- i4, s4, nr4 = index, [], []
410
+ i4, s4 = index, []
387
411
  r5 = _nt_space
388
412
  s4 << r5
389
- if r5.success?
413
+ if r5
390
414
  r6 = _nt_declaration
391
415
  s4 << r6
392
416
  end
393
- if s4.last.success?
417
+ if s4.last
394
418
  r4 = (SyntaxNode).new(input, i4...index, s4)
395
419
  r4.extend(DeclarationSequence0)
396
420
  else
397
421
  self.index = i4
398
- r4 = ParseFailure.new(input, i4, s4)
422
+ r4 = nil
399
423
  end
400
- nr3 << r4
401
- if r4.success?
424
+ if r4
402
425
  s3 << r4
403
426
  else
404
427
  break
405
428
  end
406
429
  end
407
- r3 = SyntaxNode.new(input, i3...index, s3, nr3)
430
+ r3 = SyntaxNode.new(input, i3...index, s3)
408
431
  s1 << r3
409
432
  end
410
- if s1.last.success?
433
+ if s1.last
411
434
  r1 = (DeclarationSequence).new(input, i1...index, s1)
412
435
  r1.extend(DeclarationSequence1)
413
436
  r1.extend(DeclarationSequence2)
414
437
  else
415
438
  self.index = i1
416
- r1 = ParseFailure.new(input, i1, s1)
439
+ r1 = nil
417
440
  end
418
- nr0 << r1
419
- if r1.success?
441
+ if r1
420
442
  r0 = r1
421
- r1.update_nested_results(nr0)
422
443
  else
423
- r7 = parse_terminal('', SyntaxNode, DeclarationSequence3)
424
- nr0 << r7
425
- if r7.success?
444
+ if input.index('', index) == index
445
+ r7 = (SyntaxNode).new(input, index...(index + 0))
446
+ r7.extend(DeclarationSequence3)
447
+ @index += 0
448
+ else
449
+ terminal_parse_failure('')
450
+ r7 = nil
451
+ end
452
+ if r7
426
453
  r0 = r7
427
- r7.update_nested_results(nr0)
428
454
  else
429
455
  self.index = i0
430
- r0 = ParseFailure.new(input, i0, nr0)
456
+ r0 = nil
431
457
  end
432
458
  end
433
459
 
@@ -444,21 +470,17 @@ module Treetop
444
470
  return cached
445
471
  end
446
472
 
447
- i0, nr0 = index, []
473
+ i0 = index
448
474
  r1 = _nt_parsing_rule
449
- nr0 << r1
450
- if r1.success?
475
+ if r1
451
476
  r0 = r1
452
- r1.update_nested_results(nr0)
453
477
  else
454
478
  r2 = _nt_include_declaration
455
- nr0 << r2
456
- if r2.success?
479
+ if r2
457
480
  r0 = r2
458
- r2.update_nested_results(nr0)
459
481
  else
460
482
  self.index = i0
461
- r0 = ParseFailure.new(input, i0, nr0)
483
+ r0 = nil
462
484
  end
463
485
  end
464
486
 
@@ -488,54 +510,66 @@ module Treetop
488
510
  return cached
489
511
  end
490
512
 
491
- i0, s0, nr0 = index, [], []
492
- r1 = parse_terminal('include', SyntaxNode)
513
+ i0, s0 = index, []
514
+ if input.index('include', index) == index
515
+ r1 = (SyntaxNode).new(input, index...(index + 7))
516
+ @index += 7
517
+ else
518
+ terminal_parse_failure('include')
519
+ r1 = nil
520
+ end
493
521
  s0 << r1
494
- if r1.success?
522
+ if r1
495
523
  r2 = _nt_space
496
524
  s0 << r2
497
- if r2.success?
498
- r3 = parse_char_class(/[A-Z]/, 'A-Z', SyntaxNode)
525
+ if r2
526
+ if input.index(/[A-Z]/, index) == index
527
+ r3 = (SyntaxNode).new(input, index...(index + 1))
528
+ @index += 1
529
+ else
530
+ r3 = nil
531
+ end
499
532
  s0 << r3
500
- if r3.success?
501
- s4, nr4, i4 = [], [], index
533
+ if r3
534
+ s4, i4 = [], index
502
535
  loop do
503
- i5, nr5 = index, []
536
+ i5 = index
504
537
  r6 = _nt_alphanumeric_char
505
- nr5 << r6
506
- if r6.success?
538
+ if r6
507
539
  r5 = r6
508
- r6.update_nested_results(nr5)
509
540
  else
510
- r7 = parse_terminal('::', SyntaxNode)
511
- nr5 << r7
512
- if r7.success?
541
+ if input.index('::', index) == index
542
+ r7 = (SyntaxNode).new(input, index...(index + 2))
543
+ @index += 2
544
+ else
545
+ terminal_parse_failure('::')
546
+ r7 = nil
547
+ end
548
+ if r7
513
549
  r5 = r7
514
- r7.update_nested_results(nr5)
515
550
  else
516
551
  self.index = i5
517
- r5 = ParseFailure.new(input, i5, nr5)
552
+ r5 = nil
518
553
  end
519
554
  end
520
- nr4 << r5
521
- if r5.success?
555
+ if r5
522
556
  s4 << r5
523
557
  else
524
558
  break
525
559
  end
526
560
  end
527
- r4 = SyntaxNode.new(input, i4...index, s4, nr4)
561
+ r4 = SyntaxNode.new(input, i4...index, s4)
528
562
  s0 << r4
529
563
  end
530
564
  end
531
565
  end
532
- if s0.last.success?
566
+ if s0.last
533
567
  r0 = (SyntaxNode).new(input, i0...index, s0)
534
568
  r0.extend(IncludeDeclaration0)
535
569
  r0.extend(IncludeDeclaration1)
536
570
  else
537
571
  self.index = i0
538
- r0 = ParseFailure.new(input, i0, s0)
572
+ r0 = nil
539
573
  end
540
574
 
541
575
  node_cache[:include_declaration][start_index] = r0
@@ -574,26 +608,38 @@ module Treetop
574
608
  return cached
575
609
  end
576
610
 
577
- i0, s0, nr0 = index, [], []
578
- r1 = parse_terminal('rule', SyntaxNode)
611
+ i0, s0 = index, []
612
+ if input.index('rule', index) == index
613
+ r1 = (SyntaxNode).new(input, index...(index + 4))
614
+ @index += 4
615
+ else
616
+ terminal_parse_failure('rule')
617
+ r1 = nil
618
+ end
579
619
  s0 << r1
580
- if r1.success?
620
+ if r1
581
621
  r2 = _nt_space
582
622
  s0 << r2
583
- if r2.success?
623
+ if r2
584
624
  r3 = _nt_nonterminal
585
625
  s0 << r3
586
- if r3.success?
626
+ if r3
587
627
  r4 = _nt_space
588
628
  s0 << r4
589
- if r4.success?
629
+ if r4
590
630
  r5 = _nt_parsing_expression
591
631
  s0 << r5
592
- if r5.success?
632
+ if r5
593
633
  r6 = _nt_space
594
634
  s0 << r6
595
- if r6.success?
596
- r7 = parse_terminal('end', SyntaxNode)
635
+ if r6
636
+ if input.index('end', index) == index
637
+ r7 = (SyntaxNode).new(input, index...(index + 3))
638
+ @index += 3
639
+ else
640
+ terminal_parse_failure('end')
641
+ r7 = nil
642
+ end
597
643
  s0 << r7
598
644
  end
599
645
  end
@@ -601,12 +647,12 @@ module Treetop
601
647
  end
602
648
  end
603
649
  end
604
- if s0.last.success?
650
+ if s0.last
605
651
  r0 = (ParsingRule).new(input, i0...index, s0)
606
652
  r0.extend(ParsingRule0)
607
653
  else
608
654
  self.index = i0
609
- r0 = ParseFailure.new(input, i0, s0)
655
+ r0 = nil
610
656
  end
611
657
 
612
658
  node_cache[:parsing_rule][start_index] = r0
@@ -622,27 +668,21 @@ module Treetop
622
668
  return cached
623
669
  end
624
670
 
625
- i0, nr0 = index, []
671
+ i0 = index
626
672
  r1 = _nt_choice
627
- nr0 << r1
628
- if r1.success?
673
+ if r1
629
674
  r0 = r1
630
- r1.update_nested_results(nr0)
631
675
  else
632
676
  r2 = _nt_sequence
633
- nr0 << r2
634
- if r2.success?
677
+ if r2
635
678
  r0 = r2
636
- r2.update_nested_results(nr0)
637
679
  else
638
680
  r3 = _nt_primary
639
- nr0 << r3
640
- if r3.success?
681
+ if r3
641
682
  r0 = r3
642
- r3.update_nested_results(nr0)
643
683
  else
644
684
  self.index = i0
645
- r0 = ParseFailure.new(input, i0, nr0)
685
+ r0 = nil
646
686
  end
647
687
  end
648
688
  end
@@ -690,46 +730,51 @@ module Treetop
690
730
  return cached
691
731
  end
692
732
 
693
- i0, s0, nr0 = index, [], []
733
+ i0, s0 = index, []
694
734
  r1 = _nt_alternative
695
735
  s0 << r1
696
- if r1.success?
697
- s2, nr2, i2 = [], [], index
736
+ if r1
737
+ s2, i2 = [], index
698
738
  loop do
699
- i3, s3, nr3 = index, [], []
739
+ i3, s3 = index, []
700
740
  r5 = _nt_space
701
- if r5.success?
741
+ if r5
702
742
  r4 = r5
703
743
  else
704
- r4 = SyntaxNode.new(input, index...index, r5.nested_failures)
744
+ r4 = SyntaxNode.new(input, index...index)
705
745
  end
706
746
  s3 << r4
707
- if r4.success?
708
- r6 = parse_terminal('/', SyntaxNode)
747
+ if r4
748
+ if input.index('/', index) == index
749
+ r6 = (SyntaxNode).new(input, index...(index + 1))
750
+ @index += 1
751
+ else
752
+ terminal_parse_failure('/')
753
+ r6 = nil
754
+ end
709
755
  s3 << r6
710
- if r6.success?
756
+ if r6
711
757
  r8 = _nt_space
712
- if r8.success?
758
+ if r8
713
759
  r7 = r8
714
760
  else
715
- r7 = SyntaxNode.new(input, index...index, r8.nested_failures)
761
+ r7 = SyntaxNode.new(input, index...index)
716
762
  end
717
763
  s3 << r7
718
- if r7.success?
764
+ if r7
719
765
  r9 = _nt_alternative
720
766
  s3 << r9
721
767
  end
722
768
  end
723
769
  end
724
- if s3.last.success?
770
+ if s3.last
725
771
  r3 = (SyntaxNode).new(input, i3...index, s3)
726
772
  r3.extend(Choice0)
727
773
  else
728
774
  self.index = i3
729
- r3 = ParseFailure.new(input, i3, s3)
775
+ r3 = nil
730
776
  end
731
- nr2 << r3
732
- if r3.success?
777
+ if r3
733
778
  s2 << r3
734
779
  else
735
780
  break
@@ -737,19 +782,19 @@ module Treetop
737
782
  end
738
783
  if s2.empty?
739
784
  self.index = i2
740
- r2 = ParseFailure.new(input, i2, nr2)
785
+ r2 = nil
741
786
  else
742
- r2 = SyntaxNode.new(input, i2...index, s2, nr2)
787
+ r2 = SyntaxNode.new(input, i2...index, s2)
743
788
  end
744
789
  s0 << r2
745
790
  end
746
- if s0.last.success?
791
+ if s0.last
747
792
  r0 = (Choice).new(input, i0...index, s0)
748
793
  r0.extend(Choice1)
749
794
  r0.extend(Choice2)
750
795
  else
751
796
  self.index = i0
752
- r0 = ParseFailure.new(input, i0, s0)
797
+ r0 = nil
753
798
  end
754
799
 
755
800
  node_cache[:choice][start_index] = r0
@@ -809,28 +854,27 @@ module Treetop
809
854
  return cached
810
855
  end
811
856
 
812
- i0, s0, nr0 = index, [], []
857
+ i0, s0 = index, []
813
858
  r1 = _nt_labeled_sequence_primary
814
859
  s0 << r1
815
- if r1.success?
816
- s2, nr2, i2 = [], [], index
860
+ if r1
861
+ s2, i2 = [], index
817
862
  loop do
818
- i3, s3, nr3 = index, [], []
863
+ i3, s3 = index, []
819
864
  r4 = _nt_space
820
865
  s3 << r4
821
- if r4.success?
866
+ if r4
822
867
  r5 = _nt_labeled_sequence_primary
823
868
  s3 << r5
824
869
  end
825
- if s3.last.success?
870
+ if s3.last
826
871
  r3 = (SyntaxNode).new(input, i3...index, s3)
827
872
  r3.extend(Sequence0)
828
873
  else
829
874
  self.index = i3
830
- r3 = ParseFailure.new(input, i3, s3)
875
+ r3 = nil
831
876
  end
832
- nr2 << r3
833
- if r3.success?
877
+ if r3
834
878
  s2 << r3
835
879
  else
836
880
  break
@@ -838,23 +882,23 @@ module Treetop
838
882
  end
839
883
  if s2.empty?
840
884
  self.index = i2
841
- r2 = ParseFailure.new(input, i2, nr2)
885
+ r2 = nil
842
886
  else
843
- r2 = SyntaxNode.new(input, i2...index, s2, nr2)
887
+ r2 = SyntaxNode.new(input, i2...index, s2)
844
888
  end
845
889
  s0 << r2
846
- if r2.success?
890
+ if r2
847
891
  r6 = _nt_node_class_declarations
848
892
  s0 << r6
849
893
  end
850
894
  end
851
- if s0.last.success?
895
+ if s0.last
852
896
  r0 = (Sequence).new(input, i0...index, s0)
853
897
  r0.extend(Sequence1)
854
898
  r0.extend(Sequence2)
855
899
  else
856
900
  self.index = i0
857
- r0 = ParseFailure.new(input, i0, s0)
901
+ r0 = nil
858
902
  end
859
903
 
860
904
  node_cache[:sequence][start_index] = r0
@@ -870,21 +914,17 @@ module Treetop
870
914
  return cached
871
915
  end
872
916
 
873
- i0, nr0 = index, []
917
+ i0 = index
874
918
  r1 = _nt_sequence
875
- nr0 << r1
876
- if r1.success?
919
+ if r1
877
920
  r0 = r1
878
- r1.update_nested_results(nr0)
879
921
  else
880
922
  r2 = _nt_primary
881
- nr0 << r2
882
- if r2.success?
923
+ if r2
883
924
  r0 = r2
884
- r2.update_nested_results(nr0)
885
925
  else
886
926
  self.index = i0
887
- r0 = ParseFailure.new(input, i0, nr0)
927
+ r0 = nil
888
928
  end
889
929
  end
890
930
 
@@ -993,73 +1033,67 @@ module Treetop
993
1033
  return cached
994
1034
  end
995
1035
 
996
- i0, nr0 = index, []
997
- i1, s1, nr1 = index, [], []
1036
+ i0 = index
1037
+ i1, s1 = index, []
998
1038
  r2 = _nt_prefix
999
1039
  s1 << r2
1000
- if r2.success?
1040
+ if r2
1001
1041
  r3 = _nt_atomic
1002
1042
  s1 << r3
1003
1043
  end
1004
- if s1.last.success?
1044
+ if s1.last
1005
1045
  r1 = (SyntaxNode).new(input, i1...index, s1)
1006
1046
  r1.extend(Primary0)
1007
1047
  r1.extend(Primary1)
1008
1048
  else
1009
1049
  self.index = i1
1010
- r1 = ParseFailure.new(input, i1, s1)
1050
+ r1 = nil
1011
1051
  end
1012
- nr0 << r1
1013
- if r1.success?
1052
+ if r1
1014
1053
  r0 = r1
1015
- r1.update_nested_results(nr0)
1016
1054
  else
1017
- i4, s4, nr4 = index, [], []
1055
+ i4, s4 = index, []
1018
1056
  r5 = _nt_atomic
1019
1057
  s4 << r5
1020
- if r5.success?
1058
+ if r5
1021
1059
  r6 = _nt_suffix
1022
1060
  s4 << r6
1023
- if r6.success?
1061
+ if r6
1024
1062
  r7 = _nt_node_class_declarations
1025
1063
  s4 << r7
1026
1064
  end
1027
1065
  end
1028
- if s4.last.success?
1066
+ if s4.last
1029
1067
  r4 = (SyntaxNode).new(input, i4...index, s4)
1030
1068
  r4.extend(Primary2)
1031
1069
  r4.extend(Primary3)
1032
1070
  else
1033
1071
  self.index = i4
1034
- r4 = ParseFailure.new(input, i4, s4)
1072
+ r4 = nil
1035
1073
  end
1036
- nr0 << r4
1037
- if r4.success?
1074
+ if r4
1038
1075
  r0 = r4
1039
- r4.update_nested_results(nr0)
1040
1076
  else
1041
- i8, s8, nr8 = index, [], []
1077
+ i8, s8 = index, []
1042
1078
  r9 = _nt_atomic
1043
1079
  s8 << r9
1044
- if r9.success?
1080
+ if r9
1045
1081
  r10 = _nt_node_class_declarations
1046
1082
  s8 << r10
1047
1083
  end
1048
- if s8.last.success?
1084
+ if s8.last
1049
1085
  r8 = (SyntaxNode).new(input, i8...index, s8)
1050
1086
  r8.extend(Primary4)
1051
1087
  r8.extend(Primary5)
1052
1088
  else
1053
1089
  self.index = i8
1054
- r8 = ParseFailure.new(input, i8, s8)
1090
+ r8 = nil
1055
1091
  end
1056
- nr0 << r8
1057
- if r8.success?
1092
+ if r8
1058
1093
  r0 = r8
1059
- r8.update_nested_results(nr0)
1060
1094
  else
1061
1095
  self.index = i0
1062
- r0 = ParseFailure.new(input, i0, nr0)
1096
+ r0 = nil
1063
1097
  end
1064
1098
  end
1065
1099
  end
@@ -1107,20 +1141,20 @@ module Treetop
1107
1141
  return cached
1108
1142
  end
1109
1143
 
1110
- i0, s0, nr0 = index, [], []
1144
+ i0, s0 = index, []
1111
1145
  r1 = _nt_label
1112
1146
  s0 << r1
1113
- if r1.success?
1147
+ if r1
1114
1148
  r2 = _nt_sequence_primary
1115
1149
  s0 << r2
1116
1150
  end
1117
- if s0.last.success?
1151
+ if s0.last
1118
1152
  r0 = (SyntaxNode).new(input, i0...index, s0)
1119
1153
  r0.extend(LabeledSequencePrimary0)
1120
1154
  r0.extend(LabeledSequencePrimary1)
1121
1155
  else
1122
1156
  self.index = i0
1123
- r0 = ParseFailure.new(input, i0, s0)
1157
+ r0 = nil
1124
1158
  end
1125
1159
 
1126
1160
  node_cache[:labeled_sequence_primary][start_index] = r0
@@ -1158,58 +1192,66 @@ module Treetop
1158
1192
  return cached
1159
1193
  end
1160
1194
 
1161
- i0, nr0 = index, []
1162
- i1, s1, nr1 = index, [], []
1163
- i2, s2, nr2 = index, [], []
1195
+ i0 = index
1196
+ i1, s1 = index, []
1197
+ i2, s2 = index, []
1164
1198
  r3 = _nt_alpha_char
1165
1199
  s2 << r3
1166
- if r3.success?
1167
- s4, nr4, i4 = [], [], index
1200
+ if r3
1201
+ s4, i4 = [], index
1168
1202
  loop do
1169
1203
  r5 = _nt_alphanumeric_char
1170
- nr4 << r5
1171
- if r5.success?
1204
+ if r5
1172
1205
  s4 << r5
1173
1206
  else
1174
1207
  break
1175
1208
  end
1176
1209
  end
1177
- r4 = SyntaxNode.new(input, i4...index, s4, nr4)
1210
+ r4 = SyntaxNode.new(input, i4...index, s4)
1178
1211
  s2 << r4
1179
1212
  end
1180
- if s2.last.success?
1213
+ if s2.last
1181
1214
  r2 = (SyntaxNode).new(input, i2...index, s2)
1182
1215
  r2.extend(Label0)
1183
1216
  else
1184
1217
  self.index = i2
1185
- r2 = ParseFailure.new(input, i2, s2)
1218
+ r2 = nil
1186
1219
  end
1187
1220
  s1 << r2
1188
- if r2.success?
1189
- r6 = parse_terminal(':', SyntaxNode)
1221
+ if r2
1222
+ if input.index(':', index) == index
1223
+ r6 = (SyntaxNode).new(input, index...(index + 1))
1224
+ @index += 1
1225
+ else
1226
+ terminal_parse_failure(':')
1227
+ r6 = nil
1228
+ end
1190
1229
  s1 << r6
1191
1230
  end
1192
- if s1.last.success?
1231
+ if s1.last
1193
1232
  r1 = (SyntaxNode).new(input, i1...index, s1)
1194
1233
  r1.extend(Label1)
1195
1234
  r1.extend(Label2)
1196
1235
  else
1197
1236
  self.index = i1
1198
- r1 = ParseFailure.new(input, i1, s1)
1237
+ r1 = nil
1199
1238
  end
1200
- nr0 << r1
1201
- if r1.success?
1239
+ if r1
1202
1240
  r0 = r1
1203
- r1.update_nested_results(nr0)
1204
1241
  else
1205
- r7 = parse_terminal('', SyntaxNode, Label3)
1206
- nr0 << r7
1207
- if r7.success?
1242
+ if input.index('', index) == index
1243
+ r7 = (SyntaxNode).new(input, index...(index + 0))
1244
+ r7.extend(Label3)
1245
+ @index += 0
1246
+ else
1247
+ terminal_parse_failure('')
1248
+ r7 = nil
1249
+ end
1250
+ if r7
1208
1251
  r0 = r7
1209
- r7.update_nested_results(nr0)
1210
1252
  else
1211
1253
  self.index = i0
1212
- r0 = ParseFailure.new(input, i0, nr0)
1254
+ r0 = nil
1213
1255
  end
1214
1256
  end
1215
1257
 
@@ -1282,55 +1324,49 @@ module Treetop
1282
1324
  return cached
1283
1325
  end
1284
1326
 
1285
- i0, nr0 = index, []
1286
- i1, s1, nr1 = index, [], []
1327
+ i0 = index
1328
+ i1, s1 = index, []
1287
1329
  r2 = _nt_prefix
1288
1330
  s1 << r2
1289
- if r2.success?
1331
+ if r2
1290
1332
  r3 = _nt_atomic
1291
1333
  s1 << r3
1292
1334
  end
1293
- if s1.last.success?
1335
+ if s1.last
1294
1336
  r1 = (SyntaxNode).new(input, i1...index, s1)
1295
1337
  r1.extend(SequencePrimary0)
1296
1338
  r1.extend(SequencePrimary1)
1297
1339
  else
1298
1340
  self.index = i1
1299
- r1 = ParseFailure.new(input, i1, s1)
1341
+ r1 = nil
1300
1342
  end
1301
- nr0 << r1
1302
- if r1.success?
1343
+ if r1
1303
1344
  r0 = r1
1304
- r1.update_nested_results(nr0)
1305
1345
  else
1306
- i4, s4, nr4 = index, [], []
1346
+ i4, s4 = index, []
1307
1347
  r5 = _nt_atomic
1308
1348
  s4 << r5
1309
- if r5.success?
1349
+ if r5
1310
1350
  r6 = _nt_suffix
1311
1351
  s4 << r6
1312
1352
  end
1313
- if s4.last.success?
1353
+ if s4.last
1314
1354
  r4 = (SyntaxNode).new(input, i4...index, s4)
1315
1355
  r4.extend(SequencePrimary2)
1316
1356
  r4.extend(SequencePrimary3)
1317
1357
  else
1318
1358
  self.index = i4
1319
- r4 = ParseFailure.new(input, i4, s4)
1359
+ r4 = nil
1320
1360
  end
1321
- nr0 << r4
1322
- if r4.success?
1361
+ if r4
1323
1362
  r0 = r4
1324
- r4.update_nested_results(nr0)
1325
1363
  else
1326
1364
  r7 = _nt_atomic
1327
- nr0 << r7
1328
- if r7.success?
1365
+ if r7
1329
1366
  r0 = r7
1330
- r7.update_nested_results(nr0)
1331
1367
  else
1332
1368
  self.index = i0
1333
- r0 = ParseFailure.new(input, i0, nr0)
1369
+ r0 = nil
1334
1370
  end
1335
1371
  end
1336
1372
  end
@@ -1348,21 +1384,17 @@ module Treetop
1348
1384
  return cached
1349
1385
  end
1350
1386
 
1351
- i0, nr0 = index, []
1387
+ i0 = index
1352
1388
  r1 = _nt_repetition_suffix
1353
- nr0 << r1
1354
- if r1.success?
1389
+ if r1
1355
1390
  r0 = r1
1356
- r1.update_nested_results(nr0)
1357
1391
  else
1358
1392
  r2 = _nt_optional_suffix
1359
- nr0 << r2
1360
- if r2.success?
1393
+ if r2
1361
1394
  r0 = r2
1362
- r2.update_nested_results(nr0)
1363
1395
  else
1364
1396
  self.index = i0
1365
- r0 = ParseFailure.new(input, i0, nr0)
1397
+ r0 = nil
1366
1398
  end
1367
1399
  end
1368
1400
 
@@ -1379,7 +1411,13 @@ module Treetop
1379
1411
  return cached
1380
1412
  end
1381
1413
 
1382
- r0 = parse_terminal('?', Optional)
1414
+ if input.index('?', index) == index
1415
+ r0 = (Optional).new(input, index...(index + 1))
1416
+ @index += 1
1417
+ else
1418
+ terminal_parse_failure('?')
1419
+ r0 = nil
1420
+ end
1383
1421
 
1384
1422
  node_cache[:optional_suffix][start_index] = r0
1385
1423
 
@@ -1422,20 +1460,20 @@ module Treetop
1422
1460
  return cached
1423
1461
  end
1424
1462
 
1425
- i0, s0, nr0 = index, [], []
1463
+ i0, s0 = index, []
1426
1464
  r1 = _nt_node_class_expression
1427
1465
  s0 << r1
1428
- if r1.success?
1466
+ if r1
1429
1467
  r2 = _nt_trailing_inline_module
1430
1468
  s0 << r2
1431
1469
  end
1432
- if s0.last.success?
1470
+ if s0.last
1433
1471
  r0 = (SyntaxNode).new(input, i0...index, s0)
1434
1472
  r0.extend(NodeClassDeclarations0)
1435
1473
  r0.extend(NodeClassDeclarations1)
1436
1474
  else
1437
1475
  self.index = i0
1438
- r0 = ParseFailure.new(input, i0, s0)
1476
+ r0 = nil
1439
1477
  end
1440
1478
 
1441
1479
  node_cache[:node_class_declarations][start_index] = r0
@@ -1451,21 +1489,29 @@ module Treetop
1451
1489
  return cached
1452
1490
  end
1453
1491
 
1454
- i0, nr0 = index, []
1455
- r1 = parse_terminal('+', OneOrMore)
1456
- nr0 << r1
1457
- if r1.success?
1492
+ i0 = index
1493
+ if input.index('+', index) == index
1494
+ r1 = (OneOrMore).new(input, index...(index + 1))
1495
+ @index += 1
1496
+ else
1497
+ terminal_parse_failure('+')
1498
+ r1 = nil
1499
+ end
1500
+ if r1
1458
1501
  r0 = r1
1459
- r1.update_nested_results(nr0)
1460
1502
  else
1461
- r2 = parse_terminal('*', ZeroOrMore)
1462
- nr0 << r2
1463
- if r2.success?
1503
+ if input.index('*', index) == index
1504
+ r2 = (ZeroOrMore).new(input, index...(index + 1))
1505
+ @index += 1
1506
+ else
1507
+ terminal_parse_failure('*')
1508
+ r2 = nil
1509
+ end
1510
+ if r2
1464
1511
  r0 = r2
1465
- r2.update_nested_results(nr0)
1466
1512
  else
1467
1513
  self.index = i0
1468
- r0 = ParseFailure.new(input, i0, nr0)
1514
+ r0 = nil
1469
1515
  end
1470
1516
  end
1471
1517
 
@@ -1482,21 +1528,29 @@ module Treetop
1482
1528
  return cached
1483
1529
  end
1484
1530
 
1485
- i0, nr0 = index, []
1486
- r1 = parse_terminal('&', AndPredicate)
1487
- nr0 << r1
1488
- if r1.success?
1531
+ i0 = index
1532
+ if input.index('&', index) == index
1533
+ r1 = (AndPredicate).new(input, index...(index + 1))
1534
+ @index += 1
1535
+ else
1536
+ terminal_parse_failure('&')
1537
+ r1 = nil
1538
+ end
1539
+ if r1
1489
1540
  r0 = r1
1490
- r1.update_nested_results(nr0)
1491
1541
  else
1492
- r2 = parse_terminal('!', NotPredicate)
1493
- nr0 << r2
1494
- if r2.success?
1542
+ if input.index('!', index) == index
1543
+ r2 = (NotPredicate).new(input, index...(index + 1))
1544
+ @index += 1
1545
+ else
1546
+ terminal_parse_failure('!')
1547
+ r2 = nil
1548
+ end
1549
+ if r2
1495
1550
  r0 = r2
1496
- r2.update_nested_results(nr0)
1497
1551
  else
1498
1552
  self.index = i0
1499
- r0 = ParseFailure.new(input, i0, nr0)
1553
+ r0 = nil
1500
1554
  end
1501
1555
  end
1502
1556
 
@@ -1513,27 +1567,21 @@ module Treetop
1513
1567
  return cached
1514
1568
  end
1515
1569
 
1516
- i0, nr0 = index, []
1570
+ i0 = index
1517
1571
  r1 = _nt_terminal
1518
- nr0 << r1
1519
- if r1.success?
1572
+ if r1
1520
1573
  r0 = r1
1521
- r1.update_nested_results(nr0)
1522
1574
  else
1523
1575
  r2 = _nt_nonterminal
1524
- nr0 << r2
1525
- if r2.success?
1576
+ if r2
1526
1577
  r0 = r2
1527
- r2.update_nested_results(nr0)
1528
1578
  else
1529
1579
  r3 = _nt_parenthesized_expression
1530
- nr0 << r3
1531
- if r3.success?
1580
+ if r3
1532
1581
  r0 = r3
1533
- r3.update_nested_results(nr0)
1534
1582
  else
1535
1583
  self.index = i0
1536
- r0 = ParseFailure.new(input, i0, nr0)
1584
+ r0 = nil
1537
1585
  end
1538
1586
  end
1539
1587
  end
@@ -1564,42 +1612,54 @@ module Treetop
1564
1612
  return cached
1565
1613
  end
1566
1614
 
1567
- i0, s0, nr0 = index, [], []
1568
- r1 = parse_terminal('(', SyntaxNode)
1615
+ i0, s0 = index, []
1616
+ if input.index('(', index) == index
1617
+ r1 = (SyntaxNode).new(input, index...(index + 1))
1618
+ @index += 1
1619
+ else
1620
+ terminal_parse_failure('(')
1621
+ r1 = nil
1622
+ end
1569
1623
  s0 << r1
1570
- if r1.success?
1624
+ if r1
1571
1625
  r3 = _nt_space
1572
- if r3.success?
1626
+ if r3
1573
1627
  r2 = r3
1574
1628
  else
1575
- r2 = SyntaxNode.new(input, index...index, r3.nested_failures)
1629
+ r2 = SyntaxNode.new(input, index...index)
1576
1630
  end
1577
1631
  s0 << r2
1578
- if r2.success?
1632
+ if r2
1579
1633
  r4 = _nt_parsing_expression
1580
1634
  s0 << r4
1581
- if r4.success?
1635
+ if r4
1582
1636
  r6 = _nt_space
1583
- if r6.success?
1637
+ if r6
1584
1638
  r5 = r6
1585
1639
  else
1586
- r5 = SyntaxNode.new(input, index...index, r6.nested_failures)
1640
+ r5 = SyntaxNode.new(input, index...index)
1587
1641
  end
1588
1642
  s0 << r5
1589
- if r5.success?
1590
- r7 = parse_terminal(')', SyntaxNode)
1643
+ if r5
1644
+ if input.index(')', index) == index
1645
+ r7 = (SyntaxNode).new(input, index...(index + 1))
1646
+ @index += 1
1647
+ else
1648
+ terminal_parse_failure(')')
1649
+ r7 = nil
1650
+ end
1591
1651
  s0 << r7
1592
1652
  end
1593
1653
  end
1594
1654
  end
1595
1655
  end
1596
- if s0.last.success?
1656
+ if s0.last
1597
1657
  r0 = (ParenthesizedExpression).new(input, i0...index, s0)
1598
1658
  r0.extend(ParenthesizedExpression0)
1599
1659
  r0.extend(ParenthesizedExpression1)
1600
1660
  else
1601
1661
  self.index = i0
1602
- r0 = ParseFailure.new(input, i0, s0)
1662
+ r0 = nil
1603
1663
  end
1604
1664
 
1605
1665
  node_cache[:parenthesized_expression][start_index] = r0
@@ -1625,49 +1685,48 @@ module Treetop
1625
1685
  return cached
1626
1686
  end
1627
1687
 
1628
- i0, s0, nr0 = index, [], []
1688
+ i0, s0 = index, []
1629
1689
  i1 = index
1630
1690
  r2 = _nt_keyword_inside_grammar
1631
- if r2.success?
1632
- r1 = ParseFailure.new(input, i1, r2.nested_failures)
1691
+ if r2
1692
+ r1 = nil
1633
1693
  else
1634
1694
  self.index = i1
1635
- r1 = SyntaxNode.new(input, index...index, r2.nested_failures)
1695
+ r1 = SyntaxNode.new(input, index...index)
1636
1696
  end
1637
1697
  s0 << r1
1638
- if r1.success?
1639
- i3, s3, nr3 = index, [], []
1698
+ if r1
1699
+ i3, s3 = index, []
1640
1700
  r4 = _nt_alpha_char
1641
1701
  s3 << r4
1642
- if r4.success?
1643
- s5, nr5, i5 = [], [], index
1702
+ if r4
1703
+ s5, i5 = [], index
1644
1704
  loop do
1645
1705
  r6 = _nt_alphanumeric_char
1646
- nr5 << r6
1647
- if r6.success?
1706
+ if r6
1648
1707
  s5 << r6
1649
1708
  else
1650
1709
  break
1651
1710
  end
1652
1711
  end
1653
- r5 = SyntaxNode.new(input, i5...index, s5, nr5)
1712
+ r5 = SyntaxNode.new(input, i5...index, s5)
1654
1713
  s3 << r5
1655
1714
  end
1656
- if s3.last.success?
1715
+ if s3.last
1657
1716
  r3 = (SyntaxNode).new(input, i3...index, s3)
1658
1717
  r3.extend(Nonterminal0)
1659
1718
  else
1660
1719
  self.index = i3
1661
- r3 = ParseFailure.new(input, i3, s3)
1720
+ r3 = nil
1662
1721
  end
1663
1722
  s0 << r3
1664
1723
  end
1665
- if s0.last.success?
1724
+ if s0.last
1666
1725
  r0 = (Nonterminal).new(input, i0...index, s0)
1667
1726
  r0.extend(Nonterminal1)
1668
1727
  else
1669
1728
  self.index = i0
1670
- r0 = ParseFailure.new(input, i0, s0)
1729
+ r0 = nil
1671
1730
  end
1672
1731
 
1673
1732
  node_cache[:nonterminal][start_index] = r0
@@ -1683,34 +1742,21 @@ module Treetop
1683
1742
  return cached
1684
1743
  end
1685
1744
 
1686
- i0, nr0 = index, []
1687
- r1 = _nt_single_quoted_string
1688
- nr0 << r1
1689
- if r1.success?
1745
+ i0 = index
1746
+ r1 = _nt_quoted_string
1747
+ if r1
1690
1748
  r0 = r1
1691
- r1.update_nested_results(nr0)
1692
1749
  else
1693
- r2 = _nt_double_quoted_string
1694
- nr0 << r2
1695
- if r2.success?
1750
+ r2 = _nt_character_class
1751
+ if r2
1696
1752
  r0 = r2
1697
- r2.update_nested_results(nr0)
1698
1753
  else
1699
- r3 = _nt_character_class
1700
- nr0 << r3
1701
- if r3.success?
1754
+ r3 = _nt_anything_symbol
1755
+ if r3
1702
1756
  r0 = r3
1703
- r3.update_nested_results(nr0)
1704
1757
  else
1705
- r4 = _nt_anything_symbol
1706
- nr0 << r4
1707
- if r4.success?
1708
- r0 = r4
1709
- r4.update_nested_results(nr0)
1710
- else
1711
- self.index = i0
1712
- r0 = ParseFailure.new(input, i0, nr0)
1713
- end
1758
+ self.index = i0
1759
+ r0 = nil
1714
1760
  end
1715
1761
  end
1716
1762
  end
@@ -1720,10 +1766,49 @@ module Treetop
1720
1766
  return r0
1721
1767
  end
1722
1768
 
1769
+ module QuotedString0
1770
+ def string
1771
+ super.text_value
1772
+ end
1773
+ end
1774
+
1775
+ def _nt_quoted_string
1776
+ start_index = index
1777
+ cached = node_cache[:quoted_string][index]
1778
+ if cached
1779
+ @index = cached.interval.end
1780
+ return cached
1781
+ end
1782
+
1783
+ i0 = index
1784
+ r1 = _nt_single_quoted_string
1785
+ if r1
1786
+ r0 = r1
1787
+ r0.extend(QuotedString0)
1788
+ else
1789
+ r2 = _nt_double_quoted_string
1790
+ if r2
1791
+ r0 = r2
1792
+ r0.extend(QuotedString0)
1793
+ else
1794
+ self.index = i0
1795
+ r0 = nil
1796
+ end
1797
+ end
1798
+
1799
+ node_cache[:quoted_string][start_index] = r0
1800
+
1801
+ return r0
1802
+ end
1803
+
1723
1804
  module DoubleQuotedString0
1724
1805
  end
1725
1806
 
1726
1807
  module DoubleQuotedString1
1808
+ def string
1809
+ elements[1]
1810
+ end
1811
+
1727
1812
  end
1728
1813
 
1729
1814
  def _nt_double_quoted_string
@@ -1734,76 +1819,105 @@ module Treetop
1734
1819
  return cached
1735
1820
  end
1736
1821
 
1737
- i0, s0, nr0 = index, [], []
1738
- r1 = parse_terminal('"', SyntaxNode)
1822
+ i0, s0 = index, []
1823
+ if input.index('"', index) == index
1824
+ r1 = (SyntaxNode).new(input, index...(index + 1))
1825
+ @index += 1
1826
+ else
1827
+ terminal_parse_failure('"')
1828
+ r1 = nil
1829
+ end
1739
1830
  s0 << r1
1740
- if r1.success?
1741
- s2, nr2, i2 = [], [], index
1831
+ if r1
1832
+ s2, i2 = [], index
1742
1833
  loop do
1743
- i3, s3, nr3 = index, [], []
1834
+ i3, s3 = index, []
1744
1835
  i4 = index
1745
- r5 = parse_terminal('"', SyntaxNode)
1746
- if r5.success?
1747
- r4 = ParseFailure.new(input, i4, r5.nested_failures)
1836
+ if input.index('"', index) == index
1837
+ r5 = (SyntaxNode).new(input, index...(index + 1))
1838
+ @index += 1
1839
+ else
1840
+ terminal_parse_failure('"')
1841
+ r5 = nil
1842
+ end
1843
+ if r5
1844
+ r4 = nil
1748
1845
  else
1749
1846
  self.index = i4
1750
- r4 = SyntaxNode.new(input, index...index, r5.nested_failures)
1847
+ r4 = SyntaxNode.new(input, index...index)
1751
1848
  end
1752
1849
  s3 << r4
1753
- if r4.success?
1754
- i6, nr6 = index, []
1755
- r7 = parse_terminal("\\\\", SyntaxNode)
1756
- nr6 << r7
1757
- if r7.success?
1850
+ if r4
1851
+ i6 = index
1852
+ if input.index("\\\\", index) == index
1853
+ r7 = (SyntaxNode).new(input, index...(index + 2))
1854
+ @index += 2
1855
+ else
1856
+ terminal_parse_failure("\\\\")
1857
+ r7 = nil
1858
+ end
1859
+ if r7
1758
1860
  r6 = r7
1759
- r7.update_nested_results(nr6)
1760
1861
  else
1761
- r8 = parse_terminal('\"', SyntaxNode)
1762
- nr6 << r8
1763
- if r8.success?
1862
+ if input.index('\"', index) == index
1863
+ r8 = (SyntaxNode).new(input, index...(index + 2))
1864
+ @index += 2
1865
+ else
1866
+ terminal_parse_failure('\"')
1867
+ r8 = nil
1868
+ end
1869
+ if r8
1764
1870
  r6 = r8
1765
- r8.update_nested_results(nr6)
1766
1871
  else
1767
- r9 = parse_anything(SyntaxNode)
1768
- nr6 << r9
1769
- if r9.success?
1872
+ if index < input_length
1873
+ r9 = (SyntaxNode).new(input, index...(index + 1))
1874
+ @index += 1
1875
+ else
1876
+ terminal_parse_failure("any character")
1877
+ r9 = nil
1878
+ end
1879
+ if r9
1770
1880
  r6 = r9
1771
- r9.update_nested_results(nr6)
1772
1881
  else
1773
1882
  self.index = i6
1774
- r6 = ParseFailure.new(input, i6, nr6)
1883
+ r6 = nil
1775
1884
  end
1776
1885
  end
1777
1886
  end
1778
1887
  s3 << r6
1779
1888
  end
1780
- if s3.last.success?
1889
+ if s3.last
1781
1890
  r3 = (SyntaxNode).new(input, i3...index, s3)
1782
1891
  r3.extend(DoubleQuotedString0)
1783
1892
  else
1784
1893
  self.index = i3
1785
- r3 = ParseFailure.new(input, i3, s3)
1894
+ r3 = nil
1786
1895
  end
1787
- nr2 << r3
1788
- if r3.success?
1896
+ if r3
1789
1897
  s2 << r3
1790
1898
  else
1791
1899
  break
1792
1900
  end
1793
1901
  end
1794
- r2 = SyntaxNode.new(input, i2...index, s2, nr2)
1902
+ r2 = SyntaxNode.new(input, i2...index, s2)
1795
1903
  s0 << r2
1796
- if r2.success?
1797
- r10 = parse_terminal('"', SyntaxNode)
1904
+ if r2
1905
+ if input.index('"', index) == index
1906
+ r10 = (SyntaxNode).new(input, index...(index + 1))
1907
+ @index += 1
1908
+ else
1909
+ terminal_parse_failure('"')
1910
+ r10 = nil
1911
+ end
1798
1912
  s0 << r10
1799
1913
  end
1800
1914
  end
1801
- if s0.last.success?
1915
+ if s0.last
1802
1916
  r0 = (Terminal).new(input, i0...index, s0)
1803
1917
  r0.extend(DoubleQuotedString1)
1804
1918
  else
1805
1919
  self.index = i0
1806
- r0 = ParseFailure.new(input, i0, s0)
1920
+ r0 = nil
1807
1921
  end
1808
1922
 
1809
1923
  node_cache[:double_quoted_string][start_index] = r0
@@ -1815,6 +1929,10 @@ module Treetop
1815
1929
  end
1816
1930
 
1817
1931
  module SingleQuotedString1
1932
+ def string
1933
+ elements[1]
1934
+ end
1935
+
1818
1936
  end
1819
1937
 
1820
1938
  def _nt_single_quoted_string
@@ -1825,76 +1943,105 @@ module Treetop
1825
1943
  return cached
1826
1944
  end
1827
1945
 
1828
- i0, s0, nr0 = index, [], []
1829
- r1 = parse_terminal("'", SyntaxNode)
1946
+ i0, s0 = index, []
1947
+ if input.index("'", index) == index
1948
+ r1 = (SyntaxNode).new(input, index...(index + 1))
1949
+ @index += 1
1950
+ else
1951
+ terminal_parse_failure("'")
1952
+ r1 = nil
1953
+ end
1830
1954
  s0 << r1
1831
- if r1.success?
1832
- s2, nr2, i2 = [], [], index
1955
+ if r1
1956
+ s2, i2 = [], index
1833
1957
  loop do
1834
- i3, s3, nr3 = index, [], []
1958
+ i3, s3 = index, []
1835
1959
  i4 = index
1836
- r5 = parse_terminal("'", SyntaxNode)
1837
- if r5.success?
1838
- r4 = ParseFailure.new(input, i4, r5.nested_failures)
1960
+ if input.index("'", index) == index
1961
+ r5 = (SyntaxNode).new(input, index...(index + 1))
1962
+ @index += 1
1963
+ else
1964
+ terminal_parse_failure("'")
1965
+ r5 = nil
1966
+ end
1967
+ if r5
1968
+ r4 = nil
1839
1969
  else
1840
1970
  self.index = i4
1841
- r4 = SyntaxNode.new(input, index...index, r5.nested_failures)
1971
+ r4 = SyntaxNode.new(input, index...index)
1842
1972
  end
1843
1973
  s3 << r4
1844
- if r4.success?
1845
- i6, nr6 = index, []
1846
- r7 = parse_terminal("\\\\", SyntaxNode)
1847
- nr6 << r7
1848
- if r7.success?
1974
+ if r4
1975
+ i6 = index
1976
+ if input.index("\\\\", index) == index
1977
+ r7 = (SyntaxNode).new(input, index...(index + 2))
1978
+ @index += 2
1979
+ else
1980
+ terminal_parse_failure("\\\\")
1981
+ r7 = nil
1982
+ end
1983
+ if r7
1849
1984
  r6 = r7
1850
- r7.update_nested_results(nr6)
1851
1985
  else
1852
- r8 = parse_terminal("\\'", SyntaxNode)
1853
- nr6 << r8
1854
- if r8.success?
1986
+ if input.index("\\'", index) == index
1987
+ r8 = (SyntaxNode).new(input, index...(index + 2))
1988
+ @index += 2
1989
+ else
1990
+ terminal_parse_failure("\\'")
1991
+ r8 = nil
1992
+ end
1993
+ if r8
1855
1994
  r6 = r8
1856
- r8.update_nested_results(nr6)
1857
1995
  else
1858
- r9 = parse_anything(SyntaxNode)
1859
- nr6 << r9
1860
- if r9.success?
1996
+ if index < input_length
1997
+ r9 = (SyntaxNode).new(input, index...(index + 1))
1998
+ @index += 1
1999
+ else
2000
+ terminal_parse_failure("any character")
2001
+ r9 = nil
2002
+ end
2003
+ if r9
1861
2004
  r6 = r9
1862
- r9.update_nested_results(nr6)
1863
2005
  else
1864
2006
  self.index = i6
1865
- r6 = ParseFailure.new(input, i6, nr6)
2007
+ r6 = nil
1866
2008
  end
1867
2009
  end
1868
2010
  end
1869
2011
  s3 << r6
1870
2012
  end
1871
- if s3.last.success?
2013
+ if s3.last
1872
2014
  r3 = (SyntaxNode).new(input, i3...index, s3)
1873
2015
  r3.extend(SingleQuotedString0)
1874
2016
  else
1875
2017
  self.index = i3
1876
- r3 = ParseFailure.new(input, i3, s3)
2018
+ r3 = nil
1877
2019
  end
1878
- nr2 << r3
1879
- if r3.success?
2020
+ if r3
1880
2021
  s2 << r3
1881
2022
  else
1882
2023
  break
1883
2024
  end
1884
2025
  end
1885
- r2 = SyntaxNode.new(input, i2...index, s2, nr2)
2026
+ r2 = SyntaxNode.new(input, i2...index, s2)
1886
2027
  s0 << r2
1887
- if r2.success?
1888
- r10 = parse_terminal("'", SyntaxNode)
2028
+ if r2
2029
+ if input.index("'", index) == index
2030
+ r10 = (SyntaxNode).new(input, index...(index + 1))
2031
+ @index += 1
2032
+ else
2033
+ terminal_parse_failure("'")
2034
+ r10 = nil
2035
+ end
1889
2036
  s0 << r10
1890
2037
  end
1891
2038
  end
1892
- if s0.last.success?
2039
+ if s0.last
1893
2040
  r0 = (Terminal).new(input, i0...index, s0)
1894
2041
  r0.extend(SingleQuotedString1)
1895
2042
  else
1896
2043
  self.index = i0
1897
- r0 = ParseFailure.new(input, i0, s0)
2044
+ r0 = nil
1898
2045
  end
1899
2046
 
1900
2047
  node_cache[:single_quoted_string][start_index] = r0
@@ -1906,6 +2053,16 @@ module Treetop
1906
2053
  end
1907
2054
 
1908
2055
  module CharacterClass1
2056
+ def characters
2057
+ elements[1]
2058
+ end
2059
+
2060
+ end
2061
+
2062
+ module CharacterClass2
2063
+ def characters
2064
+ super.text_value
2065
+ end
1909
2066
  end
1910
2067
 
1911
2068
  def _nt_character_class
@@ -1916,51 +2073,70 @@ module Treetop
1916
2073
  return cached
1917
2074
  end
1918
2075
 
1919
- i0, s0, nr0 = index, [], []
1920
- r1 = parse_terminal('[', SyntaxNode)
2076
+ i0, s0 = index, []
2077
+ if input.index('[', index) == index
2078
+ r1 = (SyntaxNode).new(input, index...(index + 1))
2079
+ @index += 1
2080
+ else
2081
+ terminal_parse_failure('[')
2082
+ r1 = nil
2083
+ end
1921
2084
  s0 << r1
1922
- if r1.success?
1923
- s2, nr2, i2 = [], [], index
2085
+ if r1
2086
+ s2, i2 = [], index
1924
2087
  loop do
1925
- i3, s3, nr3 = index, [], []
2088
+ i3, s3 = index, []
1926
2089
  i4 = index
1927
- r5 = parse_terminal(']', SyntaxNode)
1928
- if r5.success?
1929
- r4 = ParseFailure.new(input, i4, r5.nested_failures)
2090
+ if input.index(']', index) == index
2091
+ r5 = (SyntaxNode).new(input, index...(index + 1))
2092
+ @index += 1
2093
+ else
2094
+ terminal_parse_failure(']')
2095
+ r5 = nil
2096
+ end
2097
+ if r5
2098
+ r4 = nil
1930
2099
  else
1931
2100
  self.index = i4
1932
- r4 = SyntaxNode.new(input, index...index, r5.nested_failures)
2101
+ r4 = SyntaxNode.new(input, index...index)
1933
2102
  end
1934
2103
  s3 << r4
1935
- if r4.success?
1936
- i6, nr6 = index, []
1937
- r7 = parse_terminal('\]', SyntaxNode)
1938
- nr6 << r7
1939
- if r7.success?
2104
+ if r4
2105
+ i6 = index
2106
+ if input.index('\]', index) == index
2107
+ r7 = (SyntaxNode).new(input, index...(index + 2))
2108
+ @index += 2
2109
+ else
2110
+ terminal_parse_failure('\]')
2111
+ r7 = nil
2112
+ end
2113
+ if r7
1940
2114
  r6 = r7
1941
- r7.update_nested_results(nr6)
1942
2115
  else
1943
- r8 = parse_anything(SyntaxNode)
1944
- nr6 << r8
1945
- if r8.success?
2116
+ if index < input_length
2117
+ r8 = (SyntaxNode).new(input, index...(index + 1))
2118
+ @index += 1
2119
+ else
2120
+ terminal_parse_failure("any character")
2121
+ r8 = nil
2122
+ end
2123
+ if r8
1946
2124
  r6 = r8
1947
- r8.update_nested_results(nr6)
1948
2125
  else
1949
2126
  self.index = i6
1950
- r6 = ParseFailure.new(input, i6, nr6)
2127
+ r6 = nil
1951
2128
  end
1952
2129
  end
1953
2130
  s3 << r6
1954
2131
  end
1955
- if s3.last.success?
2132
+ if s3.last
1956
2133
  r3 = (SyntaxNode).new(input, i3...index, s3)
1957
2134
  r3.extend(CharacterClass0)
1958
2135
  else
1959
2136
  self.index = i3
1960
- r3 = ParseFailure.new(input, i3, s3)
2137
+ r3 = nil
1961
2138
  end
1962
- nr2 << r3
1963
- if r3.success?
2139
+ if r3
1964
2140
  s2 << r3
1965
2141
  else
1966
2142
  break
@@ -1968,22 +2144,29 @@ module Treetop
1968
2144
  end
1969
2145
  if s2.empty?
1970
2146
  self.index = i2
1971
- r2 = ParseFailure.new(input, i2, nr2)
2147
+ r2 = nil
1972
2148
  else
1973
- r2 = SyntaxNode.new(input, i2...index, s2, nr2)
2149
+ r2 = SyntaxNode.new(input, i2...index, s2)
1974
2150
  end
1975
2151
  s0 << r2
1976
- if r2.success?
1977
- r9 = parse_terminal(']', SyntaxNode)
2152
+ if r2
2153
+ if input.index(']', index) == index
2154
+ r9 = (SyntaxNode).new(input, index...(index + 1))
2155
+ @index += 1
2156
+ else
2157
+ terminal_parse_failure(']')
2158
+ r9 = nil
2159
+ end
1978
2160
  s0 << r9
1979
2161
  end
1980
2162
  end
1981
- if s0.last.success?
2163
+ if s0.last
1982
2164
  r0 = (CharacterClass).new(input, i0...index, s0)
1983
2165
  r0.extend(CharacterClass1)
2166
+ r0.extend(CharacterClass2)
1984
2167
  else
1985
2168
  self.index = i0
1986
- r0 = ParseFailure.new(input, i0, s0)
2169
+ r0 = nil
1987
2170
  end
1988
2171
 
1989
2172
  node_cache[:character_class][start_index] = r0
@@ -1999,7 +2182,13 @@ module Treetop
1999
2182
  return cached
2000
2183
  end
2001
2184
 
2002
- r0 = parse_terminal('.', AnythingSymbol)
2185
+ if input.index('.', index) == index
2186
+ r0 = (AnythingSymbol).new(input, index...(index + 1))
2187
+ @index += 1
2188
+ else
2189
+ terminal_parse_failure('.')
2190
+ r0 = nil
2191
+ end
2003
2192
 
2004
2193
  node_cache[:anything_symbol][start_index] = r0
2005
2194
 
@@ -2036,39 +2225,56 @@ module Treetop
2036
2225
  return cached
2037
2226
  end
2038
2227
 
2039
- i0, nr0 = index, []
2040
- i1, s1, nr1 = index, [], []
2228
+ i0 = index
2229
+ i1, s1 = index, []
2041
2230
  r2 = _nt_space
2042
2231
  s1 << r2
2043
- if r2.success?
2044
- r3 = parse_terminal('<', SyntaxNode)
2232
+ if r2
2233
+ if input.index('<', index) == index
2234
+ r3 = (SyntaxNode).new(input, index...(index + 1))
2235
+ @index += 1
2236
+ else
2237
+ terminal_parse_failure('<')
2238
+ r3 = nil
2239
+ end
2045
2240
  s1 << r3
2046
- if r3.success?
2047
- s4, nr4, i4 = [], [], index
2241
+ if r3
2242
+ s4, i4 = [], index
2048
2243
  loop do
2049
- i5, s5, nr5 = index, [], []
2244
+ i5, s5 = index, []
2050
2245
  i6 = index
2051
- r7 = parse_terminal('>', SyntaxNode)
2052
- if r7.success?
2053
- r6 = ParseFailure.new(input, i6, r7.nested_failures)
2246
+ if input.index('>', index) == index
2247
+ r7 = (SyntaxNode).new(input, index...(index + 1))
2248
+ @index += 1
2249
+ else
2250
+ terminal_parse_failure('>')
2251
+ r7 = nil
2252
+ end
2253
+ if r7
2254
+ r6 = nil
2054
2255
  else
2055
2256
  self.index = i6
2056
- r6 = SyntaxNode.new(input, index...index, r7.nested_failures)
2257
+ r6 = SyntaxNode.new(input, index...index)
2057
2258
  end
2058
2259
  s5 << r6
2059
- if r6.success?
2060
- r8 = parse_anything(SyntaxNode)
2260
+ if r6
2261
+ if index < input_length
2262
+ r8 = (SyntaxNode).new(input, index...(index + 1))
2263
+ @index += 1
2264
+ else
2265
+ terminal_parse_failure("any character")
2266
+ r8 = nil
2267
+ end
2061
2268
  s5 << r8
2062
2269
  end
2063
- if s5.last.success?
2270
+ if s5.last
2064
2271
  r5 = (SyntaxNode).new(input, i5...index, s5)
2065
2272
  r5.extend(NodeClassExpression0)
2066
2273
  else
2067
2274
  self.index = i5
2068
- r5 = ParseFailure.new(input, i5, s5)
2275
+ r5 = nil
2069
2276
  end
2070
- nr4 << r5
2071
- if r5.success?
2277
+ if r5
2072
2278
  s4 << r5
2073
2279
  else
2074
2280
  break
@@ -2076,38 +2282,47 @@ module Treetop
2076
2282
  end
2077
2283
  if s4.empty?
2078
2284
  self.index = i4
2079
- r4 = ParseFailure.new(input, i4, nr4)
2285
+ r4 = nil
2080
2286
  else
2081
- r4 = SyntaxNode.new(input, i4...index, s4, nr4)
2287
+ r4 = SyntaxNode.new(input, i4...index, s4)
2082
2288
  end
2083
2289
  s1 << r4
2084
- if r4.success?
2085
- r9 = parse_terminal('>', SyntaxNode)
2290
+ if r4
2291
+ if input.index('>', index) == index
2292
+ r9 = (SyntaxNode).new(input, index...(index + 1))
2293
+ @index += 1
2294
+ else
2295
+ terminal_parse_failure('>')
2296
+ r9 = nil
2297
+ end
2086
2298
  s1 << r9
2087
2299
  end
2088
2300
  end
2089
2301
  end
2090
- if s1.last.success?
2302
+ if s1.last
2091
2303
  r1 = (SyntaxNode).new(input, i1...index, s1)
2092
2304
  r1.extend(NodeClassExpression1)
2093
2305
  r1.extend(NodeClassExpression2)
2094
2306
  else
2095
2307
  self.index = i1
2096
- r1 = ParseFailure.new(input, i1, s1)
2308
+ r1 = nil
2097
2309
  end
2098
- nr0 << r1
2099
- if r1.success?
2310
+ if r1
2100
2311
  r0 = r1
2101
- r1.update_nested_results(nr0)
2102
2312
  else
2103
- r10 = parse_terminal('', SyntaxNode, NodeClassExpression3)
2104
- nr0 << r10
2105
- if r10.success?
2313
+ if input.index('', index) == index
2314
+ r10 = (SyntaxNode).new(input, index...(index + 0))
2315
+ r10.extend(NodeClassExpression3)
2316
+ @index += 0
2317
+ else
2318
+ terminal_parse_failure('')
2319
+ r10 = nil
2320
+ end
2321
+ if r10
2106
2322
  r0 = r10
2107
- r10.update_nested_results(nr0)
2108
2323
  else
2109
2324
  self.index = i0
2110
- r0 = ParseFailure.new(input, i0, nr0)
2325
+ r0 = nil
2111
2326
  end
2112
2327
  end
2113
2328
 
@@ -2158,35 +2373,38 @@ module Treetop
2158
2373
  return cached
2159
2374
  end
2160
2375
 
2161
- i0, nr0 = index, []
2162
- i1, s1, nr1 = index, [], []
2376
+ i0 = index
2377
+ i1, s1 = index, []
2163
2378
  r2 = _nt_space
2164
2379
  s1 << r2
2165
- if r2.success?
2380
+ if r2
2166
2381
  r3 = _nt_inline_module
2167
2382
  s1 << r3
2168
2383
  end
2169
- if s1.last.success?
2384
+ if s1.last
2170
2385
  r1 = (SyntaxNode).new(input, i1...index, s1)
2171
2386
  r1.extend(TrailingInlineModule0)
2172
2387
  r1.extend(TrailingInlineModule1)
2173
2388
  else
2174
2389
  self.index = i1
2175
- r1 = ParseFailure.new(input, i1, s1)
2390
+ r1 = nil
2176
2391
  end
2177
- nr0 << r1
2178
- if r1.success?
2392
+ if r1
2179
2393
  r0 = r1
2180
- r1.update_nested_results(nr0)
2181
2394
  else
2182
- r4 = parse_terminal('', SyntaxNode, TrailingInlineModule2)
2183
- nr0 << r4
2184
- if r4.success?
2395
+ if input.index('', index) == index
2396
+ r4 = (SyntaxNode).new(input, index...(index + 0))
2397
+ r4.extend(TrailingInlineModule2)
2398
+ @index += 0
2399
+ else
2400
+ terminal_parse_failure('')
2401
+ r4 = nil
2402
+ end
2403
+ if r4
2185
2404
  r0 = r4
2186
- r4.update_nested_results(nr0)
2187
2405
  else
2188
2406
  self.index = i0
2189
- r0 = ParseFailure.new(input, i0, nr0)
2407
+ r0 = nil
2190
2408
  end
2191
2409
  end
2192
2410
 
@@ -2209,69 +2427,87 @@ module Treetop
2209
2427
  return cached
2210
2428
  end
2211
2429
 
2212
- i0, s0, nr0 = index, [], []
2213
- r1 = parse_terminal('{', SyntaxNode)
2430
+ i0, s0 = index, []
2431
+ if input.index('{', index) == index
2432
+ r1 = (SyntaxNode).new(input, index...(index + 1))
2433
+ @index += 1
2434
+ else
2435
+ terminal_parse_failure('{')
2436
+ r1 = nil
2437
+ end
2214
2438
  s0 << r1
2215
- if r1.success?
2216
- s2, nr2, i2 = [], [], index
2439
+ if r1
2440
+ s2, i2 = [], index
2217
2441
  loop do
2218
- i3, nr3 = index, []
2442
+ i3 = index
2219
2443
  r4 = _nt_inline_module
2220
- nr3 << r4
2221
- if r4.success?
2444
+ if r4
2222
2445
  r3 = r4
2223
- r4.update_nested_results(nr3)
2224
2446
  else
2225
- i5, s5, nr5 = index, [], []
2447
+ i5, s5 = index, []
2226
2448
  i6 = index
2227
- r7 = parse_char_class(/[{}]/, '{}', SyntaxNode)
2228
- if r7.success?
2229
- r6 = ParseFailure.new(input, i6, r7.nested_failures)
2449
+ if input.index(/[{}]/, index) == index
2450
+ r7 = (SyntaxNode).new(input, index...(index + 1))
2451
+ @index += 1
2452
+ else
2453
+ r7 = nil
2454
+ end
2455
+ if r7
2456
+ r6 = nil
2230
2457
  else
2231
2458
  self.index = i6
2232
- r6 = SyntaxNode.new(input, index...index, r7.nested_failures)
2459
+ r6 = SyntaxNode.new(input, index...index)
2233
2460
  end
2234
2461
  s5 << r6
2235
- if r6.success?
2236
- r8 = parse_anything(SyntaxNode)
2462
+ if r6
2463
+ if index < input_length
2464
+ r8 = (SyntaxNode).new(input, index...(index + 1))
2465
+ @index += 1
2466
+ else
2467
+ terminal_parse_failure("any character")
2468
+ r8 = nil
2469
+ end
2237
2470
  s5 << r8
2238
2471
  end
2239
- if s5.last.success?
2472
+ if s5.last
2240
2473
  r5 = (SyntaxNode).new(input, i5...index, s5)
2241
2474
  r5.extend(InlineModule0)
2242
2475
  else
2243
2476
  self.index = i5
2244
- r5 = ParseFailure.new(input, i5, s5)
2477
+ r5 = nil
2245
2478
  end
2246
- nr3 << r5
2247
- if r5.success?
2479
+ if r5
2248
2480
  r3 = r5
2249
- r5.update_nested_results(nr3)
2250
2481
  else
2251
2482
  self.index = i3
2252
- r3 = ParseFailure.new(input, i3, nr3)
2483
+ r3 = nil
2253
2484
  end
2254
2485
  end
2255
- nr2 << r3
2256
- if r3.success?
2486
+ if r3
2257
2487
  s2 << r3
2258
2488
  else
2259
2489
  break
2260
2490
  end
2261
2491
  end
2262
- r2 = SyntaxNode.new(input, i2...index, s2, nr2)
2492
+ r2 = SyntaxNode.new(input, i2...index, s2)
2263
2493
  s0 << r2
2264
- if r2.success?
2265
- r9 = parse_terminal('}', SyntaxNode)
2494
+ if r2
2495
+ if input.index('}', index) == index
2496
+ r9 = (SyntaxNode).new(input, index...(index + 1))
2497
+ @index += 1
2498
+ else
2499
+ terminal_parse_failure('}')
2500
+ r9 = nil
2501
+ end
2266
2502
  s0 << r9
2267
2503
  end
2268
2504
  end
2269
- if s0.last.success?
2505
+ if s0.last
2270
2506
  r0 = (InlineModule).new(input, i0...index, s0)
2271
2507
  r0.extend(InlineModule1)
2272
2508
  else
2273
2509
  self.index = i0
2274
- r0 = ParseFailure.new(input, i0, s0)
2510
+ r0 = nil
2275
2511
  end
2276
2512
 
2277
2513
  node_cache[:inline_module][start_index] = r0
@@ -2290,42 +2526,50 @@ module Treetop
2290
2526
  return cached
2291
2527
  end
2292
2528
 
2293
- i0, s0, nr0 = index, [], []
2294
- i1, nr1 = index, []
2295
- r2 = parse_terminal('rule', SyntaxNode)
2296
- nr1 << r2
2297
- if r2.success?
2529
+ i0, s0 = index, []
2530
+ i1 = index
2531
+ if input.index('rule', index) == index
2532
+ r2 = (SyntaxNode).new(input, index...(index + 4))
2533
+ @index += 4
2534
+ else
2535
+ terminal_parse_failure('rule')
2536
+ r2 = nil
2537
+ end
2538
+ if r2
2298
2539
  r1 = r2
2299
- r2.update_nested_results(nr1)
2300
2540
  else
2301
- r3 = parse_terminal('end', SyntaxNode)
2302
- nr1 << r3
2303
- if r3.success?
2541
+ if input.index('end', index) == index
2542
+ r3 = (SyntaxNode).new(input, index...(index + 3))
2543
+ @index += 3
2544
+ else
2545
+ terminal_parse_failure('end')
2546
+ r3 = nil
2547
+ end
2548
+ if r3
2304
2549
  r1 = r3
2305
- r3.update_nested_results(nr1)
2306
2550
  else
2307
2551
  self.index = i1
2308
- r1 = ParseFailure.new(input, i1, nr1)
2552
+ r1 = nil
2309
2553
  end
2310
2554
  end
2311
2555
  s0 << r1
2312
- if r1.success?
2556
+ if r1
2313
2557
  i4 = index
2314
2558
  r5 = _nt_non_space_char
2315
- if r5.success?
2316
- r4 = ParseFailure.new(input, i4, r5.nested_failures)
2559
+ if r5
2560
+ r4 = nil
2317
2561
  else
2318
2562
  self.index = i4
2319
- r4 = SyntaxNode.new(input, index...index, r5.nested_failures)
2563
+ r4 = SyntaxNode.new(input, index...index)
2320
2564
  end
2321
2565
  s0 << r4
2322
2566
  end
2323
- if s0.last.success?
2567
+ if s0.last
2324
2568
  r0 = (SyntaxNode).new(input, i0...index, s0)
2325
2569
  r0.extend(KeywordInsideGrammar0)
2326
2570
  else
2327
2571
  self.index = i0
2328
- r0 = ParseFailure.new(input, i0, s0)
2572
+ r0 = nil
2329
2573
  end
2330
2574
 
2331
2575
  node_cache[:keyword_inside_grammar][start_index] = r0
@@ -2344,26 +2588,32 @@ module Treetop
2344
2588
  return cached
2345
2589
  end
2346
2590
 
2347
- i0, s0, nr0 = index, [], []
2591
+ i0, s0 = index, []
2348
2592
  i1 = index
2349
2593
  r2 = _nt_space
2350
- if r2.success?
2351
- r1 = ParseFailure.new(input, i1, r2.nested_failures)
2594
+ if r2
2595
+ r1 = nil
2352
2596
  else
2353
2597
  self.index = i1
2354
- r1 = SyntaxNode.new(input, index...index, r2.nested_failures)
2598
+ r1 = SyntaxNode.new(input, index...index)
2355
2599
  end
2356
2600
  s0 << r1
2357
- if r1.success?
2358
- r3 = parse_anything(SyntaxNode)
2601
+ if r1
2602
+ if index < input_length
2603
+ r3 = (SyntaxNode).new(input, index...(index + 1))
2604
+ @index += 1
2605
+ else
2606
+ terminal_parse_failure("any character")
2607
+ r3 = nil
2608
+ end
2359
2609
  s0 << r3
2360
2610
  end
2361
- if s0.last.success?
2611
+ if s0.last
2362
2612
  r0 = (SyntaxNode).new(input, i0...index, s0)
2363
2613
  r0.extend(NonSpaceChar0)
2364
2614
  else
2365
2615
  self.index = i0
2366
- r0 = ParseFailure.new(input, i0, s0)
2616
+ r0 = nil
2367
2617
  end
2368
2618
 
2369
2619
  node_cache[:non_space_char][start_index] = r0
@@ -2379,7 +2629,12 @@ module Treetop
2379
2629
  return cached
2380
2630
  end
2381
2631
 
2382
- r0 = parse_char_class(/[A-Za-z_]/, 'A-Za-z_', SyntaxNode)
2632
+ if input.index(/[A-Za-z_]/, index) == index
2633
+ r0 = (SyntaxNode).new(input, index...(index + 1))
2634
+ @index += 1
2635
+ else
2636
+ r0 = nil
2637
+ end
2383
2638
 
2384
2639
  node_cache[:alpha_char][start_index] = r0
2385
2640
 
@@ -2394,21 +2649,22 @@ module Treetop
2394
2649
  return cached
2395
2650
  end
2396
2651
 
2397
- i0, nr0 = index, []
2652
+ i0 = index
2398
2653
  r1 = _nt_alpha_char
2399
- nr0 << r1
2400
- if r1.success?
2654
+ if r1
2401
2655
  r0 = r1
2402
- r1.update_nested_results(nr0)
2403
2656
  else
2404
- r2 = parse_char_class(/[0-9]/, '0-9', SyntaxNode)
2405
- nr0 << r2
2406
- if r2.success?
2657
+ if input.index(/[0-9]/, index) == index
2658
+ r2 = (SyntaxNode).new(input, index...(index + 1))
2659
+ @index += 1
2660
+ else
2661
+ r2 = nil
2662
+ end
2663
+ if r2
2407
2664
  r0 = r2
2408
- r2.update_nested_results(nr0)
2409
2665
  else
2410
2666
  self.index = i0
2411
- r0 = ParseFailure.new(input, i0, nr0)
2667
+ r0 = nil
2412
2668
  end
2413
2669
  end
2414
2670
 
@@ -2425,11 +2681,22 @@ module Treetop
2425
2681
  return cached
2426
2682
  end
2427
2683
 
2428
- s0, nr0, i0 = [], [], index
2684
+ s0, i0 = [], index
2429
2685
  loop do
2430
- r1 = parse_char_class(/[ \t\n\r]/, ' \t\n\r', SyntaxNode)
2431
- nr0 << r1
2432
- if r1.success?
2686
+ i1 = index
2687
+ r2 = _nt_white
2688
+ if r2
2689
+ r1 = r2
2690
+ else
2691
+ r3 = _nt_comment_to_eol
2692
+ if r3
2693
+ r1 = r3
2694
+ else
2695
+ self.index = i1
2696
+ r1 = nil
2697
+ end
2698
+ end
2699
+ if r1
2433
2700
  s0 << r1
2434
2701
  else
2435
2702
  break
@@ -2437,9 +2704,9 @@ module Treetop
2437
2704
  end
2438
2705
  if s0.empty?
2439
2706
  self.index = i0
2440
- r0 = ParseFailure.new(input, i0, nr0)
2707
+ r0 = nil
2441
2708
  else
2442
- r0 = SyntaxNode.new(input, i0...index, s0, nr0)
2709
+ r0 = SyntaxNode.new(input, i0...index, s0)
2443
2710
  end
2444
2711
 
2445
2712
  node_cache[:space][start_index] = r0
@@ -2447,6 +2714,112 @@ module Treetop
2447
2714
  return r0
2448
2715
  end
2449
2716
 
2717
+ module CommentToEol0
2718
+ end
2719
+
2720
+ module CommentToEol1
2721
+ end
2722
+
2723
+ def _nt_comment_to_eol
2724
+ start_index = index
2725
+ cached = node_cache[:comment_to_eol][index]
2726
+ if cached
2727
+ @index = cached.interval.end
2728
+ return cached
2729
+ end
2730
+
2731
+ i0, s0 = index, []
2732
+ if input.index('#', index) == index
2733
+ r1 = (SyntaxNode).new(input, index...(index + 1))
2734
+ @index += 1
2735
+ else
2736
+ terminal_parse_failure('#')
2737
+ r1 = nil
2738
+ end
2739
+ s0 << r1
2740
+ if r1
2741
+ s2, i2 = [], index
2742
+ loop do
2743
+ i3, s3 = index, []
2744
+ i4 = index
2745
+ if input.index("\n", index) == index
2746
+ r5 = (SyntaxNode).new(input, index...(index + 1))
2747
+ @index += 1
2748
+ else
2749
+ terminal_parse_failure("\n")
2750
+ r5 = nil
2751
+ end
2752
+ if r5
2753
+ r4 = nil
2754
+ else
2755
+ self.index = i4
2756
+ r4 = SyntaxNode.new(input, index...index)
2757
+ end
2758
+ s3 << r4
2759
+ if r4
2760
+ if index < input_length
2761
+ r6 = (SyntaxNode).new(input, index...(index + 1))
2762
+ @index += 1
2763
+ else
2764
+ terminal_parse_failure("any character")
2765
+ r6 = nil
2766
+ end
2767
+ s3 << r6
2768
+ end
2769
+ if s3.last
2770
+ r3 = (SyntaxNode).new(input, i3...index, s3)
2771
+ r3.extend(CommentToEol0)
2772
+ else
2773
+ self.index = i3
2774
+ r3 = nil
2775
+ end
2776
+ if r3
2777
+ s2 << r3
2778
+ else
2779
+ break
2780
+ end
2781
+ end
2782
+ if s2.empty?
2783
+ self.index = i2
2784
+ r2 = nil
2785
+ else
2786
+ r2 = SyntaxNode.new(input, i2...index, s2)
2787
+ end
2788
+ s0 << r2
2789
+ end
2790
+ if s0.last
2791
+ r0 = (SyntaxNode).new(input, i0...index, s0)
2792
+ r0.extend(CommentToEol1)
2793
+ else
2794
+ self.index = i0
2795
+ r0 = nil
2796
+ end
2797
+
2798
+ node_cache[:comment_to_eol][start_index] = r0
2799
+
2800
+ return r0
2801
+ end
2802
+
2803
+ def _nt_white
2804
+ start_index = index
2805
+ cached = node_cache[:white][index]
2806
+ if cached
2807
+ @index = cached.interval.end
2808
+ return cached
2809
+ end
2810
+
2811
+ if input.index(/[ \t\n\r]/, index) == index
2812
+ r0 = (SyntaxNode).new(input, index...(index + 1))
2813
+ @index += 1
2814
+ else
2815
+ r0 = nil
2816
+ end
2817
+
2818
+ node_cache[:white][start_index] = r0
2819
+
2820
+ return r0
2821
+ end
2822
+
2450
2823
  end
2451
2824
 
2452
2825
  class MetagrammarParser < Treetop::Runtime::CompiledParser
@@ -2454,4 +2827,4 @@ module Treetop
2454
2827
  end
2455
2828
 
2456
2829
  end
2457
- end
2830
+ end