treetop 1.5.1 → 1.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +3 -1
- data/lib/treetop/compiler/metagrammar.rb +211 -208
- data/lib/treetop/compiler/metagrammar.treetop +1 -1
- data/lib/treetop/compiler/node_classes/character_class.rb +3 -3
- data/lib/treetop/compiler/node_classes/terminal.rb +23 -8
- data/lib/treetop/runtime/compiled_parser.rb +5 -5
- data/lib/treetop/version.rb +1 -1
- data/spec/compiler/terminal_spec.rb +53 -8
- data/treetop.gemspec +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YjM5NTQzZTQ2YjVkZmJhMTIyMDUwM2U5YWY4MTcxNTQzMGYwZGM1Mg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YTE1MTQyNWE0NDdkNTU1MmNiYWFiZWU2NDA3ZjJkYmUzNGU5ZmI3ZA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ODQyMDUyODBkYzE0MzYxNzNkMmE1MjQ0NjY3MmJjN2NjMjJjOTMxYjFkMzYy
|
10
|
+
NTk1ZmIyMzMxZDczNWIxYTZhNDEyMjMxMzQ5OGIyYmM4MWE1NjY2MTRjOTg0
|
11
|
+
ZmE5MGJiYzZhZjRjOTAzZjc2YTVlMGQ5Y2U2ZGVlMGE5MjgxZTI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
M2MzNmM5ZjI0MDJhMmE3NDk5MTMzNjUyOTE4MDc0ZWZiNjBmZjE1ZTgxYzc4
|
14
|
+
MzA4NmVhZWQ0ZTliZjg3YWY1Mjc3ZGNiYmMyYTRmYzNjOGJiODM1Mzg1YjIz
|
15
|
+
NmU4YjYwMGJlNjgyNmM2MGNjYjY2MDU4MDIxNWMwOTA2Y2MxYWY=
|
data/README.md
CHANGED
@@ -46,7 +46,9 @@ Users of *regular expressions* will find parsing expressions familiar. They shar
|
|
46
46
|
|
47
47
|
Terminal Symbols
|
48
48
|
----------------
|
49
|
-
The expression in the grammar above is a terminal symbol. It will only match a string that matches it exactly. There are two other kinds of terminal symbols, which we'll revisit later. Terminals are called *atomic expressions* because they aren't composed of smaller expressions. A terminal symbol may use either double or single quotes. If the closing quote is immediately followed by the
|
49
|
+
The expression in the grammar above is a terminal symbol. It will only match a string that matches it exactly. There are two other kinds of terminal symbols, which we'll revisit later. Terminals are called *atomic expressions* because they aren't composed of smaller expressions. A terminal symbol may use either double or single quotes. If the closing quote is immediately followed by the modifier 'i', the string is matched without case-sensitivity, that is, the input.downcase matches the terminal.downcase
|
50
|
+
|
51
|
+
Treetop now also supports regular expressions as terminals. Use a string as before, but append the modifier character 'r' (you can combine this with 'i' to get case-insensitive regular expressions). Regular expressions are generally faster than the equivalent parsing expressions, but may have polynomial worst-case behaviour, which is worse than parsing expressions. Your regular expression will always be anchored (by prepending \A) to test the current location of the input, so some special expressions like \b for word boundaries may give unexpected results.
|
50
52
|
|
51
53
|
Ordered Choices
|
52
54
|
---------------
|
@@ -144,9 +144,9 @@ module Treetop
|
|
144
144
|
end
|
145
145
|
s0 << r1
|
146
146
|
if r1
|
147
|
-
if has_terminal?("require", false, index)
|
148
|
-
r3 = instantiate_node(SyntaxNode,input, index...(index +
|
149
|
-
@index +=
|
147
|
+
if (match_len = has_terminal?("require", false, index))
|
148
|
+
r3 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
149
|
+
@index += match_len
|
150
150
|
else
|
151
151
|
terminal_parse_failure("require")
|
152
152
|
r3 = nil
|
@@ -155,7 +155,7 @@ module Treetop
|
|
155
155
|
if r3
|
156
156
|
s4, i4 = [], index
|
157
157
|
loop do
|
158
|
-
if has_terminal?(@regexps[gr = '\
|
158
|
+
if has_terminal?(@regexps[gr = '\A[ \\t]'] ||= Regexp.new(gr), :regexp, index)
|
159
159
|
r5 = true
|
160
160
|
@index += 1
|
161
161
|
else
|
@@ -177,7 +177,7 @@ module Treetop
|
|
177
177
|
if r4
|
178
178
|
s6, i6 = [], index
|
179
179
|
loop do
|
180
|
-
if has_terminal?(@regexps[gr = '\
|
180
|
+
if has_terminal?(@regexps[gr = '\A[^\\n\\r]'] ||= Regexp.new(gr), :regexp, index)
|
181
181
|
r7 = true
|
182
182
|
@index += 1
|
183
183
|
else
|
@@ -197,7 +197,7 @@ module Treetop
|
|
197
197
|
end
|
198
198
|
s0 << r6
|
199
199
|
if r6
|
200
|
-
if has_terminal?(@regexps[gr = '\
|
200
|
+
if has_terminal?(@regexps[gr = '\A[\\n\\r]'] ||= Regexp.new(gr), :regexp, index)
|
201
201
|
r8 = true
|
202
202
|
@index += 1
|
203
203
|
else
|
@@ -317,9 +317,9 @@ module Treetop
|
|
317
317
|
|
318
318
|
i0, s0 = index, []
|
319
319
|
i1, s1 = index, []
|
320
|
-
if has_terminal?('module', false, index)
|
321
|
-
r2 = instantiate_node(SyntaxNode,input, index...(index +
|
322
|
-
@index +=
|
320
|
+
if (match_len = has_terminal?('module', false, index))
|
321
|
+
r2 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
322
|
+
@index += match_len
|
323
323
|
else
|
324
324
|
terminal_parse_failure('module')
|
325
325
|
r2 = nil
|
@@ -330,7 +330,7 @@ module Treetop
|
|
330
330
|
s1 << r3
|
331
331
|
if r3
|
332
332
|
i4, s4 = index, []
|
333
|
-
if has_terminal?(@regexps[gr = '\
|
333
|
+
if has_terminal?(@regexps[gr = '\A[A-Z]'] ||= Regexp.new(gr), :regexp, index)
|
334
334
|
r5 = true
|
335
335
|
@index += 1
|
336
336
|
else
|
@@ -353,16 +353,16 @@ module Treetop
|
|
353
353
|
s8, i8 = [], index
|
354
354
|
loop do
|
355
355
|
i9, s9 = index, []
|
356
|
-
if has_terminal?('::', false, index)
|
357
|
-
r10 = instantiate_node(SyntaxNode,input, index...(index +
|
358
|
-
@index +=
|
356
|
+
if (match_len = has_terminal?('::', false, index))
|
357
|
+
r10 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
358
|
+
@index += match_len
|
359
359
|
else
|
360
360
|
terminal_parse_failure('::')
|
361
361
|
r10 = nil
|
362
362
|
end
|
363
363
|
s9 << r10
|
364
364
|
if r10
|
365
|
-
if has_terminal?(@regexps[gr = '\
|
365
|
+
if has_terminal?(@regexps[gr = '\A[A-Z]'] ||= Regexp.new(gr), :regexp, index)
|
366
366
|
r11 = true
|
367
367
|
@index += 1
|
368
368
|
else
|
@@ -444,9 +444,9 @@ module Treetop
|
|
444
444
|
r19 = _nt_space
|
445
445
|
s18 << r19
|
446
446
|
if r19
|
447
|
-
if has_terminal?('end', false, index)
|
448
|
-
r20 = instantiate_node(SyntaxNode,input, index...(index +
|
449
|
-
@index +=
|
447
|
+
if (match_len = has_terminal?('end', false, index))
|
448
|
+
r20 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
449
|
+
@index += match_len
|
450
450
|
else
|
451
451
|
terminal_parse_failure('end')
|
452
452
|
r20 = nil
|
@@ -514,9 +514,9 @@ module Treetop
|
|
514
514
|
end
|
515
515
|
|
516
516
|
i0, s0 = index, []
|
517
|
-
if has_terminal?('grammar', false, index)
|
518
|
-
r1 = instantiate_node(SyntaxNode,input, index...(index +
|
519
|
-
@index +=
|
517
|
+
if (match_len = has_terminal?('grammar', false, index))
|
518
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
519
|
+
@index += match_len
|
520
520
|
else
|
521
521
|
terminal_parse_failure('grammar')
|
522
522
|
r1 = nil
|
@@ -533,9 +533,9 @@ module Treetop
|
|
533
533
|
s0 << r4
|
534
534
|
if r4
|
535
535
|
i6, s6 = index, []
|
536
|
-
if has_terminal?('do', false, index)
|
537
|
-
r7 = instantiate_node(SyntaxNode,input, index...(index +
|
538
|
-
@index +=
|
536
|
+
if (match_len = has_terminal?('do', false, index))
|
537
|
+
r7 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
538
|
+
@index += match_len
|
539
539
|
else
|
540
540
|
terminal_parse_failure('do')
|
541
541
|
r7 = nil
|
@@ -570,9 +570,9 @@ module Treetop
|
|
570
570
|
end
|
571
571
|
s0 << r10
|
572
572
|
if r10
|
573
|
-
if has_terminal?('end', false, index)
|
574
|
-
r12 = instantiate_node(SyntaxNode,input, index...(index +
|
575
|
-
@index +=
|
573
|
+
if (match_len = has_terminal?('end', false, index))
|
574
|
+
r12 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
575
|
+
@index += match_len
|
576
576
|
else
|
577
577
|
terminal_parse_failure('end')
|
578
578
|
r12 = nil
|
@@ -613,7 +613,7 @@ module Treetop
|
|
613
613
|
end
|
614
614
|
|
615
615
|
i0, s0 = index, []
|
616
|
-
if has_terminal?(@regexps[gr = '\
|
616
|
+
if has_terminal?(@regexps[gr = '\A[A-Z]'] ||= Regexp.new(gr), :regexp, index)
|
617
617
|
r1 = true
|
618
618
|
@index += 1
|
619
619
|
else
|
@@ -734,10 +734,10 @@ module Treetop
|
|
734
734
|
r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
|
735
735
|
r0 = r1
|
736
736
|
else
|
737
|
-
if has_terminal?('', false, index)
|
738
|
-
r7 = instantiate_node(SyntaxNode,input, index...(index +
|
737
|
+
if (match_len = has_terminal?('', false, index))
|
738
|
+
r7 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
739
739
|
r7.extend(DeclarationSequence3)
|
740
|
-
@index +=
|
740
|
+
@index += match_len
|
741
741
|
else
|
742
742
|
terminal_parse_failure('')
|
743
743
|
r7 = nil
|
@@ -813,9 +813,9 @@ module Treetop
|
|
813
813
|
end
|
814
814
|
|
815
815
|
i0, s0 = index, []
|
816
|
-
if has_terminal?('include', false, index)
|
817
|
-
r1 = instantiate_node(SyntaxNode,input, index...(index +
|
818
|
-
@index +=
|
816
|
+
if (match_len = has_terminal?('include', false, index))
|
817
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
818
|
+
@index += match_len
|
819
819
|
else
|
820
820
|
terminal_parse_failure('include')
|
821
821
|
r1 = nil
|
@@ -825,7 +825,7 @@ module Treetop
|
|
825
825
|
r2 = _nt_space
|
826
826
|
s0 << r2
|
827
827
|
if r2
|
828
|
-
if has_terminal?(@regexps[gr = '\
|
828
|
+
if has_terminal?(@regexps[gr = '\A[A-Z]'] ||= Regexp.new(gr), :regexp, index)
|
829
829
|
r3 = true
|
830
830
|
@index += 1
|
831
831
|
else
|
@@ -841,9 +841,9 @@ module Treetop
|
|
841
841
|
r6 = SyntaxNode.new(input, (index-1)...index) if r6 == true
|
842
842
|
r5 = r6
|
843
843
|
else
|
844
|
-
if has_terminal?('::', false, index)
|
845
|
-
r7 = instantiate_node(SyntaxNode,input, index...(index +
|
846
|
-
@index +=
|
844
|
+
if (match_len = has_terminal?('::', false, index))
|
845
|
+
r7 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
846
|
+
@index += match_len
|
847
847
|
else
|
848
848
|
terminal_parse_failure('::')
|
849
849
|
r7 = nil
|
@@ -922,9 +922,9 @@ module Treetop
|
|
922
922
|
end
|
923
923
|
|
924
924
|
i0, s0 = index, []
|
925
|
-
if has_terminal?('rule', false, index)
|
926
|
-
r1 = instantiate_node(SyntaxNode,input, index...(index +
|
927
|
-
@index +=
|
925
|
+
if (match_len = has_terminal?('rule', false, index))
|
926
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
927
|
+
@index += match_len
|
928
928
|
else
|
929
929
|
terminal_parse_failure('rule')
|
930
930
|
r1 = nil
|
@@ -941,9 +941,9 @@ module Treetop
|
|
941
941
|
s0 << r4
|
942
942
|
if r4
|
943
943
|
i6, s6 = index, []
|
944
|
-
if has_terminal?('do', false, index)
|
945
|
-
r7 = instantiate_node(SyntaxNode,input, index...(index +
|
946
|
-
@index +=
|
944
|
+
if (match_len = has_terminal?('do', false, index))
|
945
|
+
r7 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
946
|
+
@index += match_len
|
947
947
|
else
|
948
948
|
terminal_parse_failure('do')
|
949
949
|
r7 = nil
|
@@ -973,9 +973,9 @@ module Treetop
|
|
973
973
|
r10 = _nt_space
|
974
974
|
s0 << r10
|
975
975
|
if r10
|
976
|
-
if has_terminal?('end', false, index)
|
977
|
-
r11 = instantiate_node(SyntaxNode,input, index...(index +
|
978
|
-
@index +=
|
976
|
+
if (match_len = has_terminal?('end', false, index))
|
977
|
+
r11 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
978
|
+
@index += match_len
|
979
979
|
else
|
980
980
|
terminal_parse_failure('end')
|
981
981
|
r11 = nil
|
@@ -1095,9 +1095,9 @@ module Treetop
|
|
1095
1095
|
end
|
1096
1096
|
s3 << r4
|
1097
1097
|
if r4
|
1098
|
-
if has_terminal?('/', false, index)
|
1098
|
+
if (match_len = has_terminal?('/', false, index))
|
1099
1099
|
r6 = true
|
1100
|
-
@index +=
|
1100
|
+
@index += match_len
|
1101
1101
|
else
|
1102
1102
|
terminal_parse_failure('/')
|
1103
1103
|
r6 = nil
|
@@ -1852,9 +1852,9 @@ module Treetop
|
|
1852
1852
|
end
|
1853
1853
|
s0 << r1
|
1854
1854
|
if r1
|
1855
|
-
if has_terminal?(':', false, index)
|
1855
|
+
if (match_len = has_terminal?(':', false, index))
|
1856
1856
|
r5 = true
|
1857
|
-
@index +=
|
1857
|
+
@index += match_len
|
1858
1858
|
else
|
1859
1859
|
terminal_parse_failure(':')
|
1860
1860
|
r5 = nil
|
@@ -1892,10 +1892,10 @@ module Treetop
|
|
1892
1892
|
return cached
|
1893
1893
|
end
|
1894
1894
|
|
1895
|
-
if has_terminal?('', false, index)
|
1896
|
-
r0 = instantiate_node(SyntaxNode,input, index...(index +
|
1895
|
+
if (match_len = has_terminal?('', false, index))
|
1896
|
+
r0 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
1897
1897
|
r0.extend(NullLabel0)
|
1898
|
-
@index +=
|
1898
|
+
@index += match_len
|
1899
1899
|
else
|
1900
1900
|
terminal_parse_failure('')
|
1901
1901
|
r0 = nil
|
@@ -2122,9 +2122,9 @@ module Treetop
|
|
2122
2122
|
return cached
|
2123
2123
|
end
|
2124
2124
|
|
2125
|
-
if has_terminal?('?', false, index)
|
2126
|
-
r0 = instantiate_node(Optional,input, index...(index +
|
2127
|
-
@index +=
|
2125
|
+
if (match_len = has_terminal?('?', false, index))
|
2126
|
+
r0 = instantiate_node(Optional,input, index...(index + match_len))
|
2127
|
+
@index += match_len
|
2128
2128
|
else
|
2129
2129
|
terminal_parse_failure('?')
|
2130
2130
|
r0 = nil
|
@@ -2207,9 +2207,9 @@ module Treetop
|
|
2207
2207
|
end
|
2208
2208
|
|
2209
2209
|
i0 = index
|
2210
|
-
if has_terminal?('+', false, index)
|
2211
|
-
r1 = instantiate_node(OneOrMore,input, index...(index +
|
2212
|
-
@index +=
|
2210
|
+
if (match_len = has_terminal?('+', false, index))
|
2211
|
+
r1 = instantiate_node(OneOrMore,input, index...(index + match_len))
|
2212
|
+
@index += match_len
|
2213
2213
|
else
|
2214
2214
|
terminal_parse_failure('+')
|
2215
2215
|
r1 = nil
|
@@ -2218,9 +2218,9 @@ module Treetop
|
|
2218
2218
|
r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
|
2219
2219
|
r0 = r1
|
2220
2220
|
else
|
2221
|
-
if has_terminal?('*', false, index)
|
2222
|
-
r2 = instantiate_node(ZeroOrMore,input, index...(index +
|
2223
|
-
@index +=
|
2221
|
+
if (match_len = has_terminal?('*', false, index))
|
2222
|
+
r2 = instantiate_node(ZeroOrMore,input, index...(index + match_len))
|
2223
|
+
@index += match_len
|
2224
2224
|
else
|
2225
2225
|
terminal_parse_failure('*')
|
2226
2226
|
r2 = nil
|
@@ -2277,7 +2277,7 @@ module Treetop
|
|
2277
2277
|
if r1
|
2278
2278
|
s3, i3 = [], index
|
2279
2279
|
loop do
|
2280
|
-
if has_terminal?(@regexps[gr = '\
|
2280
|
+
if has_terminal?(@regexps[gr = '\A[0-9]'] ||= Regexp.new(gr), :regexp, index)
|
2281
2281
|
r4 = true
|
2282
2282
|
@index += 1
|
2283
2283
|
else
|
@@ -2292,9 +2292,9 @@ module Treetop
|
|
2292
2292
|
r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
|
2293
2293
|
s0 << r3
|
2294
2294
|
if r3
|
2295
|
-
if has_terminal?('..', false, index)
|
2296
|
-
r5 = instantiate_node(SyntaxNode,input, index...(index +
|
2297
|
-
@index +=
|
2295
|
+
if (match_len = has_terminal?('..', false, index))
|
2296
|
+
r5 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
2297
|
+
@index += match_len
|
2298
2298
|
else
|
2299
2299
|
terminal_parse_failure('..')
|
2300
2300
|
r5 = nil
|
@@ -2303,7 +2303,7 @@ module Treetop
|
|
2303
2303
|
if r5
|
2304
2304
|
s6, i6 = [], index
|
2305
2305
|
loop do
|
2306
|
-
if has_terminal?(@regexps[gr = '\
|
2306
|
+
if has_terminal?(@regexps[gr = '\A[0-9]'] ||= Regexp.new(gr), :regexp, index)
|
2307
2307
|
r7 = true
|
2308
2308
|
@index += 1
|
2309
2309
|
else
|
@@ -2345,9 +2345,9 @@ module Treetop
|
|
2345
2345
|
end
|
2346
2346
|
|
2347
2347
|
i0 = index
|
2348
|
-
if has_terminal?('&', false, index)
|
2349
|
-
r1 = instantiate_node(AndPredicate,input, index...(index +
|
2350
|
-
@index +=
|
2348
|
+
if (match_len = has_terminal?('&', false, index))
|
2349
|
+
r1 = instantiate_node(AndPredicate,input, index...(index + match_len))
|
2350
|
+
@index += match_len
|
2351
2351
|
else
|
2352
2352
|
terminal_parse_failure('&')
|
2353
2353
|
r1 = nil
|
@@ -2356,9 +2356,9 @@ module Treetop
|
|
2356
2356
|
r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
|
2357
2357
|
r0 = r1
|
2358
2358
|
else
|
2359
|
-
if has_terminal?('!', false, index)
|
2360
|
-
r2 = instantiate_node(NotPredicate,input, index...(index +
|
2361
|
-
@index +=
|
2359
|
+
if (match_len = has_terminal?('!', false, index))
|
2360
|
+
r2 = instantiate_node(NotPredicate,input, index...(index + match_len))
|
2361
|
+
@index += match_len
|
2362
2362
|
else
|
2363
2363
|
terminal_parse_failure('!')
|
2364
2364
|
r2 = nil
|
@@ -2367,9 +2367,9 @@ module Treetop
|
|
2367
2367
|
r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
|
2368
2368
|
r0 = r2
|
2369
2369
|
else
|
2370
|
-
if has_terminal?('~', false, index)
|
2371
|
-
r3 = instantiate_node(TransientPrefix,input, index...(index +
|
2372
|
-
@index +=
|
2370
|
+
if (match_len = has_terminal?('~', false, index))
|
2371
|
+
r3 = instantiate_node(TransientPrefix,input, index...(index + match_len))
|
2372
|
+
@index += match_len
|
2373
2373
|
else
|
2374
2374
|
terminal_parse_failure('~')
|
2375
2375
|
r3 = nil
|
@@ -2452,9 +2452,9 @@ module Treetop
|
|
2452
2452
|
end
|
2453
2453
|
|
2454
2454
|
i0, s0 = index, []
|
2455
|
-
if has_terminal?('(', false, index)
|
2455
|
+
if (match_len = has_terminal?('(', false, index))
|
2456
2456
|
r1 = true
|
2457
|
-
@index +=
|
2457
|
+
@index += match_len
|
2458
2458
|
else
|
2459
2459
|
terminal_parse_failure('(')
|
2460
2460
|
r1 = nil
|
@@ -2480,9 +2480,9 @@ module Treetop
|
|
2480
2480
|
end
|
2481
2481
|
s0 << r5
|
2482
2482
|
if r5
|
2483
|
-
if has_terminal?(')', false, index)
|
2483
|
+
if (match_len = has_terminal?(')', false, index))
|
2484
2484
|
r7 = true
|
2485
|
-
@index +=
|
2485
|
+
@index += match_len
|
2486
2486
|
else
|
2487
2487
|
terminal_parse_failure(')')
|
2488
2488
|
r7 = nil
|
@@ -2619,7 +2619,7 @@ module Treetop
|
|
2619
2619
|
elements[0]
|
2620
2620
|
end
|
2621
2621
|
|
2622
|
-
def
|
2622
|
+
def modifiers
|
2623
2623
|
elements[1]
|
2624
2624
|
end
|
2625
2625
|
end
|
@@ -2659,18 +2659,21 @@ module Treetop
|
|
2659
2659
|
end
|
2660
2660
|
s0 << r1
|
2661
2661
|
if r1
|
2662
|
-
|
2663
|
-
|
2664
|
-
@
|
2665
|
-
|
2666
|
-
|
2667
|
-
|
2668
|
-
|
2669
|
-
|
2670
|
-
|
2671
|
-
|
2672
|
-
|
2662
|
+
s4, i4 = [], index
|
2663
|
+
loop do
|
2664
|
+
if has_terminal?(@regexps[gr = '\A[ir]'] ||= Regexp.new(gr), :regexp, index)
|
2665
|
+
r5 = true
|
2666
|
+
@index += 1
|
2667
|
+
else
|
2668
|
+
r5 = nil
|
2669
|
+
end
|
2670
|
+
if r5
|
2671
|
+
s4 << r5
|
2672
|
+
else
|
2673
|
+
break
|
2674
|
+
end
|
2673
2675
|
end
|
2676
|
+
r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
|
2674
2677
|
s0 << r4
|
2675
2678
|
end
|
2676
2679
|
if s0.last
|
@@ -2709,9 +2712,9 @@ module Treetop
|
|
2709
2712
|
end
|
2710
2713
|
|
2711
2714
|
i0, s0 = index, []
|
2712
|
-
if has_terminal?('"', false, index)
|
2715
|
+
if (match_len = has_terminal?('"', false, index))
|
2713
2716
|
r1 = true
|
2714
|
-
@index +=
|
2717
|
+
@index += match_len
|
2715
2718
|
else
|
2716
2719
|
terminal_parse_failure('"')
|
2717
2720
|
r1 = nil
|
@@ -2722,9 +2725,9 @@ module Treetop
|
|
2722
2725
|
loop do
|
2723
2726
|
i3, s3 = index, []
|
2724
2727
|
i4 = index
|
2725
|
-
if has_terminal?('"', false, index)
|
2728
|
+
if (match_len = has_terminal?('"', false, index))
|
2726
2729
|
r5 = true
|
2727
|
-
@index +=
|
2730
|
+
@index += match_len
|
2728
2731
|
else
|
2729
2732
|
terminal_parse_failure('"')
|
2730
2733
|
r5 = nil
|
@@ -2738,9 +2741,9 @@ module Treetop
|
|
2738
2741
|
s3 << r4
|
2739
2742
|
if r4
|
2740
2743
|
i6 = index
|
2741
|
-
if has_terminal?("\\\\", false, index)
|
2742
|
-
r7 = instantiate_node(SyntaxNode,input, index...(index +
|
2743
|
-
@index +=
|
2744
|
+
if (match_len = has_terminal?("\\\\", false, index))
|
2745
|
+
r7 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
2746
|
+
@index += match_len
|
2744
2747
|
else
|
2745
2748
|
terminal_parse_failure("\\\\")
|
2746
2749
|
r7 = nil
|
@@ -2749,9 +2752,9 @@ module Treetop
|
|
2749
2752
|
r7 = SyntaxNode.new(input, (index-1)...index) if r7 == true
|
2750
2753
|
r6 = r7
|
2751
2754
|
else
|
2752
|
-
if has_terminal?('\"', false, index)
|
2753
|
-
r8 = instantiate_node(SyntaxNode,input, index...(index +
|
2754
|
-
@index +=
|
2755
|
+
if (match_len = has_terminal?('\"', false, index))
|
2756
|
+
r8 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
2757
|
+
@index += match_len
|
2755
2758
|
else
|
2756
2759
|
terminal_parse_failure('\"')
|
2757
2760
|
r8 = nil
|
@@ -2794,9 +2797,9 @@ module Treetop
|
|
2794
2797
|
r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
|
2795
2798
|
s0 << r2
|
2796
2799
|
if r2
|
2797
|
-
if has_terminal?('"', false, index)
|
2800
|
+
if (match_len = has_terminal?('"', false, index))
|
2798
2801
|
r10 = true
|
2799
|
-
@index +=
|
2802
|
+
@index += match_len
|
2800
2803
|
else
|
2801
2804
|
terminal_parse_failure('"')
|
2802
2805
|
r10 = nil
|
@@ -2839,9 +2842,9 @@ module Treetop
|
|
2839
2842
|
end
|
2840
2843
|
|
2841
2844
|
i0, s0 = index, []
|
2842
|
-
if has_terminal?("'", false, index)
|
2845
|
+
if (match_len = has_terminal?("'", false, index))
|
2843
2846
|
r1 = true
|
2844
|
-
@index +=
|
2847
|
+
@index += match_len
|
2845
2848
|
else
|
2846
2849
|
terminal_parse_failure("'")
|
2847
2850
|
r1 = nil
|
@@ -2852,9 +2855,9 @@ module Treetop
|
|
2852
2855
|
loop do
|
2853
2856
|
i3, s3 = index, []
|
2854
2857
|
i4 = index
|
2855
|
-
if has_terminal?("'", false, index)
|
2858
|
+
if (match_len = has_terminal?("'", false, index))
|
2856
2859
|
r5 = true
|
2857
|
-
@index +=
|
2860
|
+
@index += match_len
|
2858
2861
|
else
|
2859
2862
|
terminal_parse_failure("'")
|
2860
2863
|
r5 = nil
|
@@ -2868,9 +2871,9 @@ module Treetop
|
|
2868
2871
|
s3 << r4
|
2869
2872
|
if r4
|
2870
2873
|
i6 = index
|
2871
|
-
if has_terminal?("\\\\", false, index)
|
2872
|
-
r7 = instantiate_node(SyntaxNode,input, index...(index +
|
2873
|
-
@index +=
|
2874
|
+
if (match_len = has_terminal?("\\\\", false, index))
|
2875
|
+
r7 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
2876
|
+
@index += match_len
|
2874
2877
|
else
|
2875
2878
|
terminal_parse_failure("\\\\")
|
2876
2879
|
r7 = nil
|
@@ -2879,9 +2882,9 @@ module Treetop
|
|
2879
2882
|
r7 = SyntaxNode.new(input, (index-1)...index) if r7 == true
|
2880
2883
|
r6 = r7
|
2881
2884
|
else
|
2882
|
-
if has_terminal?("\\'", false, index)
|
2883
|
-
r8 = instantiate_node(SyntaxNode,input, index...(index +
|
2884
|
-
@index +=
|
2885
|
+
if (match_len = has_terminal?("\\'", false, index))
|
2886
|
+
r8 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
2887
|
+
@index += match_len
|
2885
2888
|
else
|
2886
2889
|
terminal_parse_failure("\\'")
|
2887
2890
|
r8 = nil
|
@@ -2924,9 +2927,9 @@ module Treetop
|
|
2924
2927
|
r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
|
2925
2928
|
s0 << r2
|
2926
2929
|
if r2
|
2927
|
-
if has_terminal?("'", false, index)
|
2930
|
+
if (match_len = has_terminal?("'", false, index))
|
2928
2931
|
r10 = true
|
2929
|
-
@index +=
|
2932
|
+
@index += match_len
|
2930
2933
|
else
|
2931
2934
|
terminal_parse_failure("'")
|
2932
2935
|
r10 = nil
|
@@ -2981,9 +2984,9 @@ module Treetop
|
|
2981
2984
|
end
|
2982
2985
|
|
2983
2986
|
i0, s0 = index, []
|
2984
|
-
if has_terminal?('[', false, index)
|
2987
|
+
if (match_len = has_terminal?('[', false, index))
|
2985
2988
|
r1 = true
|
2986
|
-
@index +=
|
2989
|
+
@index += match_len
|
2987
2990
|
else
|
2988
2991
|
terminal_parse_failure('[')
|
2989
2992
|
r1 = nil
|
@@ -2994,9 +2997,9 @@ module Treetop
|
|
2994
2997
|
loop do
|
2995
2998
|
i3, s3 = index, []
|
2996
2999
|
i4 = index
|
2997
|
-
if has_terminal?(']', false, index)
|
3000
|
+
if (match_len = has_terminal?(']', false, index))
|
2998
3001
|
r5 = true
|
2999
|
-
@index +=
|
3002
|
+
@index += match_len
|
3000
3003
|
else
|
3001
3004
|
terminal_parse_failure(']')
|
3002
3005
|
r5 = nil
|
@@ -3011,9 +3014,9 @@ module Treetop
|
|
3011
3014
|
if r4
|
3012
3015
|
i6 = index
|
3013
3016
|
i7, s7 = index, []
|
3014
|
-
if has_terminal?('\\', false, index)
|
3017
|
+
if (match_len = has_terminal?('\\', false, index))
|
3015
3018
|
r8 = true
|
3016
|
-
@index +=
|
3019
|
+
@index += match_len
|
3017
3020
|
else
|
3018
3021
|
terminal_parse_failure('\\')
|
3019
3022
|
r8 = nil
|
@@ -3047,9 +3050,9 @@ module Treetop
|
|
3047
3050
|
else
|
3048
3051
|
i11, s11 = index, []
|
3049
3052
|
i12 = index
|
3050
|
-
if has_terminal?('\\', false, index)
|
3053
|
+
if (match_len = has_terminal?('\\', false, index))
|
3051
3054
|
r13 = true
|
3052
|
-
@index +=
|
3055
|
+
@index += match_len
|
3053
3056
|
else
|
3054
3057
|
terminal_parse_failure('\\')
|
3055
3058
|
r13 = nil
|
@@ -3110,9 +3113,9 @@ module Treetop
|
|
3110
3113
|
end
|
3111
3114
|
s0 << r2
|
3112
3115
|
if r2
|
3113
|
-
if has_terminal?(']', false, index)
|
3116
|
+
if (match_len = has_terminal?(']', false, index))
|
3114
3117
|
r15 = true
|
3115
|
-
@index +=
|
3118
|
+
@index += match_len
|
3116
3119
|
else
|
3117
3120
|
terminal_parse_failure(']')
|
3118
3121
|
r15 = nil
|
@@ -3149,18 +3152,18 @@ module Treetop
|
|
3149
3152
|
end
|
3150
3153
|
|
3151
3154
|
i0, s0 = index, []
|
3152
|
-
if has_terminal?('[:', false, index)
|
3153
|
-
r1 = instantiate_node(SyntaxNode,input, index...(index +
|
3154
|
-
@index +=
|
3155
|
+
if (match_len = has_terminal?('[:', false, index))
|
3156
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
3157
|
+
@index += match_len
|
3155
3158
|
else
|
3156
3159
|
terminal_parse_failure('[:')
|
3157
3160
|
r1 = nil
|
3158
3161
|
end
|
3159
3162
|
s0 << r1
|
3160
3163
|
if r1
|
3161
|
-
if has_terminal?('^', false, index)
|
3164
|
+
if (match_len = has_terminal?('^', false, index))
|
3162
3165
|
r3 = true
|
3163
|
-
@index +=
|
3166
|
+
@index += match_len
|
3164
3167
|
else
|
3165
3168
|
terminal_parse_failure('^')
|
3166
3169
|
r3 = nil
|
@@ -3173,9 +3176,9 @@ module Treetop
|
|
3173
3176
|
s0 << r2
|
3174
3177
|
if r2
|
3175
3178
|
i4 = index
|
3176
|
-
if has_terminal?('alnum', false, index)
|
3177
|
-
r5 = instantiate_node(SyntaxNode,input, index...(index +
|
3178
|
-
@index +=
|
3179
|
+
if (match_len = has_terminal?('alnum', false, index))
|
3180
|
+
r5 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
3181
|
+
@index += match_len
|
3179
3182
|
else
|
3180
3183
|
terminal_parse_failure('alnum')
|
3181
3184
|
r5 = nil
|
@@ -3184,9 +3187,9 @@ module Treetop
|
|
3184
3187
|
r5 = SyntaxNode.new(input, (index-1)...index) if r5 == true
|
3185
3188
|
r4 = r5
|
3186
3189
|
else
|
3187
|
-
if has_terminal?('alpha', false, index)
|
3188
|
-
r6 = instantiate_node(SyntaxNode,input, index...(index +
|
3189
|
-
@index +=
|
3190
|
+
if (match_len = has_terminal?('alpha', false, index))
|
3191
|
+
r6 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
3192
|
+
@index += match_len
|
3190
3193
|
else
|
3191
3194
|
terminal_parse_failure('alpha')
|
3192
3195
|
r6 = nil
|
@@ -3195,9 +3198,9 @@ module Treetop
|
|
3195
3198
|
r6 = SyntaxNode.new(input, (index-1)...index) if r6 == true
|
3196
3199
|
r4 = r6
|
3197
3200
|
else
|
3198
|
-
if has_terminal?('blank', false, index)
|
3199
|
-
r7 = instantiate_node(SyntaxNode,input, index...(index +
|
3200
|
-
@index +=
|
3201
|
+
if (match_len = has_terminal?('blank', false, index))
|
3202
|
+
r7 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
3203
|
+
@index += match_len
|
3201
3204
|
else
|
3202
3205
|
terminal_parse_failure('blank')
|
3203
3206
|
r7 = nil
|
@@ -3206,9 +3209,9 @@ module Treetop
|
|
3206
3209
|
r7 = SyntaxNode.new(input, (index-1)...index) if r7 == true
|
3207
3210
|
r4 = r7
|
3208
3211
|
else
|
3209
|
-
if has_terminal?('cntrl', false, index)
|
3210
|
-
r8 = instantiate_node(SyntaxNode,input, index...(index +
|
3211
|
-
@index +=
|
3212
|
+
if (match_len = has_terminal?('cntrl', false, index))
|
3213
|
+
r8 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
3214
|
+
@index += match_len
|
3212
3215
|
else
|
3213
3216
|
terminal_parse_failure('cntrl')
|
3214
3217
|
r8 = nil
|
@@ -3217,9 +3220,9 @@ module Treetop
|
|
3217
3220
|
r8 = SyntaxNode.new(input, (index-1)...index) if r8 == true
|
3218
3221
|
r4 = r8
|
3219
3222
|
else
|
3220
|
-
if has_terminal?('digit', false, index)
|
3221
|
-
r9 = instantiate_node(SyntaxNode,input, index...(index +
|
3222
|
-
@index +=
|
3223
|
+
if (match_len = has_terminal?('digit', false, index))
|
3224
|
+
r9 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
3225
|
+
@index += match_len
|
3223
3226
|
else
|
3224
3227
|
terminal_parse_failure('digit')
|
3225
3228
|
r9 = nil
|
@@ -3228,9 +3231,9 @@ module Treetop
|
|
3228
3231
|
r9 = SyntaxNode.new(input, (index-1)...index) if r9 == true
|
3229
3232
|
r4 = r9
|
3230
3233
|
else
|
3231
|
-
if has_terminal?('graph', false, index)
|
3232
|
-
r10 = instantiate_node(SyntaxNode,input, index...(index +
|
3233
|
-
@index +=
|
3234
|
+
if (match_len = has_terminal?('graph', false, index))
|
3235
|
+
r10 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
3236
|
+
@index += match_len
|
3234
3237
|
else
|
3235
3238
|
terminal_parse_failure('graph')
|
3236
3239
|
r10 = nil
|
@@ -3239,9 +3242,9 @@ module Treetop
|
|
3239
3242
|
r10 = SyntaxNode.new(input, (index-1)...index) if r10 == true
|
3240
3243
|
r4 = r10
|
3241
3244
|
else
|
3242
|
-
if has_terminal?('lower', false, index)
|
3243
|
-
r11 = instantiate_node(SyntaxNode,input, index...(index +
|
3244
|
-
@index +=
|
3245
|
+
if (match_len = has_terminal?('lower', false, index))
|
3246
|
+
r11 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
3247
|
+
@index += match_len
|
3245
3248
|
else
|
3246
3249
|
terminal_parse_failure('lower')
|
3247
3250
|
r11 = nil
|
@@ -3250,9 +3253,9 @@ module Treetop
|
|
3250
3253
|
r11 = SyntaxNode.new(input, (index-1)...index) if r11 == true
|
3251
3254
|
r4 = r11
|
3252
3255
|
else
|
3253
|
-
if has_terminal?('print', false, index)
|
3254
|
-
r12 = instantiate_node(SyntaxNode,input, index...(index +
|
3255
|
-
@index +=
|
3256
|
+
if (match_len = has_terminal?('print', false, index))
|
3257
|
+
r12 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
3258
|
+
@index += match_len
|
3256
3259
|
else
|
3257
3260
|
terminal_parse_failure('print')
|
3258
3261
|
r12 = nil
|
@@ -3261,9 +3264,9 @@ module Treetop
|
|
3261
3264
|
r12 = SyntaxNode.new(input, (index-1)...index) if r12 == true
|
3262
3265
|
r4 = r12
|
3263
3266
|
else
|
3264
|
-
if has_terminal?('punct', false, index)
|
3265
|
-
r13 = instantiate_node(SyntaxNode,input, index...(index +
|
3266
|
-
@index +=
|
3267
|
+
if (match_len = has_terminal?('punct', false, index))
|
3268
|
+
r13 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
3269
|
+
@index += match_len
|
3267
3270
|
else
|
3268
3271
|
terminal_parse_failure('punct')
|
3269
3272
|
r13 = nil
|
@@ -3272,9 +3275,9 @@ module Treetop
|
|
3272
3275
|
r13 = SyntaxNode.new(input, (index-1)...index) if r13 == true
|
3273
3276
|
r4 = r13
|
3274
3277
|
else
|
3275
|
-
if has_terminal?('space', false, index)
|
3276
|
-
r14 = instantiate_node(SyntaxNode,input, index...(index +
|
3277
|
-
@index +=
|
3278
|
+
if (match_len = has_terminal?('space', false, index))
|
3279
|
+
r14 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
3280
|
+
@index += match_len
|
3278
3281
|
else
|
3279
3282
|
terminal_parse_failure('space')
|
3280
3283
|
r14 = nil
|
@@ -3283,9 +3286,9 @@ module Treetop
|
|
3283
3286
|
r14 = SyntaxNode.new(input, (index-1)...index) if r14 == true
|
3284
3287
|
r4 = r14
|
3285
3288
|
else
|
3286
|
-
if has_terminal?('upper', false, index)
|
3287
|
-
r15 = instantiate_node(SyntaxNode,input, index...(index +
|
3288
|
-
@index +=
|
3289
|
+
if (match_len = has_terminal?('upper', false, index))
|
3290
|
+
r15 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
3291
|
+
@index += match_len
|
3289
3292
|
else
|
3290
3293
|
terminal_parse_failure('upper')
|
3291
3294
|
r15 = nil
|
@@ -3294,9 +3297,9 @@ module Treetop
|
|
3294
3297
|
r15 = SyntaxNode.new(input, (index-1)...index) if r15 == true
|
3295
3298
|
r4 = r15
|
3296
3299
|
else
|
3297
|
-
if has_terminal?('xdigit', false, index)
|
3298
|
-
r16 = instantiate_node(SyntaxNode,input, index...(index +
|
3299
|
-
@index +=
|
3300
|
+
if (match_len = has_terminal?('xdigit', false, index))
|
3301
|
+
r16 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
3302
|
+
@index += match_len
|
3300
3303
|
else
|
3301
3304
|
terminal_parse_failure('xdigit')
|
3302
3305
|
r16 = nil
|
@@ -3305,9 +3308,9 @@ module Treetop
|
|
3305
3308
|
r16 = SyntaxNode.new(input, (index-1)...index) if r16 == true
|
3306
3309
|
r4 = r16
|
3307
3310
|
else
|
3308
|
-
if has_terminal?('word', false, index)
|
3309
|
-
r17 = instantiate_node(SyntaxNode,input, index...(index +
|
3310
|
-
@index +=
|
3311
|
+
if (match_len = has_terminal?('word', false, index))
|
3312
|
+
r17 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
3313
|
+
@index += match_len
|
3311
3314
|
else
|
3312
3315
|
terminal_parse_failure('word')
|
3313
3316
|
r17 = nil
|
@@ -3333,9 +3336,9 @@ module Treetop
|
|
3333
3336
|
end
|
3334
3337
|
s0 << r4
|
3335
3338
|
if r4
|
3336
|
-
if has_terminal?(':]', false, index)
|
3337
|
-
r18 = instantiate_node(SyntaxNode,input, index...(index +
|
3338
|
-
@index +=
|
3339
|
+
if (match_len = has_terminal?(':]', false, index))
|
3340
|
+
r18 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
3341
|
+
@index += match_len
|
3339
3342
|
else
|
3340
3343
|
terminal_parse_failure(':]')
|
3341
3344
|
r18 = nil
|
@@ -3368,9 +3371,9 @@ module Treetop
|
|
3368
3371
|
return cached
|
3369
3372
|
end
|
3370
3373
|
|
3371
|
-
if has_terminal?('.', false, index)
|
3372
|
-
r0 = instantiate_node(AnythingSymbol,input, index...(index +
|
3373
|
-
@index +=
|
3374
|
+
if (match_len = has_terminal?('.', false, index))
|
3375
|
+
r0 = instantiate_node(AnythingSymbol,input, index...(index + match_len))
|
3376
|
+
@index += match_len
|
3374
3377
|
else
|
3375
3378
|
terminal_parse_failure('.')
|
3376
3379
|
r0 = nil
|
@@ -3419,9 +3422,9 @@ module Treetop
|
|
3419
3422
|
r2 = _nt_space
|
3420
3423
|
s1 << r2
|
3421
3424
|
if r2
|
3422
|
-
if has_terminal?('<', false, index)
|
3425
|
+
if (match_len = has_terminal?('<', false, index))
|
3423
3426
|
r3 = true
|
3424
|
-
@index +=
|
3427
|
+
@index += match_len
|
3425
3428
|
else
|
3426
3429
|
terminal_parse_failure('<')
|
3427
3430
|
r3 = nil
|
@@ -3432,9 +3435,9 @@ module Treetop
|
|
3432
3435
|
loop do
|
3433
3436
|
i5, s5 = index, []
|
3434
3437
|
i6 = index
|
3435
|
-
if has_terminal?('>', false, index)
|
3438
|
+
if (match_len = has_terminal?('>', false, index))
|
3436
3439
|
r7 = true
|
3437
|
-
@index +=
|
3440
|
+
@index += match_len
|
3438
3441
|
else
|
3439
3442
|
terminal_parse_failure('>')
|
3440
3443
|
r7 = nil
|
@@ -3477,9 +3480,9 @@ module Treetop
|
|
3477
3480
|
end
|
3478
3481
|
s1 << r4
|
3479
3482
|
if r4
|
3480
|
-
if has_terminal?('>', false, index)
|
3483
|
+
if (match_len = has_terminal?('>', false, index))
|
3481
3484
|
r9 = true
|
3482
|
-
@index +=
|
3485
|
+
@index += match_len
|
3483
3486
|
else
|
3484
3487
|
terminal_parse_failure('>')
|
3485
3488
|
r9 = nil
|
@@ -3500,10 +3503,10 @@ module Treetop
|
|
3500
3503
|
r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
|
3501
3504
|
r0 = r1
|
3502
3505
|
else
|
3503
|
-
if has_terminal?('', false, index)
|
3504
|
-
r10 = instantiate_node(SyntaxNode,input, index...(index +
|
3506
|
+
if (match_len = has_terminal?('', false, index))
|
3507
|
+
r10 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
3505
3508
|
r10.extend(NodeClassExpression3)
|
3506
|
-
@index +=
|
3509
|
+
@index += match_len
|
3507
3510
|
else
|
3508
3511
|
terminal_parse_failure('')
|
3509
3512
|
r10 = nil
|
@@ -3587,10 +3590,10 @@ module Treetop
|
|
3587
3590
|
r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
|
3588
3591
|
r0 = r1
|
3589
3592
|
else
|
3590
|
-
if has_terminal?('', false, index)
|
3591
|
-
r4 = instantiate_node(SyntaxNode,input, index...(index +
|
3593
|
+
if (match_len = has_terminal?('', false, index))
|
3594
|
+
r4 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
3592
3595
|
r4.extend(TrailingInlineModule2)
|
3593
|
-
@index +=
|
3596
|
+
@index += match_len
|
3594
3597
|
else
|
3595
3598
|
terminal_parse_failure('')
|
3596
3599
|
r4 = nil
|
@@ -3627,9 +3630,9 @@ module Treetop
|
|
3627
3630
|
end
|
3628
3631
|
|
3629
3632
|
i0, s0 = index, []
|
3630
|
-
if has_terminal?('', false, index)
|
3633
|
+
if (match_len = has_terminal?('', false, index))
|
3631
3634
|
r1 = true
|
3632
|
-
@index +=
|
3635
|
+
@index += match_len
|
3633
3636
|
else
|
3634
3637
|
terminal_parse_failure('')
|
3635
3638
|
r1 = nil
|
@@ -3670,9 +3673,9 @@ module Treetop
|
|
3670
3673
|
end
|
3671
3674
|
|
3672
3675
|
i0, s0 = index, []
|
3673
|
-
if has_terminal?('{', false, index)
|
3676
|
+
if (match_len = has_terminal?('{', false, index))
|
3674
3677
|
r1 = true
|
3675
|
-
@index +=
|
3678
|
+
@index += match_len
|
3676
3679
|
else
|
3677
3680
|
terminal_parse_failure('{')
|
3678
3681
|
r1 = nil
|
@@ -3689,7 +3692,7 @@ module Treetop
|
|
3689
3692
|
else
|
3690
3693
|
i5, s5 = index, []
|
3691
3694
|
i6 = index
|
3692
|
-
if has_terminal?(@regexps[gr = '\
|
3695
|
+
if has_terminal?(@regexps[gr = '\A[{}]'] ||= Regexp.new(gr), :regexp, index)
|
3693
3696
|
r7 = true
|
3694
3697
|
@index += 1
|
3695
3698
|
else
|
@@ -3736,9 +3739,9 @@ module Treetop
|
|
3736
3739
|
r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
|
3737
3740
|
s0 << r2
|
3738
3741
|
if r2
|
3739
|
-
if has_terminal?('}', false, index)
|
3742
|
+
if (match_len = has_terminal?('}', false, index))
|
3740
3743
|
r9 = true
|
3741
|
-
@index +=
|
3744
|
+
@index += match_len
|
3742
3745
|
else
|
3743
3746
|
terminal_parse_failure('}')
|
3744
3747
|
r9 = nil
|
@@ -3775,9 +3778,9 @@ module Treetop
|
|
3775
3778
|
|
3776
3779
|
i0, s0 = index, []
|
3777
3780
|
i1 = index
|
3778
|
-
if has_terminal?('rule', false, index)
|
3779
|
-
r2 = instantiate_node(SyntaxNode,input, index...(index +
|
3780
|
-
@index +=
|
3781
|
+
if (match_len = has_terminal?('rule', false, index))
|
3782
|
+
r2 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
3783
|
+
@index += match_len
|
3781
3784
|
else
|
3782
3785
|
terminal_parse_failure('rule')
|
3783
3786
|
r2 = nil
|
@@ -3786,9 +3789,9 @@ module Treetop
|
|
3786
3789
|
r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
|
3787
3790
|
r1 = r2
|
3788
3791
|
else
|
3789
|
-
if has_terminal?('end', false, index)
|
3790
|
-
r3 = instantiate_node(SyntaxNode,input, index...(index +
|
3791
|
-
@index +=
|
3792
|
+
if (match_len = has_terminal?('end', false, index))
|
3793
|
+
r3 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
3794
|
+
@index += match_len
|
3792
3795
|
else
|
3793
3796
|
terminal_parse_failure('end')
|
3794
3797
|
r3 = nil
|
@@ -3884,7 +3887,7 @@ module Treetop
|
|
3884
3887
|
return cached
|
3885
3888
|
end
|
3886
3889
|
|
3887
|
-
if has_terminal?(@regexps[gr = '\
|
3890
|
+
if has_terminal?(@regexps[gr = '\A[A-Za-z_]'] ||= Regexp.new(gr), :regexp, index)
|
3888
3891
|
r0 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
3889
3892
|
@index += 1
|
3890
3893
|
else
|
@@ -3913,7 +3916,7 @@ module Treetop
|
|
3913
3916
|
r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
|
3914
3917
|
r0 = r1
|
3915
3918
|
else
|
3916
|
-
if has_terminal?(@regexps[gr = '\
|
3919
|
+
if has_terminal?(@regexps[gr = '\A[0-9]'] ||= Regexp.new(gr), :regexp, index)
|
3917
3920
|
r2 = true
|
3918
3921
|
@index += 1
|
3919
3922
|
else
|
@@ -3997,9 +4000,9 @@ module Treetop
|
|
3997
4000
|
end
|
3998
4001
|
|
3999
4002
|
i0, s0 = index, []
|
4000
|
-
if has_terminal?('#', false, index)
|
4003
|
+
if (match_len = has_terminal?('#', false, index))
|
4001
4004
|
r1 = true
|
4002
|
-
@index +=
|
4005
|
+
@index += match_len
|
4003
4006
|
else
|
4004
4007
|
terminal_parse_failure('#')
|
4005
4008
|
r1 = nil
|
@@ -4010,9 +4013,9 @@ module Treetop
|
|
4010
4013
|
loop do
|
4011
4014
|
i3, s3 = index, []
|
4012
4015
|
i4 = index
|
4013
|
-
if has_terminal?("\n", false, index)
|
4016
|
+
if (match_len = has_terminal?("\n", false, index))
|
4014
4017
|
r5 = true
|
4015
|
-
@index +=
|
4018
|
+
@index += match_len
|
4016
4019
|
else
|
4017
4020
|
terminal_parse_failure("\n")
|
4018
4021
|
r5 = nil
|
@@ -4074,7 +4077,7 @@ module Treetop
|
|
4074
4077
|
return cached
|
4075
4078
|
end
|
4076
4079
|
|
4077
|
-
if has_terminal?(@regexps[gr = '\
|
4080
|
+
if has_terminal?(@regexps[gr = '\A[ \\t\\n\\r]'] ||= Regexp.new(gr), :regexp, index)
|
4078
4081
|
r0 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
4079
4082
|
@index += 1
|
4080
4083
|
else
|
@@ -389,7 +389,7 @@ module Treetop
|
|
389
389
|
end
|
390
390
|
|
391
391
|
rule quoted_string
|
392
|
-
qs:(single_quoted_string / double_quoted_string)
|
392
|
+
qs:(single_quoted_string / double_quoted_string) modifiers:([ir]*) <Terminal> {
|
393
393
|
def string
|
394
394
|
qs.text_value
|
395
395
|
end
|
@@ -11,17 +11,17 @@ module Treetop
|
|
11
11
|
else
|
12
12
|
assign_lazily_instantiated_node
|
13
13
|
end
|
14
|
-
builder << "@index += 1"
|
14
|
+
builder << "@index += 1" # Always one character
|
15
15
|
end
|
16
16
|
builder.else_ do
|
17
|
-
|
17
|
+
builder << "terminal_parse_failure(#{single_quote('['+characters+']')})"
|
18
18
|
assign_result 'nil'
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
def grounded_regexp(string)
|
23
23
|
# Double any backslashes, then backslash any single-quotes:
|
24
|
-
"'\\
|
24
|
+
"'\\A#{string.gsub(/\\/) { '\\\\' }.gsub(/'/) { "\\'"}}'"
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -3,21 +3,36 @@ module Treetop
|
|
3
3
|
class Terminal < AtomicExpression
|
4
4
|
def compile(address, builder, parent_expression = nil)
|
5
5
|
super
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
# Handle modifiers:
|
7
|
+
insensitive = modifiers.text_value.include? 'i'
|
8
|
+
re = modifiers.text_value.include? 'r'
|
9
|
+
if re
|
10
|
+
grounded_regexp = "#{('\A'+eval(string)).inspect}"
|
11
|
+
cache_key = "'__#{modifiers.text_value}__'+(gr = #{grounded_regexp})"
|
12
|
+
re_modifiers = "#{insensitive ? 'Regexp::IGNORECASE' : 0}"
|
13
|
+
str = "@regexps[#{cache_key}] ||= Regexp.new(gr, #{re_modifiers})"
|
14
|
+
mode = ':regexp'
|
15
|
+
elsif insensitive
|
16
|
+
str = string.downcase
|
17
|
+
string_length = eval(str).length
|
18
|
+
mode = ':insens'
|
19
|
+
else
|
20
|
+
str = string
|
21
|
+
string_length = eval(str).length
|
22
|
+
mode = 'false'
|
23
|
+
end
|
9
24
|
|
10
|
-
builder.if__ "has_terminal?(#{str}, #{
|
11
|
-
if address == 0 || decorated? || string_length > 1
|
12
|
-
assign_result "instantiate_node(#{node_class_name},input, index...(index +
|
25
|
+
builder.if__ "(match_len = has_terminal?(#{str}, #{mode}, index))" do
|
26
|
+
if address == 0 || decorated? || mode != 'false' || string_length > 1
|
27
|
+
assign_result "instantiate_node(#{node_class_name},input, index...(index + match_len))"
|
13
28
|
extend_result_with_inline_module
|
14
29
|
else
|
15
30
|
assign_lazily_instantiated_node
|
16
31
|
end
|
17
|
-
builder << "@index +=
|
32
|
+
builder << "@index += match_len"
|
18
33
|
end
|
19
34
|
builder.else_ do
|
20
|
-
builder << "terminal_parse_failure(#{
|
35
|
+
builder << "terminal_parse_failure(#{string})"
|
21
36
|
assign_result 'nil'
|
22
37
|
end
|
23
38
|
end
|
@@ -94,15 +94,15 @@ module Treetop
|
|
94
94
|
|
95
95
|
def has_terminal?(terminal, mode, index)
|
96
96
|
case mode
|
97
|
-
when :regexp # A Regexp has been passed in,
|
98
|
-
|
97
|
+
when :regexp # A Regexp has been passed in, either a character class or a literel regex 'foo'r
|
98
|
+
(terminal =~ input[index..-1]) == 0 && $&.length
|
99
99
|
when false # The terminal is a string which must match exactly
|
100
|
-
input[index, terminal.size] == terminal
|
100
|
+
input[index, terminal.size] == terminal && terminal.size
|
101
101
|
when :insens # The terminal is a downcased string which must match input downcased
|
102
|
-
input[index, terminal.size].downcase == terminal
|
102
|
+
input[index, terminal.size].downcase == terminal && terminal.size
|
103
103
|
when true # Only occurs with old compiled grammars, for character classes
|
104
104
|
rx = @regexps[terminal] ||= Regexp.new(terminal)
|
105
|
-
input.index(rx, index) == index
|
105
|
+
input.index(rx, index) == index && $&.length
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
data/lib/treetop/version.rb
CHANGED
@@ -112,14 +112,59 @@ module TerminalSymbolSpec
|
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
|
-
describe "a
|
116
|
-
testing_expression "
|
117
|
-
|
118
|
-
it "
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
115
|
+
describe "a terminal regexp" do
|
116
|
+
testing_expression "'Fo+'r"
|
117
|
+
|
118
|
+
it "matches the input string" do
|
119
|
+
parse "Fooo", :index => 0 do |result|
|
120
|
+
result.should_not be_nil
|
121
|
+
result.interval.should == (0...4)
|
122
|
+
result.text_value.should == 'Fooo'
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
it "fails to match the input string other than at the start" do
|
127
|
+
parse " Foo", :index => 0 do |result|
|
128
|
+
result.should be_nil
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
it "fails to match the input string in the wrong case" do
|
133
|
+
parse "foo", :index => 0 do |result|
|
134
|
+
result.should be_nil
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe "a case-insensitive terminal regexp" do
|
140
|
+
testing_expression "'Fo+'ri"
|
141
|
+
|
142
|
+
it "matches the input string in the same case" do
|
143
|
+
parse "Fooo", :index => 0 do |result|
|
144
|
+
result.should_not be_nil
|
145
|
+
result.interval.should == (0...4)
|
146
|
+
result.text_value.should == 'Fooo'
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
it "matches the input string in the same case" do
|
151
|
+
parse "foOo", :index => 0 do |result|
|
152
|
+
result.should_not be_nil
|
153
|
+
result.interval.should == (0...4)
|
154
|
+
result.text_value.should == 'foOo'
|
155
|
+
end
|
123
156
|
end
|
124
157
|
end
|
158
|
+
|
159
|
+
# Transient symbols were part of some idea of Nathan's that I no longer recall
|
160
|
+
# describe "a transient terminal symbol" do
|
161
|
+
# testing_expression "~'foo'"
|
162
|
+
#
|
163
|
+
# it "returns true upon parsing matching input prefixes at various indices" do
|
164
|
+
# pending "transient terminal expressions"
|
165
|
+
# parse("foo", :index => 0).should be_true
|
166
|
+
# parse("-foo", :index => 1).should be_true
|
167
|
+
# parse("---foo", :index => 3).should be_true
|
168
|
+
# end
|
169
|
+
# end
|
125
170
|
end
|
data/treetop.gemspec
CHANGED
@@ -2,17 +2,17 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: treetop 1.5.
|
5
|
+
# stub: treetop 1.5.3 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "treetop"
|
9
|
-
s.version = "1.5.
|
9
|
+
s.version = "1.5.3"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Nathan Sobo", "Clifford Heath"]
|
14
14
|
s.autorequire = "treetop"
|
15
|
-
s.date = "2014-03-
|
15
|
+
s.date = "2014-03-21"
|
16
16
|
s.email = "cliffordheath@gmail.com"
|
17
17
|
s.executables = ["tt"]
|
18
18
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: treetop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Sobo
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire: treetop
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-03-
|
12
|
+
date: 2014-03-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: polyglot
|