-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.d
1777 lines (1744 loc) · 66 KB
/
bootstrap.d
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
// bootstrap.d
//
// Copyright Peter Williams 2013 <[email protected]>.
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
import std.regex;
import std.string;
import std.conv;
import ddlib.templates;
mixin DDParserSupport;
alias ushort DDSymbol;
enum DDHandle : DDSymbol {
ddEND = 1,
ddINVALID_TOKEN = 2,
REGEX = 4,
LITERAL = 5,
TOKEN = 6,
FIELD = 7,
LEFT = 8,
RIGHT = 9,
NONASSOC = 10,
PRECEDENCE = 11,
SKIP = 12,
ERROR = 13,
INJECT = 14,
NEWSECTION = 15,
COLON = 16,
VBAR = 17,
DOT = 18,
IDENT = 19,
FIELDNAME = 20,
PREDICATE = 21,
ACTION = 22,
DCODE = 23,
}
string dd_literal_token_string(DDHandle dd_token)
{
with (DDHandle) switch (dd_token) {
case TOKEN: return "%token"; break;
case FIELD: return "%field"; break;
case LEFT: return "%left"; break;
case RIGHT: return "%right"; break;
case NONASSOC: return "%nonassoc"; break;
case PRECEDENCE: return "%prec"; break;
case SKIP: return "%skip"; break;
case ERROR: return "%error"; break;
case INJECT: return "%inject"; break;
case NEWSECTION: return "%%"; break;
case COLON: return ":"; break;
case VBAR: return "|"; break;
case DOT: return "."; break;
default:
}
return null;
}
enum DDNonTerminal : DDSymbol {
ddSTART = 0,
ddERROR = 3,
specification = 24,
preamble = 25,
definitions = 26,
production_rules = 27,
coda = 28,
oinjection = 29,
injection = 30,
injection_head = 31,
field_definitions = 32,
token_definitions = 33,
skip_definitions = 34,
precedence_definitions = 35,
field_definition = 36,
field_type = 37,
field_name = 38,
field_conversion_function = 39,
token_definition = 40,
new_token_name = 41,
pattern = 42,
skip_definition = 43,
precedence_definition = 44,
tag_list = 45,
tag = 46,
production_group = 47,
production_group_head = 48,
production_tail_list = 49,
production_tail = 50,
action = 51,
predicate = 52,
symbol_list = 53,
tagged_precedence = 54,
symbol = 55,
}
static DDLexicalAnalyser dd_lexical_analyser;
static this() {
static auto dd_lit_lexemes = [
DDLiteralLexeme(DDHandle.TOKEN, "%token"),
DDLiteralLexeme(DDHandle.FIELD, "%field"),
DDLiteralLexeme(DDHandle.LEFT, "%left"),
DDLiteralLexeme(DDHandle.RIGHT, "%right"),
DDLiteralLexeme(DDHandle.NONASSOC, "%nonassoc"),
DDLiteralLexeme(DDHandle.PRECEDENCE, "%prec"),
DDLiteralLexeme(DDHandle.SKIP, "%skip"),
DDLiteralLexeme(DDHandle.ERROR, "%error"),
DDLiteralLexeme(DDHandle.INJECT, "%inject"),
DDLiteralLexeme(DDHandle.NEWSECTION, "%%"),
DDLiteralLexeme(DDHandle.COLON, ":"),
DDLiteralLexeme(DDHandle.VBAR, "|"),
DDLiteralLexeme(DDHandle.DOT, "."),
];
static auto dd_regex_lexemes = [
DDRegexLexeme!(DDHandle.REGEX, `(\(.+\)(?=\s))`),
DDRegexLexeme!(DDHandle.LITERAL, `("(\\"|[^"\t\r\n\v\f])*")`),
DDRegexLexeme!(DDHandle.IDENT, `([a-zA-Z]+[a-zA-Z0-9_]*)`),
DDRegexLexeme!(DDHandle.FIELDNAME, `(<[a-zA-Z]+[a-zA-Z0-9_]*>)`),
DDRegexLexeme!(DDHandle.PREDICATE, `(\?\((.|[\n\r])*?\?\))`),
DDRegexLexeme!(DDHandle.ACTION, `(!\{(.|[\n\r])*?!\})`),
DDRegexLexeme!(DDHandle.DCODE, `(%\{(.|[\n\r])*?%\})`),
];
static auto dd_skip_rules = [
regex(`^(/\*(.|[\n\r])*?\*/)`),
regex(`^(//[^\n\r]*)`),
regex(`^(\s+)`),
];
dd_lexical_analyser = new DDLexicalAnalyser(dd_lit_lexemes, dd_regex_lexemes, dd_skip_rules);
}
alias uint DDProduction;
DDProductionData dd_get_production_data(DDProduction dd_production)
{
with (DDNonTerminal) switch(dd_production) {
case 0: return DDProductionData(ddSTART, 1);
case 1: return DDProductionData(specification, 5);
case 2: return DDProductionData(oinjection, 0);
case 3: return DDProductionData(oinjection, 1);
case 4: return DDProductionData(injection_head, 2);
case 5: return DDProductionData(injection, 2);
case 6: return DDProductionData(preamble, 0);
case 7: return DDProductionData(preamble, 3);
case 8: return DDProductionData(preamble, 5);
case 9: return DDProductionData(coda, 0);
case 10: return DDProductionData(coda, 2);
case 11: return DDProductionData(definitions, 4);
case 12: return DDProductionData(field_definitions, 0);
case 13: return DDProductionData(field_definitions, 4);
case 14: return DDProductionData(field_definition, 3);
case 15: return DDProductionData(field_definition, 4);
case 16: return DDProductionData(field_type, 1);
case 17: return DDProductionData(field_type, 1);
case 18: return DDProductionData(field_name, 1);
case 19: return DDProductionData(field_name, 1);
case 20: return DDProductionData(field_conversion_function, 1);
case 21: return DDProductionData(field_conversion_function, 1);
case 22: return DDProductionData(token_definitions, 2);
case 23: return DDProductionData(token_definitions, 4);
case 24: return DDProductionData(token_definition, 3);
case 25: return DDProductionData(token_definition, 4);
case 26: return DDProductionData(new_token_name, 1);
case 27: return DDProductionData(new_token_name, 1);
case 28: return DDProductionData(pattern, 1);
case 29: return DDProductionData(pattern, 1);
case 30: return DDProductionData(skip_definitions, 0);
case 31: return DDProductionData(skip_definitions, 4);
case 32: return DDProductionData(skip_definition, 2);
case 33: return DDProductionData(precedence_definitions, 0);
case 34: return DDProductionData(precedence_definitions, 4);
case 35: return DDProductionData(precedence_definition, 2);
case 36: return DDProductionData(precedence_definition, 2);
case 37: return DDProductionData(precedence_definition, 2);
case 38: return DDProductionData(tag_list, 1);
case 39: return DDProductionData(tag_list, 2);
case 40: return DDProductionData(tag, 1);
case 41: return DDProductionData(tag, 1);
case 42: return DDProductionData(tag, 1);
case 43: return DDProductionData(tag, 1);
case 44: return DDProductionData(production_rules, 3);
case 45: return DDProductionData(production_rules, 3);
case 46: return DDProductionData(production_group, 3);
case 47: return DDProductionData(production_group_head, 2);
case 48: return DDProductionData(production_group_head, 2);
case 49: return DDProductionData(production_group_head, 2);
case 50: return DDProductionData(production_tail_list, 1);
case 51: return DDProductionData(production_tail_list, 3);
case 52: return DDProductionData(production_tail, 0);
case 53: return DDProductionData(production_tail, 1);
case 54: return DDProductionData(production_tail, 2);
case 55: return DDProductionData(production_tail, 1);
case 56: return DDProductionData(production_tail, 4);
case 57: return DDProductionData(production_tail, 3);
case 58: return DDProductionData(production_tail, 3);
case 59: return DDProductionData(production_tail, 2);
case 60: return DDProductionData(production_tail, 3);
case 61: return DDProductionData(production_tail, 2);
case 62: return DDProductionData(production_tail, 2);
case 63: return DDProductionData(production_tail, 1);
case 64: return DDProductionData(action, 1);
case 65: return DDProductionData(predicate, 1);
case 66: return DDProductionData(tagged_precedence, 2);
case 67: return DDProductionData(tagged_precedence, 2);
case 68: return DDProductionData(symbol_list, 1);
case 69: return DDProductionData(symbol_list, 2);
case 70: return DDProductionData(symbol, 1);
case 71: return DDProductionData(symbol, 1);
case 72: return DDProductionData(symbol, 1);
default:
throw new Exception("Malformed production data table");
}
assert(false);
}
struct DDAttributes {
DDCharLocation dd_location;
string dd_matched_text;
union {
DDSyntaxErrorData dd_syntax_error_data;
SemanticAction semantic_action;
StringList string_list;
ProductionTail production_tail;
AssociativePrecedence associative_precedence;
Predicate predicate;
Symbol symbol;
SymbolList symbol_list;
ProductionTailList production_tail_list;
}
this (DDToken token)
{
dd_location = token.location;
dd_matched_text = token.matched_text;
if (token.is_valid_match) {
dd_set_attribute_value(this, token.handle, token.matched_text);
}
}
}
void dd_set_attribute_value(ref DDAttributes attrs, DDHandle dd_token, string text)
{
}
alias uint DDParserState;
DDParserState dd_get_goto_state(DDNonTerminal dd_non_terminal, DDParserState dd_current_state)
{
with (DDNonTerminal) switch(dd_current_state) {
case 0:
switch (dd_non_terminal) {
case specification: return 1;
case preamble: return 2;
case oinjection: return 6;
case injection: return 3;
case injection_head: return 5;
default:
throw new Exception(format("Malformed goto table: no entry for (%s , 0)", dd_non_terminal));
}
break;
case 2:
switch (dd_non_terminal) {
case definitions: return 7;
case field_definitions: return 8;
default:
throw new Exception(format("Malformed goto table: no entry for (%s , 2)", dd_non_terminal));
}
break;
case 8:
switch (dd_non_terminal) {
case oinjection: return 14;
case injection: return 3;
case injection_head: return 5;
case token_definitions: return 13;
default:
throw new Exception(format("Malformed goto table: no entry for (%s , 8)", dd_non_terminal));
}
break;
case 11:
switch (dd_non_terminal) {
case oinjection: return 15;
case injection: return 3;
case injection_head: return 5;
default:
throw new Exception(format("Malformed goto table: no entry for (%s , 11)", dd_non_terminal));
}
break;
case 12:
switch (dd_non_terminal) {
case production_rules: return 16;
case oinjection: return 17;
case injection: return 3;
case injection_head: return 5;
default:
throw new Exception(format("Malformed goto table: no entry for (%s , 12)", dd_non_terminal));
}
break;
case 13:
switch (dd_non_terminal) {
case oinjection: return 19;
case injection: return 3;
case injection_head: return 5;
case skip_definitions: return 18;
default:
throw new Exception(format("Malformed goto table: no entry for (%s , 13)", dd_non_terminal));
}
break;
case 14:
switch (dd_non_terminal) {
case field_definition: return 20;
case token_definition: return 22;
default:
throw new Exception(format("Malformed goto table: no entry for (%s , 14)", dd_non_terminal));
}
break;
case 16:
switch (dd_non_terminal) {
case coda: return 25;
case oinjection: return 26;
case injection: return 3;
case injection_head: return 5;
case production_group: return 27;
case production_group_head: return 28;
default:
throw new Exception(format("Malformed goto table: no entry for (%s , 16)", dd_non_terminal));
}
break;
case 17:
switch (dd_non_terminal) {
case production_group: return 30;
case production_group_head: return 28;
default:
throw new Exception(format("Malformed goto table: no entry for (%s , 17)", dd_non_terminal));
}
break;
case 18:
switch (dd_non_terminal) {
case oinjection: return 32;
case injection: return 3;
case injection_head: return 5;
case precedence_definitions: return 31;
default:
throw new Exception(format("Malformed goto table: no entry for (%s , 18)", dd_non_terminal));
}
break;
case 19:
switch (dd_non_terminal) {
case token_definition: return 33;
default:
throw new Exception(format("Malformed goto table: no entry for (%s , 19)", dd_non_terminal));
}
break;
case 20:
switch (dd_non_terminal) {
case oinjection: return 34;
case injection: return 3;
case injection_head: return 5;
default:
throw new Exception(format("Malformed goto table: no entry for (%s , 20)", dd_non_terminal));
}
break;
case 21:
switch (dd_non_terminal) {
case field_type: return 35;
default:
throw new Exception(format("Malformed goto table: no entry for (%s , 21)", dd_non_terminal));
}
break;
case 23:
switch (dd_non_terminal) {
case new_token_name: return 37;
default:
throw new Exception(format("Malformed goto table: no entry for (%s , 23)", dd_non_terminal));
}
break;
case 24:
switch (dd_non_terminal) {
case oinjection: return 40;
case injection: return 3;
case injection_head: return 5;
default:
throw new Exception(format("Malformed goto table: no entry for (%s , 24)", dd_non_terminal));
}
break;
case 27:
switch (dd_non_terminal) {
case oinjection: return 42;
case injection: return 3;
case injection_head: return 5;
default:
throw new Exception(format("Malformed goto table: no entry for (%s , 27)", dd_non_terminal));
}
break;
case 28:
switch (dd_non_terminal) {
case production_tail_list: return 43;
case production_tail: return 44;
case action: return 45;
case predicate: return 46;
case symbol_list: return 47;
case symbol: return 50;
default:
throw new Exception(format("Malformed goto table: no entry for (%s , 28)", dd_non_terminal));
}
break;
case 30:
switch (dd_non_terminal) {
case oinjection: return 55;
case injection: return 3;
case injection_head: return 5;
default:
throw new Exception(format("Malformed goto table: no entry for (%s , 30)", dd_non_terminal));
}
break;
case 31:
switch (dd_non_terminal) {
case oinjection: return 56;
case injection: return 3;
case injection_head: return 5;
default:
throw new Exception(format("Malformed goto table: no entry for (%s , 31)", dd_non_terminal));
}
break;
case 32:
switch (dd_non_terminal) {
case skip_definition: return 57;
default:
throw new Exception(format("Malformed goto table: no entry for (%s , 32)", dd_non_terminal));
}
break;
case 33:
switch (dd_non_terminal) {
case oinjection: return 59;
case injection: return 3;
case injection_head: return 5;
default:
throw new Exception(format("Malformed goto table: no entry for (%s , 33)", dd_non_terminal));
}
break;
case 35:
switch (dd_non_terminal) {
case field_name: return 60;
default:
throw new Exception(format("Malformed goto table: no entry for (%s , 35)", dd_non_terminal));
}
break;
case 37:
switch (dd_non_terminal) {
case pattern: return 62;
default:
throw new Exception(format("Malformed goto table: no entry for (%s , 37)", dd_non_terminal));
}
break;
case 38:
switch (dd_non_terminal) {
case new_token_name: return 65;
default:
throw new Exception(format("Malformed goto table: no entry for (%s , 38)", dd_non_terminal));
}
break;
case 46:
switch (dd_non_terminal) {
case action: return 68;
default:
throw new Exception(format("Malformed goto table: no entry for (%s , 46)", dd_non_terminal));
}
break;
case 47:
switch (dd_non_terminal) {
case action: return 71;
case predicate: return 69;
case tagged_precedence: return 70;
case symbol: return 73;
default:
throw new Exception(format("Malformed goto table: no entry for (%s , 47)", dd_non_terminal));
}
break;
case 56:
switch (dd_non_terminal) {
case precedence_definition: return 74;
default:
throw new Exception(format("Malformed goto table: no entry for (%s , 56)", dd_non_terminal));
}
break;
case 57:
switch (dd_non_terminal) {
case oinjection: return 78;
case injection: return 3;
case injection_head: return 5;
default:
throw new Exception(format("Malformed goto table: no entry for (%s , 57)", dd_non_terminal));
}
break;
case 60:
switch (dd_non_terminal) {
case field_conversion_function: return 80;
default:
throw new Exception(format("Malformed goto table: no entry for (%s , 60)", dd_non_terminal));
}
break;
case 65:
switch (dd_non_terminal) {
case pattern: return 82;
default:
throw new Exception(format("Malformed goto table: no entry for (%s , 65)", dd_non_terminal));
}
break;
case 67:
switch (dd_non_terminal) {
case production_tail: return 83;
case action: return 45;
case predicate: return 46;
case symbol_list: return 47;
case symbol: return 50;
default:
throw new Exception(format("Malformed goto table: no entry for (%s , 67)", dd_non_terminal));
}
break;
case 69:
switch (dd_non_terminal) {
case action: return 85;
case tagged_precedence: return 84;
default:
throw new Exception(format("Malformed goto table: no entry for (%s , 69)", dd_non_terminal));
}
break;
case 70:
switch (dd_non_terminal) {
case action: return 86;
default:
throw new Exception(format("Malformed goto table: no entry for (%s , 70)", dd_non_terminal));
}
break;
case 74:
switch (dd_non_terminal) {
case oinjection: return 89;
case injection: return 3;
case injection_head: return 5;
default:
throw new Exception(format("Malformed goto table: no entry for (%s , 74)", dd_non_terminal));
}
break;
case 75:
switch (dd_non_terminal) {
case tag_list: return 90;
case tag: return 91;
default:
throw new Exception(format("Malformed goto table: no entry for (%s , 75)", dd_non_terminal));
}
break;
case 76:
switch (dd_non_terminal) {
case tag_list: return 94;
case tag: return 91;
default:
throw new Exception(format("Malformed goto table: no entry for (%s , 76)", dd_non_terminal));
}
break;
case 77:
switch (dd_non_terminal) {
case tag_list: return 95;
case tag: return 91;
default:
throw new Exception(format("Malformed goto table: no entry for (%s , 77)", dd_non_terminal));
}
break;
case 84:
switch (dd_non_terminal) {
case action: return 96;
default:
throw new Exception(format("Malformed goto table: no entry for (%s , 84)", dd_non_terminal));
}
break;
case 90:
switch (dd_non_terminal) {
case tag: return 97;
default:
throw new Exception(format("Malformed goto table: no entry for (%s , 90)", dd_non_terminal));
}
break;
case 94:
switch (dd_non_terminal) {
case tag: return 97;
default:
throw new Exception(format("Malformed goto table: no entry for (%s , 94)", dd_non_terminal));
}
break;
case 95:
switch (dd_non_terminal) {
case tag: return 97;
default:
throw new Exception(format("Malformed goto table: no entry for (%s , 95)", dd_non_terminal));
}
break;
default:
throw new Exception(format("Malformed goto table: no entry for (%s, %s).", dd_non_terminal, dd_current_state));
}
throw new Exception(format("Malformed goto table: no entry for (%s, %s).", dd_non_terminal, dd_current_state));
}
bool dd_error_recovery_ok(DDParserState dd_parser_state, DDHandle dd_token)
{
with (DDHandle) switch(dd_parser_state) {
default:
}
return false;
}
import std.stdio;
import std.file;
import ddlib.lexan;
import symbols;
import grammar;
struct ProductionTail {
Symbol[] right_hand_side;
AssociativePrecedence associative_precedence;
Predicate predicate;
SemanticAction action;
}
// Aliases for use in field definitions
alias ProductionTail[] ProductionTailList;
alias Symbol[] SymbolList;
alias string[] StringList;
uint error_count;
uint warning_count;
void message(T...)(const CharLocation locn, const string tag, const string format, T args)
{
stderr.writef("%s:%s:", locn, tag);
stderr.writefln(format, args);
stderr.flush();
}
void warning(T...)(const CharLocation locn, const string format, T args)
{
message(locn, "Warning", format, args);
warning_count++;
}
void error(T...)(const CharLocation locn, const string format, T args)
{
message(locn, "Error", format, args);
error_count++;
}
GrammarSpecification parse_specification_text(string text, string label="") {
auto grammar_specification = new GrammarSpecification();
void
dd_do_semantic_action(ref DDAttributes dd_lhs, DDProduction dd_production, DDAttributes[] dd_args, void delegate(string, string) dd_inject)
{
switch(dd_production) {
case 2: // oinjection: <empty>
// no injection so nothing to do
break;
case 4: // injection_head: "%inject" LITERAL
auto file_path = dd_args[2 - 1].dd_matched_text[1..$ - 1];
try {
auto text = readText(file_path);
if (text.length > 0) {
dd_inject(text, file_path);
} else {
warning(dd_args[2 - 1].dd_location, "Injected file \"%s\" is empty.", file_path);
}
} catch (FileException e) {
error(dd_args[2 - 1].dd_location, " Injecting: %s.", e.msg);
}
break;
case 6: // preamble: <empty>
// no preamble defined so there's nothing to do
break;
case 7: // preamble: oinjection DCODE oinjection
grammar_specification.set_preamble(dd_args[2 - 1].dd_matched_text[2..$ - 2]);
break;
case 8: // preamble: oinjection DCODE oinjection DCODE oinjection
grammar_specification.set_header(dd_args[2 - 1].dd_matched_text[2..$ - 2]);
grammar_specification.set_preamble(dd_args[4 - 1].dd_matched_text[2..$ - 2]);
break;
case 9: // coda: <empty>
// no coda defined so there's nothing to do
break;
case 10: // coda: oinjection DCODE
grammar_specification.set_coda(dd_args[2 - 1].dd_matched_text[2..$ - 2]);
break;
case 12: // field_definitions: <empty>
// do nothing
break;
case 14: // field_definition: "%field" field_type field_name
if (grammar_specification.symbol_table.is_known_field(dd_args[3 - 1].dd_matched_text)) {
auto previous = grammar_specification.symbol_table.get_field_defined_at(dd_args[3 - 1].dd_matched_text);
error(dd_args[3 - 1].dd_location, "\"%s\" already declared at line %s.", previous.line_number);
} else {
grammar_specification.symbol_table.new_field(dd_args[3 - 1].dd_matched_text, dd_args[2 - 1].dd_matched_text, "", dd_args[3 - 1].dd_location);
}
break;
case 15: // field_definition: "%field" field_type field_name field_conversion_function
if (grammar_specification.symbol_table.is_known_field(dd_args[3 - 1].dd_matched_text)) {
auto previous = grammar_specification.symbol_table.get_field_defined_at(dd_args[3 - 1].dd_matched_text);
error(dd_args[3 - 1].dd_location, "\"%s\" already declared at line %s.", previous.line_number);
} else {
grammar_specification.symbol_table.new_field(dd_args[3 - 1].dd_matched_text, dd_args[2 - 1].dd_matched_text, dd_args[4 - 1].dd_matched_text, dd_args[3 - 1].dd_location);
}
break;
case 16: // field_type: IDENT ?( !is_allowable_name($1.dd_matched_text) ?)
warning(dd_args[1 - 1].dd_location, "field type name \"%s\" may clash with generated code", dd_args[1 - 1].dd_matched_text);
break;
case 18: // field_name: IDENT ?( !is_allowable_name($1.dd_matched_text) ?)
warning(dd_args[1 - 1].dd_location, "field name \"%s\" may clash with generated code", dd_args[1 - 1].dd_matched_text);
break;
case 20: // field_conversion_function: IDENT ?( !is_allowable_name($1.dd_matched_text) ?)
warning(dd_args[1 - 1].dd_location, "field conversion function name \"%s\" may clash with generated code", dd_args[1 - 1].dd_matched_text);
break;
case 24: // token_definition: "%token" new_token_name pattern
if (grammar_specification.symbol_table.is_known_symbol(dd_args[2 - 1].dd_matched_text)) {
auto previous = grammar_specification.symbol_table.get_declaration_point(dd_args[2 - 1].dd_matched_text);
error(dd_args[2 - 1].dd_location, "\"%s\" already declared at line %s.", previous.line_number);
} else {
grammar_specification.symbol_table.new_token(dd_args[2 - 1].dd_matched_text, dd_args[3 - 1].dd_matched_text, dd_args[2 - 1].dd_location);
}
break;
case 25: // token_definition: "%token" FIELDNAME new_token_name pattern
auto field_name = dd_args[2 - 1].dd_matched_text[1..$ - 1];
if (grammar_specification.symbol_table.is_known_symbol(dd_args[3 - 1].dd_matched_text)) {
auto previous = grammar_specification.symbol_table.get_declaration_point(dd_args[3 - 1].dd_matched_text);
error(dd_args[3 - 1].dd_location, "\"%s\" already declared at line %s.", previous.line_number);
} else if (!grammar_specification.symbol_table.is_known_field(field_name)) {
error(dd_args[2 - 1].dd_location, "field name \"%s\" is not known.", field_name);
grammar_specification.symbol_table.new_token(dd_args[3 - 1].dd_matched_text, dd_args[4 - 1].dd_matched_text, dd_args[3 - 1].dd_location);
} else {
grammar_specification.symbol_table.new_token(dd_args[3 - 1].dd_matched_text, dd_args[4 - 1].dd_matched_text, dd_args[3 - 1].dd_location, field_name);
}
break;
case 26: // new_token_name: IDENT ?( !is_allowable_name($1.dd_matched_text) ?)
warning(dd_args[1 - 1].dd_location, "token name \"%s\" may clash with generated code", dd_args[1 - 1].dd_matched_text);
break;
case 30: // skip_definitions: <empty>
// do nothing
break;
case 32: // skip_definition: "%skip" REGEX
grammar_specification.symbol_table.add_skip_rule(dd_args[2 - 1].dd_matched_text);
break;
case 33: // precedence_definitions: <empty>
// do nothing
break;
case 35: // precedence_definition: "%left" tag_list
grammar_specification.symbol_table.set_precedences(Associativity.left, dd_args[2 - 1].symbol_list);
break;
case 36: // precedence_definition: "%right" tag_list
grammar_specification.symbol_table.set_precedences(Associativity.right, dd_args[2 - 1].symbol_list);
break;
case 37: // precedence_definition: "%nonassoc" tag_list
grammar_specification.symbol_table.set_precedences(Associativity.nonassoc, dd_args[2 - 1].symbol_list);
break;
case 38: // tag_list: tag
if (dd_args[1 - 1].symbol is null) {
dd_lhs.symbol_list = [];
} else {
dd_lhs.symbol_list = [dd_args[1 - 1].symbol];
}
break;
case 39: // tag_list: tag_list tag
if (dd_args[2 - 1].symbol is null) {
dd_lhs.symbol_list = dd_args[1 - 1].symbol_list;
} else {
dd_lhs.symbol_list = dd_args[1 - 1].symbol_list ~ dd_args[2 - 1].symbol;
}
break;
case 40: // tag: LITERAL
dd_lhs.symbol = grammar_specification.symbol_table.get_literal_token(dd_args[1 - 1].dd_matched_text, dd_args[1 - 1].dd_location);
if (dd_lhs.symbol is null) {
error(dd_args[1 - 1].dd_location, "Literal \"%s\" is not known.", dd_args[1 - 1].dd_matched_text);
}
break;
case 41: // tag: IDENT ?( grammar_specification.symbol_table.is_known_token($1.dd_matched_text) ?)
dd_lhs.symbol = grammar_specification.symbol_table.get_symbol(dd_args[1 - 1].dd_matched_text, dd_args[1 - 1].dd_location);
break;
case 42: // tag: IDENT ?( grammar_specification.symbol_table.is_known_non_terminal($1.dd_matched_text) ?)
dd_lhs.symbol = null;
error(dd_args[1 - 1].dd_location, "Non terminal \"%s\" cannot be used as precedence tag.", dd_args[1 - 1].dd_matched_text);
break;
case 43: // tag: IDENT
dd_lhs.symbol = grammar_specification.symbol_table.new_tag(dd_args[1 - 1].dd_matched_text, dd_args[1 - 1].dd_location);
break;
case 46: // production_group: production_group_head production_tail_list "."
foreach (production_tail; dd_args[2 - 1].production_tail_list) {
grammar_specification.new_production(dd_args[1 - 1].symbol, production_tail.right_hand_side, production_tail.predicate, production_tail.action, production_tail.associative_precedence);
}
break;
case 47: // production_group_head: IDENT ":" ?( grammar_specification.symbol_table.is_known_token($1.dd_matched_text) ?)
auto lineNo = grammar_specification.symbol_table.get_declaration_point(dd_args[1 - 1].dd_matched_text).line_number;
error(dd_args[1 - 1].dd_location, "%s: token (defined at line %s) cannot be used as left hand side", dd_args[1 - 1].dd_matched_text, lineNo);
dd_lhs.symbol = grammar_specification.symbol_table.get_symbol(dd_args[1 - 1].dd_matched_text, dd_args[1 - 1].dd_location);
break;
case 48: // production_group_head: IDENT ":" ?( grammar_specification.symbol_table.is_known_tag($1.dd_matched_text) ?)
auto lineNo = grammar_specification.symbol_table.get_declaration_point(dd_args[1 - 1].dd_matched_text).line_number;
error(dd_args[1 - 1].dd_location, "%s: precedence tag (defined at line %s) cannot be used as left hand side", dd_args[1 - 1].dd_matched_text, lineNo);
dd_lhs.symbol = grammar_specification.symbol_table.get_symbol(dd_args[1 - 1].dd_matched_text, dd_args[1 - 1].dd_location);
break;
case 49: // production_group_head: IDENT ":"
if (!is_allowable_name(dd_args[1 - 1].dd_matched_text)) {
warning(dd_args[1 - 1].dd_location, "non terminal symbol name \"%s\" may clash with generated code", dd_args[1 - 1].dd_matched_text);
}
dd_lhs.symbol = grammar_specification.symbol_table.define_non_terminal(dd_args[1 - 1].dd_matched_text, dd_args[1 - 1].dd_location);
break;
case 50: // production_tail_list: production_tail
dd_lhs.production_tail_list = [dd_args[1 - 1].production_tail];
break;
case 51: // production_tail_list: production_tail_list "|" production_tail
dd_lhs.production_tail_list = dd_args[1 - 1].production_tail_list ~ dd_args[3 - 1].production_tail;
break;
case 52: // production_tail: <empty>
dd_lhs.production_tail = ProductionTail([], AssociativePrecedence(), null, null);
break;
case 53: // production_tail: action
dd_lhs.production_tail = ProductionTail([], AssociativePrecedence(), null, dd_args[1 - 1].semantic_action);
break;
case 54: // production_tail: predicate action
dd_lhs.production_tail = ProductionTail([], AssociativePrecedence(), dd_args[1 - 1].predicate, dd_args[2 - 1].semantic_action);
break;
case 55: // production_tail: predicate
dd_lhs.production_tail = ProductionTail([], AssociativePrecedence(), dd_args[1 - 1].predicate, null);
break;
case 56: // production_tail: symbol_list predicate tagged_precedence action
dd_lhs.production_tail = ProductionTail(dd_args[1 - 1].symbol_list, dd_args[3 - 1].associative_precedence, dd_args[2 - 1].predicate, dd_args[4 - 1].semantic_action);
break;
case 57: // production_tail: symbol_list predicate tagged_precedence
dd_lhs.production_tail = ProductionTail(dd_args[1 - 1].symbol_list, dd_args[3 - 1].associative_precedence, dd_args[2 - 1].predicate, null);
break;
case 58: // production_tail: symbol_list predicate action
dd_lhs.production_tail = ProductionTail(dd_args[1 - 1].symbol_list, AssociativePrecedence(), dd_args[2 - 1].predicate, dd_args[3 - 1].semantic_action);
break;
case 59: // production_tail: symbol_list predicate
dd_lhs.production_tail = ProductionTail(dd_args[1 - 1].symbol_list, AssociativePrecedence(), dd_args[2 - 1].predicate, null);
break;
case 60: // production_tail: symbol_list tagged_precedence action
dd_lhs.production_tail = ProductionTail(dd_args[1 - 1].symbol_list, dd_args[2 - 1].associative_precedence, null, dd_args[3 - 1].semantic_action);
break;
case 61: // production_tail: symbol_list tagged_precedence
dd_lhs.production_tail = ProductionTail(dd_args[1 - 1].symbol_list, dd_args[2 - 1].associative_precedence);
break;
case 62: // production_tail: symbol_list action
dd_lhs.production_tail = ProductionTail(dd_args[1 - 1].symbol_list, AssociativePrecedence(), null, dd_args[2 - 1].semantic_action);
break;
case 63: // production_tail: symbol_list
dd_lhs.production_tail = ProductionTail(dd_args[1 - 1].symbol_list);
break;
case 64: // action: ACTION
dd_lhs.semantic_action = dd_args[1 - 1].dd_matched_text[2..$ - 2];
break;
case 65: // predicate: PREDICATE
dd_lhs.predicate = dd_args[1 - 1].dd_matched_text[2..$ - 2];
break;
case 66: // tagged_precedence: "%prec" IDENT
auto symbol = grammar_specification.symbol_table.get_symbol(dd_args[2 - 1].dd_matched_text, dd_args[2 - 1].dd_location, false);
if (symbol is null) {
error(dd_args[2 - 1].dd_location, "%s: Unknown symbol.", dd_args[2 - 1].dd_matched_text);
dd_lhs.associative_precedence = AssociativePrecedence();
} else if (symbol.type == SymbolType.non_terminal) {
error(dd_args[2 - 1].dd_location, "%s: Illegal precedence tag (must be Token or Tag).", dd_args[2 - 1].dd_matched_text);
dd_lhs.associative_precedence = AssociativePrecedence();
} else {
dd_lhs.associative_precedence = symbol.associative_precedence;
}
break;
case 67: // tagged_precedence: "%prec" LITERAL
auto symbol = grammar_specification.symbol_table.get_literal_token(dd_args[2 - 1].dd_matched_text, dd_args[2 - 1].dd_location);
if (symbol is null) {
dd_lhs.associative_precedence = AssociativePrecedence();
error(dd_args[2 - 1].dd_location, "%s: Unknown literal token.", dd_args[2 - 1].dd_matched_text);
} else {
dd_lhs.associative_precedence = symbol.associative_precedence;
}
break;
case 68: // symbol_list: symbol
dd_lhs.symbol_list = [dd_args[1 - 1].symbol];
break;
case 69: // symbol_list: symbol_list symbol
dd_lhs.symbol_list = dd_args[1 - 1].symbol_list ~ dd_args[2 - 1].symbol;
break;
case 70: // symbol: IDENT
dd_lhs.symbol = grammar_specification.symbol_table.get_symbol(dd_args[1 - 1].dd_matched_text, dd_args[1 - 1].dd_location, true);
break;
case 71: // symbol: LITERAL
dd_lhs.symbol = grammar_specification.symbol_table.get_literal_token(dd_args[1 - 1].dd_matched_text, dd_args[1 - 1].dd_location);
if (dd_lhs.symbol is null) {
error(dd_args[1 - 1].dd_location, "%s: unknown literal token", dd_args[1 - 1].dd_matched_text);
}
break;
case 72: // symbol: "%error"
dd_lhs.symbol = grammar_specification.symbol_table.get_special_symbol(SpecialSymbols.parse_error);
break;
default:
// Do nothing
}
}
DDParseAction dd_get_next_action(DDParserState dd_current_state, DDHandle dd_next_token, in DDAttributes[] dd_attribute_stack)
{
with (DDHandle) switch(dd_current_state) {
case 0:
switch (dd_next_token) {
case INJECT: return dd_shift!(4);
case TOKEN, FIELD:
return dd_reduce!(6); // preamble: <empty>
case DCODE:
return dd_reduce!(2); // oinjection: <empty>
default:
throw new DDSyntaxError([TOKEN, FIELD, INJECT, DCODE]);
}
break;
case 1:
switch (dd_next_token) {
case ddEND:
return dd_accept!();
default:
throw new DDSyntaxError([ddEND]);
}
break;
case 2:
switch (dd_next_token) {
case TOKEN, FIELD, INJECT:
return dd_reduce!(12); // field_definitions: <empty>
default:
throw new DDSyntaxError([TOKEN, FIELD, INJECT]);
}
break;
case 3:
switch (dd_next_token) {
case ddEND, TOKEN, FIELD, LEFT, RIGHT, NONASSOC, SKIP, INJECT, NEWSECTION, IDENT, DCODE:
return dd_reduce!(3); // oinjection: injection
default:
throw new DDSyntaxError([ddEND, TOKEN, FIELD, LEFT, RIGHT, NONASSOC, SKIP, INJECT, NEWSECTION, IDENT, DCODE]);
}
break;
case 4:
switch (dd_next_token) {
case LITERAL: return dd_shift!(9);
default:
throw new DDSyntaxError([LITERAL]);
}
break;
case 5:
switch (dd_next_token) {
case DOT: return dd_shift!(10);
default:
throw new DDSyntaxError([DOT]);
}
break;
case 6:
switch (dd_next_token) {
case DCODE: return dd_shift!(11);
default:
throw new DDSyntaxError([DCODE]);
}
break;
case 7:
switch (dd_next_token) {
case NEWSECTION: return dd_shift!(12);
default:
throw new DDSyntaxError([NEWSECTION]);
}
break;
case 8:
switch (dd_next_token) {
case INJECT: return dd_shift!(4);
case TOKEN, FIELD:
return dd_reduce!(2); // oinjection: <empty>
default:
throw new DDSyntaxError([TOKEN, FIELD, INJECT]);
}
break;
case 9:
switch (dd_next_token) {
case DOT:
return dd_reduce!(4); // injection_head: "%inject" LITERAL
default:
throw new DDSyntaxError([DOT]);
}
break;
case 10:
switch (dd_next_token) {
case ddEND, TOKEN, FIELD, LEFT, RIGHT, NONASSOC, SKIP, INJECT, NEWSECTION, IDENT, DCODE:
return dd_reduce!(5); // injection: injection_head "."
default:
throw new DDSyntaxError([ddEND, TOKEN, FIELD, LEFT, RIGHT, NONASSOC, SKIP, INJECT, NEWSECTION, IDENT, DCODE]);
}
break;
case 11:
switch (dd_next_token) {