root/trunk/enki/EnkiParser.d

Revision 289, 72.4 kB (checked in by h3r3tic, 4 months ago)

ported Enki to Tango; bootstraps, no other tests done yet

Line 
1 //Generated by Enki v1.2
2
3 /+
4     Copyright (c) 2006 Eric Anderton
5
6     Permission is hereby granted, free of charge, to any person
7     obtaining a copy of this software and associated documentation
8     files (the "Software"), to deal in the Software without
9     restriction, including without limitation the rights to use,
10     copy, modify, merge, publish, distribute, sublicense, and/or
11     sell copies of the Software, and to permit persons to whom the
12     Software is furnished to do so, subject to the following
13     conditions:
14
15     The above copyright notice and this permission notice shall be
16     included in all copies or substantial portions of the Software.
17
18     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20     OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22     HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23     WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25     OTHER DEALINGS IN THE SOFTWARE.
26 +/
27
28 module enki.EnkiParser;
29 version(build) pragma(export_version,EnkiUTF8);
30
31 debug private import tango.io.Stdout;
32 private import enki.types;
33 private import enki.EnkiBackend;
34 private import enki.Rule;
35 private import enki.Expression;
36 private import enki.Directive;
37
38
39
40 class EnkiParser : BaseEnkiParser{
41
42     /*
43     
44 WS
45     ::=  ws [ (  SlashSlashComment |  SlashStarComment)  WS];
46
47     */
48     public ResultT!(bool) parse_WS(){
49         debug Stdout.formatln("parse_WS()");
50         uint start1 = position;
51         //no declarations
52        
53        
54         {//Expression
55             uint start2 = position;
56             if(!(parse_ws().success)){
57                 goto mismatch4;
58             }
59             {//OptionalExpr
60                 {//Expression
61                     uint start4 = position;
62                     {//Expression
63                         uint start5 = position;
64                         if((parse_SlashSlashComment().success) || (parse_SlashStarComment().success)){
65                             clearErrors();
66                         }else{
67                             setError("Expected SlashSlashComment or SlashStarComment.");
68                             position = start5;
69                             goto mismatch6;
70                         }
71                     }
72                     if(!(parse_WS().success)){
73                         goto mismatch6;
74                     }
75                     goto match5;
76                 mismatch6:
77                     {/*do nothing*/}
78                     position = start4;
79                     {/*do nothing*/}
80                 match5:
81                     clearErrors();
82                     {/*do nothing*/}
83                 }
84             }
85             goto match3;
86         mismatch4:
87             setError("Expected ws.");
88             position = start2;
89             goto mismatch2;
90         match3:
91             clearErrors();
92             goto match1;
93         }
94     match1:
95         debug Stdout.formatln("parse_WS() PASS");
96         return ResultT!(bool)(true);
97     mismatch2:
98         position = start1;
99         return ResultT!(bool)();
100     }
101
102     /*
103     
104 Syntax
105     = void createSyntax(SyntaxLine[] lines)
106     ::=  WS { (  Rule:~lines |  Comment:~lines |  Directive:~lines)  WS} eoi;
107
108     */
109     public ResultT!(String) parse_Syntax(){
110         debug Stdout.formatln("parse_Syntax()");
111         uint start6 = position;
112         SyntaxLine[] bind_lines;
113        
114        
115         {//Expression
116             uint start7 = position;
117             if(!(parse_WS().success)){
118                 goto mismatch10;
119             }
120             {//ZeroOrMoreExpr
121                 uint start8 = position;
122                 uint termPos9;
123             loop11:
124                 termPos9 = position;
125                 if(parse_eoi().success){
126                     goto loopend12;
127                 }else{
128                     goto exprStart13;
129                 }
130             exprStart13:
131                 {//Expression
132                     uint start10 = position;
133                     {//Expression
134                         uint start11 = position;
135                         if((parse_Rule().assignCat!(SyntaxLine[])(bind_lines)) || (parse_Comment().assignCat!(SyntaxLine[])(bind_lines)) || (parse_Directive().assignCat!(SyntaxLine[])(bind_lines))){
136                             clearErrors();
137                         }else{
138                             setError("Expected Rule, Comment or Directive.");
139                             position = start11;
140                             goto mismatch15;
141                         }
142                     }
143                     if(!(parse_WS().success)){
144                         goto mismatch15;
145                     }
146                     goto match14;
147                 mismatch15:
148                     {/*do nothing*/}
149                     position = start10;
150                     goto loopend12;
151                 match14:
152                     clearErrors();
153                     goto loop11;
154                 }
155             loopend12:
156                 {/*do nothing*/}
157             }
158             goto match9;
159         mismatch10:
160             setError("Expected WS.");
161             position = start7;
162             goto mismatch8;
163         match9:
164             clearErrors();
165             goto match7;
166         }
167     match7:
168         debug Stdout.formatln("parse_Syntax() PASS");
169         createSyntax(bind_lines);
170         return ResultT!(String)(sliceData(start6,position));
171     mismatch8:
172         position = start6;
173         return ResultT!(String)();
174     }
175
176     /*
177     
178 Rule
179     = new Rule(String name,RulePredicate pred,Expression expr,RuleDecl decl)
180     ::=  Identifier:name  WS [  RuleDecl:decl  WS] [  RulePredicate:pred]  WS  "::="  WS  Expression:expr  WS  ";";
181
182     */
183     public ResultT!(Rule) parse_Rule(){
184         debug Stdout.formatln("parse_Rule()");
185         uint start12 = position;
186         String bind_name;
187         RulePredicate bind_pred;
188         Expression bind_expr;
189         RuleDecl bind_decl;
190        
191        
192         {//Expression
193             uint start13 = position;
194             if(!(parse_Identifier().assign!(String)(bind_name))){
195                 goto mismatch19;
196             }
197             if(!(parse_WS().success)){
198                 goto mismatch19;
199             }
200             {//OptionalExpr
201                 {//Expression
202                     uint start15 = position;
203                     if((parse_RuleDecl().assign!(RuleDecl)(bind_decl) && parse_WS().success)){
204                         clearErrors();
205                     }else{
206                         position = start15;
207                     }
208                 }
209             }
210             {//OptionalExpr
211                 {//Expression
212                     uint start17 = position;
213                     if((parse_RulePredicate().assign!(RulePredicate)(bind_pred))){
214                         clearErrors();
215                     }else{
216                         position = start17;
217                     }
218                 }
219             }
220             if(!(parse_WS().success)){
221                 goto mismatch19;
222             }
223             if(!(terminal("::=").success)){
224                 goto mismatch19;
225             }
226             if(!(parse_WS().success)){
227                 goto mismatch19;
228             }
229             if(!(parse_Expression().assign!(Expression)(bind_expr))){
230                 goto mismatch19;
231             }
232             if(!(parse_WS().success)){
233                 goto mismatch19;
234             }
235             if(!(terminal(";").success)){
236                 goto mismatch19;
237             }
238             goto match18;
239         mismatch19:
240             setError("Expected Identifier.");
241             position = start13;
242             goto mismatch17;
243         match18:
244             clearErrors();
245             goto match16;
246         }
247     match16:
248         debug Stdout.formatln("parse_Rule() PASS");
249         ResultT!(Rule) passed = ResultT!(Rule)(new Rule(bind_name,bind_pred,bind_expr,bind_decl));
250         return passed;
251     mismatch17:
252         position = start12;
253         ResultT!(Rule) failed = ResultT!(Rule)();
254         return failed;
255     }
256
257     /*
258     
259 RuleDecl
260     = new RuleDecl(Param[] params)
261     ::=  ParamsExpr:params;
262
263     */
264     public ResultT!(RuleDecl) parse_RuleDecl(){
265         debug Stdout.formatln("parse_RuleDecl()");
266         uint start18 = position;
267         Param[] bind_params;
268        
269        
270         {//Expression
271             uint start19 = position;
272             if((parse_ParamsExpr().assign!(Param[])(bind_params))){
273                 clearErrors();
274                 goto match20;
275             }else{
276                 setError("Expected ParamsExpr.");
277                 position = start19;
278                 goto mismatch21;
279             }
280         }
281     match20:
282         debug Stdout.formatln("parse_RuleDecl() PASS");
283         ResultT!(RuleDecl) passed = ResultT!(RuleDecl)(new RuleDecl(bind_params));
284         return passed;
285     mismatch21:
286         position = start18;
287         ResultT!(RuleDecl) failed = ResultT!(RuleDecl)();
288         return failed;
289     }
290
291     /*
292     
293 RulePredicate
294     = RulePredicate pred
295     ::=  "="  WS (  ClassPredicate:pred |  FunctionPredicate:pred |  BindingPredicate:pred);
296
297     */
298     public ResultT!(RulePredicate) parse_RulePredicate(){
299         debug Stdout.formatln("parse_RulePredicate()");
300         uint start20 = position;
301         RulePredicate bind_pred;
302        
303        
304         {//Expression
305             uint start21 = position;
306             if(!(terminal("=").success)){
307                 goto mismatch25;
308             }
309             if(!(parse_WS().success)){
310                 goto mismatch25;
311             }
312             {//Expression
313                 uint start22 = position;
314                 if((parse_ClassPredicate().assign!(RulePredicate)(bind_pred)) || (parse_FunctionPredicate().assign!(RulePredicate)(bind_pred)) || (parse_BindingPredicate().assign!(RulePredicate)(bind_pred))){
315                     clearErrors();
316                 }else{
317                     setError("Expected ClassPredicate, FunctionPredicate or BindingPredicate.");
318                     position = start22;
319                     goto mismatch25;
320                 }
321             }
322             goto match24;
323         mismatch25:
324             {/*do nothing*/}
325             position = start21;
326             goto mismatch23;
327         match24:
328             clearErrors();
329             goto match22;
330         }
331     match22:
332         debug Stdout.formatln("parse_RulePredicate() PASS");
333         return ResultT!(RulePredicate)(bind_pred);
334     mismatch23:
335         position = start20;
336         return ResultT!(RulePredicate)();
337     }
338
339     /*
340     
341 ClassPredicate
342     = new ClassPredicate(String name,Param[] params)
343     ::=  "new"  WS  Identifier:name  WS  ParamsExpr:params;
344
345     */
346     public ResultT!(ClassPredicate) parse_ClassPredicate(){
347         debug Stdout.formatln("parse_ClassPredicate()");
348         uint start23 = position;
349         String bind_name;
350         Param[] bind_params;
351        
352        
353         {//Expression
354             uint start24 = position;
355             if((terminal("new").success && parse_WS().success && parse_Identifier().assign!(String)(bind_name) && parse_WS().success && parse_ParamsExpr().assign!(Param[])(bind_params))){
356                 clearErrors();
357                 goto match26;
358             }else{
359                 position = start24;
360                 goto mismatch27;
361             }
362         }
363     match26:
364         debug Stdout.formatln("parse_ClassPredicate() PASS");
365         ResultT!(ClassPredicate) passed = ResultT!(ClassPredicate)(new ClassPredicate(bind_name,bind_params));
366         return passed;
367     mismatch27:
368         position = start23;
369         ResultT!(ClassPredicate) failed = ResultT!(ClassPredicate)();
370         return failed;
371     }
372
373     /*
374     
375 FunctionPredicate
376     = new FunctionPredicate(Param decl,Param[] params)
377     ::=  ExplicitParam:decl  WS  ParamsExpr:params;
378
379     */
380     public ResultT!(FunctionPredicate) parse_FunctionPredicate(){
381         debug Stdout.formatln("parse_FunctionPredicate()");
382         uint start25 = position;
383         Param bind_decl;
384         Param[] bind_params;
385        
386        
387         {//Expression
388             uint start26 = position;
389             if((parse_ExplicitParam().assign!(Param)(bind_decl) && parse_WS().success && parse_ParamsExpr().assign!(Param[])(bind_params))){
390                 clearErrors();
391                 goto match28;
392             }else{
393                 setError("Expected ExplicitParam.");
394                 position = start26;
395                 goto mismatch29;
396             }
397         }
398     match28:
399         debug Stdout.formatln("parse_FunctionPredicate() PASS");
400         ResultT!(FunctionPredicate) passed = ResultT!(FunctionPredicate)(new FunctionPredicate(bind_decl,bind_params));
401         return passed;
402     mismatch29:
403         position = start25;
404         ResultT!(FunctionPredicate) failed = ResultT!(FunctionPredicate)();
405         return failed;
406     }
407
408     /*
409     
410 BindingPredicate
411     = new BindingPredicate(Param param)
412     ::=  Param:param;
413
414     */
415     public ResultT!(BindingPredicate) parse_BindingPredicate(){
416         debug Stdout.formatln("parse_BindingPredicate()");
417         uint start27 = position;
418         Param bind_param;
419        
420        
421         {//Expression
422             uint start28 = position;
423             if((parse_Param().assign!(Param)(bind_param))){
424                 clearErrors();
425                 goto match30;
426             }else{
427                 setError("Expected Param.");
428                 position = start28;
429                 goto mismatch31;
430             }
431         }
432     match30:
433         debug Stdout.formatln("parse_BindingPredicate() PASS");
434         ResultT!(BindingPredicate) passed = ResultT!(BindingPredicate)(new BindingPredicate(bind_param));
435         return passed;
436     mismatch31:
437         position = start27;
438         ResultT!(BindingPredicate) failed = ResultT!(BindingPredicate)();
439         return failed;
440     }
441
442     /*
443     
444 ParamsExpr
445     = Param[] params
446     ::=  "("  WS [  Param:~params  WS {  ","  WS  Param:~params  WS}]  ")";
447
448     */
449     public ResultT!(Param[]) parse_ParamsExpr(){
450         debug Stdout.formatln("parse_ParamsExpr()");
451         uint start29 = position;
452         Param[] bind_params;
453        
454        
455         {//Expression
456             uint start30 = position;
457             if(!(terminal("(").success)){
458                 goto mismatch35;
459             }
460             if(!(parse_WS().success)){
461                 goto mismatch35;
462             }
463             {//OptionalExpr
464                 {//Expression
465                     uint start32 = position;
466                     if(!(parse_Param().assignCat!(Param[])(bind_params))){
467                         goto mismatch37;
468                     }
469                     if(!(parse_WS().success)){
470                         goto mismatch37;
471                     }
472                     {//ZeroOrMoreExpr
473                         uint termPos34;
474                     loop38:
475                         termPos34 = position;
476                     exprStart40:
477                         {//Expression
478                             uint start35 = position;
479                             if((terminal(",").success && parse_WS().success && parse_Param().assignCat!(Param[])(bind_params) && parse_WS().success)){
480                                 clearErrors();
481                                 goto loop38;
482                             }else{
483                                 position = start35;
484                                 goto loopend39;
485                             }
486                         }
487                     loopend39:
488                         {/*do nothing*/}
489                     }
490                     goto match36;
491                 mismatch37:
492                     {/*do nothing*/}
493                     position = start32;
494                     {/*do nothing*/}
495                 match36:
496                     clearErrors();
497                     {/*do nothing*/}
498                 }
499             }
500             if(!(terminal(")").success)){
501                 goto mismatch35;
502             }
503             goto match34;
504         mismatch35:
505             {/*do nothing*/}
506             position = start30;
507             goto mismatch33;
508         match34:
509             clearErrors();
510             goto match32;
511         }
512     match32:
513         debug Stdout.formatln("parse_ParamsExpr() PASS");
514         return ResultT!(Param[])(bind_params);
515     mismatch33:
516         position = start29;
517         return ResultT!(Param[])();
518     }
519
520     /*
521     
522 Param
523     = Param param
524     ::=  ExplicitParam:param |  WeakParam:param;
525
526     */
527     public ResultT!(Param) parse_Param(){
528         debug Stdout.formatln("parse_Param()");
529         uint start36 = position;
530         Param bind_param;
531        
532        
533         {//Expression
534             uint start37 = position;
535             if((parse_ExplicitParam().assign!(Param)(bind_param)) || (parse_WeakParam().assign!(Param)(bind_param))){
536                 clearErrors();
537                 goto match41;
538             }else{
539                 setError("Expected ExplicitParam or WeakParam.");
540                 position = start37;
541                 goto mismatch42;
542             }
543         }
544     match41:
545         debug Stdout.formatln("parse_Param() PASS");
546         return ResultT!(Param)(bind_param);
547     mismatch42:
548         position = start36;
549         return ResultT!(Param)();
550     }
551
552     /*
553     
554 WeakParam
555     = new Param(String name)
556     ::=  Identifier:name;
557
558     */
559     public ResultT!(Param) parse_WeakParam(){
560         debug Stdout.formatln("parse_WeakParam()");
561         uint start38 = position;
562         String bind_name;
563        
564        
565         {//Expression
566             uint start39 = position;
567             if((parse_Identifier().assign!(String)(bind_name))){
568                 clearErrors();
569                 goto match43;
570             }else{
571                 setError("Expected Identifier.");
572                 position = start39;
573                 goto mismatch44;
574             }
575         }
576     match43:
577         debug Stdout.formatln("parse_WeakParam() PASS");
578         ResultT!(Param) passed = ResultT!(Param)(new Param(bind_name));
579         return passed;
580     mismatch44:
581         position = start38;
582         ResultT!(Param) failed = ResultT!(Param)();
583         return failed;
584     }
585
586     /*
587     
588 ExplicitParam
589     = new Param(bool isArray,String type,String name)
590     ::=  Identifier:type  WS [  "[]":isArray  Brackets  WS]  Identifier:name;
591
592     */
593     public ResultT!(Param) parse_ExplicitParam(){
594         debug Stdout.formatln("parse_ExplicitParam()");
595         uint start40 = position;
596         bool bind_isArray;
597         String bind_type;
598         String bind_name;
599        
600        
601         {//Expression
602             uint start41 = position;
603             if(!(parse_Identifier().assign!(String)(bind_type))){
604                 goto mismatch48;
605             }
606             if(!(parse_WS().success)){
607                 goto mismatch48;
608             }
609             {//OptionalExpr
610                 {//Expression
611                     uint start43 = position;
612                     if((terminal("[]").assign!(bool)(bind_isArray) && parse_Brackets().success && parse_WS().success)){
613                         clearErrors();
614                     }else{
615                         position = start43;
616                     }
617                 }
618             }
619             if(!(parse_Identifier().assign!(String)(bind_name))){
620                 goto mismatch48;
621             }
622             goto match47;
623         mismatch48:
624             setError("Expected Identifier.");
625             position = start41;
626             goto mismatch46;
627         match47:
628             clearErrors();
629             goto match45;
630         }
631     match45:
632         debug Stdout.formatln("parse_ExplicitParam() PASS");
633         ResultT!(Param) passed = ResultT!(Param)(new Param(bind_isArray,bind_type,bind_name));
634         return passed;
635     mismatch46:
636         position = start40;
637         ResultT!(Param) failed = ResultT!(Param)();
638         return failed;
639     }
640
641     /*
642     
643 Brackets
644     ::= [  "[]"  Brackets];
645
646     */
647     public