1 using System;
2 using System.Collections;
3 using System.Lex;
4 using System.Parsing;
5 using RegExTokens;
6
7
8
9 public static class RegExParser
10 {
11 public static soulcm.scmlg.Nfa Parse(RegExLexer& lexer, soulcm.scmlg.LexerContext* lexerContext)
12 {
13 UniquePtr<Value<soulcm.scmlg.Nfa>> value;
14 #if (DEBUG)
15 if (lexer.Log() != null)
16 {
17 lexer.Log()->WriteBeginRule(u"parse");
18 lexer.Log()->IncIndent();
19 }
20 #endif
21 ++lexer;
22 System.Lex.Span span = lexer.GetSpan();
23 Match match = RegularExpression(lexer, lexerContext);
24 value.Reset(cast<Value<soulcm.scmlg.Nfa>*>(match.value));
25 #if (DEBUG)
26 if (lexer.Log() != null)
27 {
28 lexer.Log()->DecIndent();
29 lexer.Log()->WriteEndRule(u"parse");
30 }
31 #endif
32 if (match.hit)
33 {
34 if (*lexer == System.Lex.END_TOKEN)
35 {
36 return value->value;
37 }
38 else
39 {
40 lexer.ThrowExpectationFailure(lexer.GetSpan(), GetEndTokenInfo());
41 }
42 }
43 else
44 {
45 lexer.ThrowExpectationFailure(span, u"regular expression");
46 }
47 return value->value;
48 }
49 public static Match RegularExpression(RegExLexer& lexer, soulcm.scmlg.LexerContext* lexerContext)
50 {
51 #if (DEBUG)
52 Span debugSpan;
53 bool writeToLog = lexer.Log() != null;
54 if (writeToLog)
55 {
56 debugSpan = lexer.GetSpan();
57 System.Lex.WriteBeginRuleToLog(lexer, u"RegularExpression");
58 }
59 #endif
60 UniquePtr<Value<soulcm.scmlg.Nfa>> alternative;
61 Match match(false);
62 Match* parentMatch0 = &match;
63 {
64 long pos = lexer.GetPos();
65 Match match = RegExParser.Alternative(lexer, lexerContext);
66 alternative.Reset(cast<Value<soulcm.scmlg.Nfa>*>(match.value));
67 if (match.hit)
68 {
69 {
70 #if (DEBUG)
71 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"RegularExpression");
72 #endif
73 return Match(true, new Value<soulcm.scmlg.Nfa>(alternative->value));
74 }
75 }
76 *parentMatch0 = match;
77 }
78 #if (DEBUG)
79 if (writeToLog)
80 {
81 if (match.hit)
82 {
83 System.Lex.WriteSuccessToLog(lexer, debugSpan, u"RegularExpression");
84 }
85 else
86 {
87 System.Lex.WriteFailureToLog(lexer, u"RegularExpression");
88 }
89 }
90 #endif
91 if (!match.hit)
92 {
93 match.value = null;
94 }
95 return match;
96 }
97 public static Match Alternative(RegExLexer& lexer, soulcm.scmlg.LexerContext* lexerContext)
98 {
99 #if (DEBUG)
100 Span debugSpan;
101 bool writeToLog = lexer.Log() != null;
102 if (writeToLog)
103 {
104 debugSpan = lexer.GetSpan();
105 System.Lex.WriteBeginRuleToLog(lexer, u"Alternative");
106 }
107 #endif
108 soulcm.scmlg.Nfa value;
109 UniquePtr<Value<soulcm.scmlg.Nfa>> left;
110 UniquePtr<Value<soulcm.scmlg.Nfa>> right;
111 Match match(false);
112 Match* parentMatch0 = &match;
113 {
114 long pos = lexer.GetPos();
115 Match match(false);
116 Match* parentMatch1 = &match;
117 {
118 Match match(false);
119 Match* parentMatch2 = &match;
120 {
121 Match match(false);
122 Match* parentMatch3 = &match;
123 {
124 long pos = lexer.GetPos();
125 Match match = RegExParser.Catenation(lexer, lexerContext);
126 left.Reset(cast<Value<soulcm.scmlg.Nfa>*>(match.value));
127 if (match.hit)
128 {
129 value = left->value;
130 }
131 *parentMatch3 = match;
132 }
133 *parentMatch2 = match;
134 }
135 if (match.hit)
136 {
137 Match match(false);
138 Match* parentMatch4 = &match;
139 {
140 Match match(true);
141 Match* parentMatch5 = &match;
142 {
143 while (true)
144 {
145 long save = lexer.GetPos();
146 {
147 Match match(false);
148 Match* parentMatch6 = &match;
149 {
150 Match match(false);
151 Match* parentMatch7 = &match;
152 {
153 Match match(false);
154 if (*lexer == ALT)
155 {
156 ++lexer;
157 match.hit = true;
158 }
159 *parentMatch7 = match;
160 }
161 if (match.hit)
162 {
163 Match match(false);
164 Match* parentMatch8 = &match;
165 {
166 Match match(false);
167 Match* parentMatch9 = &match;
168 {
169 long pos = lexer.GetPos();
170 Match match(true);
171 Match* parentMatch10 = &match;
172 {
173 System.Lex.Span span = lexer.GetSpan();
174 Match match = RegExParser.Catenation(lexer, lexerContext);
175 right.Reset(cast<Value<soulcm.scmlg.Nfa>*>(match.value));
176 if (match.hit)
177 {
178 *parentMatch10 = match;
179 }
180 else
181 {
182 lexer.ThrowExpectationFailure(span, u"catenation");
183 }
184 }
185 if (match.hit)
186 {
187 value = soulcm.scmlg.Alt(*lexerContext, value, right->value);
188 }
189 *parentMatch9 = match;
190 }
191 *parentMatch8 = match;
192 }
193 *parentMatch7 = match;
194 }
195 *parentMatch6 = match;
196 }
197 if (match.hit)
198 {
199 *parentMatch5 = match;
200 }
201 else
202 {
203 lexer.SetPos(save);
204 break;
205 }
206 }
207 }
208 }
209 *parentMatch4 = match;
210 }
211 *parentMatch2 = match;
212 }
213 *parentMatch1 = match;
214 }
215 if (match.hit)
216 {
217 {
218 #if (DEBUG)
219 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Alternative");
220 #endif
221 return Match(true, new Value<soulcm.scmlg.Nfa>(value));
222 }
223 }
224 *parentMatch0 = match;
225 }
226 #if (DEBUG)
227 if (writeToLog)
228 {
229 if (match.hit)
230 {
231 System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Alternative");
232 }
233 else
234 {
235 System.Lex.WriteFailureToLog(lexer, u"Alternative");
236 }
237 }
238 #endif
239 if (!match.hit)
240 {
241 match.value = null;
242 }
243 return match;
244 }
245 public static Match Catenation(RegExLexer& lexer, soulcm.scmlg.LexerContext* lexerContext)
246 {
247 #if (DEBUG)
248 Span debugSpan;
249 bool writeToLog = lexer.Log() != null;
250 if (writeToLog)
251 {
252 debugSpan = lexer.GetSpan();
253 System.Lex.WriteBeginRuleToLog(lexer, u"Catenation");
254 }
255 #endif
256 soulcm.scmlg.Nfa value;
257 UniquePtr<Value<soulcm.scmlg.Nfa>> left;
258 UniquePtr<Value<soulcm.scmlg.Nfa>> right;
259 Match match(false);
260 Match* parentMatch0 = &match;
261 {
262 long pos = lexer.GetPos();
263 Match match(false);
264 Match* parentMatch1 = &match;
265 {
266 Match match(false);
267 Match* parentMatch2 = &match;
268 {
269 Match match(false);
270 Match* parentMatch3 = &match;
271 {
272 long pos = lexer.GetPos();
273 Match match = RegExParser.Repetition(lexer, lexerContext);
274 left.Reset(cast<Value<soulcm.scmlg.Nfa>*>(match.value));
275 if (match.hit)
276 {
277 value = left->value;
278 }
279 *parentMatch3 = match;
280 }
281 *parentMatch2 = match;
282 }
283 if (match.hit)
284 {
285 Match match(false);
286 Match* parentMatch4 = &match;
287 {
288 Match match(true);
289 Match* parentMatch5 = &match;
290 {
291 while (true)
292 {
293 long save = lexer.GetPos();
294 {
295 Match match(false);
296 Match* parentMatch6 = &match;
297 {
298 Match match(false);
299 Match* parentMatch7 = &match;
300 {
301 long pos = lexer.GetPos();
302 Match match = RegExParser.Repetition(lexer, lexerContext);
303 right.Reset(cast<Value<soulcm.scmlg.Nfa>*>(match.value));
304 if (match.hit)
305 {
306 value = soulcm.scmlg.Cat(value, right->value);
307 }
308 *parentMatch7 = match;
309 }
310 *parentMatch6 = match;
311 }
312 if (match.hit)
313 {
314 *parentMatch5 = match;
315 }
316 else
317 {
318 lexer.SetPos(save);
319 break;
320 }
321 }
322 }
323 }
324 *parentMatch4 = match;
325 }
326 *parentMatch2 = match;
327 }
328 *parentMatch1 = match;
329 }
330 if (match.hit)
331 {
332 {
333 #if (DEBUG)
334 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Catenation");
335 #endif
336 return Match(true, new Value<soulcm.scmlg.Nfa>(value));
337 }
338 }
339 *parentMatch0 = match;
340 }
341 #if (DEBUG)
342 if (writeToLog)
343 {
344 if (match.hit)
345 {
346 System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Catenation");
347 }
348 else
349 {
350 System.Lex.WriteFailureToLog(lexer, u"Catenation");
351 }
352 }
353 #endif
354 if (!match.hit)
355 {
356 match.value = null;
357 }
358 return match;
359 }
360 public static Match Repetition(RegExLexer& lexer, soulcm.scmlg.LexerContext* lexerContext)
361 {
362 #if (DEBUG)
363 Span debugSpan;
364 bool writeToLog = lexer.Log() != null;
365 if (writeToLog)
366 {
367 debugSpan = lexer.GetSpan();
368 System.Lex.WriteBeginRuleToLog(lexer, u"Repetition");
369 }
370 #endif
371 soulcm.scmlg.Nfa value;
372 UniquePtr<Value<soulcm.scmlg.Nfa>> left;
373 Match match(false);
374 Match* parentMatch0 = &match;
375 {
376 long pos = lexer.GetPos();
377 Match match(false);
378 Match* parentMatch1 = &match;
379 {
380 Match match(false);
381 Match* parentMatch2 = &match;
382 {
383 Match match(false);
384 Match* parentMatch3 = &match;
385 {
386 long pos = lexer.GetPos();
387 Match match = RegExParser.Primary(lexer, lexerContext);
388 left.Reset(cast<Value<soulcm.scmlg.Nfa>*>(match.value));
389 if (match.hit)
390 {
391 value = left->value;
392 }
393 *parentMatch3 = match;
394 }
395 *parentMatch2 = match;
396 }
397 if (match.hit)
398 {
399 Match match(false);
400 Match* parentMatch4 = &match;
401 {
402 Match match(true);
403 long save = lexer.GetPos();
404 Match* parentMatch5 = &match;
405 {
406 Match match(false);
407 Match* parentMatch6 = &match;
408 {
409 Match match(false);
410 Match* parentMatch7 = &match;
411 {
412 long save = lexer.GetPos();
413 Match match(false);
414 Match* parentMatch8 = &match;
415 {
416 long save = lexer.GetPos();
417 Match match(false);
418 Match* parentMatch9 = &match;
419 {
420 long pos = lexer.GetPos();
421 Match match(false);
422 if (*lexer == STAR)
423 {
424 ++lexer;
425 match.hit = true;
426 }
427 if (match.hit)
428 {
429 value = soulcm.scmlg.Kleene(*lexerContext, value);
430 }
431 *parentMatch9 = match;
432 }
433 *parentMatch8 = match;
434 if (!match.hit)
435 {
436 Match match(false);
437 Match* parentMatch10 = &match;
438 lexer.SetPos(save);
439 {
440 Match match(false);
441 Match* parentMatch11 = &match;
442 {
443 long pos = lexer.GetPos();
444 Match match(false);
445 if (*lexer == PLUS)
446 {
447 ++lexer;
448 match.hit = true;
449 }
450 if (match.hit)
451 {
452 value = soulcm.scmlg.Pos(*lexerContext, value);
453 }
454 *parentMatch11 = match;
455 }
456 *parentMatch10 = match;
457 }
458 *parentMatch8 = match;
459 }
460 }
461 *parentMatch7 = match;
462 if (!match.hit)
463 {
464 Match match(false);
465 Match* parentMatch12 = &match;
466 lexer.SetPos(save);
467 {
468 Match match(false);
469 Match* parentMatch13 = &match;
470 {
471 long pos = lexer.GetPos();
472 Match match(false);
473 if (*lexer == QUEST)
474 {
475 ++lexer;
476 match.hit = true;
477 }
478 if (match.hit)
479 {
480 value = soulcm.scmlg.Opt(*lexerContext, value);
481 }
482 *parentMatch13 = match;
483 }
484 *parentMatch12 = match;
485 }
486 *parentMatch7 = match;
487 }
488 }
489 *parentMatch6 = match;
490 }
491 if (match.hit)
492 {
493 *parentMatch5 = match;
494 }
495 else
496 {
497 lexer.SetPos(save);
498 }
499 }
500 *parentMatch4 = match;
501 }
502 *parentMatch2 = match;
503 }
504 *parentMatch1 = match;
505 }
506 if (match.hit)
507 {
508 {
509 #if (DEBUG)
510 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Repetition");
511 #endif
512 return Match(true, new Value<soulcm.scmlg.Nfa>(value));
513 }
514 }
515 *parentMatch0 = match;
516 }
517 #if (DEBUG)
518 if (writeToLog)
519 {
520 if (match.hit)
521 {
522 System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Repetition");
523 }
524 else
525 {
526 System.Lex.WriteFailureToLog(lexer, u"Repetition");
527 }
528 }
529 #endif
530 if (!match.hit)
531 {
532 match.value = null;
533 }
534 return match;
535 }
536 public static Match Primary(RegExLexer& lexer, soulcm.scmlg.LexerContext* lexerContext)
537 {
538 #if (DEBUG)
539 Span debugSpan;
540 bool writeToLog = lexer.Log() != null;
541 if (writeToLog)
542 {
543 debugSpan = lexer.GetSpan();
544 System.Lex.WriteBeginRuleToLog(lexer, u"Primary");
545 }
546 #endif
547 soulcm.scmlg.Nfa value;
548 UniquePtr<Value<soulcm.scmlg.Nfa>> alt;
549 UniquePtr<soulcm.scmlg.Class> cls;
550 UniquePtr<Value<ustring>> ref;
551 Match match(false);
552 Match* parentMatch0 = &match;
553 {
554 long pos = lexer.GetPos();
555 Match match(false);
556 Match* parentMatch1 = &match;
557 {
558 Match match(false);
559 Match* parentMatch2 = &match;
560 {
561 long save = lexer.GetPos();
562 Match match(false);
563 Match* parentMatch3 = &match;
564 {
565 long save = lexer.GetPos();
566 Match match(false);
567 Match* parentMatch4 = &match;
568 {
569 long save = lexer.GetPos();
570 Match match(false);
571 Match* parentMatch5 = &match;
572 {
573 long save = lexer.GetPos();
574 Match match(false);
575 Match* parentMatch6 = &match;
576 {
577 long save = lexer.GetPos();
578 Match match(false);
579 Match* parentMatch7 = &match;
580 {
581 long save = lexer.GetPos();
582 Match match(false);
583 Match* parentMatch8 = &match;
584 {
585 long save = lexer.GetPos();
586 Match match(false);
587 Match* parentMatch9 = &match;
588 {
589 Match match(false);
590 Match* parentMatch10 = &match;
591 {
592 Match match(false);
593 if (*lexer == LPAREN)
594 {
595 ++lexer;
596 match.hit = true;
597 }
598 *parentMatch10 = match;
599 }
600 if (match.hit)
601 {
602 Match match(false);
603 Match* parentMatch11 = &match;
604 {
605 Match match(false);
606 Match* parentMatch12 = &match;
607 {
608 long pos = lexer.GetPos();
609 Match match(true);
610 Match* parentMatch13 = &match;
611 {
612 System.Lex.Span span = lexer.GetSpan();
613 Match match = RegExParser.Alternative(lexer, lexerContext);
614 alt.Reset(cast<Value<soulcm.scmlg.Nfa>*>(match.value));
615 if (match.hit)
616 {
617 *parentMatch13 = match;
618 }
619 else
620 {
621 lexer.ThrowExpectationFailure(span, u"alternative");
622 }
623 }
624 if (match.hit)
625 {
626 value = alt->value;
627 }
628 *parentMatch12 = match;
629 }
630 *parentMatch11 = match;
631 }
632 *parentMatch10 = match;
633 }
634 *parentMatch9 = match;
635 }
636 if (match.hit)
637 {
638 Match match(false);
639 Match* parentMatch14 = &match;
640 {
641 Match match(true);
642 Match* parentMatch15 = &match;
643 {
644 System.Lex.Span span = lexer.GetSpan();
645 Match match(false);
646 if (*lexer == RPAREN)
647 {
648 ++lexer;
649 match.hit = true;
650 }
651 if (match.hit)
652 {
653 *parentMatch15 = match;
654 }
655 else
656 {
657 lexer.ThrowExpectationFailure(span, GetTokenName(RPAREN));
658 }
659 }
660 *parentMatch14 = match;
661 }
662 *parentMatch9 = match;
663 }
664 *parentMatch8 = match;
665 if (!match.hit)
666 {
667 Match match(false);
668 Match* parentMatch16 = &match;
669 lexer.SetPos(save);
670 {
671 Match match(false);
672 Match* parentMatch17 = &match;
673 {
674 long pos = lexer.GetPos();
675 Match match(false);
676 if (*lexer == ESCAPE)
677 {
678 ++lexer;
679 match.hit = true;
680 }
681 if (match.hit)
682 {
683 value = soulcm.scmlg.MakeNfa(*lexerContext, lexerContext->MakeChar(soulcm.scmlg.MakeEscapeValue(lexer.FileName(), lexer.GetToken(pos))));
684 }
685 *parentMatch17 = match;
686 }
687 *parentMatch16 = match;
688 }
689 *parentMatch8 = match;
690 }
691 }
692 *parentMatch7 = match;
693 if (!match.hit)
694 {
695 Match match(false);
696 Match* parentMatch18 = &match;
697 lexer.SetPos(save);
698 {
699 Match match(false);
700 Match* parentMatch19 = &match;
701 {
702 long pos = lexer.GetPos();
703 Match match(false);
704 if (*lexer == INVERSE)
705 {
706 ++lexer;
707 match.hit = true;
708 }
709 if (match.hit)
710 {
711 value = soulcm.scmlg.MakeNfa(*lexerContext, lexerContext->MakeChar('^'));
712 }
713 *parentMatch19 = match;
714 }
715 *parentMatch18 = match;
716 }
717 *parentMatch7 = match;
718 }
719 }
720 *parentMatch6 = match;
721 if (!match.hit)
722 {
723 Match match(false);
724 Match* parentMatch20 = &match;
725 lexer.SetPos(save);
726 {
727 Match match(false);
728 Match* parentMatch21 = &match;
729 {
730 long pos = lexer.GetPos();
731 Match match(false);
732 if (*lexer == MINUS)
733 {
734 ++lexer;
735 match.hit = true;
736 }
737 if (match.hit)
738 {
739 value = soulcm.scmlg.MakeNfa(*lexerContext, lexerContext->MakeChar('-'));
740 }
741 *parentMatch21 = match;
742 }
743 *parentMatch20 = match;
744 }
745 *parentMatch6 = match;
746 }
747 }
748 *parentMatch5 = match;
749 if (!match.hit)
750 {
751 Match match(false);
752 Match* parentMatch22 = &match;
753 lexer.SetPos(save);
754 {
755 Match match(false);
756 Match* parentMatch23 = &match;
757 {
758 long pos = lexer.GetPos();
759 Span span = lexer.GetSpan();
760 Match match(false);
761 if (*lexer == CHAR)
762 {
763 ++lexer;
764 match.hit = true;
765 }
766 if (match.hit)
767 {
768 ustring match = lexer.GetMatch(span);
769 value = soulcm.scmlg.MakeNfa(*lexerContext, lexerContext->MakeChar(match[0]));
770 }
771 *parentMatch23 = match;
772 }
773 *parentMatch22 = match;
774 }
775 *parentMatch5 = match;
776 }
777 }
778 *parentMatch4 = match;
779 if (!match.hit)
780 {
781 Match match(false);
782 Match* parentMatch24 = &match;
783 lexer.SetPos(save);
784 {
785 Match match(false);
786 Match* parentMatch25 = &match;
787 {
788 long pos = lexer.GetPos();
789 Match match(false);
790 if (*lexer == DOT)
791 {
792 ++lexer;
793 match.hit = true;
794 }
795 if (match.hit)
796 {
797 value = soulcm.scmlg.MakeNfa(*lexerContext, lexerContext->MakeAny());
798 }
799 *parentMatch25 = match;
800 }
801 *parentMatch24 = match;
802 }
803 *parentMatch4 = match;
804 }
805 }
806 *parentMatch3 = match;
807 if (!match.hit)
808 {
809 Match match(false);
810 Match* parentMatch26 = &match;
811 lexer.SetPos(save);
812 {
813 Match match(false);
814 Match* parentMatch27 = &match;
815 {
816 long pos = lexer.GetPos();
817 Match match = RegExParser.Class(lexer, lexerContext);
818 cls.Reset(cast<soulcm.scmlg.Class*>(match.value));
819 if (match.hit)
820 {
821 value = soulcm.scmlg.MakeNfa(*lexerContext, cls.Release());
822 }
823 *parentMatch27 = match;
824 }
825 *parentMatch26 = match;
826 }
827 *parentMatch3 = match;
828 }
829 }
830 *parentMatch2 = match;
831 if (!match.hit)
832 {
833 Match match(false);
834 Match* parentMatch28 = &match;
835 lexer.SetPos(save);
836 {
837 Match match(false);
838 Match* parentMatch29 = &match;
839 {
840 long pos = lexer.GetPos();
841 Match match = RegExParser.ExpressionReference(lexer);
842 ref.Reset(cast<Value<ustring>*>(match.value));
843 if (match.hit)
844 {
845 value = lexerContext->MakeExpr(ref->value);
846 }
847 *parentMatch29 = match;
848 }
849 *parentMatch28 = match;
850 }
851 *parentMatch2 = match;
852 }
853 }
854 *parentMatch1 = match;
855 }
856 if (match.hit)
857 {
858 {
859 #if (DEBUG)
860 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Primary");
861 #endif
862 return Match(true, new Value<soulcm.scmlg.Nfa>(value));
863 }
864 }
865 *parentMatch0 = match;
866 }
867 #if (DEBUG)
868 if (writeToLog)
869 {
870 if (match.hit)
871 {
872 System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Primary");
873 }
874 else
875 {
876 System.Lex.WriteFailureToLog(lexer, u"Primary");
877 }
878 }
879 #endif
880 if (!match.hit)
881 {
882 match.value = null;
883 }
884 return match;
885 }
886 public static Match Class(RegExLexer& lexer, soulcm.scmlg.LexerContext* lexerContext)
887 {
888 #if (DEBUG)
889 Span debugSpan;
890 bool writeToLog = lexer.Log() != null;
891 if (writeToLog)
892 {
893 debugSpan = lexer.GetSpan();
894 System.Lex.WriteBeginRuleToLog(lexer, u"Class");
895 }
896 #endif
897 soulcm.scmlg.Class* cls;
898 UniquePtr<soulcm.scmlg.Symbol> r;
899 Match match(false);
900 Match* parentMatch0 = &match;
901 {
902 long pos = lexer.GetPos();
903 Match match(false);
904 Match* parentMatch1 = &match;
905 {
906 Match match(false);
907 Match* parentMatch2 = &match;
908 {
909 Match match(false);
910 Match* parentMatch3 = &match;
911 {
912 Match match(false);
913 Match* parentMatch4 = &match;
914 {
915 long pos = lexer.GetPos();
916 Match match(false);
917 if (*lexer == LBRACKET)
918 {
919 ++lexer;
920 match.hit = true;
921 }
922 if (match.hit)
923 {
924 cls = lexerContext->MakeClass();
925 }
926 *parentMatch4 = match;
927 }
928 *parentMatch3 = match;
929 }
930 if (match.hit)
931 {
932 Match match(false);
933 Match* parentMatch5 = &match;
934 {
935 Match match(false);
936 Match* parentMatch6 = &match;
937 {
938 Match match(false);
939 Match* parentMatch7 = &match;
940 {
941 Match match(true);
942 long save = lexer.GetPos();
943 Match* parentMatch8 = &match;
944 {
945 Match match(false);
946 Match* parentMatch9 = &match;
947 {
948 Match match(false);
949 Match* parentMatch10 = &match;
950 {
951 long pos = lexer.GetPos();
952 Match match(false);
953 if (*lexer == INVERSE)
954 {
955 ++lexer;
956 match.hit = true;
957 }
958 if (match.hit)
959 {
960 cls->SetInverse();
961 }
962 *parentMatch10 = match;
963 }
964 *parentMatch9 = match;
965 }
966 if (match.hit)
967 {
968 *parentMatch8 = match;
969 }
970 else
971 {
972 lexer.SetPos(save);
973 }
974 }
975 *parentMatch7 = match;
976 }
977 if (match.hit)
978 {
979 Match match(false);
980 Match* parentMatch11 = &match;
981 {
982 Match match(true);
983 Match* parentMatch12 = &match;
984 {
985 while (true)
986 {
987 long save = lexer.GetPos();
988 {
989 Match match(false);
990 Match* parentMatch13 = &match;
991 {
992 Match match(false);
993 Match* parentMatch14 = &match;
994 {
995 long pos = lexer.GetPos();
996 Match match = RegExParser.Range(lexer, lexerContext);
997 r.Reset(cast<soulcm.scmlg.Symbol*>(match.value));
998 if (match.hit)
999 {
1000 cls->AddSymbol(r.Release());
1001 }
1002 *parentMatch14 = match;
1003 }
1004 *parentMatch13 = match;
1005 }
1006 if (match.hit)
1007 {
1008 *parentMatch12 = match;
1009 }
1010 else
1011 {
1012 lexer.SetPos(save);
1013 break;
1014 }
1015 }
1016 }
1017 }
1018 *parentMatch11 = match;
1019 }
1020 *parentMatch7 = match;
1021 }
1022 *parentMatch6 = match;
1023 }
1024 *parentMatch5 = match;
1025 }
1026 *parentMatch3 = match;
1027 }
1028 *parentMatch2 = match;
1029 }
1030 if (match.hit)
1031 {
1032 Match match(false);
1033 Match* parentMatch15 = &match;
1034 {
1035 Match match(true);
1036 Match* parentMatch16 = &match;
1037 {
1038 System.Lex.Span span = lexer.GetSpan();
1039 Match match(false);
1040 if (*lexer == RBRACKET)
1041 {
1042 ++lexer;
1043 match.hit = true;
1044 }
1045 if (match.hit)
1046 {
1047 *parentMatch16 = match;
1048 }
1049 else
1050 {
1051 lexer.ThrowExpectationFailure(span, GetTokenName(RBRACKET));
1052 }
1053 }
1054 *parentMatch15 = match;
1055 }
1056 *parentMatch2 = match;
1057 }
1058 *parentMatch1 = match;
1059 }
1060 if (match.hit)
1061 {
1062 {
1063 #if (DEBUG)
1064 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Class");
1065 #endif
1066 return Match(true, cls);
1067 }
1068 }
1069 *parentMatch0 = match;
1070 }
1071 #if (DEBUG)
1072 if (writeToLog)
1073 {
1074 if (match.hit)
1075 {
1076 System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Class");
1077 }
1078 else
1079 {
1080 System.Lex.WriteFailureToLog(lexer, u"Class");
1081 }
1082 }
1083 #endif
1084 if (!match.hit)
1085 {
1086 match.value = null;
1087 }
1088 return match;
1089 }
1090 public static Match Range(RegExLexer& lexer, soulcm.scmlg.LexerContext* lexerContext)
1091 {
1092 #if (DEBUG)
1093 Span debugSpan;
1094 bool writeToLog = lexer.Log() != null;
1095 if (writeToLog)
1096 {
1097 debugSpan = lexer.GetSpan();
1098 System.Lex.WriteBeginRuleToLog(lexer, u"Range");
1099 }
1100 #endif
1101 soulcm.scmlg.Symbol* symbol;
1102 UniquePtr<Value<uchar>> s;
1103 UniquePtr<Value<uchar>> e;
1104 Match match(false);
1105 Match* parentMatch0 = &match;
1106 {
1107 long pos = lexer.GetPos();
1108 Match match(false);
1109 Match* parentMatch1 = &match;
1110 {
1111 Match match(false);
1112 Match* parentMatch2 = &match;
1113 {
1114 Match match = RegExParser.Char(lexer);
1115 s.Reset(cast<Value<uchar>*>(match.value));
1116 *parentMatch2 = match;
1117 }
1118 if (match.hit)
1119 {
1120 Match match(false);
1121 Match* parentMatch3 = &match;
1122 {
1123 Match match(false);
1124 Match* parentMatch4 = &match;
1125 {
1126 Match match(false);
1127 Match* parentMatch5 = &match;
1128 {
1129 long save = lexer.GetPos();
1130 Match match(false);
1131 Match* parentMatch6 = &match;
1132 {
1133 Match match(false);
1134 if (*lexer == MINUS)
1135 {
1136 ++lexer;
1137 match.hit = true;
1138 }
1139 *parentMatch6 = match;
1140 }
1141 if (match.hit)
1142 {
1143 Match match(false);
1144 Match* parentMatch7 = &match;
1145 {
1146 Match match(false);
1147 Match* parentMatch8 = &match;
1148 {
1149 long pos = lexer.GetPos();
1150 Match match = RegExParser.Char(lexer);
1151 e.Reset(cast<Value<uchar>*>(match.value));
1152 if (match.hit)
1153 {
1154 symbol = lexerContext->MakeRange(s->value, e->value);
1155 }
1156 *parentMatch8 = match;
1157 }
1158 *parentMatch7 = match;
1159 }
1160 *parentMatch6 = match;
1161 }
1162 *parentMatch5 = match;
1163 if (!match.hit)
1164 {
1165 Match match(false);
1166 Match* parentMatch9 = &match;
1167 lexer.SetPos(save);
1168 {
1169 Match match(false);
1170 Match* parentMatch10 = &match;
1171 {
1172 long pos = lexer.GetPos();
1173 Match match(true);
1174 if (match.hit)
1175 {
1176 symbol = lexerContext->MakeChar(s->value);
1177 }
1178 *parentMatch10 = match;
1179 }
1180 *parentMatch9 = match;
1181 }
1182 *parentMatch5 = match;
1183 }
1184 }
1185 *parentMatch4 = match;
1186 }
1187 *parentMatch3 = match;
1188 }
1189 *parentMatch2 = match;
1190 }
1191 *parentMatch1 = match;
1192 }
1193 if (match.hit)
1194 {
1195 {
1196 #if (DEBUG)
1197 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Range");
1198 #endif
1199 return Match(true, symbol);
1200 }
1201 }
1202 *parentMatch0 = match;
1203 }
1204 #if (DEBUG)
1205 if (writeToLog)
1206 {
1207 if (match.hit)
1208 {
1209 System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Range");
1210 }
1211 else
1212 {
1213 System.Lex.WriteFailureToLog(lexer, u"Range");
1214 }
1215 }
1216 #endif
1217 if (!match.hit)
1218 {
1219 match.value = null;
1220 }
1221 return match;
1222 }
1223 public static Match Char(RegExLexer& lexer)
1224 {
1225 #if (DEBUG)
1226 Span debugSpan;
1227 bool writeToLog = lexer.Log() != null;
1228 if (writeToLog)
1229 {
1230 debugSpan = lexer.GetSpan();
1231 System.Lex.WriteBeginRuleToLog(lexer, u"Char");
1232 }
1233 #endif
1234 Match match(false);
1235 long pos = lexer.GetPos();
1236 Span span = lexer.GetSpan();
1237 switch (*lexer)
1238 {
1239 case LPAREN:
1240 {
1241 ++lexer;
1242 {
1243 #if (DEBUG)
1244 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Char");
1245 #endif
1246 return Match(true, new Value<uchar>('('));
1247 }
1248 break;
1249 }
1250 case RPAREN:
1251 {
1252 ++lexer;
1253 {
1254 #if (DEBUG)
1255 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Char");
1256 #endif
1257 return Match(true, new Value<uchar>(')'));
1258 }
1259 break;
1260 }
1261 case LBRACKET:
1262 {
1263 ++lexer;
1264 {
1265 #if (DEBUG)
1266 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Char");
1267 #endif
1268 return Match(true, new Value<uchar>('['));
1269 }
1270 break;
1271 }
1272 case LBRACE:
1273 {
1274 ++lexer;
1275 {
1276 #if (DEBUG)
1277 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Char");
1278 #endif
1279 return Match(true, new Value<uchar>('{'));
1280 }
1281 break;
1282 }
1283 case RBRACE:
1284 {
1285 ++lexer;
1286 {
1287 #if (DEBUG)
1288 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Char");
1289 #endif
1290 return Match(true, new Value<uchar>('}'));
1291 }
1292 break;
1293 }
1294 case ALT:
1295 {
1296 ++lexer;
1297 {
1298 #if (DEBUG)
1299 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Char");
1300 #endif
1301 return Match(true, new Value<uchar>('|'));
1302 }
1303 break;
1304 }
1305 case STAR:
1306 {
1307 ++lexer;
1308 {
1309 #if (DEBUG)
1310 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Char");
1311 #endif
1312 return Match(true, new Value<uchar>('*'));
1313 }
1314 break;
1315 }
1316 case PLUS:
1317 {
1318 ++lexer;
1319 {
1320 #if (DEBUG)
1321 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Char");
1322 #endif
1323 return Match(true, new Value<uchar>('+'));
1324 }
1325 break;
1326 }
1327 case QUEST:
1328 {
1329 ++lexer;
1330 {
1331 #if (DEBUG)
1332 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Char");
1333 #endif
1334 return Match(true, new Value<uchar>('?'));
1335 }
1336 break;
1337 }
1338 case DOT:
1339 {
1340 ++lexer;
1341 {
1342 #if (DEBUG)
1343 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Char");
1344 #endif
1345 return Match(true, new Value<uchar>('.'));
1346 }
1347 break;
1348 }
1349 case ESCAPE:
1350 {
1351 ++lexer;
1352 {
1353 #if (DEBUG)
1354 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Char");
1355 #endif
1356 return Match(true, new Value<uchar>(soulcm.scmlg.MakeEscapeValue(lexer.FileName(), lexer.GetToken(pos))));
1357 }
1358 break;
1359 }
1360 case INVERSE:
1361 {
1362 ++lexer;
1363 {
1364 #if (DEBUG)
1365 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Char");
1366 #endif
1367 return Match(true, new Value<uchar>('^'));
1368 }
1369 break;
1370 }
1371 case MINUS:
1372 {
1373 ++lexer;
1374 {
1375 #if (DEBUG)
1376 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Char");
1377 #endif
1378 return Match(true, new Value<uchar>('-'));
1379 }
1380 break;
1381 }
1382 case CHAR:
1383 {
1384 ++lexer;
1385 ustring match = lexer.GetMatch(span);
1386 {
1387 #if (DEBUG)
1388 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Char");
1389 #endif
1390 return Match(true, new Value<uchar>(match[0]));
1391 }
1392 break;
1393 }
1394 }
1395 #if (DEBUG)
1396 if (writeToLog)
1397 {
1398 if (match.hit)
1399 {
1400 System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Char");
1401 }
1402 else
1403 {
1404 System.Lex.WriteFailureToLog(lexer, u"Char");
1405 }
1406 }
1407 #endif
1408 if (!match.hit)
1409 {
1410 match.value = null;
1411 }
1412 return match;
1413 }
1414 public static Match ExpressionReference(RegExLexer& lexer)
1415 {
1416 #if (DEBUG)
1417 Span debugSpan;
1418 bool writeToLog = lexer.Log() != null;
1419 if (writeToLog)
1420 {
1421 debugSpan = lexer.GetSpan();
1422 System.Lex.WriteBeginRuleToLog(lexer, u"ExpressionReference");
1423 }
1424 #endif
1425 Span s;
1426 Match match(false);
1427 Match* parentMatch0 = &match;
1428 {
1429 Match match(false);
1430 Match* parentMatch1 = &match;
1431 {
1432 Match match(false);
1433 Match* parentMatch2 = &match;
1434 {
1435 long pos = lexer.GetPos();
1436 Span span = lexer.GetSpan();
1437 Match match(false);
1438 if (*lexer == LBRACE)
1439 {
1440 ++lexer;
1441 match.hit = true;
1442 }
1443 if (match.hit)
1444 {
1445 s = span;
1446 }
1447 *parentMatch2 = match;
1448 }
1449 *parentMatch1 = match;
1450 }
1451 if (match.hit)
1452 {
1453 Match match(false);
1454 Match* parentMatch3 = &match;
1455 {
1456 Match match(false);
1457 Match* parentMatch4 = &match;
1458 {
1459 Match match(false);
1460 if (*lexer == CHAR)
1461 {
1462 ++lexer;
1463 match.hit = true;
1464 }
1465 *parentMatch4 = match;
1466 }
1467 if (match.hit)
1468 {
1469 Match match(true);
1470 Match* parentMatch5 = &match;
1471 while (true)
1472 {
1473 long save = lexer.GetPos();
1474 {
1475 Match match(false);
1476 if (*lexer == CHAR)
1477 {
1478 ++lexer;
1479 match.hit = true;
1480 }
1481 if (match.hit)
1482 {
1483 *parentMatch5 = match;
1484 }
1485 else
1486 {
1487 lexer.SetPos(save);
1488 break;
1489 }
1490 }
1491 }
1492 }
1493 *parentMatch3 = match;
1494 }
1495 *parentMatch1 = match;
1496 }
1497 *parentMatch0 = match;
1498 }
1499 if (match.hit)
1500 {
1501 Match match(false);
1502 Match* parentMatch6 = &match;
1503 {
1504 Match match(false);
1505 Match* parentMatch7 = &match;
1506 {
1507 long pos = lexer.GetPos();
1508 Span span = lexer.GetSpan();
1509 Match match(false);
1510 if (*lexer == RBRACE)
1511 {
1512 ++lexer;
1513 match.hit = true;
1514 }
1515 if (match.hit)
1516 {
1517 s.end = span.end;
1518 {
1519 #if (DEBUG)
1520 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"ExpressionReference");
1521 #endif
1522 return Match(true, new Value<ustring>(soulcm.scmlg.MakeExprRefId(lexer.FileName(), lexer.GetMatch(s), lexer.GetToken(pos).line)));
1523 }
1524 }
1525 *parentMatch7 = match;
1526 }
1527 *parentMatch6 = match;
1528 }
1529 *parentMatch0 = match;
1530 }
1531 #if (DEBUG)
1532 if (writeToLog)
1533 {
1534 if (match.hit)
1535 {
1536 System.Lex.WriteSuccessToLog(lexer, debugSpan, u"ExpressionReference");
1537 }
1538 else
1539 {
1540 System.Lex.WriteFailureToLog(lexer, u"ExpressionReference");
1541 }
1542 }
1543 #endif
1544 if (!match.hit)
1545 {
1546 match.value = null;
1547 }
1548 return match;
1549 }
1550 }