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