treetop 1.4.5 → 1.4.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +44 -20
- data/lib/treetop/compiler/metagrammar.rb +126 -33
- data/lib/treetop/compiler/metagrammar.treetop +46 -42
- data/lib/treetop/compiler/node_classes/repetition.rb +39 -5
- data/lib/treetop/version.rb +1 -1
- data/spec/compiler/and_predicate_spec.rb +36 -0
- data/spec/compiler/anything_symbol_spec.rb +44 -0
- data/spec/compiler/character_class_spec.rb +276 -0
- data/spec/compiler/choice_spec.rb +80 -0
- data/spec/compiler/circular_compilation_spec.rb +30 -0
- data/spec/compiler/failure_propagation_functional_spec.rb +21 -0
- data/spec/compiler/grammar_compiler_spec.rb +91 -0
- data/spec/compiler/grammar_spec.rb +41 -0
- data/spec/compiler/multibyte_chars_spec.rb +38 -0
- data/spec/compiler/nonterminal_symbol_spec.rb +40 -0
- data/spec/compiler/not_predicate_spec.rb +38 -0
- data/spec/compiler/occurrence_range_spec.rb +191 -0
- data/spec/compiler/one_or_more_spec.rb +35 -0
- data/spec/compiler/optional_spec.rb +37 -0
- data/spec/compiler/parenthesized_expression_spec.rb +19 -0
- data/spec/compiler/parsing_rule_spec.rb +61 -0
- data/spec/compiler/repeated_subrule_spec.rb +29 -0
- data/spec/compiler/semantic_predicate_spec.rb +175 -0
- data/spec/compiler/sequence_spec.rb +115 -0
- data/spec/compiler/terminal_spec.rb +81 -0
- data/spec/compiler/terminal_symbol_spec.rb +37 -0
- data/spec/compiler/test_grammar.treetop +7 -0
- data/spec/compiler/test_grammar.tt +7 -0
- data/spec/compiler/test_grammar_do.treetop +7 -0
- data/spec/compiler/tt_compiler_spec.rb +215 -0
- data/spec/compiler/zero_or_more_spec.rb +56 -0
- data/spec/composition/a.treetop +11 -0
- data/spec/composition/b.treetop +11 -0
- data/spec/composition/c.treetop +10 -0
- data/spec/composition/d.treetop +10 -0
- data/spec/composition/f.treetop +17 -0
- data/spec/composition/grammar_composition_spec.rb +40 -0
- data/spec/composition/subfolder/e_includes_c.treetop +15 -0
- data/spec/ruby_extensions/string_spec.rb +32 -0
- data/spec/runtime/compiled_parser_spec.rb +101 -0
- data/spec/runtime/interval_skip_list/delete_spec.rb +147 -0
- data/spec/runtime/interval_skip_list/expire_range_spec.rb +349 -0
- data/spec/runtime/interval_skip_list/insert_and_delete_node.rb +385 -0
- data/spec/runtime/interval_skip_list/insert_spec.rb +660 -0
- data/spec/runtime/interval_skip_list/interval_skip_list_spec.graffle +6175 -0
- data/spec/runtime/interval_skip_list/interval_skip_list_spec.rb +58 -0
- data/spec/runtime/interval_skip_list/palindromic_fixture.rb +23 -0
- data/spec/runtime/interval_skip_list/palindromic_fixture_spec.rb +163 -0
- data/spec/runtime/interval_skip_list/spec_helper.rb +84 -0
- data/spec/runtime/syntax_node_spec.rb +77 -0
- data/spec/spec_helper.rb +110 -0
- data/treetop.gemspec +18 -0
- metadata +70 -9
data/README.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
Support
|
2
|
+
=======
|
3
|
+
|
4
|
+
Support for Treetop is provided through the mailing list you can join or browse here:
|
5
|
+
http://groups.google.com/group/treetop-dev
|
6
|
+
|
1
7
|
Tutorial
|
2
8
|
========
|
3
9
|
Languages can be split into two components, their *syntax* and their *semantics*. It's your understanding of English syntax that tells you the stream of words "Sleep furiously green ideas colorless" is not a valid sentence. Semantics is deeper. Even if we rearrange the above sentence to be "Colorless green ideas sleep furiously", which is syntactically correct, it remains nonsensical on a semantic level. With Treetop, you'll be dealing with languages that are much simpler than English, but these basic concepts apply. Your programs will need to address both the syntax and the semantics of the languages they interpret.
|
@@ -112,7 +118,16 @@ Any item in a rule may be followed by a '+' or a '*' character, signifying one-o
|
|
112
118
|
end
|
113
119
|
end
|
114
120
|
|
115
|
-
The 'a'* will always eat up any 'a's that follow, and the subsequent 'a' will find none there, so the whole rule will fail. You might need to use lookahead to avoid matching too much.
|
121
|
+
The 'a'* will always eat up any 'a's that follow, and the subsequent 'a' will find none there, so the whole rule will fail. You might need to use lookahead to avoid matching too much. Alternatively, you can use an occurrence range:
|
122
|
+
|
123
|
+
# toogreedy.treetop
|
124
|
+
grammar TooGreedy
|
125
|
+
rule two_to_four_as
|
126
|
+
'a' 2..4
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
In an occurrence range, you may omit either the minimum count or the maximum count, so that "0.. " works like "*" and "1.. " works like '+'.
|
116
131
|
|
117
132
|
Negative Lookahead
|
118
133
|
------------------
|
@@ -141,24 +156,33 @@ Positive lookahead
|
|
141
156
|
|
142
157
|
Sometimes you want an item to match, but only if the *following* text would match some pattern. You don't want to consume that following text, but if it's not there, you want this rule to fail. You can append a positive lookahead like this to a rule by appending the lookahead rule preceeded by an & character.
|
143
158
|
|
159
|
+
Semantic predicates
|
160
|
+
-------------------
|
161
|
+
|
162
|
+
Warning: This is an advanced feature. You need to understand the way a packrat parser operates to use it correctly. The result of computing a rule containing a semantic predicate will be memoized, even if the same rule, applied later at the same location in the input, would work differently due to a semantic predicate returning a different value. If you don't understand the previous sentence yet still use this feature, you're on your own, so test carefully!
|
163
|
+
|
164
|
+
Sometimes, you need to run external Ruby code to decide whether this syntax rule should continue or should fail. You can do this using either positive or negative semantic predicates. These are Ruby code blocks (lambdas) which are called when the parser reaches that location. For this rule to succeed, the value must be true for a positive predicate (a block like &{ ... }), or false for a negative predicate (a block like !{ ... }).
|
165
|
+
|
166
|
+
The block is called with one argument, the array containing the preceding syntax nodes in the current sequence. Within the block, you cannot use node names or labels for the preceding nodes, as the node for the current rule does not yet exist. You must refer to preceding nodes using their position in the sequence.
|
144
167
|
|
168
|
+
grammar Keywords
|
169
|
+
rule sequence_of_reserved_and_nonreserved_words
|
170
|
+
( reserved / word )*
|
171
|
+
end
|
172
|
+
|
173
|
+
rule reserved
|
174
|
+
word &{ |s| symbol_reserved?(s[0].text_value) }
|
175
|
+
end
|
176
|
+
|
177
|
+
rule word
|
178
|
+
([a-zA-Z]+ [ \t]+)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
One case where it is always safe to use a semantic predicate is to invoke the Ruby debugger, but don't forget to return true so the rule succeeds! Assuming you have required the 'ruby-debug' module somewhere, it looks like this:
|
183
|
+
|
184
|
+
rule problems
|
185
|
+
word &{ |s| debugger; true }
|
186
|
+
end
|
145
187
|
|
146
|
-
|
147
|
-
=============================
|
148
|
-
|
149
|
-
* Treetop files
|
150
|
-
* Grammar definition
|
151
|
-
* Rules
|
152
|
-
* Loading a grammar
|
153
|
-
* Compiling a grammar with the `tt` command
|
154
|
-
* Accessing a parser for the grammar from Ruby
|
155
|
-
* Parsing Expressions of all kinds
|
156
|
-
? Left recursion and factorization
|
157
|
-
- Here I can talk about function application, discussing how the operator
|
158
|
-
could be an arbitrary expression
|
159
|
-
* Inline node class eval blocks
|
160
|
-
* Node class declarations
|
161
|
-
* Labels
|
162
|
-
* Use of super within within labels
|
163
|
-
* Grammar composition with include
|
164
|
-
* Use of super with grammar composition
|
188
|
+
When the debugger stops here, you can inspect the contents of the SyntaxNode for "word" by looking at s[0], and the stack trace will show how you got there.
|
@@ -575,7 +575,7 @@ module Treetop
|
|
575
575
|
def declarations
|
576
576
|
[head] + tail
|
577
577
|
end
|
578
|
-
|
578
|
+
|
579
579
|
def tail
|
580
580
|
super.elements.map { |elt| elt.declaration }
|
581
581
|
end
|
@@ -955,11 +955,11 @@ module Treetop
|
|
955
955
|
def alternatives
|
956
956
|
[head] + tail
|
957
957
|
end
|
958
|
-
|
958
|
+
|
959
959
|
def tail
|
960
960
|
super.elements.map {|elt| elt.alternative}
|
961
961
|
end
|
962
|
-
|
962
|
+
|
963
963
|
def inline_modules
|
964
964
|
(alternatives.map {|alt| alt.inline_modules }).flatten
|
965
965
|
end
|
@@ -1076,17 +1076,17 @@ module Treetop
|
|
1076
1076
|
def sequence_elements
|
1077
1077
|
[head] + tail
|
1078
1078
|
end
|
1079
|
-
|
1079
|
+
|
1080
1080
|
def tail
|
1081
1081
|
super.elements.map {|elt| elt.labeled_sequence_primary }
|
1082
1082
|
end
|
1083
|
-
|
1083
|
+
|
1084
1084
|
def inline_modules
|
1085
1085
|
(sequence_elements.map {|elt| elt.inline_modules}).flatten +
|
1086
1086
|
[sequence_element_accessor_module] +
|
1087
1087
|
node_class_declarations.inline_modules
|
1088
1088
|
end
|
1089
|
-
|
1089
|
+
|
1090
1090
|
def inline_module_name
|
1091
1091
|
node_class_declarations.inline_module_name
|
1092
1092
|
end
|
@@ -1199,15 +1199,15 @@ module Treetop
|
|
1199
1199
|
def compile(address, builder, parent_expression=nil)
|
1200
1200
|
prefix.compile(address, builder, self)
|
1201
1201
|
end
|
1202
|
-
|
1202
|
+
|
1203
1203
|
def prefixed_expression
|
1204
1204
|
atomic
|
1205
1205
|
end
|
1206
|
-
|
1206
|
+
|
1207
1207
|
def inline_modules
|
1208
1208
|
atomic.inline_modules
|
1209
1209
|
end
|
1210
|
-
|
1210
|
+
|
1211
1211
|
def inline_module_name
|
1212
1212
|
nil
|
1213
1213
|
end
|
@@ -1253,19 +1253,19 @@ module Treetop
|
|
1253
1253
|
def compile(address, builder, parent_expression=nil)
|
1254
1254
|
suffix.compile(address, builder, self)
|
1255
1255
|
end
|
1256
|
-
|
1256
|
+
|
1257
1257
|
def optional_expression
|
1258
1258
|
atomic
|
1259
1259
|
end
|
1260
|
-
|
1260
|
+
|
1261
1261
|
def node_class_name
|
1262
1262
|
node_class_declarations.node_class_name
|
1263
1263
|
end
|
1264
|
-
|
1264
|
+
|
1265
1265
|
def inline_modules
|
1266
1266
|
atomic.inline_modules + node_class_declarations.inline_modules
|
1267
1267
|
end
|
1268
|
-
|
1268
|
+
|
1269
1269
|
def inline_module_name
|
1270
1270
|
node_class_declarations.inline_module_name
|
1271
1271
|
end
|
@@ -1285,15 +1285,15 @@ module Treetop
|
|
1285
1285
|
def compile(address, builder, parent_expression=nil)
|
1286
1286
|
atomic.compile(address, builder, self)
|
1287
1287
|
end
|
1288
|
-
|
1288
|
+
|
1289
1289
|
def node_class_name
|
1290
1290
|
node_class_declarations.node_class_name
|
1291
1291
|
end
|
1292
|
-
|
1292
|
+
|
1293
1293
|
def inline_modules
|
1294
1294
|
atomic.inline_modules + node_class_declarations.inline_modules
|
1295
1295
|
end
|
1296
|
-
|
1296
|
+
|
1297
1297
|
def inline_module_name
|
1298
1298
|
node_class_declarations.inline_module_name
|
1299
1299
|
end
|
@@ -1422,11 +1422,11 @@ module Treetop
|
|
1422
1422
|
def compile(lexical_address, builder)
|
1423
1423
|
sequence_primary.compile(lexical_address, builder)
|
1424
1424
|
end
|
1425
|
-
|
1425
|
+
|
1426
1426
|
def inline_modules
|
1427
1427
|
sequence_primary.inline_modules
|
1428
1428
|
end
|
1429
|
-
|
1429
|
+
|
1430
1430
|
def label_name
|
1431
1431
|
if label.name
|
1432
1432
|
label.name
|
@@ -1585,15 +1585,15 @@ module Treetop
|
|
1585
1585
|
def compile(lexical_address, builder)
|
1586
1586
|
prefix.compile(lexical_address, builder, self)
|
1587
1587
|
end
|
1588
|
-
|
1588
|
+
|
1589
1589
|
def prefixed_expression
|
1590
1590
|
elements[1]
|
1591
1591
|
end
|
1592
|
-
|
1592
|
+
|
1593
1593
|
def inline_modules
|
1594
1594
|
atomic.inline_modules
|
1595
1595
|
end
|
1596
|
-
|
1596
|
+
|
1597
1597
|
def inline_module_name
|
1598
1598
|
nil
|
1599
1599
|
end
|
@@ -1635,15 +1635,15 @@ module Treetop
|
|
1635
1635
|
def compile(lexical_address, builder)
|
1636
1636
|
suffix.compile(lexical_address, builder, self)
|
1637
1637
|
end
|
1638
|
-
|
1638
|
+
|
1639
1639
|
def node_class_name
|
1640
1640
|
nil
|
1641
1641
|
end
|
1642
|
-
|
1642
|
+
|
1643
1643
|
def inline_modules
|
1644
1644
|
atomic.inline_modules
|
1645
1645
|
end
|
1646
|
-
|
1646
|
+
|
1647
1647
|
def inline_module_name
|
1648
1648
|
nil
|
1649
1649
|
end
|
@@ -1808,15 +1808,15 @@ module Treetop
|
|
1808
1808
|
def node_class_name
|
1809
1809
|
node_class_expression.node_class_name
|
1810
1810
|
end
|
1811
|
-
|
1811
|
+
|
1812
1812
|
def inline_modules
|
1813
1813
|
trailing_inline_module.inline_modules
|
1814
1814
|
end
|
1815
|
-
|
1815
|
+
|
1816
1816
|
def inline_module
|
1817
1817
|
trailing_inline_module.inline_module
|
1818
1818
|
end
|
1819
|
-
|
1819
|
+
|
1820
1820
|
def inline_module_name
|
1821
1821
|
inline_module.module_name if inline_module
|
1822
1822
|
end
|
@@ -1886,8 +1886,13 @@ module Treetop
|
|
1886
1886
|
if r2
|
1887
1887
|
r0 = r2
|
1888
1888
|
else
|
1889
|
-
|
1890
|
-
|
1889
|
+
r3 = _nt_occurrence_range
|
1890
|
+
if r3
|
1891
|
+
r0 = r3
|
1892
|
+
else
|
1893
|
+
@index = i0
|
1894
|
+
r0 = nil
|
1895
|
+
end
|
1891
1896
|
end
|
1892
1897
|
end
|
1893
1898
|
|
@@ -1896,6 +1901,94 @@ module Treetop
|
|
1896
1901
|
r0
|
1897
1902
|
end
|
1898
1903
|
|
1904
|
+
module OccurrenceRange0
|
1905
|
+
def min
|
1906
|
+
elements[1]
|
1907
|
+
end
|
1908
|
+
|
1909
|
+
def max
|
1910
|
+
elements[3]
|
1911
|
+
end
|
1912
|
+
end
|
1913
|
+
|
1914
|
+
def _nt_occurrence_range
|
1915
|
+
start_index = index
|
1916
|
+
if node_cache[:occurrence_range].has_key?(index)
|
1917
|
+
cached = node_cache[:occurrence_range][index]
|
1918
|
+
if cached
|
1919
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
1920
|
+
@index = cached.interval.end
|
1921
|
+
end
|
1922
|
+
return cached
|
1923
|
+
end
|
1924
|
+
|
1925
|
+
i0, s0 = index, []
|
1926
|
+
r2 = _nt_space
|
1927
|
+
if r2
|
1928
|
+
r1 = r2
|
1929
|
+
else
|
1930
|
+
r1 = instantiate_node(SyntaxNode,input, index...index)
|
1931
|
+
end
|
1932
|
+
s0 << r1
|
1933
|
+
if r1
|
1934
|
+
s3, i3 = [], index
|
1935
|
+
loop do
|
1936
|
+
if has_terminal?('\G[0-9]', true, index)
|
1937
|
+
r4 = true
|
1938
|
+
@index += 1
|
1939
|
+
else
|
1940
|
+
r4 = nil
|
1941
|
+
end
|
1942
|
+
if r4
|
1943
|
+
s3 << r4
|
1944
|
+
else
|
1945
|
+
break
|
1946
|
+
end
|
1947
|
+
end
|
1948
|
+
r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
|
1949
|
+
s0 << r3
|
1950
|
+
if r3
|
1951
|
+
if has_terminal?('..', false, index)
|
1952
|
+
r5 = instantiate_node(SyntaxNode,input, index...(index + 2))
|
1953
|
+
@index += 2
|
1954
|
+
else
|
1955
|
+
terminal_parse_failure('..')
|
1956
|
+
r5 = nil
|
1957
|
+
end
|
1958
|
+
s0 << r5
|
1959
|
+
if r5
|
1960
|
+
s6, i6 = [], index
|
1961
|
+
loop do
|
1962
|
+
if has_terminal?('\G[0-9]', true, index)
|
1963
|
+
r7 = true
|
1964
|
+
@index += 1
|
1965
|
+
else
|
1966
|
+
r7 = nil
|
1967
|
+
end
|
1968
|
+
if r7
|
1969
|
+
s6 << r7
|
1970
|
+
else
|
1971
|
+
break
|
1972
|
+
end
|
1973
|
+
end
|
1974
|
+
r6 = instantiate_node(SyntaxNode,input, i6...index, s6)
|
1975
|
+
s0 << r6
|
1976
|
+
end
|
1977
|
+
end
|
1978
|
+
end
|
1979
|
+
if s0.last
|
1980
|
+
r0 = instantiate_node(OccurrenceRange,input, i0...index, s0)
|
1981
|
+
r0.extend(OccurrenceRange0)
|
1982
|
+
else
|
1983
|
+
@index = i0
|
1984
|
+
r0 = nil
|
1985
|
+
end
|
1986
|
+
|
1987
|
+
node_cache[:occurrence_range][start_index] = r0
|
1988
|
+
|
1989
|
+
r0
|
1990
|
+
end
|
1991
|
+
|
1899
1992
|
def _nt_prefix
|
1900
1993
|
start_index = index
|
1901
1994
|
if node_cache[:prefix].has_key?(index)
|
@@ -2816,7 +2909,7 @@ module Treetop
|
|
2816
2909
|
def inline_modules
|
2817
2910
|
[inline_module]
|
2818
2911
|
end
|
2819
|
-
|
2912
|
+
|
2820
2913
|
def inline_module_name
|
2821
2914
|
inline_module.module_name
|
2822
2915
|
end
|
@@ -2826,11 +2919,11 @@ module Treetop
|
|
2826
2919
|
def inline_modules
|
2827
2920
|
[]
|
2828
2921
|
end
|
2829
|
-
|
2922
|
+
|
2830
2923
|
def inline_module
|
2831
|
-
nil
|
2924
|
+
nil
|
2832
2925
|
end
|
2833
|
-
|
2926
|
+
|
2834
2927
|
def inline_module_name
|
2835
2928
|
nil
|
2836
2929
|
end
|
@@ -8,11 +8,11 @@ module Treetop
|
|
8
8
|
end
|
9
9
|
}
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
rule require_statement
|
13
13
|
prefix:space? "require" [ \t]+ [^\n\r]+ [\n\r]
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
rule module_declaration
|
17
17
|
prefix:('module' space [A-Z] alphanumeric_char* space) module_contents:(module_declaration / grammar) suffix:(space 'end') {
|
18
18
|
def compile
|
@@ -34,7 +34,7 @@ module Treetop
|
|
34
34
|
def declarations
|
35
35
|
[head] + tail
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
def tail
|
39
39
|
super.elements.map { |elt| elt.declaration }
|
40
40
|
end
|
@@ -45,11 +45,11 @@ module Treetop
|
|
45
45
|
end
|
46
46
|
}
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
rule declaration
|
50
50
|
parsing_rule / include_declaration
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
rule include_declaration
|
54
54
|
'include' space [A-Z] (alphanumeric_char / '::')* {
|
55
55
|
def compile(builder)
|
@@ -71,11 +71,11 @@ module Treetop
|
|
71
71
|
def alternatives
|
72
72
|
[head] + tail
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
def tail
|
76
76
|
super.elements.map {|elt| elt.alternative}
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
def inline_modules
|
80
80
|
(alternatives.map {|alt| alt.inline_modules }).flatten
|
81
81
|
end
|
@@ -87,17 +87,17 @@ module Treetop
|
|
87
87
|
def sequence_elements
|
88
88
|
[head] + tail
|
89
89
|
end
|
90
|
-
|
90
|
+
|
91
91
|
def tail
|
92
92
|
super.elements.map {|elt| elt.labeled_sequence_primary }
|
93
93
|
end
|
94
|
-
|
94
|
+
|
95
95
|
def inline_modules
|
96
96
|
(sequence_elements.map {|elt| elt.inline_modules}).flatten +
|
97
97
|
[sequence_element_accessor_module] +
|
98
98
|
node_class_declarations.inline_modules
|
99
99
|
end
|
100
|
-
|
100
|
+
|
101
101
|
def inline_module_name
|
102
102
|
node_class_declarations.inline_module_name
|
103
103
|
end
|
@@ -113,15 +113,15 @@ module Treetop
|
|
113
113
|
def compile(address, builder, parent_expression=nil)
|
114
114
|
prefix.compile(address, builder, self)
|
115
115
|
end
|
116
|
-
|
116
|
+
|
117
117
|
def prefixed_expression
|
118
118
|
atomic
|
119
119
|
end
|
120
|
-
|
120
|
+
|
121
121
|
def inline_modules
|
122
122
|
atomic.inline_modules
|
123
123
|
end
|
124
|
-
|
124
|
+
|
125
125
|
def inline_module_name
|
126
126
|
nil
|
127
127
|
end
|
@@ -143,19 +143,19 @@ module Treetop
|
|
143
143
|
def compile(address, builder, parent_expression=nil)
|
144
144
|
suffix.compile(address, builder, self)
|
145
145
|
end
|
146
|
-
|
146
|
+
|
147
147
|
def optional_expression
|
148
148
|
atomic
|
149
149
|
end
|
150
|
-
|
150
|
+
|
151
151
|
def node_class_name
|
152
152
|
node_class_declarations.node_class_name
|
153
153
|
end
|
154
|
-
|
154
|
+
|
155
155
|
def inline_modules
|
156
156
|
atomic.inline_modules + node_class_declarations.inline_modules
|
157
157
|
end
|
158
|
-
|
158
|
+
|
159
159
|
def inline_module_name
|
160
160
|
node_class_declarations.inline_module_name
|
161
161
|
end
|
@@ -165,15 +165,15 @@ module Treetop
|
|
165
165
|
def compile(address, builder, parent_expression=nil)
|
166
166
|
atomic.compile(address, builder, self)
|
167
167
|
end
|
168
|
-
|
168
|
+
|
169
169
|
def node_class_name
|
170
170
|
node_class_declarations.node_class_name
|
171
171
|
end
|
172
|
-
|
172
|
+
|
173
173
|
def inline_modules
|
174
174
|
atomic.inline_modules + node_class_declarations.inline_modules
|
175
175
|
end
|
176
|
-
|
176
|
+
|
177
177
|
def inline_module_name
|
178
178
|
node_class_declarations.inline_module_name
|
179
179
|
end
|
@@ -185,11 +185,11 @@ module Treetop
|
|
185
185
|
def compile(lexical_address, builder)
|
186
186
|
sequence_primary.compile(lexical_address, builder)
|
187
187
|
end
|
188
|
-
|
188
|
+
|
189
189
|
def inline_modules
|
190
190
|
sequence_primary.inline_modules
|
191
191
|
end
|
192
|
-
|
192
|
+
|
193
193
|
def label_name
|
194
194
|
if label.name
|
195
195
|
label.name
|
@@ -201,7 +201,7 @@ module Treetop
|
|
201
201
|
end
|
202
202
|
}
|
203
203
|
end
|
204
|
-
|
204
|
+
|
205
205
|
rule label
|
206
206
|
(alpha_char alphanumeric_char*) ':' {
|
207
207
|
def name
|
@@ -221,15 +221,15 @@ module Treetop
|
|
221
221
|
def compile(lexical_address, builder)
|
222
222
|
prefix.compile(lexical_address, builder, self)
|
223
223
|
end
|
224
|
-
|
224
|
+
|
225
225
|
def prefixed_expression
|
226
226
|
elements[1]
|
227
227
|
end
|
228
|
-
|
228
|
+
|
229
229
|
def inline_modules
|
230
230
|
atomic.inline_modules
|
231
231
|
end
|
232
|
-
|
232
|
+
|
233
233
|
def inline_module_name
|
234
234
|
nil
|
235
235
|
end
|
@@ -251,15 +251,15 @@ module Treetop
|
|
251
251
|
def compile(lexical_address, builder)
|
252
252
|
suffix.compile(lexical_address, builder, self)
|
253
253
|
end
|
254
|
-
|
254
|
+
|
255
255
|
def node_class_name
|
256
256
|
nil
|
257
257
|
end
|
258
|
-
|
258
|
+
|
259
259
|
def inline_modules
|
260
260
|
atomic.inline_modules
|
261
261
|
end
|
262
|
-
|
262
|
+
|
263
263
|
def inline_module_name
|
264
264
|
nil
|
265
265
|
end
|
@@ -267,29 +267,29 @@ module Treetop
|
|
267
267
|
/
|
268
268
|
atomic
|
269
269
|
end
|
270
|
-
|
270
|
+
|
271
271
|
rule suffix
|
272
272
|
repetition_suffix / optional_suffix
|
273
273
|
end
|
274
|
-
|
274
|
+
|
275
275
|
rule optional_suffix
|
276
276
|
'?' <Optional>
|
277
277
|
end
|
278
|
-
|
278
|
+
|
279
279
|
rule node_class_declarations
|
280
280
|
node_class_expression trailing_inline_module {
|
281
281
|
def node_class_name
|
282
282
|
node_class_expression.node_class_name
|
283
283
|
end
|
284
|
-
|
284
|
+
|
285
285
|
def inline_modules
|
286
286
|
trailing_inline_module.inline_modules
|
287
287
|
end
|
288
|
-
|
288
|
+
|
289
289
|
def inline_module
|
290
290
|
trailing_inline_module.inline_module
|
291
291
|
end
|
292
|
-
|
292
|
+
|
293
293
|
def inline_module_name
|
294
294
|
inline_module.module_name if inline_module
|
295
295
|
end
|
@@ -297,7 +297,11 @@ module Treetop
|
|
297
297
|
end
|
298
298
|
|
299
299
|
rule repetition_suffix
|
300
|
-
'+' <OneOrMore> / '*' <ZeroOrMore>
|
300
|
+
'+' <OneOrMore> / '*' <ZeroOrMore> / occurrence_range
|
301
|
+
end
|
302
|
+
|
303
|
+
rule occurrence_range
|
304
|
+
space? min:([0-9])* '..' max:([0-9])* <OccurrenceRange>
|
301
305
|
end
|
302
306
|
|
303
307
|
rule prefix
|
@@ -327,7 +331,7 @@ module Treetop
|
|
327
331
|
rule terminal
|
328
332
|
quoted_string / character_class / anything_symbol
|
329
333
|
end
|
330
|
-
|
334
|
+
|
331
335
|
rule quoted_string
|
332
336
|
(single_quoted_string / double_quoted_string) {
|
333
337
|
def string
|
@@ -335,7 +339,7 @@ module Treetop
|
|
335
339
|
end
|
336
340
|
}
|
337
341
|
end
|
338
|
-
|
342
|
+
|
339
343
|
rule double_quoted_string
|
340
344
|
'"' string:(!'"' ("\\\\" / '\"' / .))* '"' <Terminal>
|
341
345
|
end
|
@@ -375,7 +379,7 @@ module Treetop
|
|
375
379
|
def inline_modules
|
376
380
|
[inline_module]
|
377
381
|
end
|
378
|
-
|
382
|
+
|
379
383
|
def inline_module_name
|
380
384
|
inline_module.module_name
|
381
385
|
end
|
@@ -385,11 +389,11 @@ module Treetop
|
|
385
389
|
def inline_modules
|
386
390
|
[]
|
387
391
|
end
|
388
|
-
|
392
|
+
|
389
393
|
def inline_module
|
390
|
-
nil
|
394
|
+
nil
|
391
395
|
end
|
392
|
-
|
396
|
+
|
393
397
|
def inline_module_name
|
394
398
|
nil
|
395
399
|
end
|