This repository was archived by the owner on Nov 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathepeg.lua
More file actions
5090 lines (4929 loc) · 104 KB
/
epeg.lua
File metadata and controls
5090 lines (4929 loc) · 104 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--[[
Copyright 2008 Victor Camps
This file is part of epeg.
Epeg is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Epeg is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
]]
--------------------------------------------------------------------------------
-- --
-- Plumbing --
-- --
--------------------------------------------------------------------------------
epeg = {}
epeg_proxy = {}
-- If we don't use a function to check against invalid function names,
-- lua will just stop without any notice which is hard to track.
function epeg_proxy.__index(table, key)
if epeg[key] == nil then error("Called unknown function "..key..".\n") end
return epeg[key]
end
--------------------------------------------------------------------------------
-- --
-- Mainfunctions --
-- --
--------------------------------------------------------------------------------
-- Reads a grammar from file filename and returns it.
-- If unsuccessful, it returns false and prints errors to stdout.
-- It is possible that it prints other informations to stdout.
function epeg.read_grammar(filename)
local file, input, error
file, error = io.open(filename, 'r')
if file == nil then
io.write("Error: could not open ", filename, ".\nReason: ", error)
return false
end
input = file:read('*a')
file:close()
if input == nil then
io.write("Error: Could not read out of file or file is empty.")
return false
end
local result
-- Get ast from epeg.
result = epeg.parse_text(epeg.grammar, input)
if not result then return false end
-- Refine ast to grammar.
local r = result[1].name.string
local grammar = { [0] = r }
local ok = grammar
for i,v in ipairs(result) do
if grammar[v.name.string] then
io.write("Error: Rule ", v.name.string, " redeclared at ", v.row, ":", v.column, ".\n")
if not type(grammar[v.name.string]) == "bool" then
io.write("Error: Original declaration at ", grammar[v.name.string].row, ":", grammar[v.name.string].column, ".\n")
else
grammar[v.name.string] = false
end
ok = false
else
grammar[v.name.string] = v
end
end
if ok and not epeg.check(grammar) then ok = false end
return ok
end
-- Parses a given text using the grammar and returns the specified ast
-- for the grammar.
function epeg.parse_text(grammar, text)
local topnode = {
["position"] = 1,
["column"] = 0,
["row"] = 1,
["string"] = ""
}
local parser = {
["position"] = 1,
["column"] = 0,
["row"] = 1,
["to_parse"] = text,
["grammar"] = grammar,
["grabs"] = 0,
["anchor"] = {},
["topnode"] = topnode,
}
setmetatable(parser, epeg_proxy)
parsing = coroutine.create(epeg.run_rule)
if not coroutine.resume(parsing, parser, grammar[grammar[0]], topnode) then
return false
end
return topnode
end
-- Dumps the given grammar as a lua table to file 'filename'. If filename is
-- nil, stdout is used.
-- if name is nil, it writes return { ... instead of tablename = {
-- returns true if success, else error string.
-- works only correct on grammars.
--
-- Note: is a specialized function to dump noncyclic tables.
function epeg.dump_grammar(grammar, name, filename)
local file, err
if not filename then
file = io.stdout
else
file, err = io.open(filename, "w")
if not file then return err end
end
if type(name) ~= "string" then
file:write("return {\n")
else
file:write(name, " = {\n")
end
epeg.dump_table(grammar, file, 1)
file:write("}\n")
return true
end
--------------------------------------------------------------------------------
-- --
-- Parsing --
-- --
--------------------------------------------------------------------------------
-- Returns the string which matches with the regex. The search start at the
-- actual position in the input stream. if walk is NOT set, the position will
-- be updated after a successfull match
-- If plain is set to true, the regex is a normal string.
-- returns false if the regex was not found.
function epeg:read_next(regex, walk, plain)
local start, length, char, row, column, position, to_parse
position = self.position
row = self.row
column = self.column
to_parse = self.to_parse
start, stop = string.find(to_parse, regex, position, plain)
if start == nil then
return false
end
if start ~= position then
io.write("Note: Regex ", regex,
" does not match against the actual position. (position=",
position,", row=", row, ", column=", column,
")\n")
end
-- update row/column/position
if walk ~= false then
for i = position, stop do
char = string.sub(to_parse, position, position)
if char == '\n' then
row = row + 1
column = 0
-- tabs count as 4 whitespaces
elseif char == '\t' then
column = column + 4
else
column = column + 1
end
position = position + 1
end
self.position = position
self.row = row
self.column = column
end
return string.sub(to_parse, start, stop)
end
-- Workhorse for transforming text to an ast with help of a grammar.
-- Both used by read_grammar and parse_text.
function epeg.run_rule(parser, rule, node, parent)
local position = parser.position
local row = parser.row
local column = parser.column
local string_old_length = #(node.string)
local string_old = node.string
local newnode = {
["position"] = position,
["column"] = column,
["row"] = row,
["string"] = "",
["parent"] = node
}
local result = false
if rule.type.string == "Rule" then
result = epeg.run_rule(parser, rule.rule, node)
return result
elseif rule.type.string == "Choice" then
-- Only one list out of the selection has to match successfull.
for rulename, subrule in ipairs(rule) do
if epeg.run_rule(parser, subrule, node) then
return true
end
end
-- Failed. Resetting the parser gets handled at the end of the function.
elseif rule.type.string == "List" then
-- Every pattern in the list needs to succeed. If not, we have to
-- reset the tree and parser to the state before we went through
-- the list.
-- To reset the tree, we use parser.anchor to store a reference to all
-- newly created child nodes. If the rule fails, we can use this list to
-- remove the newly added childs from our actual node.
-- The parser gets reset at the end of the function.
local oldanchor = parser.anchor
local anchor = {}
parser.anchor = anchor
local worked = true
for rulename, subrule in ipairs(rule) do
if not epeg.run_rule(parser, subrule, node) then
worked = false
break
end
end
parser.anchor = oldanchor
if worked then return true end
-- the rule failed and we have to remove every created child node from
-- our node to clean the mess up.
for i,v in ipairs(anchor) do
if v ~= -1 then
node[v] = nil
end
end
anchor = nil
elseif rule.type.string == "RuleName" then
return epeg.run_rule(parser, parser.grammar[rule.name.string], node)
elseif rule.type.string == "AnonymousFixedNode" then
newnode.string = rule.grabs.string
table.insert(node, newnode)
table.insert(parser.anchor, #node)
newnode.pindex = #node
return true
elseif rule.type.string == "AnonymousGrabbingNode" then
table.insert(node, newnode)
newnode.pindex = #node
table.insert(parser.anchor, #node)
if not epeg.run_rule(parser, rule.grabs, newnode) then
table.remove(node)
parser.anchor[#parser.anchor] = -1
return false
end
newnode.string = epeg.unescape_string(newnode.string)
return true
elseif rule.type.string == "FixedNode" then
if node[rule.name.string] then
epeg.print_table(node)
epeg.print_table(rule)
parser:error("Tried to add second node with same name ("..rule.name.string..") to parent node.")
end
node[rule.name.string] = newnode
newnode.pindex = rule.name.string
newnode.string = rule.grabs.string
table.insert(parser.anchor, rule.name.string)
return true
elseif rule.type.string == "GrabbingNode" then
if node[rule.name.string] then
epeg.print_table(node)
epeg.print_table(rule)
parser:error("Tried to add second node with same name ("..rule.name.string..") to parent node.")
end
node[rule.name.string] = newnode
newnode.pindex = rule.name.string
table.insert(parser.anchor, rule.name.string)
if not epeg.run_rule(parser, rule.grabs, newnode) then
node[rule.name.string] = nil
parser.anchor[#parser.anchor] = -1
return false
end
newnode.string = epeg.unescape_string(newnode.string)
return true
elseif rule.type.string == "CollectInput" then
parser.grabs = parser.grabs + 1
result = epeg.run_rule(parser, rule.grabs, node)
parser.grabs = parser.grabs - 1
return result
elseif rule.type.string == "FunctionCall" then
result = _G[rule["function"]["string"]](parser, node)
if parent and parent.type.string == "Pattern" and parent.prefix then
if parent.prefix.string == "!" then return not result
else return result end
end
return true
elseif rule.type.string == "Pattern" then
local repetition = ""
local prefix = ""
if rule.errorhandling and rule.errorhandling.type.string == "Warning" then
io.write("Warning (row="..parser.row..", column="..parser.column.."): "..rule.errorhandling.message.string)
end
if rule.prefix then prefix = rule.prefix.string end
if rule.repetition then repetition = rule.repetition.string end
-- First check for simple rules (string, dot and class), because we can
-- use regular expressions to match them.
if rule.pattern.type.string == "String" then
if not rule.pattern.is_escaped then
rule.pattern.value.string = string.gsub(rule.pattern.value.string, "[%$%^%(%)%%%.%[%]%*%+%-%?]", "%%%0")
rule.pattern.is_escaped = true
end
result = parser:read_next("^"..rule.pattern.value.string..repetition)
if parser.grabs ~= 0 and result then node.string = node.string..result end
elseif rule.pattern.type.string == "Dot" then
result = parser:read_next("^".."."..repetition)
if parser.grabs ~= 0 and result then node.string = node.string..result end
elseif rule.pattern.type.string == "Class" then
result = parser:read_next("^".."["..rule.pattern.value.string.."]"..repetition)
if parser.grabs ~= 0 and result then node.string = node.string..result end
else
-- Otherwise we handle the complex rules:
if repetition == "*" then
while epeg.run_rule(parser, rule.pattern, node, rule) do end
result = true
elseif repetition == "?" then
epeg.run_rule(parser, rule.pattern, node, rule)
result = true
elseif repetition == "+" then
result = epeg.run_rule(parser, rule.pattern, node, rule)
while epeg.run_rule(parser, rule.pattern, node, rule) do end
else
result = epeg.run_rule(parser, rule.pattern, node, rule)
end
end
if rule.prefix and rule.prefix.string == "!" then result = not result end
if result and not rule.prefix then return true end
if not result and rule.errorhandling and rule.errorhandling.type.string == "Error" then
parser:error(rule.errorhandling.message.string)
end
else
parser:error("Epeg construct "..tostring(rule.type.string).." not implemented or unknown.")
end
-- Reset parser to position before we processed the rule.
-- (used by !, & and if the rule failed)
-- If the rule failed, we have to reset the grabbed input, too.
if parser.grabs ~= 0 and #(node.string) ~= string_old_length and not result then
node.string = string_old
end
parser.row = row
parser.column = column
parser.position = position
return result
end
-- Finishes the coroutine with an errormessage and returns false.
function epeg:error(text)
io.write("Error (row=", tostring(self.row),
", column=", tostring(self.column),
"): ", tostring(text), ".\n")
yield(false)
end
--------------------------------------------------------------------------------
-- --
-- Validation of Grammar --
-- --
--------------------------------------------------------------------------------
-- Checks grammar against infinite left recursion.
-- returns true if no error, else false.
-- Prints its status to stdout.
function epeg.check(grammar)
local ok = true
local top = grammar[0]
io.write("Checking...\n")
-- check against possible infinite left recursion. Algorithm taken from
-- peg/leg by Ian Piumarta.
-- See: http://piumarta.com/software/peg/ for more information.
for i,v in pairs(grammar) do
if i ~= 0 then
epeg.consumesInput(v, grammar)
end
end
for i,v in pairs(grammar) do
if i ~= 0 then
if v.is_marked_lr then ok = false end
end
end
if ok then
io.write("... Success\n")
end
return ok
end
function epeg.consumesInput(node, grammar)
if node == nil then return false end
if node.type.string == "Rule" then
local result = false
if node.reached ~= nil then
if node.is_marked_lr == nil then
io.write("Possible endless left recursion in ", node.name.string, ".\n")
node.is_marked_lr = true
end
else
node.reached = true
result = epeg.consumesInput(node.rule, grammar)
node.reached = nil
end
return result
elseif node.type.string == "Choice" then
for i,v in ipairs(node) do
if not epeg.consumesInput(v, grammar) then return false end
end
return true
elseif node.type.string == "List" then
for i,v in ipairs(node) do
if epeg.consumesInput(v, grammar) then return true end
end
return false
elseif node.type.string == "RuleName" then
return epeg.consumesInput(grammar[node.name.string], grammar)
elseif node.type.string == "AnonymousFixedNode" then
return false
elseif node.type.string == "AnonymousGrabbingNode" then
return epeg.consumesInput(node.grabs, grammar)
elseif node.type.string == "FixedNode" then
return false
elseif node.type.string == "GrabbingNode" then
return epeg.consumesInput(node.grabs, grammar)
elseif node.type.string == "CollectInput" then
return epeg.consumesInput(node.grabs, grammar)
elseif node.type.string == "Error" then
return false
elseif node.type.string == "Warning" then
return false
elseif node.type.string == "Resume" then
return false
elseif node.type.string == "FunctionCall" then
return false
elseif node.type.string == "EmbeddedCode" then
return false
elseif node.type.string == "String" then
if node.value.string == "" then return false end
return true
elseif node.type.string == "Class" then
if node.value.string == "" then return false end
return true
elseif node.type.string == "Dot" then
return true
elseif node.type.string == "Pattern" then
-- The pattern does not need to consume input if it uses ? or *.
if node.repetition and
(node.repetition.string == "*" or
node.repetition.string == "?") then
return false
end
return epeg.consumesInput(node.pattern, grammar)
else
io.write("Error: Unknown epeg construct: ", tostring(node.type.string), ".\n")
return false
end
end
--------------------------------------------------------------------------------
-- --
-- Dumping --
-- --
--------------------------------------------------------------------------------
-- Dumps a table and its child tables into the specified file.
-- Does not work with cyclic tables (endless recursion).
function epeg.dump_table(table, file, depth)
local tabs = string.rep("\t", depth)
for i,v in pairs(table) do
if i ~= "position" and i ~= "column" and i ~= "row" and
i ~= "pindex" and i ~= "parent" then
if type(i) == "string" then
file:write(tabs, "[\"", i, "\"] = ")
else
file:write(tabs, "[", tostring(i), "] = ")
end
if type(v) == "table" then
file:write("{\n")
epeg.dump_table(v, file, depth + 1)
file:write(tabs, "},\n")
else
if type(v) == "string" then
file:write("\"", epeg.escape_string(v), "\",\n")
else
file:write(tostring(v), ",\n")
end
end
end
end
end
--------------------------------------------------------------------------------
-- --
-- Debugging --
-- --
--------------------------------------------------------------------------------
-- Prints a noncyclic table to stdout. Cyclic tables cause
-- infinite rekursion (DONT USE ON GRAMMARS OR ASTS!).
function epeg.print_table(tab, depth)
if not (type(tab) == "table") then print ("failure"); return end
if depth == nil then depth = 0 end
local tabs = string.rep("\t", depth)
for i,v in pairs(tab) do
if type(v) ~= "table" then
io.write(tabs, tostring(i), ": ", tostring(v), "\n")
end
end
for i,v in pairs(tab) do
if type(v) == "table" then
io.write(tabs, tostring(i), ": (table)\n")
epeg.print_table(v, depth + 1)
end
end
end
-- Prints a grammar translated back as epeg to stdout.
-- warning: old
function epeg.grammar2epeg(grammar)
for i,v in pairs(grammar) do
io.write("\n", i, " <- ")
epeg.translate_node(v.rule)
io.write('\n')
end
end
-- warning: old
function epeg.translate_node(node)
if node.type.string == "Choice" then
for i,v in ipairs(node) do
epeg.translate_node(v)
if node.list[i + 1] ~= nil then io.write('/ ') end
end
elseif node.type.string == "List" then
for i,v in ipairs(node) do
epeg.translate_node(v)
end
elseif node.type.string == "RuleName" then
io.write(node.name.string, " ")
elseif node.type.string == "AnonymousFixedNode" then
io.write("<:: ")
epeg.translate_node(node.grabs)
io.write(">")
elseif node.type.string == "AnonymousGrabbingNode" then
io.write("<: ")
epeg.translate_node(node.grabs)
io.write(">")
elseif node.type.string == "FixedNode" then
io.write("<", node.name.string, ":: ")
epeg.translate_node(node.grabs)
io.write(">")
elseif node.type.string == "GrabbingNode" then
io.write("<", node.name.string, ": ")
epeg.translate_node(node.grabs)
io.write(">")
elseif node.type.string == "CollectInput" then
io.write("< ")
epeg.translate_node(node.grabs)
io.write(" >")
elseif node.type.string == "Error" then
io.write(" error (")
epeg.translate_node(node.message)
io.write(") ")
if node.recover then
io.write("recover (")
epeg.translate_node(node.recover)
io.write(") ")
end
elseif node.type.string == "Warning" then
io.write("warning (")
epeg.translate_node(node.message)
io.write(") ")
elseif node.type.string == "Resume" then
io.write("resume ")
elseif node.type.string == "FunctionCall" then
io.write("{: ", node.name.string, " } ")
elseif node.type.string == "EmbeddedCode" then
io.write("{", node.code, "} ")
elseif node.type.string == "String" then
io.write("\"", node.value.string, "\" ")
elseif node.type.string == "Class" then
io.write("[", node.value.string, "] ")
elseif node.type.string == "Dot" then
io.write(".")
elseif node.type.string == "Pattern" then
if node.prefix then io.write(node.prefix.string) end
if node.pattern.type.string == "Choice" then
io.write("(")
epeg.translate_node(node.pattern)
io.write(")")
else
epeg.translate_node(node.pattern)
end
if node.repetition then
io.write(node.repetition.string)
end
if node.errorhandling then
epeg.translate_node(node.errorhandling)
end
else
io.write("\n***ERROR***:", node.type.string, " \n")
end
end
--------------------------------------------------------------------------------
-- --
-- Escaping/Unescaping --
-- --
--------------------------------------------------------------------------------
epeg.esc_table = {
["\a"] = '\\a',
["\b"] = '\\b',
["\f"] = '\\f',
["\n"] = "\\n",
["\r"] = "\\r",
["\t"] = '\\t',
["\v"] = '\\v',
["\""] = '\\\"',
["\'"] = '\\\'',
["["] = '\\[',
["]"] = '\\]',
["\\"] = '\\\\',
}
epeg.unesc_table = {
["\\a"] = '\a',
["\\b"] = '\b',
["\\f"] = '\f',
["\\n"] = '\n',
["\\r"] = '\r',
["\\t"] = '\t',
["\\v"] = '\v',
['\\"'] = '\"',
["\\'"] = "\'",
["\\["] = '[',
["\\]"] = ']',
["\\\\"] = '\\',
}
function epeg.unescape_string(str)
local result = {}
local pos = 1
local oldpos = 1
local echar, tesc
result = string.gsub(str, "\\.", epeg.unesc_table)
return result
end
function epeg.escape_string(str)
local result
result = string.gsub(str, "[]\\\a\b\f\n\r\t\v\"\'[]", epeg.esc_table)
return result
end
--------------------------------------------------------------------------------
-- --
-- Grammar --
-- --
--------------------------------------------------------------------------------
epeg.grammar = {
[0] = "Grammar",
["Pattern"] = {
["string"] = "",
["name"] = {
["string"] = "Pattern",
},
["rule"] = {
["string"] = "",
[1] = {
[1] = {
["string"] = "",
["name"] = {
["string"] = "type",
},
["grabs"] = {
["string"] = "Pattern",
},
["type"] = {
["string"] = "FixedNode",
},
},
[2] = {
["string"] = "",
["pattern"] = {
[1] = {
[1] = {
["string"] = "",
["pattern"] = {
[1] = {
["string"] = "",
[2] = {
["string"] = "",
["name"] = {
["string"] = "prefix",
},
["grabs"] = {
["string"] = "&",
},
["type"] = {
["string"] = "FixedNode",
},
},
[1] = {
["string"] = "",
["pattern"] = {
["string"] = "",
["name"] = {
["string"] = "and",
},
["type"] = {
["string"] = "RuleName",
},
},
["type"] = {
["string"] = "Pattern",
},
},
["type"] = {
["string"] = "List",
},
},
[2] = {
["string"] = "",
[2] = {
["string"] = "",
["name"] = {
["string"] = "prefix",
},
["grabs"] = {
["string"] = "!",
},
["type"] = {
["string"] = "FixedNode",
},
},
[1] = {
["string"] = "",
["pattern"] = {
["string"] = "",
["name"] = {
["string"] = "not",
},
["type"] = {
["string"] = "RuleName",
},
},
["type"] = {
["string"] = "Pattern",
},
},
["type"] = {
["string"] = "List",
},
},
["type"] = {
["string"] = "Choice",
},
["string"] = "",
},
["type"] = {
["string"] = "Pattern",
},
},
[2] = {
["string"] = "",
["name"] = {
["string"] = "pattern",
},
["grabs"] = {
["string"] = "",
[1] = {
["string"] = "",
["pattern"] = {
[1] = {
["string"] = "",
[1] = {
["string"] = "",
["pattern"] = {
["string"] = "",
["name"] = {
["string"] = "FunctionCall",
},
["type"] = {
["string"] = "RuleName",
},
},
["type"] = {
["string"] = "Pattern",
},
},
["type"] = {
["string"] = "List",
},
},
[2] = {
["string"] = "",
[2] = {
["string"] = "",
["name"] = {
["string"] = "type",
},
["grabs"] = {
["string"] = "Dot",
},
["type"] = {
["string"] = "FixedNode",
},
},
[1] = {
["string"] = "",
["pattern"] = {
["string"] = "",
["name"] = {
["string"] = "dot",
},
["type"] = {
["string"] = "RuleName",
},
},
["type"] = {
["string"] = "Pattern",
},
},
["type"] = {
["string"] = "List",
},
},
[3] = {
["string"] = "",
[2] = {
["string"] = "",
["name"] = {
["string"] = "type",
},
["grabs"] = {
["string"] = "RuleName",
},
["type"] = {
["string"] = "FixedNode",
},
},
[1] = {
["string"] = "",
["name"] = {
["string"] = "name",
},
["grabs"] = {
["string"] = "",
[1] = {
["string"] = "",
["pattern"] = {
["string"] = "",
["name"] = {
["string"] = "Identifier",
},
["type"] = {
["string"] = "RuleName",
},
},
["type"] = {
["string"] = "Pattern",
},
},
["type"] = {
["string"] = "List",