treetop 1.6.2 → 1.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +8 -1
- data/doc/syntactic_recognition.markdown +3 -0
- data/examples/indented_blocks/indented_blocks.tt +73 -0
- data/examples/indented_blocks/indented_blocks_test.rb +24 -0
- data/examples/inner_outer.rb +51 -0
- data/examples/inner_outer.tt +14 -0
- data/examples/numerals.rb +210 -0
- data/examples/numerals.tt +21 -0
- data/lib/treetop/compiler/metagrammar.rb +3 -57
- data/lib/treetop/compiler/metagrammar.treetop +3 -57
- data/lib/treetop/compiler/node_classes/anything_symbol.rb +1 -1
- data/lib/treetop/compiler/node_classes/character_class.rb +1 -1
- data/lib/treetop/compiler/node_classes/choice.rb +5 -5
- data/lib/treetop/compiler/node_classes/nonterminal.rb +2 -2
- data/lib/treetop/compiler/node_classes/parsing_expression.rb +2 -8
- data/lib/treetop/compiler/node_classes/repetition.rb +6 -6
- data/lib/treetop/compiler/node_classes/sequence.rb +1 -1
- data/lib/treetop/compiler/node_classes/terminal.rb +1 -7
- data/lib/treetop/runtime/syntax_node.rb +13 -20
- data/lib/treetop/version.rb +1 -1
- data/spec/compiler/choice_spec.rb +10 -19
- data/spec/compiler/grammar_compiler_spec.rb +4 -4
- data/spec/compiler/parenthesized_expression_spec.rb +0 -11
- data/spec/compiler/tt_compiler_spec.rb +40 -40
- data/spec/compiler/zero_or_more_spec.rb +0 -2
- data/spec/spec_helper.rb +1 -1
- data/treetop.gemspec +10 -5
- metadata +14 -8
@@ -1071,10 +1071,6 @@ module Treetop
|
|
1071
1071
|
super.elements.map {|elt| elt.alternative}
|
1072
1072
|
end
|
1073
1073
|
|
1074
|
-
def parent_modules
|
1075
|
-
[]
|
1076
|
-
end
|
1077
|
-
|
1078
1074
|
def inline_modules
|
1079
1075
|
(alternatives.map {|alt| alt.inline_modules }).flatten
|
1080
1076
|
end
|
@@ -1182,14 +1178,10 @@ module Treetop
|
|
1182
1178
|
sequence_body.tail
|
1183
1179
|
end
|
1184
1180
|
|
1185
|
-
def parent_modules
|
1186
|
-
node_class_declarations.inline_modules
|
1187
|
-
end
|
1188
|
-
|
1189
1181
|
def inline_modules
|
1190
1182
|
(sequence_elements.map {|elt| elt.inline_modules}).flatten +
|
1191
1183
|
[sequence_element_accessor_module] +
|
1192
|
-
|
1184
|
+
node_class_declarations.inline_modules
|
1193
1185
|
end
|
1194
1186
|
|
1195
1187
|
def inline_module_name
|
@@ -1426,10 +1418,6 @@ module Treetop
|
|
1426
1418
|
atomic
|
1427
1419
|
end
|
1428
1420
|
|
1429
|
-
def parent_modules
|
1430
|
-
[]
|
1431
|
-
end
|
1432
|
-
|
1433
1421
|
def inline_modules
|
1434
1422
|
atomic.inline_modules
|
1435
1423
|
end
|
@@ -1456,9 +1444,6 @@ module Treetop
|
|
1456
1444
|
def prefixed_expression
|
1457
1445
|
atomic
|
1458
1446
|
end
|
1459
|
-
def parent_modules
|
1460
|
-
[]
|
1461
|
-
end
|
1462
1447
|
def inline_modules
|
1463
1448
|
[]
|
1464
1449
|
end
|
@@ -1480,7 +1465,6 @@ module Treetop
|
|
1480
1465
|
|
1481
1466
|
module Primary5
|
1482
1467
|
def compile(address, builder, parent_expression=nil)
|
1483
|
-
# debugger if node_class_declarations.inline_modules.size > 0 && atomic.inline_modules.size > 0
|
1484
1468
|
suffix.compile(address, builder, self)
|
1485
1469
|
end
|
1486
1470
|
|
@@ -1492,12 +1476,8 @@ module Treetop
|
|
1492
1476
|
node_class_declarations.node_class_name
|
1493
1477
|
end
|
1494
1478
|
|
1495
|
-
def parent_modules
|
1496
|
-
node_class_declarations.inline_modules
|
1497
|
-
end
|
1498
|
-
|
1499
1479
|
def inline_modules
|
1500
|
-
atomic.inline_modules +
|
1480
|
+
atomic.inline_modules + node_class_declarations.inline_modules
|
1501
1481
|
end
|
1502
1482
|
|
1503
1483
|
def inline_module_name
|
@@ -1517,7 +1497,6 @@ module Treetop
|
|
1517
1497
|
|
1518
1498
|
module Primary7
|
1519
1499
|
def compile(address, builder, parent_expression=nil)
|
1520
|
-
# debugger if node_class_declarations.inline_modules.size > 0 && atomic.inline_modules.size > 0
|
1521
1500
|
atomic.compile(address, builder, self)
|
1522
1501
|
end
|
1523
1502
|
|
@@ -1525,12 +1504,8 @@ module Treetop
|
|
1525
1504
|
node_class_declarations.node_class_name
|
1526
1505
|
end
|
1527
1506
|
|
1528
|
-
def parent_modules
|
1529
|
-
node_class_declarations.inline_modules
|
1530
|
-
end
|
1531
|
-
|
1532
1507
|
def inline_modules
|
1533
|
-
atomic.inline_modules +
|
1508
|
+
atomic.inline_modules + node_class_declarations.inline_modules
|
1534
1509
|
end
|
1535
1510
|
|
1536
1511
|
def inline_module_name
|
@@ -1698,10 +1673,6 @@ module Treetop
|
|
1698
1673
|
sequence_primary.compile(lexical_address, builder)
|
1699
1674
|
end
|
1700
1675
|
|
1701
|
-
def parent_modules
|
1702
|
-
[]
|
1703
|
-
end
|
1704
|
-
|
1705
1676
|
def inline_modules
|
1706
1677
|
sequence_primary.inline_modules
|
1707
1678
|
end
|
@@ -1758,10 +1729,6 @@ module Treetop
|
|
1758
1729
|
sequence_primary.compile(lexical_address, builder)
|
1759
1730
|
end
|
1760
1731
|
|
1761
|
-
def parent_modules
|
1762
|
-
[]
|
1763
|
-
end
|
1764
|
-
|
1765
1732
|
def inline_modules
|
1766
1733
|
sequence_primary.inline_modules
|
1767
1734
|
end
|
@@ -1965,10 +1932,6 @@ module Treetop
|
|
1965
1932
|
elements[1]
|
1966
1933
|
end
|
1967
1934
|
|
1968
|
-
def parent_modules
|
1969
|
-
[]
|
1970
|
-
end
|
1971
|
-
|
1972
1935
|
def inline_modules
|
1973
1936
|
atomic.inline_modules
|
1974
1937
|
end
|
@@ -1995,9 +1958,6 @@ module Treetop
|
|
1995
1958
|
def prefixed_expression
|
1996
1959
|
atomic
|
1997
1960
|
end
|
1998
|
-
def parent_modules
|
1999
|
-
[]
|
2000
|
-
end
|
2001
1961
|
def inline_modules
|
2002
1962
|
[]
|
2003
1963
|
end
|
@@ -2022,10 +1982,6 @@ module Treetop
|
|
2022
1982
|
nil
|
2023
1983
|
end
|
2024
1984
|
|
2025
|
-
def parent_modules
|
2026
|
-
[]
|
2027
|
-
end
|
2028
|
-
|
2029
1985
|
def inline_modules
|
2030
1986
|
atomic.inline_modules
|
2031
1987
|
end
|
@@ -2201,7 +2157,6 @@ module Treetop
|
|
2201
2157
|
node_class_expression.node_class_name
|
2202
2158
|
end
|
2203
2159
|
|
2204
|
-
# !!!! cjh !!!!!
|
2205
2160
|
def inline_modules
|
2206
2161
|
trailing_inline_module.inline_modules
|
2207
2162
|
end
|
@@ -2489,9 +2444,6 @@ module Treetop
|
|
2489
2444
|
end
|
2490
2445
|
|
2491
2446
|
module ParenthesizedExpression1
|
2492
|
-
def parent_modules
|
2493
|
-
[]
|
2494
|
-
end
|
2495
2447
|
def inline_modules
|
2496
2448
|
parsing_expression.inline_modules
|
2497
2449
|
end
|
@@ -3594,9 +3546,6 @@ module Treetop
|
|
3594
3546
|
end
|
3595
3547
|
|
3596
3548
|
module TrailingInlineModule1
|
3597
|
-
def parent_modules
|
3598
|
-
[]
|
3599
|
-
end
|
3600
3549
|
def inline_modules
|
3601
3550
|
[inline_module]
|
3602
3551
|
end
|
@@ -3607,9 +3556,6 @@ module Treetop
|
|
3607
3556
|
end
|
3608
3557
|
|
3609
3558
|
module TrailingInlineModule2
|
3610
|
-
def parent_modules
|
3611
|
-
[]
|
3612
|
-
end
|
3613
3559
|
def inline_modules
|
3614
3560
|
[]
|
3615
3561
|
end
|
@@ -84,10 +84,6 @@ module Treetop
|
|
84
84
|
super.elements.map {|elt| elt.alternative}
|
85
85
|
end
|
86
86
|
|
87
|
-
def parent_modules
|
88
|
-
[]
|
89
|
-
end
|
90
|
-
|
91
87
|
def inline_modules
|
92
88
|
(alternatives.map {|alt| alt.inline_modules }).flatten
|
93
89
|
end
|
@@ -104,14 +100,10 @@ module Treetop
|
|
104
100
|
sequence_body.tail
|
105
101
|
end
|
106
102
|
|
107
|
-
def parent_modules
|
108
|
-
node_class_declarations.inline_modules
|
109
|
-
end
|
110
|
-
|
111
103
|
def inline_modules
|
112
104
|
(sequence_elements.map {|elt| elt.inline_modules}).flatten +
|
113
105
|
[sequence_element_accessor_module] +
|
114
|
-
|
106
|
+
node_class_declarations.inline_modules
|
115
107
|
end
|
116
108
|
|
117
109
|
def inline_module_name
|
@@ -158,10 +150,6 @@ module Treetop
|
|
158
150
|
atomic
|
159
151
|
end
|
160
152
|
|
161
|
-
def parent_modules
|
162
|
-
[]
|
163
|
-
end
|
164
|
-
|
165
153
|
def inline_modules
|
166
154
|
atomic.inline_modules
|
167
155
|
end
|
@@ -178,9 +166,6 @@ module Treetop
|
|
178
166
|
def prefixed_expression
|
179
167
|
atomic
|
180
168
|
end
|
181
|
-
def parent_modules
|
182
|
-
[]
|
183
|
-
end
|
184
169
|
def inline_modules
|
185
170
|
[]
|
186
171
|
end
|
@@ -188,7 +173,6 @@ module Treetop
|
|
188
173
|
/
|
189
174
|
atomic suffix node_class_declarations {
|
190
175
|
def compile(address, builder, parent_expression=nil)
|
191
|
-
raise "Extraneous module ignored after suffix: #{input[interval].inspect}" if node_class_declarations.inline_modules.size > 0 && atomic.inline_modules.size > 0
|
192
176
|
suffix.compile(address, builder, self)
|
193
177
|
end
|
194
178
|
|
@@ -200,12 +184,8 @@ module Treetop
|
|
200
184
|
node_class_declarations.node_class_name
|
201
185
|
end
|
202
186
|
|
203
|
-
def parent_modules
|
204
|
-
node_class_declarations.inline_modules
|
205
|
-
end
|
206
|
-
|
207
187
|
def inline_modules
|
208
|
-
atomic.inline_modules +
|
188
|
+
atomic.inline_modules + node_class_declarations.inline_modules
|
209
189
|
end
|
210
190
|
|
211
191
|
def inline_module_name
|
@@ -215,7 +195,6 @@ module Treetop
|
|
215
195
|
/
|
216
196
|
atomic node_class_declarations {
|
217
197
|
def compile(address, builder, parent_expression=nil)
|
218
|
-
raise "Extraneous module ignored with nested atomic: #{input[interval].inspect}" if node_class_declarations.inline_modules.size > 0 && atomic.inline_modules.size > 0
|
219
198
|
atomic.compile(address, builder, self)
|
220
199
|
end
|
221
200
|
|
@@ -223,12 +202,8 @@ module Treetop
|
|
223
202
|
node_class_declarations.node_class_name
|
224
203
|
end
|
225
204
|
|
226
|
-
def parent_modules
|
227
|
-
node_class_declarations.inline_modules
|
228
|
-
end
|
229
|
-
|
230
205
|
def inline_modules
|
231
|
-
atomic.inline_modules +
|
206
|
+
atomic.inline_modules + node_class_declarations.inline_modules
|
232
207
|
end
|
233
208
|
|
234
209
|
def inline_module_name
|
@@ -247,10 +222,6 @@ module Treetop
|
|
247
222
|
sequence_primary.compile(lexical_address, builder)
|
248
223
|
end
|
249
224
|
|
250
|
-
def parent_modules
|
251
|
-
[]
|
252
|
-
end
|
253
|
-
|
254
225
|
def inline_modules
|
255
226
|
sequence_primary.inline_modules
|
256
227
|
end
|
@@ -267,10 +238,6 @@ module Treetop
|
|
267
238
|
sequence_primary.compile(lexical_address, builder)
|
268
239
|
end
|
269
240
|
|
270
|
-
def parent_modules
|
271
|
-
[]
|
272
|
-
end
|
273
|
-
|
274
241
|
def inline_modules
|
275
242
|
sequence_primary.inline_modules
|
276
243
|
end
|
@@ -315,10 +282,6 @@ module Treetop
|
|
315
282
|
elements[1]
|
316
283
|
end
|
317
284
|
|
318
|
-
def parent_modules
|
319
|
-
[]
|
320
|
-
end
|
321
|
-
|
322
285
|
def inline_modules
|
323
286
|
atomic.inline_modules
|
324
287
|
end
|
@@ -335,9 +298,6 @@ module Treetop
|
|
335
298
|
def prefixed_expression
|
336
299
|
atomic
|
337
300
|
end
|
338
|
-
def parent_modules
|
339
|
-
[]
|
340
|
-
end
|
341
301
|
def inline_modules
|
342
302
|
[]
|
343
303
|
end
|
@@ -352,10 +312,6 @@ module Treetop
|
|
352
312
|
nil
|
353
313
|
end
|
354
314
|
|
355
|
-
def parent_modules
|
356
|
-
[]
|
357
|
-
end
|
358
|
-
|
359
315
|
def inline_modules
|
360
316
|
atomic.inline_modules
|
361
317
|
end
|
@@ -382,7 +338,6 @@ module Treetop
|
|
382
338
|
node_class_expression.node_class_name
|
383
339
|
end
|
384
340
|
|
385
|
-
# !!!! cjh !!!!!
|
386
341
|
def inline_modules
|
387
342
|
trailing_inline_module.inline_modules
|
388
343
|
end
|
@@ -419,9 +374,6 @@ module Treetop
|
|
419
374
|
|
420
375
|
rule parenthesized_expression
|
421
376
|
'(' space? parsing_expression space? ')' <ParenthesizedExpression> {
|
422
|
-
def parent_modules
|
423
|
-
[]
|
424
|
-
end
|
425
377
|
def inline_modules
|
426
378
|
parsing_expression.inline_modules
|
427
379
|
end
|
@@ -487,9 +439,6 @@ module Treetop
|
|
487
439
|
|
488
440
|
rule trailing_inline_module
|
489
441
|
space inline_module {
|
490
|
-
def parent_modules
|
491
|
-
[]
|
492
|
-
end
|
493
442
|
def inline_modules
|
494
443
|
[inline_module]
|
495
444
|
end
|
@@ -500,9 +449,6 @@ module Treetop
|
|
500
449
|
}
|
501
450
|
/
|
502
451
|
'' {
|
503
|
-
def parent_modules
|
504
|
-
[]
|
505
|
-
end
|
506
452
|
def inline_modules
|
507
453
|
[]
|
508
454
|
end
|
@@ -6,7 +6,7 @@ module Treetop
|
|
6
6
|
builder.if__ "index < input_length" do
|
7
7
|
if address == 0 || decorated?
|
8
8
|
assign_result "instantiate_node(#{node_class_name},input, index...(index + 1))"
|
9
|
-
extend_result_with_inline_module
|
9
|
+
extend_result_with_inline_module
|
10
10
|
else
|
11
11
|
assign_lazily_instantiated_node
|
12
12
|
end
|
@@ -7,7 +7,7 @@ module Treetop
|
|
7
7
|
builder.if__ "has_terminal?(@regexps[gr = #{grounded_regexp(text_value)}] ||= Regexp.new(gr), :regexp, index)" do
|
8
8
|
if address == 0 || decorated?
|
9
9
|
assign_result "instantiate_node(#{node_class_name},input, index...(index + 1))"
|
10
|
-
extend_result_with_inline_module
|
10
|
+
extend_result_with_inline_module
|
11
11
|
else
|
12
12
|
assign_lazily_instantiated_node
|
13
13
|
end
|
@@ -5,11 +5,11 @@ module Treetop
|
|
5
5
|
super
|
6
6
|
begin_comment(self)
|
7
7
|
use_vars :result, :start_index
|
8
|
-
compile_alternatives(alternatives
|
8
|
+
compile_alternatives(alternatives)
|
9
9
|
end_comment(self)
|
10
10
|
end
|
11
|
-
|
12
|
-
def compile_alternatives(alternatives
|
11
|
+
|
12
|
+
def compile_alternatives(alternatives)
|
13
13
|
obtain_new_subexpression_address
|
14
14
|
alternatives.first.compile(subexpression_address, builder)
|
15
15
|
builder.if__ subexpression_success? do
|
@@ -17,14 +17,14 @@ module Treetop
|
|
17
17
|
builder << "#{subexpression_result_var} = SyntaxNode.new(input, (index-1)...index) if #{subexpression_result_var} == true"
|
18
18
|
assign_result subexpression_result_var
|
19
19
|
extend_result_with_declared_module
|
20
|
-
extend_result_with_inline_module
|
20
|
+
extend_result_with_inline_module
|
21
21
|
end
|
22
22
|
builder.else_ do
|
23
23
|
if alternatives.size == 1
|
24
24
|
reset_index
|
25
25
|
assign_failure start_index_var
|
26
26
|
else
|
27
|
-
compile_alternatives(alternatives[1..-1]
|
27
|
+
compile_alternatives(alternatives[1..-1])
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -6,8 +6,8 @@ module Treetop
|
|
6
6
|
use_vars :result
|
7
7
|
assign_result text_value == 'super' ? 'super' : "_nt_#{text_value}"
|
8
8
|
extend_result_with_declared_module
|
9
|
-
extend_result_with_inline_module
|
9
|
+
extend_result_with_inline_module
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
13
|
-
end
|
13
|
+
end
|
@@ -78,14 +78,8 @@ module Treetop
|
|
78
78
|
extend_result declared_module_name if declared_module_name
|
79
79
|
end
|
80
80
|
|
81
|
-
def extend_result_with_inline_module
|
82
|
-
|
83
|
-
if parent_expression && parent_expression.parent_modules.size > 0
|
84
|
-
parent_expression.parent_modules.each do |inline|
|
85
|
-
extend_result inline.module_name
|
86
|
-
end
|
87
|
-
end
|
88
|
-
extend_result inline_module_name if inline_module_name
|
81
|
+
def extend_result_with_inline_module
|
82
|
+
extend_result inline_module_name if inline_module_name
|
89
83
|
end
|
90
84
|
|
91
85
|
def reset_index
|
@@ -28,9 +28,9 @@ module Treetop
|
|
28
28
|
parent_expression.inline_module_name
|
29
29
|
end
|
30
30
|
|
31
|
-
def assign_and_extend_result
|
31
|
+
def assign_and_extend_result
|
32
32
|
assign_result "instantiate_node(#{node_class_name},input, #{start_index_var}...index, #{accumulator_var})"
|
33
|
-
extend_result_with_inline_module
|
33
|
+
extend_result_with_inline_module
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -38,7 +38,7 @@ module Treetop
|
|
38
38
|
class ZeroOrMore < Repetition
|
39
39
|
def compile(address, builder, parent_expression)
|
40
40
|
super
|
41
|
-
assign_and_extend_result
|
41
|
+
assign_and_extend_result
|
42
42
|
end_comment(parent_expression)
|
43
43
|
end
|
44
44
|
|
@@ -55,7 +55,7 @@ module Treetop
|
|
55
55
|
assign_failure start_index_var
|
56
56
|
end
|
57
57
|
builder.else_ do
|
58
|
-
assign_and_extend_result
|
58
|
+
assign_and_extend_result
|
59
59
|
end
|
60
60
|
end_comment(parent_expression)
|
61
61
|
end
|
@@ -81,11 +81,11 @@ module Treetop
|
|
81
81
|
end
|
82
82
|
builder.else_ do
|
83
83
|
clean_unsaturated
|
84
|
-
assign_and_extend_result
|
84
|
+
assign_and_extend_result
|
85
85
|
end
|
86
86
|
else
|
87
87
|
clean_unsaturated
|
88
|
-
assign_and_extend_result
|
88
|
+
assign_and_extend_result
|
89
89
|
end
|
90
90
|
|
91
91
|
end_comment(parent_expression)
|