Changeset 203
- Timestamp:
- 06/18/06 10:10:52 (2 years ago)
- Files:
-
- trunk/enki/BaseParser.d (modified) (4 diffs)
- trunk/enki/CodeGenerator.d (modified) (2 diffs)
- trunk/enki/Directive.d (modified) (5 diffs)
- trunk/enki/EnkiBackend.d (modified) (5 diffs)
- trunk/enki/EnkiParser.d (modified) (78 diffs)
- trunk/enki/Expression.d (modified) (14 diffs)
- trunk/enki/Rule.d (modified) (3 diffs)
- trunk/enki/bootstrap.d (modified) (16 diffs)
- trunk/enki/enki_bn.d (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/enki/BaseParser.d
r202 r203 69 69 return data[start..end]; 70 70 } 71 72 /** conversion helpers **/73 74 protected String hexToChar(String hexValue){75 return "\\x" ~ hexValue;76 }77 71 78 72 /** error handling **/ … … 116 110 } 117 111 118 /** rudimentary parsers **/112 /** IParser hooks **/ 119 113 120 114 public ResultString terminal(String str){ … … 128 122 return ResultString(data[start..pos]); 129 123 } 124 125 public ResultString terminal(ubyte start){ 126 if(pos >= data.length || data[pos] != cast(char)start){ 127 //TODO: find an error message for this 128 //setError("Expected char"); 129 return ResultString(); 130 } 131 pos++; 132 return ResultString(data[pos-1..pos]); 133 } 130 134 131 135 public ResultString regexp(String str){ … … 140 144 return ResultString(); 141 145 } 146 147 public ResultString range(uint start,uint end){ 148 assert(false,"32bit/dchar ranges not supported"); 149 } 150 151 public ResultString range(short start,short end){ 152 assert(false,"16bit/wchar ranges not supported"); 153 } 154 155 public ResultString range(ubyte start,ubyte end){ 156 if(pos >= data.length || !(data[pos] >= cast(char)start && data[pos] <= cast(char)end)){ 157 //TODO: find an error message for this 158 //setError("Expected range"); 159 return ResultString(); 160 } 161 pos++; 162 return ResultString(data[pos-1..pos]); 163 } 164 165 /** rudimentary parsers **/ 142 166 143 167 public ResultBool parse_eoi(){ trunk/enki/CodeGenerator.d
r196 r203 70 70 71 71 public void render(CodeGenerator generator,Statement passterm,Statement failterm){ 72 generator.emit(name ~ ": ");72 generator.emit(name ~ ": ;"); 73 73 } 74 74 } … … 147 147 String tabs; 148 148 String code; 149 150 public this(){ 149 String parsetype; 150 151 public this(String parsetype){ 151 152 counter = 0; 152 153 tabs = ""; 154 this.parsetype = parsetype; 155 } 156 157 public String getParseType(){ 158 return this.parsetype; 153 159 } 154 160 trunk/enki/Directive.d
r202 r203 109 109 } 110 110 111 class StartDirective : Directive{112 String prod;113 114 public this(String prod){115 this.prod = prod;116 }117 118 public void semanticPass(BaseEnkiParser root){119 root.getTypeForRule(prod); // prod root to determine if this is valid120 root.setStartProduction(prod);121 }122 123 public String toBNF(){124 return ".start(\"" ~ prod ~ "\");\n";125 }126 127 public String toString(){128 return "Start Directive";129 }130 }131 132 111 class DefineDirective : Directive{ 133 112 String returnType; … … 178 157 179 158 public void semanticPass(BaseEnkiParser root){ 159 // cannot reference the parser duing bootstrap - it doesn't exist yet 180 160 version(Bootstrap){ 181 161 throw new Exception("Include directive is meaningless during bootstrap phase."); … … 185 165 throw new Exception("Cannot include '" ~ filename ~ "'; file doesn't exist."); 186 166 } 187 // cannot reference the parser duing bootstrap - it doesn't exist yet188 167 189 168 auto parser = new EnkiParser(); … … 193 172 if(result.success){ 194 173 auto syntax = result.result; 195 parser.semanticPass();196 174 root.add(parser); 197 175 } … … 278 256 } 279 257 } 258 259 class TypelibDirective : Directive{ 260 String moduleName; 261 262 public this(String moduleName){ 263 this.moduleName = moduleName; 264 } 265 266 public void semanticPass(BaseEnkiParser root){ 267 root.setTypelibName(moduleName); 268 } 269 270 public String toBNF(){ 271 return ".typelib(\"" ~ moduleName ~ "\");\n"; 272 } 273 274 public String toString(){ 275 return "Typelib Directive"; 276 } 277 } 278 279 class ParseTypeDirective : Directive{ 280 String typeName; 281 282 public this(String typeName){ 283 this.typeName = typeName; 284 } 285 286 public void semanticPass(BaseEnkiParser root){ 287 root.setParseType(typeName); 288 } 289 290 public String toBNF(){ 291 return ".parsetype(\"" ~ typeName ~ "\");\n"; 292 } 293 294 public String toString(){ 295 return "Parse-Type Directive"; 296 } 297 } trunk/enki/EnkiBackend.d
r196 r203 62 62 String classname; 63 63 String moduleName; 64 String startProduction; 64 String typelib; 65 String parseType; 65 66 UserProduction[] userProductions; 66 67 67 68 public this(){ 68 this.startProduction = "Syntax";69 69 this.baseclass = "BaseParser"; 70 70 this.classname = "Parser"; 71 } 72 73 public bool createSyntax(SyntaxLine[] lines){ 71 this.typelib = "enki.types"; 72 this.parseType = "String"; 73 } 74 75 public void createSyntax(SyntaxLine[] lines){ 74 76 this.lines = lines; 75 return true;76 77 } 77 78 … … 107 108 } 108 109 109 public void setStartProduction(String prod){ 110 startProduction = prod; 110 public void setTypelibName(String name){ 111 typelib = name; 112 } 113 114 public void setParseType(String name){ 115 debug writefln("parse type set to: %s",name); 116 parseType = name; 117 } 118 119 public String getParseType(){ 120 return parseType; 111 121 } 112 122 … … 123 133 if(name in rules) throw new Exception("Rule '" ~ name ~ "' is already defined."); 124 134 rules[name] = rule; 135 } 136 137 public Rule[String] getRules(){ 138 return this.rules; 125 139 } 126 140 … … 178 192 179 193 String render(){ 180 auto CodeGenerator generator = new CodeGenerator( );194 auto CodeGenerator generator = new CodeGenerator(this.parseType); 181 195 with(generator){ 182 196 emit("//auto-generated parser"); … … 185 199 } 186 200 emit("debug private import std.stdio;"); 201 202 if(typelib != ""){ 203 emit("private import " ~ typelib ~ ";"); 204 } 187 205 foreach(imp; imports){ 188 206 emit("private import " ~ imp ~ ";"); trunk/enki/EnkiParser.d
r202 r203 37 37 38 38 Syntax 39 = boolcreateSyntax(SyntaxLine[] lines)40 ::= ws { ( Rule:~lines | Comment:~lines | Directive:~lines ) ws} eoi;41 42 */ 43 public ResultT!( bool) parse_Syntax(){39 = void createSyntax(SyntaxLine[] lines) 40 ::= ws { ( Rule:~lines | Comment:~lines | Directive:~lines ) ws} eoi; 41 42 */ 43 public ResultT!(String) parse_Syntax(){ 44 44 debug writefln("parse_Syntax()"); 45 45 uint start = position; … … 55 55 uint start = position; 56 56 uint termPos; 57 loop5: 57 loop5: ; 58 58 termPos = position; 59 {//Expression 60 uint start = position; 61 if((parse_eoi().success)){ 62 clearErrors(); 63 goto loopend6; 64 }else{ 65 position = start; 66 } 59 if(parse_eoi().success){ 60 goto loopend6; 67 61 } 68 62 {//Expression … … 82 76 } 83 77 goto match7; 84 mismatch8: 78 mismatch8: ; 85 79 position = start; 86 80 goto mismatch4; 87 match7: 81 match7: ; 88 82 clearErrors(); 89 83 goto loop5; 90 84 } 91 loopend6: 92 {} 85 loopend6: ; 93 86 } 94 87 goto match3; 95 mismatch4: 88 mismatch4: ; 96 89 setError("Expected Whitespace."); 97 90 position = start; 98 91 goto mismatch2; 99 match3: 92 match3: ; 100 93 clearErrors(); 101 94 goto match1; 102 95 } 103 match1: 96 match1: ; 104 97 debug writefln("parse_Syntax() PASS"); 105 auto value =createSyntax(bind_lines);106 return ResultT!( bool)(value);107 mismatch2: 108 position = start; 109 return ResultT!( bool)();98 createSyntax(bind_lines); 99 return ResultT!(String)(sliceData(start,position)); 100 mismatch2: ; 101 position = start; 102 return ResultT!(String)(); 110 103 } 111 104 … … 176 169 } 177 170 goto match11; 178 mismatch12: 171 mismatch12: ; 179 172 setError("Expected Whitespace."); 180 173 position = start; 181 174 goto mismatch10; 182 match11: 175 match11: ; 183 176 clearErrors(); 184 177 goto match9; 185 178 } 186 match9: 179 match9: ; 187 180 debug writefln("parse_Rule() PASS"); 188 181 ResultT!(Rule) passed = ResultT!(Rule)(new Rule(bind_name,bind_pred,bind_expr,bind_decl)); 189 182 return passed; 190 mismatch10: 183 mismatch10: ; 191 184 position = start; 192 185 ResultT!(Rule) failed = ResultT!(Rule)(); … … 218 211 } 219 212 } 220 match13: 213 match13: ; 221 214 debug writefln("parse_RuleDecl() PASS"); 222 215 ResultT!(RuleDecl) passed = ResultT!(RuleDecl)(new RuleDecl(bind_params)); 223 216 return passed; 224 mismatch14: 217 mismatch14: ; 225 218 position = start; 226 219 ResultT!(RuleDecl) failed = ResultT!(RuleDecl)(); … … 260 253 } 261 254 goto match17; 262 mismatch18: 255 mismatch18: ; 263 256 position = start; 264 257 goto mismatch16; 265 match17: 258 match17: ; 266 259 clearErrors(); 267 260 goto match15; 268 261 } 269 match15: 262 match15: ; 270 263 debug writefln("parse_RulePredicate() PASS"); 271 264 return ResultT!(RulePredicate)(bind_pred); 272 mismatch16: 265 mismatch16: ; 273 266 position = start; 274 267 return ResultT!(RulePredicate)(); … … 299 292 } 300 293 } 301 match19: 294 match19: ; 302 295 debug writefln("parse_ClassPredicate() PASS"); 303 296 ResultT!(ClassPredicate) passed = ResultT!(ClassPredicate)(new ClassPredicate(bind_name,bind_params)); 304 297 return passed; 305 mismatch20: 298 mismatch20: ; 306 299 position = start; 307 300 ResultT!(ClassPredicate) failed = ResultT!(ClassPredicate)(); … … 334 327 } 335 328 } 336 match21: 329 match21: ; 337 330 debug writefln("parse_FunctionPredicate() PASS"); 338 331 ResultT!(FunctionPredicate) passed = ResultT!(FunctionPredicate)(new FunctionPredicate(bind_decl,bind_params)); 339 332 return passed; 340 mismatch22: 333 mismatch22: ; 341 334 position = start; 342 335 ResultT!(FunctionPredicate) failed = ResultT!(FunctionPredicate)(); … … 368 361 } 369 362 } 370 match23: 363 match23: ; 371 364 debug writefln("parse_BindingPredicate() PASS"); 372 365 ResultT!(BindingPredicate) passed = ResultT!(BindingPredicate)(new BindingPredicate(bind_param)); 373 366 return passed; 374 mismatch24: 367 mismatch24: ; 375 368 position = start; 376 369 ResultT!(BindingPredicate) failed = ResultT!(BindingPredicate)(); … … 410 403 {//ZeroOrMoreExpr 411 404 uint termPos; 412 loop31: 405 loop31: ; 413 406 termPos = position; 414 407 {//Expression … … 422 415 } 423 416 } 424 loopend32: 425 {} 417 loopend32: ; 426 418 } 427 419 goto match29; 428 mismatch30: 420 mismatch30: ; 429 421 position = start; 430 match29: 422 match29: ; 431 423 clearErrors(); 432 424 } … … 436 428 } 437 429 goto match27; 438 mismatch28: 430 mismatch28: ; 439 431 position = start; 440 432 goto mismatch26; 441 match27: 433 match27: ; 442 434 clearErrors(); 443 435 goto match25; 444 436 } 445 match25: 437 match25: ; 446 438 debug writefln("parse_ParamsExpr() PASS"); 447 439 return ResultT!(Param[])(bind_params); 448 mismatch26: 440 mismatch26: ; 449 441 position = start; 450 442 return ResultT!(Param[])(); … … 475 467 } 476 468 } 477 match33: 469 match33: ; 478 470 debug writefln("parse_Param() PASS"); 479 471 return ResultT!(Param)(bind_param); 480 mismatch34: 472 mismatch34: ; 481 473 position = start; 482 474 return ResultT!(Param)(); … … 507 499 } 508 500 } 509 match35: 501 match35: ; 510 502 debug writefln("parse_WeakParam() PASS"); 511 503 ResultT!(Param) passed = ResultT!(Param)(new Param(bind_name)); 512 504 return passed; 513 mismatch36: 505 mismatch36: ; 514 506 position = start; 515 507 ResultT!(Param) failed = ResultT!(Param)(); … … 554 546 } 555 547 goto match39; 556 mismatch40: 548 mismatch40: ; 557 549 setError("Expected Identifier."); 558 550 position = start; 559 551 goto mismatch38; 560 match39: 552 match39: ; 561 553 clearErrors(); 562 554 goto match37; 563 555 } 564 match37: 556 match37: ; 565 557 debug writefln("parse_ExplicitParam() PASS"); 566 558 ResultT!(Param) passed = ResultT!(Param)(new Param(bind_isArray,bind_type,bind_name)); 567 559 return passed; 568 mismatch38: 560 mismatch38: ; 569 561 position = start; 570 562 ResultT!(Param) failed = ResultT!(Param)(); … … 595 587 {//ZeroOrMoreExpr 596 588 uint termPos; 597 loop45: 589 loop45: ; 598 590 termPos = position; 599 591 {//Expression … … 607 599 } 608 600 } 609 loopend46: 610 {} 601 loopend46: ; 611 602 } 612 603 goto match43; 613 mismatch44: 604 mismatch44: ; 614 605 setError("Expected Term."); 615 606 position = start; 616 607 goto mismatch42; 617 match43: 608 match43: ; 618 609 clearErrors(); 619 610 goto match41; 620 611 } 621 match41: 612 match41: ; 622 613 debug writefln("parse_Expression() PASS"); 623 614 ResultT!(Expression) passed = ResultT!(Expression)(new Expression(bind_terms)); 624 615 return passed; 625 mismatch42: 616 mismatch42: ; 626 617 position = start; 627 618 ResultT!(Expression) failed = ResultT!(Expression)(); … … 652 643 {//ZeroOrMoreExpr 653 644 uint termPos; 654 loop51: 645 loop51: ; 655 646 termPos = position; 656 647 {//Expression … … 665 656 } 666 657 } 667 loopend52: 668 {} 658 loopend52: ; 669 659 } 670 660 goto match49; 671 mismatch50: 661 mismatch50: ; 672 662 setError("Expected SubExpression."); 673 663 position = start; 674 664 goto mismatch48; 675 match49: 665 match49: ; 676 666 clearErrors(); 677 667 goto match47; 678 668 } 679 match47: 669 match47: ; 680 670 debug writefln("parse_Term() PASS"); 681 671 return ResultT!(SubExpression[])(bind_factors); 682 mismatch48: 672 mismatch48: ; 683 673 position = start; 684 674 return ResultT!(SubExpression[])(); … … 689 679 SubExpression 690 680 = SubExpression expr 691 ::= Production:expr | Substitution:expr | Terminal:expr | R egexp:expr | GroupExpr:expr | OptionalExpr:expr | ZeroOrMoreExpr:expr | NegateExpr:expr | TestExpr:expr | LiteralExpr:expr | CustomTerminal:expr ;681 ::= Production:expr | Substitution:expr | Terminal:expr | Range:expr | Regexp:expr | GroupExpr:expr | OptionalExpr:expr | ZeroOrMoreExpr:expr | NegateExpr:expr | TestExpr:expr | LiteralExpr:expr | CustomTerminal:expr ; 692 682 693 683 */ … … 700 690 {//Expression 701 691 uint start = position; 702 if((parse_Production().assign!(SubExpression)(bind_expr)) || (parse_Substitution().assign!(SubExpression)(bind_expr)) || (parse_Terminal().assign!(SubExpression)(bind_expr)) || (parse_R egexp().assign!(SubExpression)(bind_expr)) || (parse_GroupExpr().assign!(SubExpression)(bind_expr)) || (parse_OptionalExpr().assign!(SubExpression)(bind_expr)) || (parse_ZeroOrMoreExpr().assign!(SubExpression)(bind_expr)) || (parse_NegateExpr().assign!(SubExpression)(bind_expr)) || (parse_TestExpr().assign!(SubExpression)(bind_expr)) || (parse_LiteralExpr().assign!(SubExpression)(bind_expr)) || (parse_CustomTerminal().assign!(SubExpression)(bind_expr))){692 if((parse_Production().assign!(SubExpression)(bind_expr)) || (parse_Substitution().assign!(SubExpression)(bind_expr)) || (parse_Terminal().assign!(SubExpression)(bind_expr)) || (parse_Range().assign!(SubExpression)(bind_expr)) || (parse_Regexp().assign!(SubExpression)(bind_expr)) || (parse_GroupExpr().assign!(SubExpression)(bind_expr)) || (parse_OptionalExpr().assign!(SubExpression)(bind_expr)) || (parse_ZeroOrMoreExpr().assign!(SubExpression)(bind_expr)) || (parse_NegateExpr().assign!(SubExpression)(bind_expr)) || (parse_TestExpr().assign!(SubExpression)(bind_expr)) || (parse_LiteralExpr().assign!(SubExpression)(bind_expr)) || (parse_CustomTerminal().assign!(SubExpression)(bind_expr))){ 703 693 clearErrors(); 704 694 goto match53; 705 695 }else{ 706 setError("Expected Production, Substitution, Terminal, R egexp, GroupExpr, OptionalExpr, ZeroOrMoreExpr, NegateExpr, TestExpr, LiteralExpr or CustomTerminal.");696 setError("Expected Production, Substitution, Terminal, Range, Regexp, GroupExpr, OptionalExpr, ZeroOrMoreExpr, NegateExpr, TestExpr, LiteralExpr or CustomTerminal."); 707 697 position = start; 708 698 goto mismatch54; 709 699 } 710 700 } 711 match53: 701 match53: ; 712 702 debug writefln("parse_SubExpression() PASS"); 713 703 return ResultT!(SubExpression)(bind_expr); 714 mismatch54: 704 mismatch54: ; 715 705 position = start; 716 706 return ResultT!(SubExpression)(); … … 721 711 Production 722 712 = new Production(String name,Binding binding,ProductionArg[] args) 723 ::= Identifier:name ws [ "!(" ws ProductionArg:~args { ws "," ws ProductionArg:~args } ")"] [ Binding:binding ] ;713 ::= Identifier:name ws [ "!(" ws ProductionArg:~args { ws "," ws ProductionArg:~args } ")"] [ Binding:binding ] ; 724 714 725 715 */ … … 755 745 uint start = position; 756 746 uint termPos; 757 loop61: 747 loop61: ; 758 748 termPos = position; 759 {//Expression 760 uint start = position; 761 if((terminal(")").success)){ 762 clearErrors(); 763 goto loopend62; 764 }else{ 765 position = start; 766 } 749 if(terminal(")").success){ 750 goto loopend62; 767 751 } 768 752 {//Expression … … 777 761 } 778 762 } 779 loopend62: 780 {} 763 loopend62: ; 781 764 } 782 765 goto match59; 783 mismatch60: 766 mismatch60: ; 784 767 position = start; 785 match59: 768 match59: ; 786 769 clearErrors(); 787 770 } … … 798 781 } 799 782 goto match57; 800 mismatch58: 783 mismatch58: ; 801 784 setError("Expected Identifier."); 802 785 position = start; 803 786 goto mismatch56; 804 match57: 787 match57: ; 805 788 clearErrors(); 806 789 goto match55; 807 790 } 808 match55: 791 match55: ; 809 792 debug writefln("parse_Production() PASS"); 810 793 ResultT!(Production) passed = ResultT!(Production)(new Production(bind_name,bind_binding,bind_args)); 811 794 return passed; 812 mismatch56: 795 mismatch56: ; 813 796 position = start; 814 797 ResultT!(Production) failed = ResultT!(Production)(); … … 840 823 } 841 824 } 842 match63: 825 match63: ; 843 826 debug writefln("parse_ProductionArg() PASS"); 844 827 return ResultT!(ProductionArg)(bind_arg); 845 mismatch64: 828 mismatch64: ; 846 829 position = start; 847 830 return ResultT!(ProductionArg)(); … … 872 855 } 873 856 } 874 match65: 857 match65: ; 875 858 debug writefln("parse_StringProductionArg() PASS"); 876 859 ResultT!(StringProductionArg) passed = ResultT!(StringProductionArg)(new StringProductionArg(bind_value)); 877 860 return passed; 878 mismatch66: 861 mismatch66: ; 879 862 position = start; 880 863 ResultT!(StringProductionArg) failed = ResultT!(StringProductionArg)(); … … 906 889 } 907 890 } 908 match67: 891 match67: ; 909 892 debug writefln("parse_BindingProductionArg() PASS"); 910 893 ResultT!(BindingProductionArg) passed = ResultT!(BindingProductionArg)(new BindingProductionArg(bind_value)); 911 894 return passed; 912 mismatch68: 895 mismatch68: ; 913 896 position = start; 914 897 ResultT!(BindingProductionArg) failed = ResultT!(BindingProductionArg)(); … … 952 935 } 953 936 goto match71; 954 mismatch72: 937 mismatch72: ; 955 938 position = start; 956 939 goto mismatch70; 957 match71: 940 match71: ; 958 941 clearErrors(); 959 942 goto match69; 960 943 } 961 match69: 944 match69: ; 962 945 debug writefln("parse_Substitution() PASS"); 963 946 ResultT!(Substitution) passed = ResultT!(Substitution)(new Substitution(bind_name,bind_binding)); 964 947 return passed; 965 mismatch70: 948 mismatch70: ; 966 949 position = start; 967 950 ResultT!(Substitution) failed = ResultT!(Substitution)(); … … 1014 997 } 1015 998 goto match75; 1016 mismatch76: 999 mismatch76: ; 1017 1000 position = start; 1018 1001 goto mismatch74; 1019 match75: 1002 match75: ; 1020 1003 clearErrors(); 1021 1004 goto match73; 1022 1005 } 1023 match73: 1006 match73: ; 1024 1007 debug writefln("parse_GroupExpr() PASS"); 1025 1008 ResultT!(GroupExpr) passed = ResultT!(GroupExpr)(new GroupExpr(bind_expr,bind_binding)); 1026 1009 return passed; 1027 mismatch74: 1010 mismatch74: ; 1028 1011 position = start; 1029 1012 ResultT!(GroupExpr) failed = ResultT!(GroupExpr)(); … … 1076 1059 } 1077 1060 goto match79; 1078 mismatch80: 1061 mismatch80: ; 1079 1062 position = start; 1080 1063 goto mismatch78; 1081 match79: 1064 match79: ; 1082 1065 clearErrors(); 1083 1066 goto match77; 1084 1067 } 1085 match77: 1068 match77: ; 1086 1069 debug writefln("parse_OptionalExpr() PASS"); 1087 1070 ResultT!(OptionalExpr) passed = ResultT!(OptionalExpr)(new OptionalExpr(bind_expr,bind_binding)); 1088 1071 return passed; 1089 mismatch78: 1072 mismatch78: ; 1090 1073 position = start; 1091 1074 ResultT!(OptionalExpr) failed = ResultT!(OptionalExpr)(); … … 1096 1079 1097 1080 ZeroOrMoreExpr 1098 = new ZeroOrMoreExpr(Expression expr,Binding binding, Expression term)1099 ::= "{" ws Expression:expr ws "}" ws [ Binding:binding ws] [ Expression:term ] ;1081 = new ZeroOrMoreExpr(Expression expr,Binding binding,SubExpression term) 1082 ::= "{" ws Expression:expr ws "}" ws [ Binding:binding ws] [ SubExpression:term ] ; 1100 1083 1101 1084 */ … … 1105 1088 Expression bind_expr; 1106 1089 Binding bind_binding; 1107 Expression bind_term;1090 SubExpression bind_term; 1108 1091 1109 1092 … … 1141 1124 {//Expression 1142 1125 uint start = position; 1143 if((parse_ Expression().assign!(Expression)(bind_term))){1126 if((parse_SubExpression().assign!(SubExpression)(bind_term))){ 1144 1127 clearErrors(); 1145 1128 }else{ … … 1149 1132 } 1150 1133 goto match83; 1151 mismatch84: 1134 mismatch84: ; 1152 1135 position = start; 1153 1136 goto mismatch82; 1154 match83: 1137 match83: ; 1155 1138 clearErrors(); 1156 1139 goto match81; 1157 1140 } 1158 match81: 1141 match81: ; 1159 1142 debug writefln("parse_ZeroOrMoreExpr() PASS"); 1160 1143 ResultT!(ZeroOrMoreExpr) passed = ResultT!(ZeroOrMoreExpr)(new ZeroOrMoreExpr(bind_expr,bind_binding,bind_term)); 1161 1144 return passed; 1162 mismatch82: 1145 mismatch82: ; 1163 1146 position = start; 1164 1147 ResultT!(ZeroOrMoreExpr) failed = ResultT!(ZeroOrMoreExpr)(); … … 1170 1153 Terminal 1171 1154 = new Terminal(String text,Binding binding) 1172 ::= ( String:text | HexChar:text )ws [ Binding:binding ] ;1155 ::= String:text ws [ Binding:binding ] ; 1173 1156 1174 1157 */ … … 1182 1165 {//Expression 1183 1166 uint start = position; 1184 {//Expression 1185 uint start = position; 1186 if((parse_String().assign!(String)(bind_text)) || (parse_HexChar().assign!(String)(bind_text))){ 1187 clearErrors(); 1188 }else{ 1189 setError("Expected String or HexChar."); 1190 position = start; 1191 goto mismatch88; 1192 } 1167 if(!(parse_String().assign!(String)(bind_text))){ 1168 goto mismatch88; 1193 1169 } 1194 1170 if(!(parse_ws().success)){ … … 1206 1182 } 1207 1183 goto match87; 1208 mismatch88: 1184 mismatch88: ; 1185 setError("Expected String."); 1209 1186 position = start; 1210 1187 goto mismatch86; 1211 match87: 1188 match87: ; 1212 1189 clearErrors(); 1213 1190 goto match85; 1214 1191 } 1215 match85: 1192 match85: ; 1216 1193 debug writefln("parse_Terminal() PASS"); 1217 1194 ResultT!(Terminal) passed = ResultT!(Terminal)(new Terminal(bind_text,bind_binding)); 1218 1195 return passed; 1219 mismatch86: 1196 mismatch86: ; 1220 1197 position = start; 1221 1198 ResultT!(Terminal) failed = ResultT!(Terminal)(); 1199 return failed; 1200 } 1201 1202 /* 1203 1204 Range 1205 = new Range(String start,String end,Binding binding) 1206 ::= HexExpr:start ws [ "-" ws HexExpr:end ws] [ Binding:binding ] ; 1207 1208 */ 1209 public ResultT!(Range) parse_Range(){ 1210 debug writefln("parse_Range()"); 1211 uint start = position; 1212 String bind_start; 1213 String bind_end; 1214 Binding bind_binding; 1215 1216 1217 {//Expression 1218 uint start = position; 1219 if(!(parse_HexExpr().assign!(String)(bind_start))){ 1220 goto mismatch92; 1221 } 1222 if(!(parse_ws().success)){ 1223 goto mismatch92; 1224 } 1225 {//OptionalExpr 1226 {//Expression 1227 uint start = position; 1228 if((terminal("-").success && parse_ws().success && parse_HexExpr().assign!(String)(bind_end) && parse_ws().success)){ 1229 clearErrors(); 1230 }else{ 1231 position = start; 1232 } 1233 } 1234 } 1235 {//OptionalExpr 1236 {//Expression 1237 uint start = position; 1238 if((parse_Binding().assign!(Binding)(bind_binding))){ 1239 clearErrors(); 1240 }else{ 1241 position = start; 1242 } 1243 } 1244 } 1245 goto match91; 1246 mismatch92: ; 1247 setError("Expected HexExpr."); 1248 position = start; 1249 goto mismatch90; 1250 match91: ; 1251 clearErrors(); 1252 goto match89; 1253 } 1254 match89: ; 1255 debug writefln("parse_Range() PASS"); 1256 ResultT!(Range) passed = ResultT!(Range)(new Range(bind_start,bind_end,bind_binding)); 1257
