1 using System;
2 using System.Collections;
3 using System.Lex;
4 using System.Parsing;
5 using System.Lex;
6 using ProjectFileTokens;
7
8
9
10 public static class ProjectFileParser
11 {
12 public static UniquePtr<soulcm.scmpg.ProjectFile> Parse(ProjectFileLexer& lexer)
13 {
14 UniquePtr<soulcm.scmpg.ProjectFile> value;
15 #if (DEBUG)
16 if (lexer.Log() != null)
17 {
18 lexer.Log()->WriteBeginRule(u"parse");
19 lexer.Log()->IncIndent();
20 }
21 #endif
22 ++lexer;
23 System.Lex.Span span = lexer.GetSpan();
24 Match match = ProjectFile(lexer);
25 value.Reset(cast<soulcm.scmpg.ProjectFile*>(match.value));
26 #if (DEBUG)
27 if (lexer.Log() != null)
28 {
29 lexer.Log()->DecIndent();
30 lexer.Log()->WriteEndRule(u"parse");
31 }
32 #endif
33 if (match.hit)
34 {
35 if (*lexer == System.Lex.END_TOKEN)
36 {
37 return value;
38 }
39 else
40 {
41 lexer.ThrowExpectationFailure(lexer.GetSpan(), GetEndTokenInfo());
42 }
43 }
44 else
45 {
46 lexer.ThrowExpectationFailure(span, u"ProjectFile");
47 }
48 return value;
49 }
50 public static Match ProjectFile(ProjectFileLexer& lexer)
51 {
52 #if (DEBUG)
53 Span debugSpan;
54 bool writeToLog = lexer.Log() != null;
55 if (writeToLog)
56 {
57 debugSpan = lexer.GetSpan();
58 System.Lex.WriteBeginRuleToLog(lexer, u"ProjectFile");
59 }
60 #endif
61 UniquePtr<soulcm.scmpg.ProjectFile> projectFile;
62 UniquePtr<Value<ustring>> projectName;
63 Match match(false);
64 Match* parentMatch0 = &match;
65 {
66 Match match(false);
67 Match* parentMatch1 = &match;
68 {
69 Match match(false);
70 Match* parentMatch2 = &match;
71 {
72 Match match(false);
73 if (*lexer == PROJECT)
74 {
75 ++lexer;
76 match.hit = true;
77 }
78 *parentMatch2 = match;
79 }
80 if (match.hit)
81 {
82 Match match(false);
83 Match* parentMatch3 = &match;
84 {
85 Match match(true);
86 Match* parentMatch4 = &match;
87 {
88 System.Lex.Span span = lexer.GetSpan();
89 Match match = ProjectFileParser.QualifiedId(lexer);
90 projectName.Reset(cast<Value<ustring>*>(match.value));
91 if (match.hit)
92 {
93 *parentMatch4 = match;
94 }
95 else
96 {
97 lexer.ThrowExpectationFailure(span, u"QualifiedId");
98 }
99 }
100 *parentMatch3 = match;
101 }
102 *parentMatch2 = match;
103 }
104 *parentMatch1 = match;
105 }
106 if (match.hit)
107 {
108 Match match(false);
109 Match* parentMatch5 = &match;
110 {
111 Match match(false);
112 Match* parentMatch6 = &match;
113 {
114 long pos = lexer.GetPos();
115 Match match(true);
116 Match* parentMatch7 = &match;
117 {
118 System.Lex.Span span = lexer.GetSpan();
119 Match match(false);
120 if (*lexer == SEMICOLON)
121 {
122 ++lexer;
123 match.hit = true;
124 }
125 if (match.hit)
126 {
127 *parentMatch7 = match;
128 }
129 else
130 {
131 lexer.ThrowExpectationFailure(span, GetTokenName(SEMICOLON));
132 }
133 }
134 if (match.hit)
135 {
136 projectFile.Reset(new soulcm.scmpg.ProjectFile(lexer.FileName(), projectName->value));
137 }
138 *parentMatch6 = match;
139 }
140 *parentMatch5 = match;
141 }
142 *parentMatch1 = match;
143 }
144 *parentMatch0 = match;
145 }
146 if (match.hit)
147 {
148 Match match(false);
149 Match* parentMatch8 = &match;
150 {
151 Match match(false);
152 Match* parentMatch9 = &match;
153 {
154 long pos = lexer.GetPos();
155 Match match = ProjectFileParser.ProjectFileContent(lexer, projectFile.Get());
156 if (match.hit)
157 {
158 {
159 #if (DEBUG)
160 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"ProjectFile");
161 #endif
162 return Match(true, projectFile.Release());
163 }
164 }
165 *parentMatch9 = match;
166 }
167 *parentMatch8 = match;
168 }
169 *parentMatch0 = match;
170 }
171 #if (DEBUG)
172 if (writeToLog)
173 {
174 if (match.hit)
175 {
176 System.Lex.WriteSuccessToLog(lexer, debugSpan, u"ProjectFile");
177 }
178 else
179 {
180 System.Lex.WriteFailureToLog(lexer, u"ProjectFile");
181 }
182 }
183 #endif
184 if (!match.hit)
185 {
186 match.value = null;
187 }
188 return match;
189 }
190 public static Match ProjectFileContent(ProjectFileLexer& lexer, soulcm.scmpg.ProjectFile* projectFile)
191 {
192 #if (DEBUG)
193 Span debugSpan;
194 bool writeToLog = lexer.Log() != null;
195 if (writeToLog)
196 {
197 debugSpan = lexer.GetSpan();
198 System.Lex.WriteBeginRuleToLog(lexer, u"ProjectFileContent");
199 }
200 #endif
201 Match match(true);
202 Match* parentMatch0 = &match;
203 {
204 while (true)
205 {
206 long save = lexer.GetPos();
207 {
208 Match match(false);
209 Match* parentMatch1 = &match;
210 {
211 Match match(false);
212 Match* parentMatch2 = &match;
213 {
214 long save = lexer.GetPos();
215 Match match = ProjectFileParser.SourceFile(lexer, projectFile);
216 *parentMatch2 = match;
217 if (!match.hit)
218 {
219 Match match(false);
220 Match* parentMatch3 = &match;
221 lexer.SetPos(save);
222 {
223 Match match = ProjectFileParser.RuleFile(lexer, projectFile);
224 *parentMatch3 = match;
225 }
226 *parentMatch2 = match;
227 }
228 }
229 *parentMatch1 = match;
230 }
231 if (match.hit)
232 {
233 *parentMatch0 = match;
234 }
235 else
236 {
237 lexer.SetPos(save);
238 break;
239 }
240 }
241 }
242 }
243 #if (DEBUG)
244 if (writeToLog)
245 {
246 if (match.hit)
247 {
248 System.Lex.WriteSuccessToLog(lexer, debugSpan, u"ProjectFileContent");
249 }
250 else
251 {
252 System.Lex.WriteFailureToLog(lexer, u"ProjectFileContent");
253 }
254 }
255 #endif
256 if (!match.hit)
257 {
258 match.value = null;
259 }
260 return match;
261 }
262 public static Match QualifiedId(ProjectFileLexer& lexer)
263 {
264 #if (DEBUG)
265 Span debugSpan;
266 bool writeToLog = lexer.Log() != null;
267 if (writeToLog)
268 {
269 debugSpan = lexer.GetSpan();
270 System.Lex.WriteBeginRuleToLog(lexer, u"QualifiedId");
271 }
272 #endif
273 Span s;
274 Match match(false);
275 Match* parentMatch0 = &match;
276 {
277 long pos = lexer.GetPos();
278 Match match(false);
279 Match* parentMatch1 = &match;
280 {
281 Match match(false);
282 Match* parentMatch2 = &match;
283 {
284 Match match(false);
285 Match* parentMatch3 = &match;
286 {
287 long pos = lexer.GetPos();
288 Span span = lexer.GetSpan();
289 Match match(false);
290 if (*lexer == ID)
291 {
292 ++lexer;
293 match.hit = true;
294 }
295 if (match.hit)
296 {
297 s = span;
298 }
299 *parentMatch3 = match;
300 }
301 *parentMatch2 = match;
302 }
303 if (match.hit)
304 {
305 Match match(false);
306 Match* parentMatch4 = &match;
307 {
308 Match match(true);
309 Match* parentMatch5 = &match;
310 {
311 while (true)
312 {
313 long save = lexer.GetPos();
314 {
315 Match match(false);
316 Match* parentMatch6 = &match;
317 {
318 Match match(false);
319 Match* parentMatch7 = &match;
320 {
321 Match match(false);
322 if (*lexer == DOT)
323 {
324 ++lexer;
325 match.hit = true;
326 }
327 *parentMatch7 = match;
328 }
329 if (match.hit)
330 {
331 Match match(false);
332 Match* parentMatch8 = &match;
333 {
334 Match match(false);
335 Match* parentMatch9 = &match;
336 {
337 long pos = lexer.GetPos();
338 Span span = lexer.GetSpan();
339 Match match(false);
340 if (*lexer == ID)
341 {
342 ++lexer;
343 match.hit = true;
344 }
345 if (match.hit)
346 {
347 s.end = span.end;
348 }
349 *parentMatch9 = match;
350 }
351 *parentMatch8 = match;
352 }
353 *parentMatch7 = match;
354 }
355 *parentMatch6 = match;
356 }
357 if (match.hit)
358 {
359 *parentMatch5 = match;
360 }
361 else
362 {
363 lexer.SetPos(save);
364 break;
365 }
366 }
367 }
368 }
369 *parentMatch4 = match;
370 }
371 *parentMatch2 = match;
372 }
373 *parentMatch1 = match;
374 }
375 if (match.hit)
376 {
377 {
378 #if (DEBUG)
379 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"QualifiedId");
380 #endif
381 return Match(true, new Value<ustring>(lexer.GetMatch(s)));
382 }
383 }
384 *parentMatch0 = match;
385 }
386 #if (DEBUG)
387 if (writeToLog)
388 {
389 if (match.hit)
390 {
391 System.Lex.WriteSuccessToLog(lexer, debugSpan, u"QualifiedId");
392 }
393 else
394 {
395 System.Lex.WriteFailureToLog(lexer, u"QualifiedId");
396 }
397 }
398 #endif
399 if (!match.hit)
400 {
401 match.value = null;
402 }
403 return match;
404 }
405 public static Match SourceFile(ProjectFileLexer& lexer, soulcm.scmpg.ProjectFile* projectFile)
406 {
407 #if (DEBUG)
408 Span debugSpan;
409 bool writeToLog = lexer.Log() != null;
410 if (writeToLog)
411 {
412 debugSpan = lexer.GetSpan();
413 System.Lex.WriteBeginRuleToLog(lexer, u"SourceFile");
414 }
415 #endif
416 Match match(false);
417 Match* parentMatch0 = &match;
418 {
419 Match match(false);
420 Match* parentMatch1 = &match;
421 {
422 Match match(false);
423 if (*lexer == SOURCE)
424 {
425 ++lexer;
426 match.hit = true;
427 }
428 *parentMatch1 = match;
429 }
430 if (match.hit)
431 {
432 Match match(false);
433 Match* parentMatch2 = &match;
434 {
435 Match match(false);
436 Match* parentMatch3 = &match;
437 {
438 long pos = lexer.GetPos();
439 Match match(true);
440 Match* parentMatch4 = &match;
441 {
442 System.Lex.Span span = lexer.GetSpan();
443 Match match(false);
444 if (*lexer == FILEPATH)
445 {
446 ++lexer;
447 match.hit = true;
448 }
449 if (match.hit)
450 {
451 *parentMatch4 = match;
452 }
453 else
454 {
455 lexer.ThrowExpectationFailure(span, GetTokenName(FILEPATH));
456 }
457 }
458 if (match.hit)
459 {
460 projectFile->AddSourceFile(lexer.filePath);
461 }
462 *parentMatch3 = match;
463 }
464 *parentMatch2 = match;
465 }
466 *parentMatch1 = match;
467 }
468 *parentMatch0 = match;
469 }
470 if (match.hit)
471 {
472 Match match(false);
473 Match* parentMatch5 = &match;
474 {
475 Match match(true);
476 Match* parentMatch6 = &match;
477 {
478 System.Lex.Span span = lexer.GetSpan();
479 Match match(false);
480 if (*lexer == SEMICOLON)
481 {
482 ++lexer;
483 match.hit = true;
484 }
485 if (match.hit)
486 {
487 *parentMatch6 = match;
488 }
489 else
490 {
491 lexer.ThrowExpectationFailure(span, GetTokenName(SEMICOLON));
492 }
493 }
494 *parentMatch5 = match;
495 }
496 *parentMatch0 = match;
497 }
498 #if (DEBUG)
499 if (writeToLog)
500 {
501 if (match.hit)
502 {
503 System.Lex.WriteSuccessToLog(lexer, debugSpan, u"SourceFile");
504 }
505 else
506 {
507 System.Lex.WriteFailureToLog(lexer, u"SourceFile");
508 }
509 }
510 #endif
511 if (!match.hit)
512 {
513 match.value = null;
514 }
515 return match;
516 }
517 public static Match RuleFile(ProjectFileLexer& lexer, soulcm.scmpg.ProjectFile* projectFile)
518 {
519 #if (DEBUG)
520 Span debugSpan;
521 bool writeToLog = lexer.Log() != null;
522 if (writeToLog)
523 {
524 debugSpan = lexer.GetSpan();
525 System.Lex.WriteBeginRuleToLog(lexer, u"RuleFile");
526 }
527 #endif
528 Match match(false);
529 Match* parentMatch0 = &match;
530 {
531 Match match(false);
532 Match* parentMatch1 = &match;
533 {
534 Match match(false);
535 if (*lexer == RULES)
536 {
537 ++lexer;
538 match.hit = true;
539 }
540 *parentMatch1 = match;
541 }
542 if (match.hit)
543 {
544 Match match(false);
545 Match* parentMatch2 = &match;
546 {
547 Match match(false);
548 Match* parentMatch3 = &match;
549 {
550 long pos = lexer.GetPos();
551 Match match(true);
552 Match* parentMatch4 = &match;
553 {
554 System.Lex.Span span = lexer.GetSpan();
555 Match match(false);
556 if (*lexer == FILEPATH)
557 {
558 ++lexer;
559 match.hit = true;
560 }
561 if (match.hit)
562 {
563 *parentMatch4 = match;
564 }
565 else
566 {
567 lexer.ThrowExpectationFailure(span, GetTokenName(FILEPATH));
568 }
569 }
570 if (match.hit)
571 {
572 projectFile->AddRuleFile(lexer.filePath);
573 }
574 *parentMatch3 = match;
575 }
576 *parentMatch2 = match;
577 }
578 *parentMatch1 = match;
579 }
580 *parentMatch0 = match;
581 }
582 if (match.hit)
583 {
584 Match match(false);
585 Match* parentMatch5 = &match;
586 {
587 Match match(true);
588 Match* parentMatch6 = &match;
589 {
590 System.Lex.Span span = lexer.GetSpan();
591 Match match(false);
592 if (*lexer == SEMICOLON)
593 {
594 ++lexer;
595 match.hit = true;
596 }
597 if (match.hit)
598 {
599 *parentMatch6 = match;
600 }
601 else
602 {
603 lexer.ThrowExpectationFailure(span, GetTokenName(SEMICOLON));
604 }
605 }
606 *parentMatch5 = match;
607 }
608 *parentMatch0 = match;
609 }
610 #if (DEBUG)
611 if (writeToLog)
612 {
613 if (match.hit)
614 {
615 System.Lex.WriteSuccessToLog(lexer, debugSpan, u"RuleFile");
616 }
617 else
618 {
619 System.Lex.WriteFailureToLog(lexer, u"RuleFile");
620 }
621 }
622 #endif
623 if (!match.hit)
624 {
625 match.value = null;
626 }
627 return match;
628 }
629 }