cognita-treetop 1.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. data/README +164 -0
  2. data/Rakefile +35 -0
  3. data/bin/tt +25 -0
  4. data/doc/contributing_and_planned_features.markdown +103 -0
  5. data/doc/grammar_composition.markdown +65 -0
  6. data/doc/index.markdown +90 -0
  7. data/doc/pitfalls_and_advanced_techniques.markdown +51 -0
  8. data/doc/semantic_interpretation.markdown +189 -0
  9. data/doc/site.rb +110 -0
  10. data/doc/sitegen.rb +60 -0
  11. data/doc/syntactic_recognition.markdown +100 -0
  12. data/doc/using_in_ruby.markdown +21 -0
  13. data/examples/lambda_calculus/arithmetic.rb +551 -0
  14. data/examples/lambda_calculus/arithmetic.treetop +97 -0
  15. data/examples/lambda_calculus/arithmetic_node_classes.rb +7 -0
  16. data/examples/lambda_calculus/arithmetic_test.rb +54 -0
  17. data/examples/lambda_calculus/lambda_calculus +0 -0
  18. data/examples/lambda_calculus/lambda_calculus.rb +718 -0
  19. data/examples/lambda_calculus/lambda_calculus.treetop +132 -0
  20. data/examples/lambda_calculus/lambda_calculus_node_classes.rb +5 -0
  21. data/examples/lambda_calculus/lambda_calculus_test.rb +89 -0
  22. data/examples/lambda_calculus/test_helper.rb +18 -0
  23. data/lib/treetop.rb +8 -0
  24. data/lib/treetop/bootstrap_gen_1_metagrammar.rb +45 -0
  25. data/lib/treetop/compiler.rb +6 -0
  26. data/lib/treetop/compiler/grammar_compiler.rb +40 -0
  27. data/lib/treetop/compiler/lexical_address_space.rb +17 -0
  28. data/lib/treetop/compiler/metagrammar.rb +2887 -0
  29. data/lib/treetop/compiler/metagrammar.treetop +404 -0
  30. data/lib/treetop/compiler/node_classes.rb +19 -0
  31. data/lib/treetop/compiler/node_classes/anything_symbol.rb +18 -0
  32. data/lib/treetop/compiler/node_classes/atomic_expression.rb +14 -0
  33. data/lib/treetop/compiler/node_classes/character_class.rb +19 -0
  34. data/lib/treetop/compiler/node_classes/choice.rb +31 -0
  35. data/lib/treetop/compiler/node_classes/declaration_sequence.rb +24 -0
  36. data/lib/treetop/compiler/node_classes/grammar.rb +28 -0
  37. data/lib/treetop/compiler/node_classes/inline_module.rb +27 -0
  38. data/lib/treetop/compiler/node_classes/nonterminal.rb +13 -0
  39. data/lib/treetop/compiler/node_classes/optional.rb +19 -0
  40. data/lib/treetop/compiler/node_classes/parenthesized_expression.rb +9 -0
  41. data/lib/treetop/compiler/node_classes/parsing_expression.rb +138 -0
  42. data/lib/treetop/compiler/node_classes/parsing_rule.rb +55 -0
  43. data/lib/treetop/compiler/node_classes/predicate.rb +45 -0
  44. data/lib/treetop/compiler/node_classes/repetition.rb +55 -0
  45. data/lib/treetop/compiler/node_classes/sequence.rb +68 -0
  46. data/lib/treetop/compiler/node_classes/terminal.rb +20 -0
  47. data/lib/treetop/compiler/node_classes/transient_prefix.rb +9 -0
  48. data/lib/treetop/compiler/node_classes/treetop_file.rb +9 -0
  49. data/lib/treetop/compiler/ruby_builder.rb +113 -0
  50. data/lib/treetop/ruby_extensions.rb +2 -0
  51. data/lib/treetop/ruby_extensions/string.rb +42 -0
  52. data/lib/treetop/runtime.rb +5 -0
  53. data/lib/treetop/runtime/compiled_parser.rb +87 -0
  54. data/lib/treetop/runtime/interval_skip_list.rb +4 -0
  55. data/lib/treetop/runtime/interval_skip_list/head_node.rb +15 -0
  56. data/lib/treetop/runtime/interval_skip_list/interval_skip_list.rb +200 -0
  57. data/lib/treetop/runtime/interval_skip_list/node.rb +164 -0
  58. data/lib/treetop/runtime/syntax_node.rb +72 -0
  59. data/lib/treetop/runtime/terminal_parse_failure.rb +16 -0
  60. data/lib/treetop/runtime/terminal_syntax_node.rb +17 -0
  61. metadata +119 -0
@@ -0,0 +1,132 @@
1
+ grammar LambdaCalculus
2
+ include Arithmetic
3
+
4
+ rule program
5
+ expression more_expressions:(';' space expression)* {
6
+ def eval(env={})
7
+ env = env.clone
8
+ last_eval = nil
9
+ expressions.each do |exp|
10
+ last_eval = exp.eval(env)
11
+ end
12
+ last_eval
13
+ end
14
+
15
+ def expressions
16
+ [expression] + more_expressions.elements.map {|elt| elt.expression}
17
+ end
18
+ }
19
+ end
20
+
21
+ rule expression
22
+ definition / conditional / application / function / super
23
+ end
24
+
25
+ rule definition
26
+ 'def' space variable space expression {
27
+ def eval(env)
28
+ env[variable.name] = expression.eval(env)
29
+ end
30
+ }
31
+ end
32
+
33
+ rule conditional
34
+ 'if' space '(' space condition:expression space ')' space
35
+ true_case:expression space 'else' space false_case:expression {
36
+ def eval(env)
37
+ if condition.eval(env)
38
+ true_case.eval(env)
39
+ else
40
+ false_case.eval(env)
41
+ end
42
+ end
43
+ }
44
+ end
45
+
46
+ rule primary
47
+ application / super
48
+ end
49
+
50
+ rule application
51
+ operator space expression <Application> {
52
+ def eval(env={})
53
+ left_associative_apply(operator.eval(env), env)
54
+ end
55
+
56
+ def left_associative_apply(operator, env)
57
+ if expression.instance_of?(Application)
58
+ expression.left_associative_apply(operator.apply(expression.operator.eval(env)), env)
59
+ else
60
+ operator.apply(expression.eval(env))
61
+ end
62
+ end
63
+
64
+ def to_s(env={})
65
+ operator.to_s(env) + ' ' + expression.to_s(env)
66
+ end
67
+ }
68
+ end
69
+
70
+ rule operator
71
+ function / variable
72
+ end
73
+
74
+ rule non_application
75
+ function / variable
76
+ end
77
+
78
+ rule function
79
+ '\\' param:variable '(' body:expression ')' {
80
+ class Closure
81
+ attr_reader :env, :function
82
+
83
+ def initialize(function, env)
84
+ @function = function
85
+ @env = env
86
+ end
87
+
88
+ def apply(arg)
89
+ function.body.eval(function.param.bind(arg, env))
90
+ end
91
+
92
+ def to_s(other_env={})
93
+ "\\#{function.param.to_s}(#{function.body.to_s(other_env.merge(env))})"
94
+ end
95
+ end
96
+
97
+ def eval(env={})
98
+ Closure.new(self, env)
99
+ end
100
+
101
+ def to_s(env={})
102
+ eval(env).to_s
103
+ end
104
+ }
105
+ end
106
+
107
+ rule variable
108
+ !keyword (
109
+ super {
110
+ def bind(value, env)
111
+ env.merge(name => value)
112
+ end
113
+
114
+ def to_s(env={})
115
+ env.has_key?(name) ? env[name].to_s : name
116
+ end
117
+ }
118
+ )
119
+ end
120
+
121
+ rule keyword
122
+ ('if' / 'else') !non_space_char
123
+ end
124
+
125
+ rule non_space_char
126
+ ![ \n] .
127
+ end
128
+
129
+ rule space
130
+ [ \n]*
131
+ end
132
+ end
@@ -0,0 +1,5 @@
1
+ module LambdaCalculus
2
+ class Application < Treetop::Runtime::SyntaxNode
3
+
4
+ end
5
+ end
@@ -0,0 +1,89 @@
1
+ dir = File.dirname(__FILE__)
2
+ require File.expand_path("#{dir}/test_helper")
3
+ require File.expand_path("#{dir}/arithmetic_node_classes")
4
+ require File.expand_path("#{dir}/lambda_calculus_node_classes")
5
+ Treetop.load File.expand_path("#{dir}/arithmetic")
6
+ Treetop.load File.expand_path("#{dir}/lambda_calculus")
7
+
8
+ class Treetop::Runtime::SyntaxNode
9
+ def method_missing(method, *args)
10
+ raise "Node representing #{text_value} does not respond to #{method}"
11
+ end
12
+ end
13
+
14
+ class LambdaCalculusParserTest < Test::Unit::TestCase
15
+ include ParserTestHelper
16
+
17
+ def setup
18
+ @parser = LambdaCalculusParser.new
19
+ end
20
+
21
+ def test_free_variable
22
+ assert_equal 'x', parse('x').eval.to_s
23
+ end
24
+
25
+ def test_variable_binding
26
+ variable = parse('x').eval
27
+ env = variable.bind(1, {})
28
+ assert_equal 1, env['x']
29
+ end
30
+
31
+ def test_bound_variable_evaluation
32
+ assert_equal 1, parse('x').eval({'x' => 1})
33
+ end
34
+
35
+ def test_identity_function
36
+ assert_equal '\x(x)', parse('\x(x)').eval.to_s
37
+ end
38
+
39
+ def test_function_returning_constant_function
40
+ assert_equal '\x(\y(x))', parse('\x(\y(x))').eval.to_s
41
+ end
42
+
43
+ def test_identity_function_application
44
+ assert_equal 1, parse('\x(x) 1').eval
45
+ assert_equal '\y(y)', parse('\x(x) \y(y)').eval.to_s
46
+ end
47
+
48
+ def test_constant_function_construction
49
+ assert_equal '\y(1)', parse('\x(\y(x)) 1').eval.to_s
50
+ end
51
+
52
+ def test_multiple_argument_application_is_left_associative
53
+ assert_equal '\b(b)', parse('\x(\y(x y)) \a(a) \b(b)').eval.to_s
54
+ end
55
+
56
+ def test_parentheses_override_application_order
57
+ assert_equal '\y(\b(b) y)', parse('\x(\y(x y)) (\a(a) \b(b))').eval.to_s
58
+ end
59
+
60
+ def test_arithmetic_in_function_body
61
+ assert_equal 10, parse('\x(x + 5) 5').eval
62
+ end
63
+
64
+ def test_addition_of_function_results
65
+ assert_equal 20, parse('\x(x + 5) 5 + \x(15 - x) 5').eval
66
+ end
67
+
68
+ def test_conditional
69
+ result = parse('if (x) 1 else 2')
70
+ assert_equal 1, result.eval({'x' => true})
71
+ assert_equal 2, result.eval({'x' => false})
72
+ end
73
+
74
+ def test_keyword
75
+ assert @parser.parse('if').failure?
76
+ assert @parser.parse('else').failure?
77
+ assert parse('elsee').success?
78
+ assert parse('iff').success?
79
+ end
80
+
81
+ def test_program
82
+ result = parse('def fact \x(if (x == 0)
83
+ 1
84
+ else
85
+ x * fact (x - 1));
86
+ fact(5)').eval
87
+ assert_equal 5 * 4 * 3 * 2, result
88
+ end
89
+ end
@@ -0,0 +1,18 @@
1
+ require 'test/unit'
2
+ require 'rubygems'
3
+ require 'treetop'
4
+
5
+ module ParserTestHelper
6
+ def assert_evals_to_self(input)
7
+ assert_evals_to(input, input)
8
+ end
9
+
10
+ def parse(input)
11
+ result = @parser.parse(input)
12
+ unless result
13
+ puts @parser.terminal_failures.join("\n")
14
+ end
15
+ assert !result.nil?
16
+ result
17
+ end
18
+ end
data/lib/treetop.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+
3
+ dir = File.dirname(__FILE__)
4
+
5
+ TREETOP_ROOT = File.join(dir, 'treetop')
6
+ require File.join(TREETOP_ROOT, "ruby_extensions")
7
+ require File.join(TREETOP_ROOT, "runtime")
8
+ require File.join(TREETOP_ROOT, "compiler")
@@ -0,0 +1,45 @@
1
+ # This file's job is to load a Treetop::Compiler::Metagrammar and Treetop::Compiler::MetagrammarParser
2
+ # into the environment by compiling the current metagrammar.treetop using a trusted version of Treetop.
3
+
4
+ require 'rubygems'
5
+ dir = File.dirname(__FILE__)
6
+
7
+ TREETOP_VERSION_REQUIRED_TO_BOOTSTRAP = '>= 1.1.5'
8
+
9
+ # Loading trusted version of Treetop to compile the compiler
10
+ gem_spec = Gem.source_index.find_name('treetop', TREETOP_VERSION_REQUIRED_TO_BOOTSTRAP).last
11
+ raise "Install a Treetop Gem version #{TREETOP_VERSION_REQUIRED_TO_BOOTSTRAP} to bootstrap." unless gem_spec
12
+ trusted_treetop_path = gem_spec.full_gem_path
13
+ require File.join(trusted_treetop_path, 'lib', 'treetop')
14
+
15
+ # Relocating trusted version of Treetop to Trusted::Treetop
16
+ Trusted = Module.new
17
+ Trusted::Treetop = Treetop
18
+ Object.send(:remove_const, :Treetop)
19
+ Object.send(:remove_const, :TREETOP_ROOT)
20
+
21
+ # Requiring version of Treetop that is under test
22
+ $exclude_metagrammar = true
23
+ require File.expand_path(File.join(dir, '..', 'treetop'))
24
+
25
+ # Compile and evaluate freshly generated metagrammar source
26
+ METAGRAMMAR_PATH = File.join(TREETOP_ROOT, 'compiler', 'metagrammar.treetop')
27
+ compiled_metagrammar_source = Trusted::Treetop::Compiler::GrammarCompiler.new.ruby_source(METAGRAMMAR_PATH)
28
+ Object.class_eval(compiled_metagrammar_source)
29
+
30
+ # The compiler under test was compiled with the trusted grammar and therefore depends on its runtime
31
+ # But the runtime in the global namespace is the new runtime. We therefore inject the trusted runtime
32
+ # into the compiler so its parser functions correctly. It will still not work for custom classes that
33
+ # explicitly subclass the wrong runtime. For now I am working around this by keeping 1 generation of
34
+ # backward compatibility in these cases.
35
+ # Treetop::Compiler::Metagrammar.module_eval do
36
+ # include Trusted::Treetop::Runtime
37
+ # end
38
+ #
39
+ # Treetop::Compiler.send(:remove_const, :MetagrammarParser)
40
+ # class Treetop::Compiler::MetagrammarParser < Trusted::Treetop::Runtime::CompiledParser
41
+ # include Treetop::Compiler::Metagrammar
42
+ # include Trusted::Treetop::Runtime
43
+ # end
44
+
45
+ $bootstrapped_gen_1_metagrammar = true
@@ -0,0 +1,6 @@
1
+ dir = File.dirname(__FILE__)
2
+ require File.join(dir, *%w[compiler lexical_address_space])
3
+ require File.join(dir, *%w[compiler ruby_builder])
4
+ require File.join(dir, *%w[compiler node_classes])
5
+ require File.join(dir, *%w[compiler metagrammar]) unless $exclude_metagrammar
6
+ require File.join(dir, *%w[compiler grammar_compiler])
@@ -0,0 +1,40 @@
1
+ module Treetop
2
+ module Compiler
3
+ class GrammarCompiler
4
+ def compile(source_path, target_path = source_path.gsub(/\.(treetop|tt)\Z/, '.rb'))
5
+ File.open(target_path, 'w') do |target_file|
6
+ target_file.write(ruby_source(source_path))
7
+ end
8
+ end
9
+
10
+ # compile a treetop file into ruby
11
+ def ruby_source(source_path)
12
+ ruby_source_from_string(File.read(source_path))
13
+ end
14
+
15
+ # compile a string containing treetop source into ruby
16
+ def ruby_source_from_string(s)
17
+ parser = MetagrammarParser.new
18
+ result = parser.parse(s)
19
+ unless result
20
+ raise RuntimeError.new(parser.failure_reason)
21
+ end
22
+ result.compile
23
+ end
24
+ end
25
+ end
26
+
27
+ # compile a treetop source file and load it
28
+ def self.load(path)
29
+ adjusted_path = path =~ /\.(treetop|tt)\Z/ ? path : path + '.treetop'
30
+ File.open(adjusted_path) do |source_file|
31
+ load_from_string(source_file.read)
32
+ end
33
+ end
34
+
35
+ # compile a treetop source string and load it
36
+ def self.load_from_string(s)
37
+ compiler = Treetop::Compiler::GrammarCompiler.new
38
+ Object.class_eval(compiler.ruby_source_from_string(s))
39
+ end
40
+ end
@@ -0,0 +1,17 @@
1
+ module Treetop
2
+ module Compiler
3
+ class LexicalAddressSpace
4
+ def initialize
5
+ reset_addresses
6
+ end
7
+
8
+ def next_address
9
+ @next_address += 1
10
+ end
11
+
12
+ def reset_addresses
13
+ @next_address = -1
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,2887 @@
1
+ module Treetop
2
+ module Compiler
3
+ module Metagrammar
4
+ include Treetop::Runtime
5
+
6
+ def root
7
+ @root || :treetop_file
8
+ end
9
+
10
+ module TreetopFile0
11
+ def prefix
12
+ elements[0]
13
+ end
14
+
15
+ def module_or_grammar
16
+ elements[1]
17
+ end
18
+
19
+ def suffix
20
+ elements[2]
21
+ end
22
+ end
23
+
24
+ module TreetopFile1
25
+ def compile
26
+ prefix.text_value + module_or_grammar.compile + suffix.text_value
27
+ end
28
+ end
29
+
30
+ def _nt_treetop_file
31
+ start_index = index
32
+ if node_cache[:treetop_file].has_key?(index)
33
+ cached = node_cache[:treetop_file][index]
34
+ @index = cached.interval.end if cached
35
+ return cached
36
+ end
37
+
38
+ i0, s0 = index, []
39
+ r2 = _nt_space
40
+ if r2
41
+ r1 = r2
42
+ else
43
+ r1 = SyntaxNode.new(input, index...index)
44
+ end
45
+ s0 << r1
46
+ if r1
47
+ i3 = index
48
+ r4 = _nt_module_declaration
49
+ if r4
50
+ r3 = r4
51
+ else
52
+ r5 = _nt_grammar
53
+ if r5
54
+ r3 = r5
55
+ else
56
+ self.index = i3
57
+ r3 = nil
58
+ end
59
+ end
60
+ s0 << r3
61
+ if r3
62
+ r7 = _nt_space
63
+ if r7
64
+ r6 = r7
65
+ else
66
+ r6 = SyntaxNode.new(input, index...index)
67
+ end
68
+ s0 << r6
69
+ end
70
+ end
71
+ if s0.last
72
+ r0 = (SyntaxNode).new(input, i0...index, s0)
73
+ r0.extend(TreetopFile0)
74
+ r0.extend(TreetopFile1)
75
+ else
76
+ self.index = i0
77
+ r0 = nil
78
+ end
79
+
80
+ node_cache[:treetop_file][start_index] = r0
81
+
82
+ return r0
83
+ end
84
+
85
+ module ModuleDeclaration0
86
+ def space
87
+ elements[1]
88
+ end
89
+
90
+ def space
91
+ elements[4]
92
+ end
93
+ end
94
+
95
+ module ModuleDeclaration1
96
+ def space
97
+ elements[0]
98
+ end
99
+
100
+ end
101
+
102
+ module ModuleDeclaration2
103
+ def prefix
104
+ elements[0]
105
+ end
106
+
107
+ def module_contents
108
+ elements[1]
109
+ end
110
+
111
+ def suffix
112
+ elements[2]
113
+ end
114
+ end
115
+
116
+ module ModuleDeclaration3
117
+ def compile
118
+ prefix.text_value + module_contents.compile + suffix.text_value
119
+ end
120
+ end
121
+
122
+ def _nt_module_declaration
123
+ start_index = index
124
+ if node_cache[:module_declaration].has_key?(index)
125
+ cached = node_cache[:module_declaration][index]
126
+ @index = cached.interval.end if cached
127
+ return cached
128
+ end
129
+
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
139
+ s1 << r2
140
+ if r2
141
+ r3 = _nt_space
142
+ s1 << r3
143
+ if r3
144
+ if input.index(Regexp.new('[A-Z]'), index) == index
145
+ r4 = (SyntaxNode).new(input, index...(index + 1))
146
+ @index += 1
147
+ else
148
+ r4 = nil
149
+ end
150
+ s1 << r4
151
+ if r4
152
+ s5, i5 = [], index
153
+ loop do
154
+ r6 = _nt_alphanumeric_char
155
+ if r6
156
+ s5 << r6
157
+ else
158
+ break
159
+ end
160
+ end
161
+ r5 = SyntaxNode.new(input, i5...index, s5)
162
+ s1 << r5
163
+ if r5
164
+ r7 = _nt_space
165
+ s1 << r7
166
+ end
167
+ end
168
+ end
169
+ end
170
+ if s1.last
171
+ r1 = (SyntaxNode).new(input, i1...index, s1)
172
+ r1.extend(ModuleDeclaration0)
173
+ else
174
+ self.index = i1
175
+ r1 = nil
176
+ end
177
+ s0 << r1
178
+ if r1
179
+ i8 = index
180
+ r9 = _nt_module_declaration
181
+ if r9
182
+ r8 = r9
183
+ else
184
+ r10 = _nt_grammar
185
+ if r10
186
+ r8 = r10
187
+ else
188
+ self.index = i8
189
+ r8 = nil
190
+ end
191
+ end
192
+ s0 << r8
193
+ if r8
194
+ i11, s11 = index, []
195
+ r12 = _nt_space
196
+ s11 << r12
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
205
+ s11 << r13
206
+ end
207
+ if s11.last
208
+ r11 = (SyntaxNode).new(input, i11...index, s11)
209
+ r11.extend(ModuleDeclaration1)
210
+ else
211
+ self.index = i11
212
+ r11 = nil
213
+ end
214
+ s0 << r11
215
+ end
216
+ end
217
+ if s0.last
218
+ r0 = (SyntaxNode).new(input, i0...index, s0)
219
+ r0.extend(ModuleDeclaration2)
220
+ r0.extend(ModuleDeclaration3)
221
+ else
222
+ self.index = i0
223
+ r0 = nil
224
+ end
225
+
226
+ node_cache[:module_declaration][start_index] = r0
227
+
228
+ return r0
229
+ end
230
+
231
+ module Grammar0
232
+ def space
233
+ elements[1]
234
+ end
235
+
236
+ def grammar_name
237
+ elements[2]
238
+ end
239
+
240
+ def space
241
+ elements[3]
242
+ end
243
+
244
+ def declaration_sequence
245
+ elements[4]
246
+ end
247
+
248
+ end
249
+
250
+ def _nt_grammar
251
+ start_index = index
252
+ if node_cache[:grammar].has_key?(index)
253
+ cached = node_cache[:grammar][index]
254
+ @index = cached.interval.end if cached
255
+ return cached
256
+ end
257
+
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
266
+ s0 << r1
267
+ if r1
268
+ r2 = _nt_space
269
+ s0 << r2
270
+ if r2
271
+ r3 = _nt_grammar_name
272
+ s0 << r3
273
+ if r3
274
+ r4 = _nt_space
275
+ s0 << r4
276
+ if r4
277
+ r5 = _nt_declaration_sequence
278
+ s0 << r5
279
+ if r5
280
+ r7 = _nt_space
281
+ if r7
282
+ r6 = r7
283
+ else
284
+ r6 = SyntaxNode.new(input, index...index)
285
+ end
286
+ s0 << r6
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
295
+ s0 << r8
296
+ end
297
+ end
298
+ end
299
+ end
300
+ end
301
+ end
302
+ if s0.last
303
+ r0 = (Grammar).new(input, i0...index, s0)
304
+ r0.extend(Grammar0)
305
+ else
306
+ self.index = i0
307
+ r0 = nil
308
+ end
309
+
310
+ node_cache[:grammar][start_index] = r0
311
+
312
+ return r0
313
+ end
314
+
315
+ module GrammarName0
316
+ end
317
+
318
+ def _nt_grammar_name
319
+ start_index = index
320
+ if node_cache[:grammar_name].has_key?(index)
321
+ cached = node_cache[:grammar_name][index]
322
+ @index = cached.interval.end if cached
323
+ return cached
324
+ end
325
+
326
+ i0, s0 = index, []
327
+ if input.index(Regexp.new('[A-Z]'), index) == index
328
+ r1 = (SyntaxNode).new(input, index...(index + 1))
329
+ @index += 1
330
+ else
331
+ r1 = nil
332
+ end
333
+ s0 << r1
334
+ if r1
335
+ s2, i2 = [], index
336
+ loop do
337
+ r3 = _nt_alphanumeric_char
338
+ if r3
339
+ s2 << r3
340
+ else
341
+ break
342
+ end
343
+ end
344
+ r2 = SyntaxNode.new(input, i2...index, s2)
345
+ s0 << r2
346
+ end
347
+ if s0.last
348
+ r0 = (SyntaxNode).new(input, i0...index, s0)
349
+ r0.extend(GrammarName0)
350
+ else
351
+ self.index = i0
352
+ r0 = nil
353
+ end
354
+
355
+ node_cache[:grammar_name][start_index] = r0
356
+
357
+ return r0
358
+ end
359
+
360
+ module DeclarationSequence0
361
+ def space
362
+ elements[0]
363
+ end
364
+
365
+ def declaration
366
+ elements[1]
367
+ end
368
+ end
369
+
370
+ module DeclarationSequence1
371
+ def head
372
+ elements[0]
373
+ end
374
+
375
+ def tail
376
+ elements[1]
377
+ end
378
+ end
379
+
380
+ module DeclarationSequence2
381
+ def declarations
382
+ [head] + tail
383
+ end
384
+
385
+ def tail
386
+ super.elements.map { |elt| elt.declaration }
387
+ end
388
+ end
389
+
390
+ module DeclarationSequence3
391
+ def compile(builder)
392
+ end
393
+ end
394
+
395
+ def _nt_declaration_sequence
396
+ start_index = index
397
+ if node_cache[:declaration_sequence].has_key?(index)
398
+ cached = node_cache[:declaration_sequence][index]
399
+ @index = cached.interval.end if cached
400
+ return cached
401
+ end
402
+
403
+ i0 = index
404
+ i1, s1 = index, []
405
+ r2 = _nt_declaration
406
+ s1 << r2
407
+ if r2
408
+ s3, i3 = [], index
409
+ loop do
410
+ i4, s4 = index, []
411
+ r5 = _nt_space
412
+ s4 << r5
413
+ if r5
414
+ r6 = _nt_declaration
415
+ s4 << r6
416
+ end
417
+ if s4.last
418
+ r4 = (SyntaxNode).new(input, i4...index, s4)
419
+ r4.extend(DeclarationSequence0)
420
+ else
421
+ self.index = i4
422
+ r4 = nil
423
+ end
424
+ if r4
425
+ s3 << r4
426
+ else
427
+ break
428
+ end
429
+ end
430
+ r3 = SyntaxNode.new(input, i3...index, s3)
431
+ s1 << r3
432
+ end
433
+ if s1.last
434
+ r1 = (DeclarationSequence).new(input, i1...index, s1)
435
+ r1.extend(DeclarationSequence1)
436
+ r1.extend(DeclarationSequence2)
437
+ else
438
+ self.index = i1
439
+ r1 = nil
440
+ end
441
+ if r1
442
+ r0 = r1
443
+ else
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
453
+ r0 = r7
454
+ else
455
+ self.index = i0
456
+ r0 = nil
457
+ end
458
+ end
459
+
460
+ node_cache[:declaration_sequence][start_index] = r0
461
+
462
+ return r0
463
+ end
464
+
465
+ def _nt_declaration
466
+ start_index = index
467
+ if node_cache[:declaration].has_key?(index)
468
+ cached = node_cache[:declaration][index]
469
+ @index = cached.interval.end if cached
470
+ return cached
471
+ end
472
+
473
+ i0 = index
474
+ r1 = _nt_parsing_rule
475
+ if r1
476
+ r0 = r1
477
+ else
478
+ r2 = _nt_include_declaration
479
+ if r2
480
+ r0 = r2
481
+ else
482
+ self.index = i0
483
+ r0 = nil
484
+ end
485
+ end
486
+
487
+ node_cache[:declaration][start_index] = r0
488
+
489
+ return r0
490
+ end
491
+
492
+ module IncludeDeclaration0
493
+ def space
494
+ elements[1]
495
+ end
496
+
497
+ end
498
+
499
+ module IncludeDeclaration1
500
+ def compile(builder)
501
+ builder << text_value
502
+ end
503
+ end
504
+
505
+ def _nt_include_declaration
506
+ start_index = index
507
+ if node_cache[:include_declaration].has_key?(index)
508
+ cached = node_cache[:include_declaration][index]
509
+ @index = cached.interval.end if cached
510
+ return cached
511
+ end
512
+
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
521
+ s0 << r1
522
+ if r1
523
+ r2 = _nt_space
524
+ s0 << r2
525
+ if r2
526
+ if input.index(Regexp.new('[A-Z]'), index) == index
527
+ r3 = (SyntaxNode).new(input, index...(index + 1))
528
+ @index += 1
529
+ else
530
+ r3 = nil
531
+ end
532
+ s0 << r3
533
+ if r3
534
+ s4, i4 = [], index
535
+ loop do
536
+ i5 = index
537
+ r6 = _nt_alphanumeric_char
538
+ if r6
539
+ r5 = r6
540
+ else
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
549
+ r5 = r7
550
+ else
551
+ self.index = i5
552
+ r5 = nil
553
+ end
554
+ end
555
+ if r5
556
+ s4 << r5
557
+ else
558
+ break
559
+ end
560
+ end
561
+ r4 = SyntaxNode.new(input, i4...index, s4)
562
+ s0 << r4
563
+ end
564
+ end
565
+ end
566
+ if s0.last
567
+ r0 = (SyntaxNode).new(input, i0...index, s0)
568
+ r0.extend(IncludeDeclaration0)
569
+ r0.extend(IncludeDeclaration1)
570
+ else
571
+ self.index = i0
572
+ r0 = nil
573
+ end
574
+
575
+ node_cache[:include_declaration][start_index] = r0
576
+
577
+ return r0
578
+ end
579
+
580
+ module ParsingRule0
581
+ def space
582
+ elements[1]
583
+ end
584
+
585
+ def nonterminal
586
+ elements[2]
587
+ end
588
+
589
+ def space
590
+ elements[3]
591
+ end
592
+
593
+ def parsing_expression
594
+ elements[4]
595
+ end
596
+
597
+ def space
598
+ elements[5]
599
+ end
600
+
601
+ end
602
+
603
+ def _nt_parsing_rule
604
+ start_index = index
605
+ if node_cache[:parsing_rule].has_key?(index)
606
+ cached = node_cache[:parsing_rule][index]
607
+ @index = cached.interval.end if cached
608
+ return cached
609
+ end
610
+
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
619
+ s0 << r1
620
+ if r1
621
+ r2 = _nt_space
622
+ s0 << r2
623
+ if r2
624
+ r3 = _nt_nonterminal
625
+ s0 << r3
626
+ if r3
627
+ r4 = _nt_space
628
+ s0 << r4
629
+ if r4
630
+ r5 = _nt_parsing_expression
631
+ s0 << r5
632
+ if r5
633
+ r6 = _nt_space
634
+ s0 << r6
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
643
+ s0 << r7
644
+ end
645
+ end
646
+ end
647
+ end
648
+ end
649
+ end
650
+ if s0.last
651
+ r0 = (ParsingRule).new(input, i0...index, s0)
652
+ r0.extend(ParsingRule0)
653
+ else
654
+ self.index = i0
655
+ r0 = nil
656
+ end
657
+
658
+ node_cache[:parsing_rule][start_index] = r0
659
+
660
+ return r0
661
+ end
662
+
663
+ def _nt_parsing_expression
664
+ start_index = index
665
+ if node_cache[:parsing_expression].has_key?(index)
666
+ cached = node_cache[:parsing_expression][index]
667
+ @index = cached.interval.end if cached
668
+ return cached
669
+ end
670
+
671
+ i0 = index
672
+ r1 = _nt_choice
673
+ if r1
674
+ r0 = r1
675
+ else
676
+ r2 = _nt_sequence
677
+ if r2
678
+ r0 = r2
679
+ else
680
+ r3 = _nt_primary
681
+ if r3
682
+ r0 = r3
683
+ else
684
+ self.index = i0
685
+ r0 = nil
686
+ end
687
+ end
688
+ end
689
+
690
+ node_cache[:parsing_expression][start_index] = r0
691
+
692
+ return r0
693
+ end
694
+
695
+ module Choice0
696
+ def alternative
697
+ elements[3]
698
+ end
699
+ end
700
+
701
+ module Choice1
702
+ def head
703
+ elements[0]
704
+ end
705
+
706
+ def tail
707
+ elements[1]
708
+ end
709
+ end
710
+
711
+ module Choice2
712
+ def alternatives
713
+ [head] + tail
714
+ end
715
+
716
+ def tail
717
+ super.elements.map {|elt| elt.alternative}
718
+ end
719
+
720
+ def inline_modules
721
+ (alternatives.map {|alt| alt.inline_modules }).flatten
722
+ end
723
+ end
724
+
725
+ def _nt_choice
726
+ start_index = index
727
+ if node_cache[:choice].has_key?(index)
728
+ cached = node_cache[:choice][index]
729
+ @index = cached.interval.end if cached
730
+ return cached
731
+ end
732
+
733
+ i0, s0 = index, []
734
+ r1 = _nt_alternative
735
+ s0 << r1
736
+ if r1
737
+ s2, i2 = [], index
738
+ loop do
739
+ i3, s3 = index, []
740
+ r5 = _nt_space
741
+ if r5
742
+ r4 = r5
743
+ else
744
+ r4 = SyntaxNode.new(input, index...index)
745
+ end
746
+ s3 << r4
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
755
+ s3 << r6
756
+ if r6
757
+ r8 = _nt_space
758
+ if r8
759
+ r7 = r8
760
+ else
761
+ r7 = SyntaxNode.new(input, index...index)
762
+ end
763
+ s3 << r7
764
+ if r7
765
+ r9 = _nt_alternative
766
+ s3 << r9
767
+ end
768
+ end
769
+ end
770
+ if s3.last
771
+ r3 = (SyntaxNode).new(input, i3...index, s3)
772
+ r3.extend(Choice0)
773
+ else
774
+ self.index = i3
775
+ r3 = nil
776
+ end
777
+ if r3
778
+ s2 << r3
779
+ else
780
+ break
781
+ end
782
+ end
783
+ if s2.empty?
784
+ self.index = i2
785
+ r2 = nil
786
+ else
787
+ r2 = SyntaxNode.new(input, i2...index, s2)
788
+ end
789
+ s0 << r2
790
+ end
791
+ if s0.last
792
+ r0 = (Choice).new(input, i0...index, s0)
793
+ r0.extend(Choice1)
794
+ r0.extend(Choice2)
795
+ else
796
+ self.index = i0
797
+ r0 = nil
798
+ end
799
+
800
+ node_cache[:choice][start_index] = r0
801
+
802
+ return r0
803
+ end
804
+
805
+ module Sequence0
806
+ def space
807
+ elements[0]
808
+ end
809
+
810
+ def labeled_sequence_primary
811
+ elements[1]
812
+ end
813
+ end
814
+
815
+ module Sequence1
816
+ def head
817
+ elements[0]
818
+ end
819
+
820
+ def tail
821
+ elements[1]
822
+ end
823
+
824
+ def node_class_declarations
825
+ elements[2]
826
+ end
827
+ end
828
+
829
+ module Sequence2
830
+ def sequence_elements
831
+ [head] + tail
832
+ end
833
+
834
+ def tail
835
+ super.elements.map {|elt| elt.labeled_sequence_primary }
836
+ end
837
+
838
+ def inline_modules
839
+ (sequence_elements.map {|elt| elt.inline_modules}).flatten +
840
+ [sequence_element_accessor_module] +
841
+ node_class_declarations.inline_modules
842
+ end
843
+
844
+ def inline_module_name
845
+ node_class_declarations.inline_module_name
846
+ end
847
+ end
848
+
849
+ def _nt_sequence
850
+ start_index = index
851
+ if node_cache[:sequence].has_key?(index)
852
+ cached = node_cache[:sequence][index]
853
+ @index = cached.interval.end if cached
854
+ return cached
855
+ end
856
+
857
+ i0, s0 = index, []
858
+ r1 = _nt_labeled_sequence_primary
859
+ s0 << r1
860
+ if r1
861
+ s2, i2 = [], index
862
+ loop do
863
+ i3, s3 = index, []
864
+ r4 = _nt_space
865
+ s3 << r4
866
+ if r4
867
+ r5 = _nt_labeled_sequence_primary
868
+ s3 << r5
869
+ end
870
+ if s3.last
871
+ r3 = (SyntaxNode).new(input, i3...index, s3)
872
+ r3.extend(Sequence0)
873
+ else
874
+ self.index = i3
875
+ r3 = nil
876
+ end
877
+ if r3
878
+ s2 << r3
879
+ else
880
+ break
881
+ end
882
+ end
883
+ if s2.empty?
884
+ self.index = i2
885
+ r2 = nil
886
+ else
887
+ r2 = SyntaxNode.new(input, i2...index, s2)
888
+ end
889
+ s0 << r2
890
+ if r2
891
+ r6 = _nt_node_class_declarations
892
+ s0 << r6
893
+ end
894
+ end
895
+ if s0.last
896
+ r0 = (Sequence).new(input, i0...index, s0)
897
+ r0.extend(Sequence1)
898
+ r0.extend(Sequence2)
899
+ else
900
+ self.index = i0
901
+ r0 = nil
902
+ end
903
+
904
+ node_cache[:sequence][start_index] = r0
905
+
906
+ return r0
907
+ end
908
+
909
+ def _nt_alternative
910
+ start_index = index
911
+ if node_cache[:alternative].has_key?(index)
912
+ cached = node_cache[:alternative][index]
913
+ @index = cached.interval.end if cached
914
+ return cached
915
+ end
916
+
917
+ i0 = index
918
+ r1 = _nt_sequence
919
+ if r1
920
+ r0 = r1
921
+ else
922
+ r2 = _nt_primary
923
+ if r2
924
+ r0 = r2
925
+ else
926
+ self.index = i0
927
+ r0 = nil
928
+ end
929
+ end
930
+
931
+ node_cache[:alternative][start_index] = r0
932
+
933
+ return r0
934
+ end
935
+
936
+ module Primary0
937
+ def prefix
938
+ elements[0]
939
+ end
940
+
941
+ def atomic
942
+ elements[1]
943
+ end
944
+ end
945
+
946
+ module Primary1
947
+ def compile(address, builder, parent_expression=nil)
948
+ prefix.compile(address, builder, self)
949
+ end
950
+
951
+ def prefixed_expression
952
+ atomic
953
+ end
954
+
955
+ def inline_modules
956
+ atomic.inline_modules
957
+ end
958
+
959
+ def inline_module_name
960
+ nil
961
+ end
962
+ end
963
+
964
+ module Primary2
965
+ def atomic
966
+ elements[0]
967
+ end
968
+
969
+ def suffix
970
+ elements[1]
971
+ end
972
+
973
+ def node_class_declarations
974
+ elements[2]
975
+ end
976
+ end
977
+
978
+ module Primary3
979
+ def compile(address, builder, parent_expression=nil)
980
+ suffix.compile(address, builder, self)
981
+ end
982
+
983
+ def optional_expression
984
+ atomic
985
+ end
986
+
987
+ def node_class_name
988
+ node_class_declarations.node_class_name
989
+ end
990
+
991
+ def inline_modules
992
+ atomic.inline_modules + node_class_declarations.inline_modules
993
+ end
994
+
995
+ def inline_module_name
996
+ node_class_declarations.inline_module_name
997
+ end
998
+ end
999
+
1000
+ module Primary4
1001
+ def atomic
1002
+ elements[0]
1003
+ end
1004
+
1005
+ def node_class_declarations
1006
+ elements[1]
1007
+ end
1008
+ end
1009
+
1010
+ module Primary5
1011
+ def compile(address, builder, parent_expression=nil)
1012
+ atomic.compile(address, builder, self)
1013
+ end
1014
+
1015
+ def node_class_name
1016
+ node_class_declarations.node_class_name
1017
+ end
1018
+
1019
+ def inline_modules
1020
+ atomic.inline_modules + node_class_declarations.inline_modules
1021
+ end
1022
+
1023
+ def inline_module_name
1024
+ node_class_declarations.inline_module_name
1025
+ end
1026
+ end
1027
+
1028
+ def _nt_primary
1029
+ start_index = index
1030
+ if node_cache[:primary].has_key?(index)
1031
+ cached = node_cache[:primary][index]
1032
+ @index = cached.interval.end if cached
1033
+ return cached
1034
+ end
1035
+
1036
+ i0 = index
1037
+ i1, s1 = index, []
1038
+ r2 = _nt_prefix
1039
+ s1 << r2
1040
+ if r2
1041
+ r3 = _nt_atomic
1042
+ s1 << r3
1043
+ end
1044
+ if s1.last
1045
+ r1 = (SyntaxNode).new(input, i1...index, s1)
1046
+ r1.extend(Primary0)
1047
+ r1.extend(Primary1)
1048
+ else
1049
+ self.index = i1
1050
+ r1 = nil
1051
+ end
1052
+ if r1
1053
+ r0 = r1
1054
+ else
1055
+ i4, s4 = index, []
1056
+ r5 = _nt_atomic
1057
+ s4 << r5
1058
+ if r5
1059
+ r6 = _nt_suffix
1060
+ s4 << r6
1061
+ if r6
1062
+ r7 = _nt_node_class_declarations
1063
+ s4 << r7
1064
+ end
1065
+ end
1066
+ if s4.last
1067
+ r4 = (SyntaxNode).new(input, i4...index, s4)
1068
+ r4.extend(Primary2)
1069
+ r4.extend(Primary3)
1070
+ else
1071
+ self.index = i4
1072
+ r4 = nil
1073
+ end
1074
+ if r4
1075
+ r0 = r4
1076
+ else
1077
+ i8, s8 = index, []
1078
+ r9 = _nt_atomic
1079
+ s8 << r9
1080
+ if r9
1081
+ r10 = _nt_node_class_declarations
1082
+ s8 << r10
1083
+ end
1084
+ if s8.last
1085
+ r8 = (SyntaxNode).new(input, i8...index, s8)
1086
+ r8.extend(Primary4)
1087
+ r8.extend(Primary5)
1088
+ else
1089
+ self.index = i8
1090
+ r8 = nil
1091
+ end
1092
+ if r8
1093
+ r0 = r8
1094
+ else
1095
+ self.index = i0
1096
+ r0 = nil
1097
+ end
1098
+ end
1099
+ end
1100
+
1101
+ node_cache[:primary][start_index] = r0
1102
+
1103
+ return r0
1104
+ end
1105
+
1106
+ module LabeledSequencePrimary0
1107
+ def label
1108
+ elements[0]
1109
+ end
1110
+
1111
+ def sequence_primary
1112
+ elements[1]
1113
+ end
1114
+ end
1115
+
1116
+ module LabeledSequencePrimary1
1117
+ def compile(lexical_address, builder)
1118
+ sequence_primary.compile(lexical_address, builder)
1119
+ end
1120
+
1121
+ def inline_modules
1122
+ sequence_primary.inline_modules
1123
+ end
1124
+
1125
+ def label_name
1126
+ if label.name
1127
+ label.name
1128
+ elsif sequence_primary.instance_of?(Nonterminal)
1129
+ sequence_primary.text_value
1130
+ else
1131
+ nil
1132
+ end
1133
+ end
1134
+ end
1135
+
1136
+ def _nt_labeled_sequence_primary
1137
+ start_index = index
1138
+ if node_cache[:labeled_sequence_primary].has_key?(index)
1139
+ cached = node_cache[:labeled_sequence_primary][index]
1140
+ @index = cached.interval.end if cached
1141
+ return cached
1142
+ end
1143
+
1144
+ i0, s0 = index, []
1145
+ r1 = _nt_label
1146
+ s0 << r1
1147
+ if r1
1148
+ r2 = _nt_sequence_primary
1149
+ s0 << r2
1150
+ end
1151
+ if s0.last
1152
+ r0 = (SyntaxNode).new(input, i0...index, s0)
1153
+ r0.extend(LabeledSequencePrimary0)
1154
+ r0.extend(LabeledSequencePrimary1)
1155
+ else
1156
+ self.index = i0
1157
+ r0 = nil
1158
+ end
1159
+
1160
+ node_cache[:labeled_sequence_primary][start_index] = r0
1161
+
1162
+ return r0
1163
+ end
1164
+
1165
+ module Label0
1166
+ def alpha_char
1167
+ elements[0]
1168
+ end
1169
+
1170
+ end
1171
+
1172
+ module Label1
1173
+ end
1174
+
1175
+ module Label2
1176
+ def name
1177
+ elements[0].text_value
1178
+ end
1179
+ end
1180
+
1181
+ module Label3
1182
+ def name
1183
+ nil
1184
+ end
1185
+ end
1186
+
1187
+ def _nt_label
1188
+ start_index = index
1189
+ if node_cache[:label].has_key?(index)
1190
+ cached = node_cache[:label][index]
1191
+ @index = cached.interval.end if cached
1192
+ return cached
1193
+ end
1194
+
1195
+ i0 = index
1196
+ i1, s1 = index, []
1197
+ i2, s2 = index, []
1198
+ r3 = _nt_alpha_char
1199
+ s2 << r3
1200
+ if r3
1201
+ s4, i4 = [], index
1202
+ loop do
1203
+ r5 = _nt_alphanumeric_char
1204
+ if r5
1205
+ s4 << r5
1206
+ else
1207
+ break
1208
+ end
1209
+ end
1210
+ r4 = SyntaxNode.new(input, i4...index, s4)
1211
+ s2 << r4
1212
+ end
1213
+ if s2.last
1214
+ r2 = (SyntaxNode).new(input, i2...index, s2)
1215
+ r2.extend(Label0)
1216
+ else
1217
+ self.index = i2
1218
+ r2 = nil
1219
+ end
1220
+ s1 << r2
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
1229
+ s1 << r6
1230
+ end
1231
+ if s1.last
1232
+ r1 = (SyntaxNode).new(input, i1...index, s1)
1233
+ r1.extend(Label1)
1234
+ r1.extend(Label2)
1235
+ else
1236
+ self.index = i1
1237
+ r1 = nil
1238
+ end
1239
+ if r1
1240
+ r0 = r1
1241
+ else
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
1251
+ r0 = r7
1252
+ else
1253
+ self.index = i0
1254
+ r0 = nil
1255
+ end
1256
+ end
1257
+
1258
+ node_cache[:label][start_index] = r0
1259
+
1260
+ return r0
1261
+ end
1262
+
1263
+ module SequencePrimary0
1264
+ def prefix
1265
+ elements[0]
1266
+ end
1267
+
1268
+ def atomic
1269
+ elements[1]
1270
+ end
1271
+ end
1272
+
1273
+ module SequencePrimary1
1274
+ def compile(lexical_address, builder)
1275
+ prefix.compile(lexical_address, builder, self)
1276
+ end
1277
+
1278
+ def prefixed_expression
1279
+ elements[1]
1280
+ end
1281
+
1282
+ def inline_modules
1283
+ atomic.inline_modules
1284
+ end
1285
+
1286
+ def inline_module_name
1287
+ nil
1288
+ end
1289
+ end
1290
+
1291
+ module SequencePrimary2
1292
+ def atomic
1293
+ elements[0]
1294
+ end
1295
+
1296
+ def suffix
1297
+ elements[1]
1298
+ end
1299
+ end
1300
+
1301
+ module SequencePrimary3
1302
+ def compile(lexical_address, builder)
1303
+ suffix.compile(lexical_address, builder, self)
1304
+ end
1305
+
1306
+ def node_class_name
1307
+ nil
1308
+ end
1309
+
1310
+ def inline_modules
1311
+ atomic.inline_modules
1312
+ end
1313
+
1314
+ def inline_module_name
1315
+ nil
1316
+ end
1317
+ end
1318
+
1319
+ def _nt_sequence_primary
1320
+ start_index = index
1321
+ if node_cache[:sequence_primary].has_key?(index)
1322
+ cached = node_cache[:sequence_primary][index]
1323
+ @index = cached.interval.end if cached
1324
+ return cached
1325
+ end
1326
+
1327
+ i0 = index
1328
+ i1, s1 = index, []
1329
+ r2 = _nt_prefix
1330
+ s1 << r2
1331
+ if r2
1332
+ r3 = _nt_atomic
1333
+ s1 << r3
1334
+ end
1335
+ if s1.last
1336
+ r1 = (SyntaxNode).new(input, i1...index, s1)
1337
+ r1.extend(SequencePrimary0)
1338
+ r1.extend(SequencePrimary1)
1339
+ else
1340
+ self.index = i1
1341
+ r1 = nil
1342
+ end
1343
+ if r1
1344
+ r0 = r1
1345
+ else
1346
+ i4, s4 = index, []
1347
+ r5 = _nt_atomic
1348
+ s4 << r5
1349
+ if r5
1350
+ r6 = _nt_suffix
1351
+ s4 << r6
1352
+ end
1353
+ if s4.last
1354
+ r4 = (SyntaxNode).new(input, i4...index, s4)
1355
+ r4.extend(SequencePrimary2)
1356
+ r4.extend(SequencePrimary3)
1357
+ else
1358
+ self.index = i4
1359
+ r4 = nil
1360
+ end
1361
+ if r4
1362
+ r0 = r4
1363
+ else
1364
+ r7 = _nt_atomic
1365
+ if r7
1366
+ r0 = r7
1367
+ else
1368
+ self.index = i0
1369
+ r0 = nil
1370
+ end
1371
+ end
1372
+ end
1373
+
1374
+ node_cache[:sequence_primary][start_index] = r0
1375
+
1376
+ return r0
1377
+ end
1378
+
1379
+ def _nt_suffix
1380
+ start_index = index
1381
+ if node_cache[:suffix].has_key?(index)
1382
+ cached = node_cache[:suffix][index]
1383
+ @index = cached.interval.end if cached
1384
+ return cached
1385
+ end
1386
+
1387
+ i0 = index
1388
+ r1 = _nt_repetition_suffix
1389
+ if r1
1390
+ r0 = r1
1391
+ else
1392
+ r2 = _nt_optional_suffix
1393
+ if r2
1394
+ r0 = r2
1395
+ else
1396
+ self.index = i0
1397
+ r0 = nil
1398
+ end
1399
+ end
1400
+
1401
+ node_cache[:suffix][start_index] = r0
1402
+
1403
+ return r0
1404
+ end
1405
+
1406
+ def _nt_optional_suffix
1407
+ start_index = index
1408
+ if node_cache[:optional_suffix].has_key?(index)
1409
+ cached = node_cache[:optional_suffix][index]
1410
+ @index = cached.interval.end if cached
1411
+ return cached
1412
+ end
1413
+
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
1421
+
1422
+ node_cache[:optional_suffix][start_index] = r0
1423
+
1424
+ return r0
1425
+ end
1426
+
1427
+ module NodeClassDeclarations0
1428
+ def node_class_expression
1429
+ elements[0]
1430
+ end
1431
+
1432
+ def trailing_inline_module
1433
+ elements[1]
1434
+ end
1435
+ end
1436
+
1437
+ module NodeClassDeclarations1
1438
+ def node_class_name
1439
+ node_class_expression.node_class_name
1440
+ end
1441
+
1442
+ def inline_modules
1443
+ trailing_inline_module.inline_modules
1444
+ end
1445
+
1446
+ def inline_module
1447
+ trailing_inline_module.inline_module
1448
+ end
1449
+
1450
+ def inline_module_name
1451
+ inline_module.module_name if inline_module
1452
+ end
1453
+ end
1454
+
1455
+ def _nt_node_class_declarations
1456
+ start_index = index
1457
+ if node_cache[:node_class_declarations].has_key?(index)
1458
+ cached = node_cache[:node_class_declarations][index]
1459
+ @index = cached.interval.end if cached
1460
+ return cached
1461
+ end
1462
+
1463
+ i0, s0 = index, []
1464
+ r1 = _nt_node_class_expression
1465
+ s0 << r1
1466
+ if r1
1467
+ r2 = _nt_trailing_inline_module
1468
+ s0 << r2
1469
+ end
1470
+ if s0.last
1471
+ r0 = (SyntaxNode).new(input, i0...index, s0)
1472
+ r0.extend(NodeClassDeclarations0)
1473
+ r0.extend(NodeClassDeclarations1)
1474
+ else
1475
+ self.index = i0
1476
+ r0 = nil
1477
+ end
1478
+
1479
+ node_cache[:node_class_declarations][start_index] = r0
1480
+
1481
+ return r0
1482
+ end
1483
+
1484
+ def _nt_repetition_suffix
1485
+ start_index = index
1486
+ if node_cache[:repetition_suffix].has_key?(index)
1487
+ cached = node_cache[:repetition_suffix][index]
1488
+ @index = cached.interval.end if cached
1489
+ return cached
1490
+ end
1491
+
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
1501
+ r0 = r1
1502
+ else
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
1511
+ r0 = r2
1512
+ else
1513
+ self.index = i0
1514
+ r0 = nil
1515
+ end
1516
+ end
1517
+
1518
+ node_cache[:repetition_suffix][start_index] = r0
1519
+
1520
+ return r0
1521
+ end
1522
+
1523
+ def _nt_prefix
1524
+ start_index = index
1525
+ if node_cache[:prefix].has_key?(index)
1526
+ cached = node_cache[:prefix][index]
1527
+ @index = cached.interval.end if cached
1528
+ return cached
1529
+ end
1530
+
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
1540
+ r0 = r1
1541
+ else
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
1550
+ r0 = r2
1551
+ else
1552
+ if input.index('~', index) == index
1553
+ r3 = (TransientPrefix).new(input, index...(index + 1))
1554
+ @index += 1
1555
+ else
1556
+ terminal_parse_failure('~')
1557
+ r3 = nil
1558
+ end
1559
+ if r3
1560
+ r0 = r3
1561
+ else
1562
+ self.index = i0
1563
+ r0 = nil
1564
+ end
1565
+ end
1566
+ end
1567
+
1568
+ node_cache[:prefix][start_index] = r0
1569
+
1570
+ return r0
1571
+ end
1572
+
1573
+ def _nt_atomic
1574
+ start_index = index
1575
+ if node_cache[:atomic].has_key?(index)
1576
+ cached = node_cache[:atomic][index]
1577
+ @index = cached.interval.end if cached
1578
+ return cached
1579
+ end
1580
+
1581
+ i0 = index
1582
+ r1 = _nt_terminal
1583
+ if r1
1584
+ r0 = r1
1585
+ else
1586
+ r2 = _nt_nonterminal
1587
+ if r2
1588
+ r0 = r2
1589
+ else
1590
+ r3 = _nt_parenthesized_expression
1591
+ if r3
1592
+ r0 = r3
1593
+ else
1594
+ self.index = i0
1595
+ r0 = nil
1596
+ end
1597
+ end
1598
+ end
1599
+
1600
+ node_cache[:atomic][start_index] = r0
1601
+
1602
+ return r0
1603
+ end
1604
+
1605
+ module ParenthesizedExpression0
1606
+ def parsing_expression
1607
+ elements[2]
1608
+ end
1609
+
1610
+ end
1611
+
1612
+ module ParenthesizedExpression1
1613
+ def inline_modules
1614
+ parsing_expression.inline_modules
1615
+ end
1616
+ end
1617
+
1618
+ def _nt_parenthesized_expression
1619
+ start_index = index
1620
+ if node_cache[:parenthesized_expression].has_key?(index)
1621
+ cached = node_cache[:parenthesized_expression][index]
1622
+ @index = cached.interval.end if cached
1623
+ return cached
1624
+ end
1625
+
1626
+ i0, s0 = index, []
1627
+ if input.index('(', index) == index
1628
+ r1 = (SyntaxNode).new(input, index...(index + 1))
1629
+ @index += 1
1630
+ else
1631
+ terminal_parse_failure('(')
1632
+ r1 = nil
1633
+ end
1634
+ s0 << r1
1635
+ if r1
1636
+ r3 = _nt_space
1637
+ if r3
1638
+ r2 = r3
1639
+ else
1640
+ r2 = SyntaxNode.new(input, index...index)
1641
+ end
1642
+ s0 << r2
1643
+ if r2
1644
+ r4 = _nt_parsing_expression
1645
+ s0 << r4
1646
+ if r4
1647
+ r6 = _nt_space
1648
+ if r6
1649
+ r5 = r6
1650
+ else
1651
+ r5 = SyntaxNode.new(input, index...index)
1652
+ end
1653
+ s0 << r5
1654
+ if r5
1655
+ if input.index(')', index) == index
1656
+ r7 = (SyntaxNode).new(input, index...(index + 1))
1657
+ @index += 1
1658
+ else
1659
+ terminal_parse_failure(')')
1660
+ r7 = nil
1661
+ end
1662
+ s0 << r7
1663
+ end
1664
+ end
1665
+ end
1666
+ end
1667
+ if s0.last
1668
+ r0 = (ParenthesizedExpression).new(input, i0...index, s0)
1669
+ r0.extend(ParenthesizedExpression0)
1670
+ r0.extend(ParenthesizedExpression1)
1671
+ else
1672
+ self.index = i0
1673
+ r0 = nil
1674
+ end
1675
+
1676
+ node_cache[:parenthesized_expression][start_index] = r0
1677
+
1678
+ return r0
1679
+ end
1680
+
1681
+ module Nonterminal0
1682
+ def alpha_char
1683
+ elements[0]
1684
+ end
1685
+
1686
+ end
1687
+
1688
+ module Nonterminal1
1689
+ end
1690
+
1691
+ def _nt_nonterminal
1692
+ start_index = index
1693
+ if node_cache[:nonterminal].has_key?(index)
1694
+ cached = node_cache[:nonterminal][index]
1695
+ @index = cached.interval.end if cached
1696
+ return cached
1697
+ end
1698
+
1699
+ i0, s0 = index, []
1700
+ i1 = index
1701
+ r2 = _nt_keyword_inside_grammar
1702
+ if r2
1703
+ r1 = nil
1704
+ else
1705
+ self.index = i1
1706
+ r1 = SyntaxNode.new(input, index...index)
1707
+ end
1708
+ s0 << r1
1709
+ if r1
1710
+ i3, s3 = index, []
1711
+ r4 = _nt_alpha_char
1712
+ s3 << r4
1713
+ if r4
1714
+ s5, i5 = [], index
1715
+ loop do
1716
+ r6 = _nt_alphanumeric_char
1717
+ if r6
1718
+ s5 << r6
1719
+ else
1720
+ break
1721
+ end
1722
+ end
1723
+ r5 = SyntaxNode.new(input, i5...index, s5)
1724
+ s3 << r5
1725
+ end
1726
+ if s3.last
1727
+ r3 = (SyntaxNode).new(input, i3...index, s3)
1728
+ r3.extend(Nonterminal0)
1729
+ else
1730
+ self.index = i3
1731
+ r3 = nil
1732
+ end
1733
+ s0 << r3
1734
+ end
1735
+ if s0.last
1736
+ r0 = (Nonterminal).new(input, i0...index, s0)
1737
+ r0.extend(Nonterminal1)
1738
+ else
1739
+ self.index = i0
1740
+ r0 = nil
1741
+ end
1742
+
1743
+ node_cache[:nonterminal][start_index] = r0
1744
+
1745
+ return r0
1746
+ end
1747
+
1748
+ def _nt_terminal
1749
+ start_index = index
1750
+ if node_cache[:terminal].has_key?(index)
1751
+ cached = node_cache[:terminal][index]
1752
+ @index = cached.interval.end if cached
1753
+ return cached
1754
+ end
1755
+
1756
+ i0 = index
1757
+ r1 = _nt_quoted_string
1758
+ if r1
1759
+ r0 = r1
1760
+ else
1761
+ r2 = _nt_character_class
1762
+ if r2
1763
+ r0 = r2
1764
+ else
1765
+ r3 = _nt_anything_symbol
1766
+ if r3
1767
+ r0 = r3
1768
+ else
1769
+ self.index = i0
1770
+ r0 = nil
1771
+ end
1772
+ end
1773
+ end
1774
+
1775
+ node_cache[:terminal][start_index] = r0
1776
+
1777
+ return r0
1778
+ end
1779
+
1780
+ module QuotedString0
1781
+ def string
1782
+ super.text_value
1783
+ end
1784
+ end
1785
+
1786
+ def _nt_quoted_string
1787
+ start_index = index
1788
+ if node_cache[:quoted_string].has_key?(index)
1789
+ cached = node_cache[:quoted_string][index]
1790
+ @index = cached.interval.end if cached
1791
+ return cached
1792
+ end
1793
+
1794
+ i0 = index
1795
+ r1 = _nt_single_quoted_string
1796
+ if r1
1797
+ r0 = r1
1798
+ r0.extend(QuotedString0)
1799
+ else
1800
+ r2 = _nt_double_quoted_string
1801
+ if r2
1802
+ r0 = r2
1803
+ r0.extend(QuotedString0)
1804
+ else
1805
+ self.index = i0
1806
+ r0 = nil
1807
+ end
1808
+ end
1809
+
1810
+ node_cache[:quoted_string][start_index] = r0
1811
+
1812
+ return r0
1813
+ end
1814
+
1815
+ module DoubleQuotedString0
1816
+ end
1817
+
1818
+ module DoubleQuotedString1
1819
+ def string
1820
+ elements[1]
1821
+ end
1822
+
1823
+ end
1824
+
1825
+ def _nt_double_quoted_string
1826
+ start_index = index
1827
+ if node_cache[:double_quoted_string].has_key?(index)
1828
+ cached = node_cache[:double_quoted_string][index]
1829
+ @index = cached.interval.end if cached
1830
+ return cached
1831
+ end
1832
+
1833
+ i0, s0 = index, []
1834
+ if input.index('"', index) == index
1835
+ r1 = (SyntaxNode).new(input, index...(index + 1))
1836
+ @index += 1
1837
+ else
1838
+ terminal_parse_failure('"')
1839
+ r1 = nil
1840
+ end
1841
+ s0 << r1
1842
+ if r1
1843
+ s2, i2 = [], index
1844
+ loop do
1845
+ i3, s3 = index, []
1846
+ i4 = index
1847
+ if input.index('"', index) == index
1848
+ r5 = (SyntaxNode).new(input, index...(index + 1))
1849
+ @index += 1
1850
+ else
1851
+ terminal_parse_failure('"')
1852
+ r5 = nil
1853
+ end
1854
+ if r5
1855
+ r4 = nil
1856
+ else
1857
+ self.index = i4
1858
+ r4 = SyntaxNode.new(input, index...index)
1859
+ end
1860
+ s3 << r4
1861
+ if r4
1862
+ i6 = index
1863
+ if input.index("\\\\", index) == index
1864
+ r7 = (SyntaxNode).new(input, index...(index + 2))
1865
+ @index += 2
1866
+ else
1867
+ terminal_parse_failure("\\\\")
1868
+ r7 = nil
1869
+ end
1870
+ if r7
1871
+ r6 = r7
1872
+ else
1873
+ if input.index('\"', index) == index
1874
+ r8 = (SyntaxNode).new(input, index...(index + 2))
1875
+ @index += 2
1876
+ else
1877
+ terminal_parse_failure('\"')
1878
+ r8 = nil
1879
+ end
1880
+ if r8
1881
+ r6 = r8
1882
+ else
1883
+ if index < input_length
1884
+ r9 = (SyntaxNode).new(input, index...(index + 1))
1885
+ @index += 1
1886
+ else
1887
+ terminal_parse_failure("any character")
1888
+ r9 = nil
1889
+ end
1890
+ if r9
1891
+ r6 = r9
1892
+ else
1893
+ self.index = i6
1894
+ r6 = nil
1895
+ end
1896
+ end
1897
+ end
1898
+ s3 << r6
1899
+ end
1900
+ if s3.last
1901
+ r3 = (SyntaxNode).new(input, i3...index, s3)
1902
+ r3.extend(DoubleQuotedString0)
1903
+ else
1904
+ self.index = i3
1905
+ r3 = nil
1906
+ end
1907
+ if r3
1908
+ s2 << r3
1909
+ else
1910
+ break
1911
+ end
1912
+ end
1913
+ r2 = SyntaxNode.new(input, i2...index, s2)
1914
+ s0 << r2
1915
+ if r2
1916
+ if input.index('"', index) == index
1917
+ r10 = (SyntaxNode).new(input, index...(index + 1))
1918
+ @index += 1
1919
+ else
1920
+ terminal_parse_failure('"')
1921
+ r10 = nil
1922
+ end
1923
+ s0 << r10
1924
+ end
1925
+ end
1926
+ if s0.last
1927
+ r0 = (Terminal).new(input, i0...index, s0)
1928
+ r0.extend(DoubleQuotedString1)
1929
+ else
1930
+ self.index = i0
1931
+ r0 = nil
1932
+ end
1933
+
1934
+ node_cache[:double_quoted_string][start_index] = r0
1935
+
1936
+ return r0
1937
+ end
1938
+
1939
+ module SingleQuotedString0
1940
+ end
1941
+
1942
+ module SingleQuotedString1
1943
+ def string
1944
+ elements[1]
1945
+ end
1946
+
1947
+ end
1948
+
1949
+ def _nt_single_quoted_string
1950
+ start_index = index
1951
+ if node_cache[:single_quoted_string].has_key?(index)
1952
+ cached = node_cache[:single_quoted_string][index]
1953
+ @index = cached.interval.end if cached
1954
+ return cached
1955
+ end
1956
+
1957
+ i0, s0 = index, []
1958
+ if input.index("'", index) == index
1959
+ r1 = (SyntaxNode).new(input, index...(index + 1))
1960
+ @index += 1
1961
+ else
1962
+ terminal_parse_failure("'")
1963
+ r1 = nil
1964
+ end
1965
+ s0 << r1
1966
+ if r1
1967
+ s2, i2 = [], index
1968
+ loop do
1969
+ i3, s3 = index, []
1970
+ i4 = index
1971
+ if input.index("'", index) == index
1972
+ r5 = (SyntaxNode).new(input, index...(index + 1))
1973
+ @index += 1
1974
+ else
1975
+ terminal_parse_failure("'")
1976
+ r5 = nil
1977
+ end
1978
+ if r5
1979
+ r4 = nil
1980
+ else
1981
+ self.index = i4
1982
+ r4 = SyntaxNode.new(input, index...index)
1983
+ end
1984
+ s3 << r4
1985
+ if r4
1986
+ i6 = index
1987
+ if input.index("\\\\", index) == index
1988
+ r7 = (SyntaxNode).new(input, index...(index + 2))
1989
+ @index += 2
1990
+ else
1991
+ terminal_parse_failure("\\\\")
1992
+ r7 = nil
1993
+ end
1994
+ if r7
1995
+ r6 = r7
1996
+ else
1997
+ if input.index("\\'", index) == index
1998
+ r8 = (SyntaxNode).new(input, index...(index + 2))
1999
+ @index += 2
2000
+ else
2001
+ terminal_parse_failure("\\'")
2002
+ r8 = nil
2003
+ end
2004
+ if r8
2005
+ r6 = r8
2006
+ else
2007
+ if index < input_length
2008
+ r9 = (SyntaxNode).new(input, index...(index + 1))
2009
+ @index += 1
2010
+ else
2011
+ terminal_parse_failure("any character")
2012
+ r9 = nil
2013
+ end
2014
+ if r9
2015
+ r6 = r9
2016
+ else
2017
+ self.index = i6
2018
+ r6 = nil
2019
+ end
2020
+ end
2021
+ end
2022
+ s3 << r6
2023
+ end
2024
+ if s3.last
2025
+ r3 = (SyntaxNode).new(input, i3...index, s3)
2026
+ r3.extend(SingleQuotedString0)
2027
+ else
2028
+ self.index = i3
2029
+ r3 = nil
2030
+ end
2031
+ if r3
2032
+ s2 << r3
2033
+ else
2034
+ break
2035
+ end
2036
+ end
2037
+ r2 = SyntaxNode.new(input, i2...index, s2)
2038
+ s0 << r2
2039
+ if r2
2040
+ if input.index("'", index) == index
2041
+ r10 = (SyntaxNode).new(input, index...(index + 1))
2042
+ @index += 1
2043
+ else
2044
+ terminal_parse_failure("'")
2045
+ r10 = nil
2046
+ end
2047
+ s0 << r10
2048
+ end
2049
+ end
2050
+ if s0.last
2051
+ r0 = (Terminal).new(input, i0...index, s0)
2052
+ r0.extend(SingleQuotedString1)
2053
+ else
2054
+ self.index = i0
2055
+ r0 = nil
2056
+ end
2057
+
2058
+ node_cache[:single_quoted_string][start_index] = r0
2059
+
2060
+ return r0
2061
+ end
2062
+
2063
+ module CharacterClass0
2064
+ end
2065
+
2066
+ module CharacterClass1
2067
+ end
2068
+
2069
+ module CharacterClass2
2070
+ end
2071
+
2072
+ module CharacterClass3
2073
+ def characters
2074
+ elements[1]
2075
+ end
2076
+
2077
+ end
2078
+
2079
+ module CharacterClass4
2080
+ def characters
2081
+ super.text_value
2082
+ end
2083
+ end
2084
+
2085
+ def _nt_character_class
2086
+ start_index = index
2087
+ if node_cache[:character_class].has_key?(index)
2088
+ cached = node_cache[:character_class][index]
2089
+ @index = cached.interval.end if cached
2090
+ return cached
2091
+ end
2092
+
2093
+ i0, s0 = index, []
2094
+ if input.index('[', index) == index
2095
+ r1 = (SyntaxNode).new(input, index...(index + 1))
2096
+ @index += 1
2097
+ else
2098
+ terminal_parse_failure('[')
2099
+ r1 = nil
2100
+ end
2101
+ s0 << r1
2102
+ if r1
2103
+ s2, i2 = [], index
2104
+ loop do
2105
+ i3, s3 = index, []
2106
+ i4 = index
2107
+ if input.index(']', index) == index
2108
+ r5 = (SyntaxNode).new(input, index...(index + 1))
2109
+ @index += 1
2110
+ else
2111
+ terminal_parse_failure(']')
2112
+ r5 = nil
2113
+ end
2114
+ if r5
2115
+ r4 = nil
2116
+ else
2117
+ self.index = i4
2118
+ r4 = SyntaxNode.new(input, index...index)
2119
+ end
2120
+ s3 << r4
2121
+ if r4
2122
+ i6 = index
2123
+ i7, s7 = index, []
2124
+ if input.index('\\', index) == index
2125
+ r8 = (SyntaxNode).new(input, index...(index + 1))
2126
+ @index += 1
2127
+ else
2128
+ terminal_parse_failure('\\')
2129
+ r8 = nil
2130
+ end
2131
+ s7 << r8
2132
+ if r8
2133
+ if index < input_length
2134
+ r9 = (SyntaxNode).new(input, index...(index + 1))
2135
+ @index += 1
2136
+ else
2137
+ terminal_parse_failure("any character")
2138
+ r9 = nil
2139
+ end
2140
+ s7 << r9
2141
+ end
2142
+ if s7.last
2143
+ r7 = (SyntaxNode).new(input, i7...index, s7)
2144
+ r7.extend(CharacterClass0)
2145
+ else
2146
+ self.index = i7
2147
+ r7 = nil
2148
+ end
2149
+ if r7
2150
+ r6 = r7
2151
+ else
2152
+ i10, s10 = index, []
2153
+ i11 = index
2154
+ if input.index('\\', index) == index
2155
+ r12 = (SyntaxNode).new(input, index...(index + 1))
2156
+ @index += 1
2157
+ else
2158
+ terminal_parse_failure('\\')
2159
+ r12 = nil
2160
+ end
2161
+ if r12
2162
+ r11 = nil
2163
+ else
2164
+ self.index = i11
2165
+ r11 = SyntaxNode.new(input, index...index)
2166
+ end
2167
+ s10 << r11
2168
+ if r11
2169
+ if index < input_length
2170
+ r13 = (SyntaxNode).new(input, index...(index + 1))
2171
+ @index += 1
2172
+ else
2173
+ terminal_parse_failure("any character")
2174
+ r13 = nil
2175
+ end
2176
+ s10 << r13
2177
+ end
2178
+ if s10.last
2179
+ r10 = (SyntaxNode).new(input, i10...index, s10)
2180
+ r10.extend(CharacterClass1)
2181
+ else
2182
+ self.index = i10
2183
+ r10 = nil
2184
+ end
2185
+ if r10
2186
+ r6 = r10
2187
+ else
2188
+ self.index = i6
2189
+ r6 = nil
2190
+ end
2191
+ end
2192
+ s3 << r6
2193
+ end
2194
+ if s3.last
2195
+ r3 = (SyntaxNode).new(input, i3...index, s3)
2196
+ r3.extend(CharacterClass2)
2197
+ else
2198
+ self.index = i3
2199
+ r3 = nil
2200
+ end
2201
+ if r3
2202
+ s2 << r3
2203
+ else
2204
+ break
2205
+ end
2206
+ end
2207
+ if s2.empty?
2208
+ self.index = i2
2209
+ r2 = nil
2210
+ else
2211
+ r2 = SyntaxNode.new(input, i2...index, s2)
2212
+ end
2213
+ s0 << r2
2214
+ if r2
2215
+ if input.index(']', index) == index
2216
+ r14 = (SyntaxNode).new(input, index...(index + 1))
2217
+ @index += 1
2218
+ else
2219
+ terminal_parse_failure(']')
2220
+ r14 = nil
2221
+ end
2222
+ s0 << r14
2223
+ end
2224
+ end
2225
+ if s0.last
2226
+ r0 = (CharacterClass).new(input, i0...index, s0)
2227
+ r0.extend(CharacterClass3)
2228
+ r0.extend(CharacterClass4)
2229
+ else
2230
+ self.index = i0
2231
+ r0 = nil
2232
+ end
2233
+
2234
+ node_cache[:character_class][start_index] = r0
2235
+
2236
+ return r0
2237
+ end
2238
+
2239
+ def _nt_anything_symbol
2240
+ start_index = index
2241
+ if node_cache[:anything_symbol].has_key?(index)
2242
+ cached = node_cache[:anything_symbol][index]
2243
+ @index = cached.interval.end if cached
2244
+ return cached
2245
+ end
2246
+
2247
+ if input.index('.', index) == index
2248
+ r0 = (AnythingSymbol).new(input, index...(index + 1))
2249
+ @index += 1
2250
+ else
2251
+ terminal_parse_failure('.')
2252
+ r0 = nil
2253
+ end
2254
+
2255
+ node_cache[:anything_symbol][start_index] = r0
2256
+
2257
+ return r0
2258
+ end
2259
+
2260
+ module NodeClassExpression0
2261
+ end
2262
+
2263
+ module NodeClassExpression1
2264
+ def space
2265
+ elements[0]
2266
+ end
2267
+
2268
+ end
2269
+
2270
+ module NodeClassExpression2
2271
+ def node_class_name
2272
+ elements[2].text_value
2273
+ end
2274
+ end
2275
+
2276
+ module NodeClassExpression3
2277
+ def node_class_name
2278
+ nil
2279
+ end
2280
+ end
2281
+
2282
+ def _nt_node_class_expression
2283
+ start_index = index
2284
+ if node_cache[:node_class_expression].has_key?(index)
2285
+ cached = node_cache[:node_class_expression][index]
2286
+ @index = cached.interval.end if cached
2287
+ return cached
2288
+ end
2289
+
2290
+ i0 = index
2291
+ i1, s1 = index, []
2292
+ r2 = _nt_space
2293
+ s1 << r2
2294
+ if r2
2295
+ if input.index('<', index) == index
2296
+ r3 = (SyntaxNode).new(input, index...(index + 1))
2297
+ @index += 1
2298
+ else
2299
+ terminal_parse_failure('<')
2300
+ r3 = nil
2301
+ end
2302
+ s1 << r3
2303
+ if r3
2304
+ s4, i4 = [], index
2305
+ loop do
2306
+ i5, s5 = index, []
2307
+ i6 = index
2308
+ if input.index('>', index) == index
2309
+ r7 = (SyntaxNode).new(input, index...(index + 1))
2310
+ @index += 1
2311
+ else
2312
+ terminal_parse_failure('>')
2313
+ r7 = nil
2314
+ end
2315
+ if r7
2316
+ r6 = nil
2317
+ else
2318
+ self.index = i6
2319
+ r6 = SyntaxNode.new(input, index...index)
2320
+ end
2321
+ s5 << r6
2322
+ if r6
2323
+ if index < input_length
2324
+ r8 = (SyntaxNode).new(input, index...(index + 1))
2325
+ @index += 1
2326
+ else
2327
+ terminal_parse_failure("any character")
2328
+ r8 = nil
2329
+ end
2330
+ s5 << r8
2331
+ end
2332
+ if s5.last
2333
+ r5 = (SyntaxNode).new(input, i5...index, s5)
2334
+ r5.extend(NodeClassExpression0)
2335
+ else
2336
+ self.index = i5
2337
+ r5 = nil
2338
+ end
2339
+ if r5
2340
+ s4 << r5
2341
+ else
2342
+ break
2343
+ end
2344
+ end
2345
+ if s4.empty?
2346
+ self.index = i4
2347
+ r4 = nil
2348
+ else
2349
+ r4 = SyntaxNode.new(input, i4...index, s4)
2350
+ end
2351
+ s1 << r4
2352
+ if r4
2353
+ if input.index('>', index) == index
2354
+ r9 = (SyntaxNode).new(input, index...(index + 1))
2355
+ @index += 1
2356
+ else
2357
+ terminal_parse_failure('>')
2358
+ r9 = nil
2359
+ end
2360
+ s1 << r9
2361
+ end
2362
+ end
2363
+ end
2364
+ if s1.last
2365
+ r1 = (SyntaxNode).new(input, i1...index, s1)
2366
+ r1.extend(NodeClassExpression1)
2367
+ r1.extend(NodeClassExpression2)
2368
+ else
2369
+ self.index = i1
2370
+ r1 = nil
2371
+ end
2372
+ if r1
2373
+ r0 = r1
2374
+ else
2375
+ if input.index('', index) == index
2376
+ r10 = (SyntaxNode).new(input, index...(index + 0))
2377
+ r10.extend(NodeClassExpression3)
2378
+ @index += 0
2379
+ else
2380
+ terminal_parse_failure('')
2381
+ r10 = nil
2382
+ end
2383
+ if r10
2384
+ r0 = r10
2385
+ else
2386
+ self.index = i0
2387
+ r0 = nil
2388
+ end
2389
+ end
2390
+
2391
+ node_cache[:node_class_expression][start_index] = r0
2392
+
2393
+ return r0
2394
+ end
2395
+
2396
+ module TrailingInlineModule0
2397
+ def space
2398
+ elements[0]
2399
+ end
2400
+
2401
+ def inline_module
2402
+ elements[1]
2403
+ end
2404
+ end
2405
+
2406
+ module TrailingInlineModule1
2407
+ def inline_modules
2408
+ [inline_module]
2409
+ end
2410
+
2411
+ def inline_module_name
2412
+ inline_module.module_name
2413
+ end
2414
+ end
2415
+
2416
+ module TrailingInlineModule2
2417
+ def inline_modules
2418
+ []
2419
+ end
2420
+
2421
+ def inline_module
2422
+ nil
2423
+ end
2424
+
2425
+ def inline_module_name
2426
+ nil
2427
+ end
2428
+ end
2429
+
2430
+ def _nt_trailing_inline_module
2431
+ start_index = index
2432
+ if node_cache[:trailing_inline_module].has_key?(index)
2433
+ cached = node_cache[:trailing_inline_module][index]
2434
+ @index = cached.interval.end if cached
2435
+ return cached
2436
+ end
2437
+
2438
+ i0 = index
2439
+ i1, s1 = index, []
2440
+ r2 = _nt_space
2441
+ s1 << r2
2442
+ if r2
2443
+ r3 = _nt_inline_module
2444
+ s1 << r3
2445
+ end
2446
+ if s1.last
2447
+ r1 = (SyntaxNode).new(input, i1...index, s1)
2448
+ r1.extend(TrailingInlineModule0)
2449
+ r1.extend(TrailingInlineModule1)
2450
+ else
2451
+ self.index = i1
2452
+ r1 = nil
2453
+ end
2454
+ if r1
2455
+ r0 = r1
2456
+ else
2457
+ if input.index('', index) == index
2458
+ r4 = (SyntaxNode).new(input, index...(index + 0))
2459
+ r4.extend(TrailingInlineModule2)
2460
+ @index += 0
2461
+ else
2462
+ terminal_parse_failure('')
2463
+ r4 = nil
2464
+ end
2465
+ if r4
2466
+ r0 = r4
2467
+ else
2468
+ self.index = i0
2469
+ r0 = nil
2470
+ end
2471
+ end
2472
+
2473
+ node_cache[:trailing_inline_module][start_index] = r0
2474
+
2475
+ return r0
2476
+ end
2477
+
2478
+ module InlineModule0
2479
+ end
2480
+
2481
+ module InlineModule1
2482
+ end
2483
+
2484
+ def _nt_inline_module
2485
+ start_index = index
2486
+ if node_cache[:inline_module].has_key?(index)
2487
+ cached = node_cache[:inline_module][index]
2488
+ @index = cached.interval.end if cached
2489
+ return cached
2490
+ end
2491
+
2492
+ i0, s0 = index, []
2493
+ if input.index('{', index) == index
2494
+ r1 = (SyntaxNode).new(input, index...(index + 1))
2495
+ @index += 1
2496
+ else
2497
+ terminal_parse_failure('{')
2498
+ r1 = nil
2499
+ end
2500
+ s0 << r1
2501
+ if r1
2502
+ s2, i2 = [], index
2503
+ loop do
2504
+ i3 = index
2505
+ r4 = _nt_inline_module
2506
+ if r4
2507
+ r3 = r4
2508
+ else
2509
+ i5, s5 = index, []
2510
+ i6 = index
2511
+ if input.index(Regexp.new('[{}]'), index) == index
2512
+ r7 = (SyntaxNode).new(input, index...(index + 1))
2513
+ @index += 1
2514
+ else
2515
+ r7 = nil
2516
+ end
2517
+ if r7
2518
+ r6 = nil
2519
+ else
2520
+ self.index = i6
2521
+ r6 = SyntaxNode.new(input, index...index)
2522
+ end
2523
+ s5 << r6
2524
+ if r6
2525
+ if index < input_length
2526
+ r8 = (SyntaxNode).new(input, index...(index + 1))
2527
+ @index += 1
2528
+ else
2529
+ terminal_parse_failure("any character")
2530
+ r8 = nil
2531
+ end
2532
+ s5 << r8
2533
+ end
2534
+ if s5.last
2535
+ r5 = (SyntaxNode).new(input, i5...index, s5)
2536
+ r5.extend(InlineModule0)
2537
+ else
2538
+ self.index = i5
2539
+ r5 = nil
2540
+ end
2541
+ if r5
2542
+ r3 = r5
2543
+ else
2544
+ self.index = i3
2545
+ r3 = nil
2546
+ end
2547
+ end
2548
+ if r3
2549
+ s2 << r3
2550
+ else
2551
+ break
2552
+ end
2553
+ end
2554
+ r2 = SyntaxNode.new(input, i2...index, s2)
2555
+ s0 << r2
2556
+ if r2
2557
+ if input.index('}', index) == index
2558
+ r9 = (SyntaxNode).new(input, index...(index + 1))
2559
+ @index += 1
2560
+ else
2561
+ terminal_parse_failure('}')
2562
+ r9 = nil
2563
+ end
2564
+ s0 << r9
2565
+ end
2566
+ end
2567
+ if s0.last
2568
+ r0 = (InlineModule).new(input, i0...index, s0)
2569
+ r0.extend(InlineModule1)
2570
+ else
2571
+ self.index = i0
2572
+ r0 = nil
2573
+ end
2574
+
2575
+ node_cache[:inline_module][start_index] = r0
2576
+
2577
+ return r0
2578
+ end
2579
+
2580
+ module KeywordInsideGrammar0
2581
+ end
2582
+
2583
+ def _nt_keyword_inside_grammar
2584
+ start_index = index
2585
+ if node_cache[:keyword_inside_grammar].has_key?(index)
2586
+ cached = node_cache[:keyword_inside_grammar][index]
2587
+ @index = cached.interval.end if cached
2588
+ return cached
2589
+ end
2590
+
2591
+ i0, s0 = index, []
2592
+ i1 = index
2593
+ if input.index('rule', index) == index
2594
+ r2 = (SyntaxNode).new(input, index...(index + 4))
2595
+ @index += 4
2596
+ else
2597
+ terminal_parse_failure('rule')
2598
+ r2 = nil
2599
+ end
2600
+ if r2
2601
+ r1 = r2
2602
+ else
2603
+ if input.index('end', index) == index
2604
+ r3 = (SyntaxNode).new(input, index...(index + 3))
2605
+ @index += 3
2606
+ else
2607
+ terminal_parse_failure('end')
2608
+ r3 = nil
2609
+ end
2610
+ if r3
2611
+ r1 = r3
2612
+ else
2613
+ self.index = i1
2614
+ r1 = nil
2615
+ end
2616
+ end
2617
+ s0 << r1
2618
+ if r1
2619
+ i4 = index
2620
+ r5 = _nt_non_space_char
2621
+ if r5
2622
+ r4 = nil
2623
+ else
2624
+ self.index = i4
2625
+ r4 = SyntaxNode.new(input, index...index)
2626
+ end
2627
+ s0 << r4
2628
+ end
2629
+ if s0.last
2630
+ r0 = (SyntaxNode).new(input, i0...index, s0)
2631
+ r0.extend(KeywordInsideGrammar0)
2632
+ else
2633
+ self.index = i0
2634
+ r0 = nil
2635
+ end
2636
+
2637
+ node_cache[:keyword_inside_grammar][start_index] = r0
2638
+
2639
+ return r0
2640
+ end
2641
+
2642
+ module NonSpaceChar0
2643
+ end
2644
+
2645
+ def _nt_non_space_char
2646
+ start_index = index
2647
+ if node_cache[:non_space_char].has_key?(index)
2648
+ cached = node_cache[:non_space_char][index]
2649
+ @index = cached.interval.end if cached
2650
+ return cached
2651
+ end
2652
+
2653
+ i0, s0 = index, []
2654
+ i1 = index
2655
+ r2 = _nt_space
2656
+ if r2
2657
+ r1 = nil
2658
+ else
2659
+ self.index = i1
2660
+ r1 = SyntaxNode.new(input, index...index)
2661
+ end
2662
+ s0 << r1
2663
+ if r1
2664
+ if index < input_length
2665
+ r3 = (SyntaxNode).new(input, index...(index + 1))
2666
+ @index += 1
2667
+ else
2668
+ terminal_parse_failure("any character")
2669
+ r3 = nil
2670
+ end
2671
+ s0 << r3
2672
+ end
2673
+ if s0.last
2674
+ r0 = (SyntaxNode).new(input, i0...index, s0)
2675
+ r0.extend(NonSpaceChar0)
2676
+ else
2677
+ self.index = i0
2678
+ r0 = nil
2679
+ end
2680
+
2681
+ node_cache[:non_space_char][start_index] = r0
2682
+
2683
+ return r0
2684
+ end
2685
+
2686
+ def _nt_alpha_char
2687
+ start_index = index
2688
+ if node_cache[:alpha_char].has_key?(index)
2689
+ cached = node_cache[:alpha_char][index]
2690
+ @index = cached.interval.end if cached
2691
+ return cached
2692
+ end
2693
+
2694
+ if input.index(Regexp.new('[A-Za-z_]'), index) == index
2695
+ r0 = (SyntaxNode).new(input, index...(index + 1))
2696
+ @index += 1
2697
+ else
2698
+ r0 = nil
2699
+ end
2700
+
2701
+ node_cache[:alpha_char][start_index] = r0
2702
+
2703
+ return r0
2704
+ end
2705
+
2706
+ def _nt_alphanumeric_char
2707
+ start_index = index
2708
+ if node_cache[:alphanumeric_char].has_key?(index)
2709
+ cached = node_cache[:alphanumeric_char][index]
2710
+ @index = cached.interval.end if cached
2711
+ return cached
2712
+ end
2713
+
2714
+ i0 = index
2715
+ r1 = _nt_alpha_char
2716
+ if r1
2717
+ r0 = r1
2718
+ else
2719
+ if input.index(Regexp.new('[0-9]'), index) == index
2720
+ r2 = (SyntaxNode).new(input, index...(index + 1))
2721
+ @index += 1
2722
+ else
2723
+ r2 = nil
2724
+ end
2725
+ if r2
2726
+ r0 = r2
2727
+ else
2728
+ self.index = i0
2729
+ r0 = nil
2730
+ end
2731
+ end
2732
+
2733
+ node_cache[:alphanumeric_char][start_index] = r0
2734
+
2735
+ return r0
2736
+ end
2737
+
2738
+ def _nt_space
2739
+ start_index = index
2740
+ if node_cache[:space].has_key?(index)
2741
+ cached = node_cache[:space][index]
2742
+ @index = cached.interval.end if cached
2743
+ return cached
2744
+ end
2745
+
2746
+ s0, i0 = [], index
2747
+ loop do
2748
+ i1 = index
2749
+ r2 = _nt_white
2750
+ if r2
2751
+ r1 = r2
2752
+ else
2753
+ r3 = _nt_comment_to_eol
2754
+ if r3
2755
+ r1 = r3
2756
+ else
2757
+ self.index = i1
2758
+ r1 = nil
2759
+ end
2760
+ end
2761
+ if r1
2762
+ s0 << r1
2763
+ else
2764
+ break
2765
+ end
2766
+ end
2767
+ if s0.empty?
2768
+ self.index = i0
2769
+ r0 = nil
2770
+ else
2771
+ r0 = SyntaxNode.new(input, i0...index, s0)
2772
+ end
2773
+
2774
+ node_cache[:space][start_index] = r0
2775
+
2776
+ return r0
2777
+ end
2778
+
2779
+ module CommentToEol0
2780
+ end
2781
+
2782
+ module CommentToEol1
2783
+ end
2784
+
2785
+ def _nt_comment_to_eol
2786
+ start_index = index
2787
+ if node_cache[:comment_to_eol].has_key?(index)
2788
+ cached = node_cache[:comment_to_eol][index]
2789
+ @index = cached.interval.end if cached
2790
+ return cached
2791
+ end
2792
+
2793
+ i0, s0 = index, []
2794
+ if input.index('#', index) == index
2795
+ r1 = (SyntaxNode).new(input, index...(index + 1))
2796
+ @index += 1
2797
+ else
2798
+ terminal_parse_failure('#')
2799
+ r1 = nil
2800
+ end
2801
+ s0 << r1
2802
+ if r1
2803
+ s2, i2 = [], index
2804
+ loop do
2805
+ i3, s3 = index, []
2806
+ i4 = index
2807
+ if input.index("\n", index) == index
2808
+ r5 = (SyntaxNode).new(input, index...(index + 1))
2809
+ @index += 1
2810
+ else
2811
+ terminal_parse_failure("\n")
2812
+ r5 = nil
2813
+ end
2814
+ if r5
2815
+ r4 = nil
2816
+ else
2817
+ self.index = i4
2818
+ r4 = SyntaxNode.new(input, index...index)
2819
+ end
2820
+ s3 << r4
2821
+ if r4
2822
+ if index < input_length
2823
+ r6 = (SyntaxNode).new(input, index...(index + 1))
2824
+ @index += 1
2825
+ else
2826
+ terminal_parse_failure("any character")
2827
+ r6 = nil
2828
+ end
2829
+ s3 << r6
2830
+ end
2831
+ if s3.last
2832
+ r3 = (SyntaxNode).new(input, i3...index, s3)
2833
+ r3.extend(CommentToEol0)
2834
+ else
2835
+ self.index = i3
2836
+ r3 = nil
2837
+ end
2838
+ if r3
2839
+ s2 << r3
2840
+ else
2841
+ break
2842
+ end
2843
+ end
2844
+ r2 = SyntaxNode.new(input, i2...index, s2)
2845
+ s0 << r2
2846
+ end
2847
+ if s0.last
2848
+ r0 = (SyntaxNode).new(input, i0...index, s0)
2849
+ r0.extend(CommentToEol1)
2850
+ else
2851
+ self.index = i0
2852
+ r0 = nil
2853
+ end
2854
+
2855
+ node_cache[:comment_to_eol][start_index] = r0
2856
+
2857
+ return r0
2858
+ end
2859
+
2860
+ def _nt_white
2861
+ start_index = index
2862
+ if node_cache[:white].has_key?(index)
2863
+ cached = node_cache[:white][index]
2864
+ @index = cached.interval.end if cached
2865
+ return cached
2866
+ end
2867
+
2868
+ if input.index(Regexp.new('[ \\t\\n\\r]'), index) == index
2869
+ r0 = (SyntaxNode).new(input, index...(index + 1))
2870
+ @index += 1
2871
+ else
2872
+ r0 = nil
2873
+ end
2874
+
2875
+ node_cache[:white][start_index] = r0
2876
+
2877
+ return r0
2878
+ end
2879
+
2880
+ end
2881
+
2882
+ class MetagrammarParser < Treetop::Runtime::CompiledParser
2883
+ include Metagrammar
2884
+ end
2885
+
2886
+ end
2887
+ end