| 1 |
/+ |
|---|
| 2 |
Copyright (c) 2006 Eric Anderton |
|---|
| 3 |
|
|---|
| 4 |
Permission is hereby granted, free of charge, to any person |
|---|
| 5 |
obtaining a copy of this software and associated documentation |
|---|
| 6 |
files (the "Software"), to deal in the Software without |
|---|
| 7 |
restriction, including without limitation the rights to use, |
|---|
| 8 |
copy, modify, merge, publish, distribute, sublicense, and/or |
|---|
| 9 |
sell copies of the Software, and to permit persons to whom the |
|---|
| 10 |
Software is furnished to do so, subject to the following |
|---|
| 11 |
conditions: |
|---|
| 12 |
|
|---|
| 13 |
The above copyright notice and this permission notice shall be |
|---|
| 14 |
included in all copies or substantial portions of the Software. |
|---|
| 15 |
|
|---|
| 16 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|---|
| 17 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|---|
| 18 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|---|
| 19 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|---|
| 20 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|---|
| 21 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|---|
| 22 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|---|
| 23 |
OTHER DEALINGS IN THE SOFTWARE. |
|---|
| 24 |
+/ |
|---|
| 25 |
module enki.bootstrap; |
|---|
| 26 |
|
|---|
| 27 |
/** |
|---|
| 28 |
Bootstrap module for Enki. |
|---|
| 29 |
|
|---|
| 30 |
Generates EnkiParser.d and enki.bnf from parse-tree declared in this module. |
|---|
| 31 |
|
|---|
| 32 |
Build using "-version=Bootstrap". |
|---|
| 33 |
*/ |
|---|
| 34 |
|
|---|
| 35 |
private import enki.types; |
|---|
| 36 |
private import enki.EnkiBackend; |
|---|
| 37 |
private import enki.CodeGenerator; |
|---|
| 38 |
private import enki.Expression; |
|---|
| 39 |
private import enki.Directive; |
|---|
| 40 |
private import enki.Rule; |
|---|
| 41 |
|
|---|
| 42 |
import tango.text.Util; |
|---|
| 43 |
import tango.text.Unicode; |
|---|
| 44 |
import tango.io.Stdout; |
|---|
| 45 |
import tango.io.File; |
|---|
| 46 |
|
|---|
| 47 |
// helper functions |
|---|
| 48 |
public SubExpression[] makeTerm(SubExpression[] factors...){ |
|---|
| 49 |
return factors.dup; |
|---|
| 50 |
} |
|---|
| 51 |
|
|---|
| 52 |
public SubExpression[][] orExpr(SubExpression[][] terms...){ |
|---|
| 53 |
return terms.dup; |
|---|
| 54 |
} |
|---|
| 55 |
|
|---|
| 56 |
class EmptyLine : SyntaxLine{ |
|---|
| 57 |
public void semanticPass(BaseEnkiParser root){ |
|---|
| 58 |
} |
|---|
| 59 |
|
|---|
| 60 |
public String toBNF(){ |
|---|
| 61 |
return "\n"; |
|---|
| 62 |
} |
|---|
| 63 |
public String toString(){ |
|---|
| 64 |
return ""; |
|---|
| 65 |
} |
|---|
| 66 |
} |
|---|
| 67 |
|
|---|
| 68 |
static EmptyLine empty; |
|---|
| 69 |
static this(){ empty = new EmptyLine(); } |
|---|
| 70 |
|
|---|
| 71 |
void main(){ |
|---|
| 72 |
SyntaxLine[] lines; |
|---|
| 73 |
|
|---|
| 74 |
lines ~= new BoilerplateDirective(`/+ |
|---|
| 75 |
Copyright (c) 2006 Eric Anderton |
|---|
| 76 |
|
|---|
| 77 |
Permission is hereby granted, free of charge, to any person |
|---|
| 78 |
obtaining a copy of this software and associated documentation |
|---|
| 79 |
files (the "Software"), to deal in the Software without |
|---|
| 80 |
restriction, including without limitation the rights to use, |
|---|
| 81 |
copy, modify, merge, publish, distribute, sublicense, and/or |
|---|
| 82 |
sell copies of the Software, and to permit persons to whom the |
|---|
| 83 |
Software is furnished to do so, subject to the following |
|---|
| 84 |
conditions: |
|---|
| 85 |
|
|---|
| 86 |
The above copyright notice and this permission notice shall be |
|---|
| 87 |
included in all copies or substantial portions of the Software. |
|---|
| 88 |
|
|---|
| 89 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|---|
| 90 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|---|
| 91 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|---|
| 92 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|---|
| 93 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|---|
| 94 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|---|
| 95 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|---|
| 96 |
OTHER DEALINGS IN THE SOFTWARE. |
|---|
| 97 |
+/`); |
|---|
| 98 |
|
|---|
| 99 |
lines ~= empty; |
|---|
| 100 |
lines ~= new Comment(" Enki Grammar Definition (self-hosting frontend)"); |
|---|
| 101 |
lines ~= new ModuleDirective("enki.EnkiParser"); |
|---|
| 102 |
lines ~= empty; |
|---|
| 103 |
lines ~= new ImportDirective("enki.EnkiBackend"); |
|---|
| 104 |
lines ~= new ImportDirective("enki.Rule"); |
|---|
| 105 |
lines ~= new ImportDirective("enki.Expression"); |
|---|
| 106 |
lines ~= new ImportDirective("enki.Directive"); |
|---|
| 107 |
|
|---|
| 108 |
lines ~= empty; |
|---|
| 109 |
lines ~= new DefineDirective("bool","eoi",true,"End of Input"); |
|---|
| 110 |
lines ~= new DefineDirective("bool","eol",true,"End of Line"); |
|---|
| 111 |
lines ~= new DefineDirective("bool","err",true,"Error"); |
|---|
| 112 |
lines ~= new DefineDirective("String","letter",true,"Letter"); |
|---|
| 113 |
lines ~= new DefineDirective("String","digit",true,"Digit"); |
|---|
| 114 |
lines ~= new DefineDirective("String","hexdigit",true,"Hexdigit"); |
|---|
| 115 |
lines ~= new DefineDirective("String","any",true,"any"); |
|---|
| 116 |
lines ~= new DefineDirective("String","newline",true,"Newline"); |
|---|
| 117 |
lines ~= new DefineDirective("String","sp",true,"Space(s)"); |
|---|
| 118 |
lines ~= new DefineDirective("String","ws",false,"Whitespace"); |
|---|
| 119 |
|
|---|
| 120 |
lines ~= empty; |
|---|
| 121 |
lines ~= new ParseTypeDirective("String"); |
|---|
| 122 |
lines ~= new UTFDirective("8"); |
|---|
| 123 |
|
|---|
| 124 |
lines ~= empty; |
|---|
| 125 |
lines ~= new BaseClassDirective("BaseEnkiParser"); |
|---|
| 126 |
lines ~= new ClassnameDirective("EnkiParser"); |
|---|
| 127 |
|
|---|
| 128 |
// SUPPORT |
|---|
| 129 |
lines ~= empty; |
|---|
| 130 |
lines ~= new Rule("WS", |
|---|
| 131 |
new DefaultPredicate(), |
|---|
| 132 |
new Expression( |
|---|
| 133 |
new Production("ws",null), |
|---|
| 134 |
new OptionalExpr( |
|---|
| 135 |
new Expression( |
|---|
| 136 |
new GroupExpr( |
|---|
| 137 |
new Expression( |
|---|
| 138 |
orExpr( |
|---|
| 139 |
makeTerm(new Production("SlashSlashComment",null)), |
|---|
| 140 |
makeTerm(new Production("SlashStarComment",null)) |
|---|
| 141 |
) |
|---|
| 142 |
), |
|---|
| 143 |
null |
|---|
| 144 |
), |
|---|
| 145 |
new Production("WS",null) |
|---|
| 146 |
), |
|---|
| 147 |
null |
|---|
| 148 |
) |
|---|
| 149 |
) |
|---|
| 150 |
); |
|---|
| 151 |
|
|---|
| 152 |
// SYNTAX |
|---|
| 153 |
lines ~= empty; |
|---|
| 154 |
lines ~= new Rule("Syntax", |
|---|
| 155 |
new FunctionPredicate( |
|---|
| 156 |
new Param(false,"void","createSyntax"), |
|---|
| 157 |
new Param(true,"SyntaxLine","lines") |
|---|
| 158 |
), |
|---|
| 159 |
new Expression( |
|---|
| 160 |
new Production("WS",null), |
|---|
| 161 |
new ZeroOrMoreExpr( |
|---|
| 162 |
new Expression( |
|---|
| 163 |
new GroupExpr( |
|---|
| 164 |
new Expression( |
|---|
| 165 |
orExpr( |
|---|
| 166 |
makeTerm(new Production("Rule",new Binding(true,"lines"))), |
|---|
| 167 |
makeTerm(new Production("Comment",new Binding(true,"lines"))), |
|---|
| 168 |
makeTerm(new Production("Directive",new Binding(true,"lines"))) |
|---|
| 169 |
) |
|---|
| 170 |
), |
|---|
| 171 |
null |
|---|
| 172 |
), |
|---|
| 173 |
new Production("WS",null) |
|---|
| 174 |
), |
|---|
| 175 |
null, |
|---|
| 176 |
new Production("eoi",null) |
|---|
| 177 |
) |
|---|
| 178 |
) |
|---|
| 179 |
); |
|---|
| 180 |
|
|---|
| 181 |
lines ~= empty; |
|---|
| 182 |
lines ~= new Comment(""); |
|---|
| 183 |
lines ~= new Comment(" Rule and Predicate"); |
|---|
| 184 |
lines ~= new Comment(""); |
|---|
| 185 |
|
|---|
| 186 |
//RULE |
|---|
| 187 |
lines ~= new Rule("Rule", |
|---|
| 188 |
new ClassPredicate( |
|---|
| 189 |
"Rule", |
|---|
| 190 |
new Param("name"), |
|---|
| 191 |
new Param("pred"), |
|---|
| 192 |
new Param("expr"), |
|---|
| 193 |
new Param("decl") |
|---|
| 194 |
), |
|---|
| 195 |
new Expression( |
|---|
| 196 |
new Production("Identifier",new Binding(false,"name")), |
|---|
| 197 |
new Production("WS",null), |
|---|
| 198 |
new OptionalExpr( |
|---|
| 199 |
new Expression( |
|---|
| 200 |
new Production("RuleDecl",new Binding(false,"decl")), |
|---|
| 201 |
new Production("WS",null) |
|---|
| 202 |
), |
|---|
| 203 |
null |
|---|
| 204 |
), |
|---|
| 205 |
new OptionalExpr( |
|---|
| 206 |
new Expression( |
|---|
| 207 |
new Production("RulePredicate",new Binding(false,"pred")) |
|---|
| 208 |
), |
|---|
| 209 |
null |
|---|
| 210 |
), |
|---|
| 211 |
new Production("WS",null), |
|---|
| 212 |
new Terminal("::=",null), |
|---|
| 213 |
new Production("WS",null), |
|---|
| 214 |
new Production("Expression",new Binding(false,"expr")), |
|---|
| 215 |
new Production("WS",null), |
|---|
| 216 |
new Terminal(";",null) |
|---|
| 217 |
) |
|---|
| 218 |
); |
|---|
| 219 |
|
|---|
| 220 |
lines ~= new Rule("RuleDecl", |
|---|
| 221 |
new ClassPredicate("RuleDecl",new Param(true,"Param","params")), |
|---|
| 222 |
new Expression( |
|---|
| 223 |
new Production("ParamsExpr",new Binding(false,"params")) |
|---|
| 224 |
) |
|---|
| 225 |
); |
|---|
| 226 |
|
|---|
| 227 |
lines ~= new Rule("RulePredicate", |
|---|
| 228 |
new BindingPredicate(new Param(false,"RulePredicate","pred")), |
|---|
| 229 |
new Expression( |
|---|
| 230 |
new Terminal("=",null), |
|---|
| 231 |
new Production("WS",null), |
|---|
| 232 |
new GroupExpr( |
|---|
| 233 |
new Expression( |
|---|
| 234 |
orExpr( |
|---|
| 235 |
makeTerm(new Production("ClassPredicate",new Binding(false,"pred"))), |
|---|
| 236 |
makeTerm(new Production("FunctionPredicate",new Binding(false,"pred"))), |
|---|
| 237 |
makeTerm(new Production("BindingPredicate",new Binding(false,"pred"))) |
|---|
| 238 |
) |
|---|
| 239 |
), |
|---|
| 240 |
null |
|---|
| 241 |
) |
|---|
| 242 |
) |
|---|
| 243 |
); |
|---|
| 244 |
|
|---|
| 245 |
lines ~= new Rule("ClassPredicate", |
|---|
| 246 |
new ClassPredicate("ClassPredicate", |
|---|
| 247 |
new Param("name"), |
|---|
| 248 |
new Param("params") |
|---|
| 249 |
), |
|---|
| 250 |
new Expression( |
|---|
| 251 |
new Terminal("new",null), |
|---|
| 252 |
new Production("WS",null), |
|---|
| 253 |
new Production("Identifier",new Binding(false,"name")), |
|---|
| 254 |
new Production("WS",null), |
|---|
| 255 |
new Production("ParamsExpr",new Binding(false,"params")) |
|---|
| 256 |
) |
|---|
| 257 |
); |
|---|
| 258 |
|
|---|
| 259 |
lines ~= new Rule("FunctionPredicate", |
|---|
| 260 |
new ClassPredicate("FunctionPredicate", |
|---|
| 261 |
new Param("decl"), |
|---|
| 262 |
new Param("params") |
|---|
| 263 |
), |
|---|
| 264 |
new Expression( |
|---|
| 265 |
new Production("ExplicitParam",new Binding(false,"decl")), |
|---|
| 266 |
new Production("WS",null), |
|---|
| 267 |
new Production("ParamsExpr",new Binding(false,"params")) |
|---|
| 268 |
) |
|---|
| 269 |
); |
|---|
| 270 |
|
|---|
| 271 |
lines ~= new Rule("BindingPredicate", |
|---|
| 272 |
new ClassPredicate("BindingPredicate", |
|---|
| 273 |
new Param("param") |
|---|
| 274 |
), |
|---|
| 275 |
new Expression( |
|---|
| 276 |
new Production("Param",new Binding(false,"param")) |
|---|
| 277 |
) |
|---|
| 278 |
); |
|---|
| 279 |
|
|---|
| 280 |
lines ~= new Rule("ParamsExpr", |
|---|
| 281 |
new BindingPredicate(new Param(true,"Param","params")), |
|---|
| 282 |
new Expression( |
|---|
| 283 |
new Terminal("(",null), |
|---|
| 284 |
new Production("WS",null), |
|---|
| 285 |
new OptionalExpr( |
|---|
| 286 |
new Expression( |
|---|
| 287 |
new Production("Param",new Binding(true,"params")), |
|---|
| 288 |
new Production("WS",null), |
|---|
| 289 |
new ZeroOrMoreExpr( |
|---|
| 290 |
new Expression( |
|---|
| 291 |
new Terminal(",",null), |
|---|
| 292 |
new Production("WS",null), |
|---|
| 293 |
new Production("Param",new Binding(true,"params")), |
|---|
| 294 |
new Production("WS",null) |
|---|
| 295 |
), |
|---|
| 296 |
null, |
|---|
| 297 |
null |
|---|
| 298 |
) |
|---|
| 299 |
), |
|---|
| 300 |
null |
|---|
| 301 |
), |
|---|
| 302 |
new Terminal(")",null) |
|---|
| 303 |
) |
|---|
| 304 |
); |
|---|
| 305 |
|
|---|
| 306 |
lines ~= new Rule("Param", |
|---|
| 307 |
new BindingPredicate(new Param("param")), |
|---|
| 308 |
new Expression( |
|---|
| 309 |
orExpr( |
|---|
| 310 |
makeTerm(new Production("ExplicitParam",new Binding(false,"param"))), |
|---|
| 311 |
makeTerm(new Production("WeakParam",new Binding(false,"param"))) |
|---|
| 312 |
) |
|---|
| 313 |
) |
|---|
| 314 |
); |
|---|
| 315 |
|
|---|
| 316 |
lines ~= new Rule("WeakParam", |
|---|
| 317 |
new ClassPredicate("Param", |
|---|
| 318 |
new Param("name") |
|---|
| 319 |
), |
|---|
| 320 |
new Expression( |
|---|
| 321 |
new Production("Identifier",new Binding(false,"name")) |
|---|
| 322 |
) |
|---|
| 323 |
); |
|---|
| 324 |
|
|---|
| 325 |
lines ~= new Rule("ExplicitParam", |
|---|
| 326 |
new ClassPredicate("Param", |
|---|
| 327 |
new Param(false,"bool","isArray"), |
|---|
| 328 |
new Param("type"), |
|---|
| 329 |
new Param("name") |
|---|
| 330 |
), |
|---|
| 331 |
new Expression( |
|---|
| 332 |
new Production("Identifier",new Binding(false,"type")), |
|---|
| 333 |
new Production("WS",null), |
|---|
| 334 |
new OptionalExpr( |
|---|
| 335 |
new Expression( |
|---|
| 336 |
new Terminal("[]",new Binding(false,"isArray")), |
|---|
| 337 |
new Production("Brackets",null), |
|---|
| 338 |
new Production("WS",null) |
|---|
| 339 |
), |
|---|
| 340 |
null |
|---|
| 341 |
), |
|---|
| 342 |
new Production("Identifier",new Binding(false,"name")) |
|---|
| 343 |
) |
|---|
| 344 |
); |
|---|
| 345 |
|
|---|
| 346 |
lines ~= new Rule("Brackets", |
|---|
| 347 |
new DefaultPredicate(), |
|---|
| 348 |
new Expression( |
|---|
| 349 |
new OptionalExpr( |
|---|
| 350 |
new Expression( |
|---|
| 351 |
new Terminal("[]",null), |
|---|
| 352 |
new Production("Brackets",null) |
|---|
| 353 |
), |
|---|
| 354 |
null |
|---|
| 355 |
) |
|---|
| 356 |
) |
|---|
| 357 |
); |
|---|
| 358 |
|
|---|
| 359 |
lines ~= new Comment(""); |
|---|
| 360 |
lines ~= new Comment(" Expressions"); |
|---|
| 361 |
lines ~= new Comment(""); |
|---|
| 362 |
|
|---|
| 363 |
lines ~= new Rule("Expression", |
|---|
| 364 |
new ClassPredicate("Expression", |
|---|
| 365 |
new Param(true,"Term","terms") |
|---|
| 366 |
), |
|---|
| 367 |
new Expression( |
|---|
| 368 |
new Production("Term",new Binding(true,"terms")), |
|---|
| 369 |
new Production("WS",null), |
|---|
| 370 |
new ZeroOrMoreExpr( |
|---|
| 371 |
new Expression( |
|---|
| 372 |
new Terminal("|",null), |
|---|
| 373 |
new Production("WS",null), |
|---|
| 374 |
new Production("Term",new Binding(true,"terms")), |
|---|
| 375 |
new Production("WS",null) |
|---|
| 376 |
), |
|---|
| 377 |
null, |
|---|
| 378 |
null |
|---|
| 379 |
) |
|---|
| 380 |
) |
|---|
| 381 |
); |
|---|
| 382 |
|
|---|
| 383 |
|
|---|
| 384 |
lines ~= new Rule("Term", |
|---|
| 385 |
new BindingPredicate(new Param(true,"SubExpression","factors")), |
|---|
| 386 |
new Expression( |
|---|
| 387 |
new Production("SubExpression",new Binding(true,"factors")), |
|---|
| 388 |
new Production("WS",null), |
|---|
| 389 |
new ZeroOrMoreExpr( |
|---|
| 390 |
new Expression( |
|---|
| 391 |
new Production("SubExpression",new Binding(true,"factors")), |
|---|
| 392 |
new Production("WS",null) |
|---|
| 393 |
), |
|---|
| 394 |
null, |
|---|
| 395 |
null |
|---|
| 396 |
) |
|---|
| 397 |
) |
|---|
| 398 |
); |
|---|
| 399 |
|
|---|
| 400 |
lines ~= new Rule("SubExpression", |
|---|
| 401 |
new BindingPredicate(new Param(false,"SubExpression","expr")), |
|---|
| 402 |
new Expression( |
|---|
| 403 |
orExpr( |
|---|
| 404 |
makeTerm(new Production("Production",new Binding(false,"expr"))), |
|---|
| 405 |
makeTerm(new Production("Substitution",new Binding(false,"expr"))), |
|---|
| 406 |
makeTerm(new Production("Terminal",new Binding(false,"expr"))), |
|---|
| 407 |
makeTerm(new Production("Range",new Binding(false,"expr"))), |
|---|
| 408 |
makeTerm(new Production("Regexp",new Binding(false,"expr"))), |
|---|
| 409 |
makeTerm(new Production("GroupExpr",new Binding(false,"expr"))), |
|---|
| 410 |
makeTerm(new Production("OptionalExpr",new Binding(false,"expr"))), |
|---|
| 411 |
makeTerm(new Production("ZeroOrMoreExpr",new Binding(false,"expr"))), |
|---|
| 412 |
makeTerm(new Production("NegateExpr",new Binding(false,"expr"))), |
|---|
| 413 |
makeTerm(new Production("TestExpr",new Binding(false,"expr"))), |
|---|
| 414 |
makeTerm(new Production("LiteralExpr",new Binding(false,"expr"))), |
|---|
| 415 |
makeTerm(new Production("CustomTerminal",new Binding(false,"expr"))) |
|---|
| 416 |
) |
|---|
| 417 |
) |
|---|
| 418 |
); |
|---|
| 419 |
|
|---|
| 420 |
lines ~= new Rule("Production", |
|---|
| 421 |
new ClassPredicate("Production", |
|---|
| 422 |
new Param("name"), |
|---|
| 423 |
new Param("binding"), |
|---|
| 424 |
new Param(true,"ProductionArg","args") |
|---|
| 425 |
), |
|---|
| 426 |
new Expression( |
|---|
| 427 |
new Production("Identifier",new Binding(false,"name")), |
|---|
| 428 |
new Production("WS",null), |
|---|
| 429 |
new OptionalExpr( |
|---|
| 430 |
new Expression( |
|---|
| 431 |
new Terminal("!(",null), |
|---|
| 432 |
new Production("WS",null), |
|---|
| 433 |
new Production("ProductionArg",new Binding(true,"args")), |
|---|
| 434 |
new ZeroOrMoreExpr( |
|---|
| 435 |
new Expression( |
|---|
| 436 |
new Production("WS",null), |
|---|
| 437 |
new Terminal(",",null), |
|---|
| 438 |
new Production("WS",null), |
|---|
| 439 |
new Production("ProductionArg",new Binding(true,"args")) |
|---|
| 440 |
), |
|---|
| 441 |
null, |
|---|
| 442 |
new Terminal(")",null) |
|---|
| 443 |
) |
|---|
| 444 |
), |
|---|
| 445 |
null |
|---|
| 446 |
), |
|---|
| 447 |
new OptionalExpr( |
|---|
| 448 |
new Expression( |
|---|
| 449 |
new Production("Binding",new Binding(false,"binding")) |
|---|
| 450 |
), |
|---|
| 451 |
null |
|---|
| 452 |
) |
|---|
| 453 |
) |
|---|
| 454 |
); |
|---|
| 455 |
|
|---|
| 456 |
lines ~= new Rule("ProductionArg", |
|---|
| 457 |
new BindingPredicate(new Param(false,"ProductionArg","arg")), |
|---|
| 458 |
new Expression( |
|---|
| 459 |
orExpr( |
|---|
| 460 |
makeTerm(new Production("StringProductionArg",new Binding(false,"arg"))), |
|---|
| 461 |
makeTerm(new Production("BindingProductionArg",new Binding(false,"arg"))) |
|---|
| 462 |
) |
|---|
| 463 |
) |
|---|
| 464 |
); |
|---|
| 465 |
|
|---|
| 466 |
lines ~= new Rule("StringProductionArg", |
|---|
| 467 |
new ClassPredicate("StringProductionArg",new Param(false,"String","value")), |
|---|
| 468 |
new Expression( |
|---|
| 469 |
new Production("String",new Binding(false,"value")) |
|---|
| 470 |
) |
|---|
| 471 |
); |
|---|
| 472 |
|
|---|
| 473 |
|
|---|
| 474 |
lines ~= new Rule("BindingProductionArg", |
|---|
| 475 |
new ClassPredicate("BindingProductionArg",new Param(false,"String","value")), |
|---|
| 476 |
new Expression( |
|---|
| 477 |
new Production("Identifier",new Binding(false,"value")) |
|---|
| 478 |
) |
|---|
| 479 |
); |
|---|
| 480 |
|
|---|
| 481 |
lines ~= new Rule("Substitution", |
|---|
| 482 |
new ClassPredicate("Substitution", |
|---|
| 483 |
new Param(false,"String","name"), |
|---|
| 484 |
new Param(false,"Binding","binding") |
|---|
| 485 |
), |
|---|
| 486 |
new Expression( |
|---|
| 487 |
new Terminal(".",null), |
|---|
| 488 |
new Production("Identifier",new Binding(false,"name")), |
|---|
| 489 |
new Production("WS",null), |
|---|
| 490 |
new OptionalExpr( |
|---|
| 491 |
new Expression( |
|---|
| 492 |
new Production("Binding",new Binding(false,"binding")) |
|---|
| 493 |
), |
|---|
| 494 |
null |
|---|
| 495 |
) |
|---|
| 496 |
) |
|---|
| 497 |
); |
|---|
| 498 |
|
|---|
| 499 |
lines ~= new Rule("GroupExpr", |
|---|
| 500 |
new ClassPredicate("GroupExpr", |
|---|
| 501 |
new Param("expr"), |
|---|
| 502 |
new Param("binding") |
|---|
| 503 |
), |
|---|
| 504 |
new Expression( |
|---|
| 505 |
new Terminal("(",null), |
|---|
| 506 |
new Production("WS",null), |
|---|
| 507 |
new Production("Expression",new Binding(false,"expr")), |
|---|
| 508 |
new Production("WS",null), |
|---|
| 509 |
new Terminal(")",null), |
|---|
| 510 |
new Production("WS",null), |
|---|
| 511 |
new OptionalExpr( |
|---|
| 512 |
new Expression( |
|---|
| 513 |
new Production("Binding",new Binding(false,"binding")) |
|---|
| 514 |
), |
|---|
| 515 |
null |
|---|
| 516 |
) |
|---|
| 517 |
) |
|---|
| 518 |
); |
|---|
| 519 |
|
|---|
| 520 |
lines ~= new Rule("OptionalExpr", |
|---|
| 521 |
new ClassPredicate("OptionalExpr", |
|---|
| 522 |
new Param("expr"), |
|---|
| 523 |
new Param("binding") |
|---|
| 524 |
), |
|---|
| 525 |
new Expression( |
|---|
| 526 |
new Terminal("[",null), |
|---|
| 527 |
new Production("WS",null), |
|---|
| 528 |
new Production("Expression",new Binding(false,"expr")), |
|---|
| 529 |
new Production("WS",null), |
|---|
| 530 |
new Terminal("]",null), |
|---|
| 531 |
new Production("WS",null), |
|---|
| 532 |
new OptionalExpr( |
|---|
| 533 |
new Expression( |
|---|
| 534 |
new Production("Binding",new Binding(false,"binding")) |
|---|
| 535 |
), |
|---|
| 536 |
null |
|---|
| 537 |
) |
|---|
| 538 |
) |
|---|
| 539 |
); |
|---|
| 540 |
|
|---|
| 541 |
lines ~= new Rule("ZeroOrMoreExpr", |
|---|
| 542 |
new ClassPredicate("ZeroOrMoreExpr", |
|---|
| 543 |
new Param("expr"), |
|---|
| 544 |
new Param("binding"), |
|---|
| 545 |
new Param("term") |
|---|
| 546 |
), |
|---|
| 547 |
new Expression( |
|---|
| 548 |
new Terminal("{",null), |
|---|
| 549 |
new Production("WS",null), |
|---|
| 550 |
new Production("Expression",new Binding(false,"expr")), |
|---|
| 551 |
new Production("WS",null), |
|---|
| 552 |
new Terminal("}",null), |
|---|
| 553 |
new Production("WS",null), |
|---|
| 554 |
new OptionalExpr( |
|---|
| 555 |
new Expression( |
|---|
| 556 |
new Production("Binding",new Binding(false,"binding")), |
|---|
| 557 |
new Production("WS",null) |
|---|
| 558 |
), |
|---|
| 559 |
null |
|---|
| 560 |
), |
|---|
| 561 |
new OptionalExpr( |
|---|
| 562 |
new Expression( |
|---|
| 563 |
new Production("SubExpression",new Binding(false,"term")) |
|---|
| 564 |
), |
|---|
| 565 |
null |
|---|
| 566 |
) |
|---|
| 567 |
) |
|---|
| 568 |
); |
|---|
| 569 |
|
|---|
| 570 |
lines ~= new Rule("Terminal", |
|---|
| 571 |
new ClassPredicate("Terminal", |
|---|
| 572 |
new Param("text"), |
|---|
| 573 |
new Param("binding") |
|---|
| 574 |
), |
|---|
| 575 |
new Expression( |
|---|
| 576 |
new Production("String",new Binding(false,"text")), |
|---|
| 577 |
new Production("WS",null), |
|---|
| 578 |
new OptionalExpr( |
|---|
| 579 |
new Expression( |
|---|
| 580 |
new Production("Binding",new Binding(false,"binding")) |
|---|
| 581 |
), |
|---|
| 582 |
null |
|---|
| 583 |
) |
|---|
| 584 |
) |
|---|
| 585 |
); |
|---|
| 586 |
|
|---|
| 587 |
lines ~= new Rule("Range", |
|---|
| 588 |
new ClassPredicate("Range", |
|---|
| 589 |
new Param("start"), |
|---|
| 590 |
new Param("end"), |
|---|
| 591 |
new Param("binding") |
|---|
| 592 |
), |
|---|
| 593 |
new Expression( |
|---|
| 594 |
new Production("HexExpr",new Binding(false,"start")), |
|---|
| 595 |
new Production("WS",null), |
|---|
| 596 |
new OptionalExpr( |
|---|
| 597 |
new Expression( |
|---|
| 598 |
new Terminal("-",null), |
|---|
| 599 |
new Production("WS",null), |
|---|
| 600 |
new Production("HexExpr",new Binding(false,"end")), |
|---|
| 601 |
new Production("WS",null) |
|---|
| 602 |
), |
|---|
| 603 |
null |
|---|
| 604 |
), |
|---|
| 605 |
new OptionalExpr( |
|---|
| 606 |
new Expression( |
|---|
| 607 |
new Production("Binding",new Binding(false,"binding")) |
|---|
| 608 |
), |
|---|
| 609 |
null |
|---|
| 610 |
) |
|---|
| 611 |
) |
|---|
| 612 |
); |
|---|
| 613 |
|
|---|
| 614 |
lines ~= new Rule("Regexp", |
|---|
| 615 |
new ClassPredicate("Regexp", |
|---|
| 616 |
new Param("text"), |
|---|
| 617 |
new Param("binding") |
|---|
| 618 |
), |
|---|
| 619 |
new Expression( |
|---|
| 620 |
new GroupExpr( |
|---|
| 621 |
new Expression( |
|---|
| 622 |
orExpr( |
|---|
| 623 |
makeTerm( |
|---|
| 624 |
new Terminal("r",null), |
|---|
| 625 |
new Production("String",new Binding(false,"text")) |
|---|
| 626 |
), |
|---|
| 627 |
makeTerm( |
|---|
| 628 |
new Terminal("`",null), |
|---|
| 629 |
new ZeroOrMoreExpr( |
|---|
| 630 |
new Expression( |
|---|
| 631 |
new Production("any",null) |
|---|
| 632 |
), |
|---|
| 633 |
new Binding(false,"text"), |
|---|
| 634 |
new Terminal("`",null) |
|---|
| 635 |
) |
|---|
| 636 |
) |
|---|
| 637 |
) |
|---|
| 638 |
), |
|---|
| 639 |
null |
|---|
| 640 |
), |
|---|
| 641 |
new Production("WS",null), |
|---|
| 642 |
new OptionalExpr( |
|---|
| 643 |
new Expression( |
|---|
| 644 |
new Production("Binding",new Binding(false,"binding")) |
|---|
| 645 |
), |
|---|
| 646 |
null |
|---|
| 647 |
) |
|---|
| 648 |
) |
|---|
| 649 |
); |
|---|
| 650 |
|
|---|
| 651 |
lines ~= new Rule("NegateExpr", |
|---|
| 652 |
new ClassPredicate("Negate", |
|---|
| 653 |
new Param(false,"SubExpression","expr") |
|---|
| 654 |
), |
|---|
| 655 |
new Expression( |
|---|
| 656 |
new Terminal("!",null), |
|---|
| 657 |
new Production("WS",null), |
|---|
| 658 |
new Production("SubExpression",new Binding(false,"expr")) |
|---|
| 659 |
) |
|---|
| 660 |
); |
|---|
| 661 |
|
|---|
| 662 |
lines ~= new Rule("TestExpr", |
|---|
| 663 |
new ClassPredicate("Test", |
|---|
| 664 |
new Param(false,"SubExpression","expr") |
|---|
| 665 |
), |
|---|
| 666 |
new Expression( |
|---|
| 667 |
new Terminal("/",null), |
|---|
| 668 |
new Production("WS",null), |
|---|
| 669 |
new Production("SubExpression",new Binding(false,"expr")) |
|---|
| 670 |
) |
|---|
| 671 |
); |
|---|
| 672 |
|
|---|
| 673 |
lines ~= new Rule("LiteralExpr", |
|---|
| 674 |
new ClassPredicate("LiteralExpr", |
|---|
| 675 |
new Param(false,"String","name"), |
|---|
| 676 |
new Param(false,"Binding","binding"), |
|---|
| 677 |
new Param(true,"ProductionArg","args") |
|---|
| 678 |
), |
|---|
| 679 |
new Expression( |
|---|
| 680 |
new Terminal("@",null), |
|---|
| 681 |
new Production("Identifier",new Binding(false,"name")), |
|---|
| 682 |
new Production("WS",null), |
|---|
| 683 |
new OptionalExpr( |
|---|
| 684 |
new Expression( |
|---|
| 685 |
new Terminal("!(",null), |
|---|
| 686 |
new Production("WS",null), |
|---|
| 687 |
new Production("ProductionArg",new Binding(true,"args")), |
|---|
| 688 |
new ZeroOrMoreExpr( |
|---|
| 689 |
new Expression( |
|---|
| 690 |
new Production("WS",null), |
|---|
| 691 |
new Terminal(",",null), |
|---|
| 692 |
new Production("WS",null), |
|---|
| 693 |
new Production("ProductionArg",new Binding(true,"args")) |
|---|
| 694 |
), |
|---|
| 695 |
null, |
|---|
| 696 |
new Terminal(")",null) |
|---|
| 697 |
) |
|---|
| 698 |
), |
|---|
| 699 |
null |
|---|
| 700 |
), |
|---|
| 701 |
new OptionalExpr( |
|---|
| 702 |
new Expression( |
|---|
| 703 |
new Production("Binding",new Binding(false,"binding")) |
|---|
| 704 |
), |
|---|
| 705 |
null |
|---|
| 706 |
) |
|---|
| 707 |
) |
|---|
| 708 |
); |
|---|
| 709 |
|
|---|
| 710 |
lines ~= new Rule("CustomTerminal", |
|---|
| 711 |
new ClassPredicate("CustomTerminal", |
|---|
| 712 |
new Param(false,"String","name"), |
|---|
| 713 |
new Param(false,"Binding","binding") |
|---|
| 714 |
), |
|---|
| 715 |
new Expression( |
|---|
| 716 |
new Terminal("&",null), |
|---|
| 717 |
new Production("Identifier",new Binding(false,"name")), |
|---|
| 718 |
new Production("WS",null), |
|---|
| 719 |
new OptionalExpr( |
|---|
| 720 |
new Expression( |
|---|
| 721 |
new Production("Binding",new Binding(false,"binding")) |
|---|
| 722 |
), |
|---|
| 723 |
null |
|---|
| 724 |
) |
|---|
| 725 |
) |
|---|
| 726 |
); |
|---|
| 727 |
lines ~= new Rule("Binding", |
|---|
| 728 |
new ClassPredicate("Binding", |
|---|
| 729 |
new Param(false,"bool","isConcat"), |
|---|
| 730 |
new Param("name") |
|---|
| 731 |
), |
|---|
| 732 |
new Expression( |
|---|
| 733 |
new Terminal(":",null), |
|---|
| 734 |
new Production("WS",null), |
|---|
| 735 |
new OptionalExpr( |
|---|
| 736 |
new Expression( |
|---|
| 737 |
new Terminal("~",null) |
|---|
| 738 |
), |
|---|
| 739 |
new Binding(false,"isConcat") |
|---|
| 740 |
), |
|---|
| 741 |
new Production("WS",null), |
|---|
| 742 |
new Production("Identifier",new Binding(false,"name")) |
|---|
| 743 |
) |
|---|
| 744 |
); |
|---|
| 745 |
|
|---|
| 746 |
lines ~= new Rule("Identifier", |
|---|
| 747 |
new BindingPredicate(new Param("value")), |
|---|
| 748 |
new Expression( |
|---|
| 749 |
new GroupExpr( |
|---|
| 750 |
new Expression( |
|---|
| 751 |
new Production("IdentifierStartChar",null), |
|---|
| 752 |
new ZeroOrMoreExpr( |
|---|
| 753 |
new Expression( |
|---|
| 754 |
new Production("IdentifierChar",null) |
|---|
| 755 |
), |
|---|
| 756 |
null, |
|---|
| 757 |
null |
|---|
| 758 |
) |
|---|
| 759 |
), |
|---|
| 760 |
new Binding(false,"value") |
|---|
| 761 |
) |
|---|
| 762 |
) |
|---|
| 763 |
); |
|---|
| 764 |
|
|---|
| 765 |
lines ~= new Rule("IdentifierStartChar", |
|---|
| 766 |
new BindingPredicate(new Param("text")), |
|---|
| 767 |
new Expression( |
|---|
| 768 |
new GroupExpr( |
|---|
| 769 |
new Expression( |
|---|
| 770 |
orExpr( |
|---|
| 771 |
makeTerm(new Production("letter",null)), |
|---|
| 772 |
makeTerm(new Terminal("_",null)) |
|---|
| 773 |
) |
|---|
| 774 |
), |
|---|
| 775 |
new Binding(false,"text") |
|---|
| 776 |
) |
|---|
| 777 |
) |
|---|
| 778 |
); |
|---|
| 779 |
|
|---|
| 780 |
lines ~= new Rule("IdentifierChar", |
|---|
| 781 |
new BindingPredicate(new Param("text")), |
|---|
| 782 |
new Expression( |
|---|
| 783 |
new GroupExpr( |
|---|
| 784 |
new Expression( |
|---|
| 785 |
orExpr( |
|---|
| 786 |
makeTerm(new Production("letter",null)), |
|---|
| 787 |
makeTerm(new Production("digit",null)), |
|---|
| 788 |
makeTerm(new Terminal("_",null)), |
|---|
| 789 |
makeTerm(new Terminal(".",null)) |
|---|
| 790 |
) |
|---|
| 791 |
), |
|---|
| 792 |
new Binding(false,"text") |
|---|
| 793 |
) |
|---|
| 794 |
) |
|---|
| 795 |
); |
|---|
| 796 |
|
|---|
| 797 |
lines ~= new Rule("String", |
|---|
| 798 |
new BindingPredicate(new Param("text")), |
|---|
| 799 |
new Expression( |
|---|
| 800 |
new GroupExpr( |
|---|
| 801 |
new Expression( |
|---|
| 802 |
orExpr( |
|---|
| 803 |
makeTerm(new Terminal("\\\"",null)), |
|---|
| 804 |
makeTerm(new Terminal("\\\'",null)) |
|---|
| 805 |
) |
|---|
| 806 |
), |
|---|
| 807 |
new Binding(true,"delim") |
|---|
| 808 |
), |
|---|
| 809 |
new ZeroOrMoreExpr( |
|---|
| 810 |
new Expression( |
|---|
| 811 |
new Production("AnyChar",null) |
|---|
| 812 |
), |
|---|
| 813 |
new Binding(false,"text"), |
|---|
| 814 |
new Substitution("delim",null) |
|---|
| 815 |
) |
|---|
| 816 |
) |
|---|
| 817 |
); |
|---|
| 818 |
|
|---|
| 819 |
lines ~= new Rule("HexExpr", |
|---|
| 820 |
new BindingPredicate(new Param(false,"String","text")), |
|---|
| 821 |
new Expression( |
|---|
| 822 |
new Terminal("#",null), |
|---|
| 823 |
new GroupExpr( |
|---|
| 824 |
new Expression( |
|---|
| 825 |
new Production("hexdigit",null), |
|---|
| 826 |
new Production("hexdigit",null), |
|---|
| 827 |
new OptionalExpr( |
|---|
| 828 |
new Expression( |
|---|
| 829 |
new Production("hexdigit",null), |
|---|
| 830 |
new Production("hexdigit",null), |
|---|
| 831 |
new OptionalExpr( |
|---|
| 832 |
new Expression( |
|---|
| 833 |
new Production("hexdigit",null), |
|---|
| 834 |
new Production("hexdigit",null), |
|---|
| 835 |
new Production("hexdigit",null), |
|---|
| 836 |
new Production("hexdigit",null), |
|---|
| 837 |
new OptionalExpr( |
|---|
| 838 |
new Expression( |
|---|
| 839 |
new Production("hexdigit",null), |
|---|
| 840 |
new Production("hexdigit",null), |
|---|
| 841 |
new Production("hexdigit",null), |
|---|
| 842 |
new Production("hexdigit",null), |
|---|
| 843 |
new Production("hexdigit",null), |
|---|
| 844 |
new Production("hexdigit",null), |
|---|
| 845 |
new Production("hexdigit",null), |
|---|
| 846 |
new Production("hexdigit",null) |
|---|
| 847 |
), |
|---|
| 848 |
null |
|---|
| 849 |
) |
|---|
| 850 |
), |
|---|
| 851 |
null |
|---|
| 852 |
) |
|---|
| 853 |
), |
|---|
| 854 |
null |
|---|
| 855 |
) |
|---|
| 856 |
), |
|---|
| 857 |
new Binding(false,"text") |
|---|
| 858 |
) |
|---|
| 859 |
) |
|---|
| 860 |
); |
|---|
| 861 |
|
|---|
| 862 |
lines ~= new Rule("AnyChar", |
|---|
| 863 |
new BindingPredicate(new Param("value")), |
|---|
| 864 |
new Expression( |
|---|
| 865 |
new OptionalExpr( |
|---|
| 866 |
new Expression( |
|---|
| 867 |
new Terminal("\\\\",new Binding(true,"value")) |
|---|
| 868 |
), |
|---|
| 869 |
null |
|---|
| 870 |
), |
|---|
| 871 |
new Production("any",new Binding(true,"value")) |
|---|
| 872 |
) |
|---|
| 873 |
); |
|---|
| 874 |
|
|---|
| 875 |
lines ~= empty; |
|---|
| 876 |
lines ~= new Comment(""); |
|---|
| 877 |
lines ~= new Comment(" Comments"); |
|---|
| 878 |
lines ~= new Comment(""); |
|---|
| 879 |
|
|---|
| 880 |
lines ~= empty; |
|---|
| 881 |
lines ~= new Rule("Comment", |
|---|
| 882 |
new ClassPredicate("Comment",new Param("text")), |
|---|
| 883 |
new Expression( |
|---|
| 884 |
orExpr( |
|---|
| 885 |
makeTerm(new Production("PoundComment",new Binding(false,"text"))), |
|---|
| 886 |
makeTerm(new Production("SlashSlashComment",new Binding(false,"text"))), |
|---|
| 887 |
makeTerm(new Production("SlashStarComment",new Binding(false,"text"))) |
|---|
| 888 |
) |
|---|
| 889 |
) |
|---|
| 890 |
); |
|---|
| 891 |
|
|---|
| 892 |
lines ~= new Rule("PoundComment", |
|---|
| 893 |
new BindingPredicate(new Param(false,"String","text")), |
|---|
| 894 |
new Expression( |
|---|
| 895 |
new Terminal("#",null), |
|---|
| 896 |
new ZeroOrMoreExpr( |
|---|
| 897 |
new Expression( |
|---|
| 898 |
new Production("any",null) |
|---|
| 899 |
), |
|---|
| 900 |
new Binding(false,"text"), |
|---|
| 901 |
new Production("eol",null) |
|---|
| 902 |
) |
|---|
| 903 |
) |
|---|
| 904 |
); |
|---|
| 905 |
|
|---|
| 906 |
lines ~= new Rule("SlashSlashComment", |
|---|
| 907 |
new BindingPredicate(new Param(false,"String","text")), |
|---|
| 908 |
new Expression( |
|---|
| 909 |
new Terminal("\\x2F\\x2F",null), |
|---|
| 910 |
new ZeroOrMoreExpr( |
|---|
| 911 |
new Expression( |
|---|
| 912 |
new Production("any",null) |
|---|
| 913 |
), |
|---|
| 914 |
new Binding(false,"text"), |
|---|
| 915 |
new Production("eol",null) |
|---|
| 916 |
) |
|---|
| 917 |
) |
|---|
| 918 |
); |
|---|
| 919 |
|
|---|
| 920 |
lines ~= new Rule("SlashStarComment", |
|---|
| 921 |
new BindingPredicate(new Param(false,"String","text")), |
|---|
| 922 |
new Expression( |
|---|
| 923 |
new Terminal("\\x2F\\x2A",null), |
|---|
| 924 |
new ZeroOrMoreExpr( |
|---|
| 925 |
new Expression( |
|---|
| 926 |
new Production("any",null) |
|---|
| 927 |
), |
|---|
| 928 |
new Binding(false,"text"), |
|---|
| 929 |
new Terminal("\\x2A\\x2F",null) |
|---|
| 930 |
) |
|---|
| 931 |
) |
|---|
| 932 |
); |
|---|
| 933 |
|
|---|
| 934 |
lines ~= empty; |
|---|
| 935 |
lines ~= new Comment(""); |
|---|
| 936 |
lines ~= new Comment(" Directives"); |
|---|
| 937 |
lines ~= new Comment(""); |
|---|
| 938 |
|
|---|
| 939 |
lines ~= new Rule("Directive", |
|---|
| 940 |
new BindingPredicate(new Param(false,"Directive","dir")), |
|---|
| 941 |
new Expression( |
|---|
| 942 |
new Terminal(".",null), |
|---|
| 943 |
new GroupExpr( |
|---|
| 944 |
new Expression( |
|---|
| 945 |
orExpr( |
|---|
| 946 |
makeTerm(new Production("ImportDirective",new Binding(true,"dir"))), |
|---|
| 947 |
makeTerm(new Production("BaseClassDirective",new Binding(true,"dir"))), |
|---|
| 948 |
makeTerm(new Production("ClassnameDirective",new Binding(true,"dir"))), |
|---|
| 949 |
makeTerm(new Production("DefineDirective",new Binding(true,"dir"))), |
|---|
| 950 |
makeTerm(new Production("IncludeDirective",new Binding(true,"dir"))), |
|---|
| 951 |
makeTerm(new Production("AliasDirective",new Binding(true,"dir"))), |
|---|
| 952 |
makeTerm(new Production("ModuleDirective",new Binding(true,"dir"))), |
|---|
| 953 |
makeTerm(new Production("CodeDirective",new Binding(true,"dir"))), |
|---|
| 954 |
makeTerm(new Production("TypelibDirective",new Binding(true,"dir"))), |
|---|
| 955 |
makeTerm(new Production("ParseTypeDirective",new Binding(true,"dir"))), |
|---|
| 956 |
makeTerm(new Production("BoilerplateDirective",new Binding(true,"dir"))), |
|---|
| 957 |
makeTerm(new Production("HeaderDirective",new Binding(true,"dir"))), |
|---|
| 958 |
makeTerm(new Production("UTFDirective",new Binding(true,"dir"))) |
|---|
| 959 |
) |
|---|
| 960 |
), |
|---|
| 961 |
null |
|---|
| 962 |
) |
|---|
| 963 |
) |
|---|
| 964 |
); |
|---|
| 965 |
|
|---|
| 966 |
lines ~= new Rule("ImportDirective", |
|---|
| 967 |
new ClassPredicate("ImportDirective", new Param("imp")), |
|---|
| 968 |
new Expression( |
|---|
| 969 |
new Terminal("import",null), |
|---|
| 970 |
new Production("WS",null), |
|---|
| 971 |
new Terminal("(",null), |
|---|
| 972 |
new Production("WS",null), |
|---|
| 973 |
new Production("DirectiveArg",new Binding(false,"imp")), |
|---|
| 974 |
new Production("WS",null), |
|---|
| 975 |
new Terminal(")",null), |
|---|
| 976 |
new Production("WS",null), |
|---|
| 977 |
new Terminal(";",null) |
|---|
| 978 |
) |
|---|
| 979 |
); |
|---|
| 980 |
|
|---|
| 981 |
lines ~= new Rule("BaseClassDirective", |
|---|
| 982 |
new ClassPredicate("BaseClassDirective", new Param("name")), |
|---|
| 983 |
new Expression( |
|---|
| 984 |
new Terminal("baseclass",null), |
|---|
| 985 |
new Production("WS",null), |
|---|
| 986 |
new Terminal("(",null), |
|---|
| 987 |
new Production("WS",null), |
|---|
| 988 |
new Production("DirectiveArg",new Binding(false,"name")), |
|---|
| 989 |
new Production("WS",null), |
|---|
| 990 |
new Terminal(")",null), |
|---|
| 991 |
new Production("WS",null), |
|---|
| 992 |
new Terminal(";",null) |
|---|
| 993 |
) |
|---|
| 994 |
); |
|---|
| 995 |
|
|---|
| 996 |
lines ~= new Rule("ClassnameDirective", |
|---|
| 997 |
new ClassPredicate("ClassnameDirective", new Param("name")), |
|---|
| 998 |
new Expression( |
|---|
| 999 |
new Terminal("classname",null), |
|---|
| 1000 |
new Production("WS",null), |
|---|
| 1001 |
new Terminal("(",null), |
|---|
| 1002 |
new Production("WS",null), |
|---|
| 1003 |
new Production("DirectiveArg",new Binding(false,"name")), |
|---|
| 1004 |
new Production("WS",null), |
|---|
| 1005 |
new Terminal(")",null), |
|---|
| 1006 |
new Production("WS",null), |
|---|
| 1007 |
new Terminal(";",null) |
|---|
| 1008 |
) |
|---|
| 1009 |
); |
|---|
| 1010 |
|
|---|
| 1011 |
lines ~= new Rule("DefineDirective", |
|---|
| 1012 |
new ClassPredicate("DefineDirective", |
|---|
| 1013 |
new Param("returnType"), |
|---|
| 1014 |
new Param("name"), |
|---|
| 1015 |
new Param(false,"bool","isTerminal"), |
|---|
| 1016 |
new Param("description") |
|---|
| 1017 |
), |
|---|
| 1018 |
new Expression( |
|---|
| 1019 |
new Terminal("define",null), |
|---|
| 1020 |
new Production("WS",null), |
|---|
| 1021 |
new Terminal("(",null), |
|---|
| 1022 |
new Production("WS",null), |
|---|
| 1023 |
new Production("DirectiveArg",new Binding(false,"returnType")), |
|---|
| 1024 |
new Production("WS",null), |
|---|
| 1025 |
|
|---|
| 1026 |
new Terminal(",",null), |
|---|
| 1027 |
new Production("WS",null), |
|---|
| 1028 |
new Production("DirectiveArg",new Binding(false,"name")), |
|---|
| 1029 |
new Production("WS",null), |
|---|
| 1030 |
|
|---|
| 1031 |
new Terminal(",",null), |
|---|
| 1032 |
new Production("WS",null), |
|---|
| 1033 |
new Production("DirectiveArg",new Binding(false,"isTerminal")), |
|---|
| 1034 |
new Production("WS",null), |
|---|
| 1035 |
|
|---|
| 1036 |
new OptionalExpr( |
|---|
| 1037 |
new Expression( |
|---|
| 1038 |
new Terminal(",",null), |
|---|
| 1039 |
new Production("WS",null), |
|---|
| 1040 |
new Production("DirectiveArg",new Binding(false,"description")), |
|---|
| 1041 |
new Production("WS",null) |
|---|
| 1042 |
), |
|---|
| 1043 |
null |
|---|
| 1044 |
), |
|---|
| 1045 |
new Terminal(")",null), |
|---|
| 1046 |
new Production("WS",null), |
|---|
| 1047 |
new Terminal(";",null) |
|---|
| 1048 |
) |
|---|
| 1049 |
); |
|---|
| 1050 |
|
|---|
| 1051 |
lines ~= new Rule("IncludeDirective", |
|---|
| 1052 |
new ClassPredicate("IncludeDirective", new Param("filename")), |
|---|
| 1053 |
new Expression( |
|---|
| 1054 |
new Terminal("include",null), |
|---|
| 1055 |
new Production("WS",null), |
|---|
| 1056 |
new Terminal("(",null), |
|---|
| 1057 |
new Production("WS",null), |
|---|
| 1058 |
new Production("String",new Binding(false,"filename")), |
|---|
| 1059 |
new Production("WS",null), |
|---|
| 1060 |
new Terminal(")",null), |
|---|
| 1061 |
new Production("WS",null), |
|---|
| 1062 |
new Terminal(";",null) |
|---|
| 1063 |
) |
|---|
| 1064 |
); |
|---|
| 1065 |
|
|---|
| 1066 |
lines ~= new Rule("AliasDirective", |
|---|
| 1067 |
new ClassPredicate("AliasDirective", |
|---|
| 1068 |
new Param("rule"), |
|---|
| 1069 |
new Param("ruleAlias") |
|---|
| 1070 |
), |
|---|
| 1071 |
new Expression( |
|---|
| 1072 |
new Terminal("alias",null), |
|---|
| 1073 |
new Production("WS",null), |
|---|
| 1074 |
new Terminal("(",null), |
|---|
| 1075 |
new Production("WS",null), |
|---|
| 1076 |
new Production("DirectiveArg",new Binding(false,"rule")), |
|---|
| 1077 |
new Production("WS",null), |
|---|
| 1078 |
new Terminal(",",null), |
|---|
| 1079 |
new Production("WS",null), |
|---|
| 1080 |
new Production("DirectiveArg",new Binding(false,"ruleAlias")), |
|---|
| 1081 |
new Production("WS",null), |
|---|
| 1082 |
new Terminal(")",null), |
|---|
| 1083 |
new Production("WS",null), |
|---|
| 1084 |
new Terminal(";",null) |
|---|
| 1085 |
) |
|---|
| 1086 |
); |
|---|
| 1087 |
|
|---|
| 1088 |
lines ~= new Rule("ModuleDirective", |
|---|
| 1089 |
new ClassPredicate("ModuleDirective", new Param("moduleName")), |
|---|
| 1090 |
new Expression( |
|---|
| 1091 |
new Terminal("module",null), |
|---|
| 1092 |
new Production("WS",null), |
|---|
| 1093 |
new Terminal("(",null), |
|---|
| 1094 |
new Production("WS",null), |
|---|
| 1095 |
new Production("DirectiveArg",new Binding(false,"moduleName")), |
|---|
| 1096 |
new Production("WS",null), |
|---|
| 1097 |
new Terminal(")",null), |
|---|
| 1098 |
new Production("WS",null), |
|---|
| 1099 |
new Terminal(";",null) |
|---|
| 1100 |
) |
|---|
| 1101 |
); |
|---|
| 1102 |
|
|---|
| 1103 |
lines ~= new Rule("CodeDirective", |
|---|
| 1104 |
new ClassPredicate("CodeDirective", new Param("code")), |
|---|
| 1105 |
new Expression( |
|---|
| 1106 |
new Terminal("code",null), |
|---|
| 1107 |
new Production("WS",null), |
|---|
| 1108 |
new Terminal("{{{",null), |
|---|
| 1109 |
new ZeroOrMoreExpr( |
|---|
| 1110 |
new Expression( |
|---|
| 1111 |
new Production("any",null) |
|---|
| 1112 |
), |
|---|
| 1113 |
new Binding(false,"code"), |
|---|
| 1114 |
new Terminal("}}}",null) |
|---|
| 1115 |
) |
|---|
| 1116 |
) |
|---|
| 1117 |
); |
|---|
| 1118 |
|
|---|
| 1119 |
lines ~= new Rule("TypelibDirective", |
|---|
| 1120 |
new ClassPredicate("TypelibDirective", new Param("importName")), |
|---|
| 1121 |
new Expression( |
|---|
| 1122 |
new Terminal("typelib",null), |
|---|
| 1123 |
new Production("WS",null), |
|---|
| 1124 |
new Terminal("(",null), |
|---|
| 1125 |
new Production("WS",null), |
|---|
| 1126 |
new Production("DirectiveArg",new Binding(false,"importName")), |
|---|
| 1127 |
new Production("WS",null), |
|---|
| 1128 |
new Terminal(")",null), |
|---|
| 1129 |
new Production("WS",null), |
|---|
| 1130 |
new Terminal(";",null) |
|---|
| 1131 |
) |
|---|
| 1132 |
); |
|---|
| 1133 |
|
|---|
| 1134 |
lines ~= new Rule("ParseTypeDirective", |
|---|
| 1135 |
new ClassPredicate("ParseTypeDirective", new Param("typeName")), |
|---|
| 1136 |
new Expression( |
|---|
| 1137 |
new Terminal("parsetype",null), |
|---|
| 1138 |
new Production("WS",null), |
|---|
| 1139 |
new Terminal("(",null), |
|---|
| 1140 |
new Production("WS",null), |
|---|
| 1141 |
new Production("DirectiveArg",new Binding(false,"typeName")), |
|---|
| 1142 |
new Production("WS",null), |
|---|
| 1143 |
new Terminal(")",null), |
|---|
| 1144 |
new Production("WS",null), |
|---|
| 1145 |
new Terminal(";",null) |
|---|
| 1146 |
) |
|---|
| 1147 |
); |
|---|
| 1148 |
|
|---|
| 1149 |
lines ~= new Rule("BoilerplateDirective", |
|---|
| 1150 |
new ClassPredicate("BoilerplateDirective", new Param("code")), |
|---|
| 1151 |
new Expression( |
|---|
| 1152 |
new Terminal("boilerplate",null), |
|---|
| 1153 |
new Production("WS",null), |
|---|
| 1154 |
new Terminal("{{{",null), |
|---|
| 1155 |
new ZeroOrMoreExpr( |
|---|
| 1156 |
new Expression( |
|---|
| 1157 |
new Production("any",null) |
|---|
| 1158 |
), |
|---|
| 1159 |
new Binding(false,"code"), |
|---|
| 1160 |
new Terminal("}}}",null) |
|---|
| 1161 |
) |
|---|
| 1162 |
) |
|---|
| 1163 |
); |
|---|
| 1164 |
|
|---|
| 1165 |
lines ~= new Rule("HeaderDirective", |
|---|
| 1166 |
new ClassPredicate("HeaderDirective", new Param("code")), |
|---|
| 1167 |
new Expression( |
|---|
| 1168 |
new Terminal("header",null), |
|---|
| 1169 |
new Production("WS",null), |
|---|
| 1170 |
new Terminal("{{{",null), |
|---|
| 1171 |
new ZeroOrMoreExpr( |
|---|
| 1172 |
new Expression( |
|---|
| 1173 |
new Production("any",null) |
|---|
| 1174 |
), |
|---|
| 1175 |
new Binding(false,"code"), |
|---|
| 1176 |
new Terminal("}}}",null) |
|---|
| 1177 |
) |
|---|
| 1178 |
) |
|---|
| 1179 |
); |
|---|
| 1180 |
|
|---|
| 1181 |
lines ~= new Rule("UTFDirective", |
|---|
| 1182 |
new ClassPredicate("UTFDirective", new Param("value")), |
|---|
| 1183 |
new Expression( |
|---|
| 1184 |
new Terminal("utf",null), |
|---|
| 1185 |
new Production("WS",null), |
|---|
| 1186 |
new Terminal("(",null), |
|---|
| 1187 |
new Production("WS",null), |
|---|
| 1188 |
new Production("DirectiveArg",new Binding(false,"value")), |
|---|
| 1189 |
new Production("WS",null), |
|---|
| 1190 |
new Terminal(")",null), |
|---|
| 1191 |
new Production("WS",null), |
|---|
| 1192 |
new Terminal(";",null) |
|---|
| 1193 |
) |
|---|
| 1194 |
); |
|---|
| 1195 |
|
|---|
| 1196 |
lines ~= new Rule("DirectiveArg", |
|---|
| 1197 |
new BindingPredicate(new Param("arg")), |
|---|
| 1198 |
new Expression( |
|---|
| 1199 |
orExpr( |
|---|
| 1200 |
makeTerm(new Production("Identifier",new Binding(false,"arg"))), |
|---|
| 1201 |
makeTerm(new Production("String",new Binding(false,"arg"))) |
|---|
| 1202 |
) |
|---|
| 1203 |
) |
|---|
| 1204 |
); |
|---|
| 1205 |
|
|---|
| 1206 |
|
|---|
| 1207 |
// setup the syntax tree |
|---|
| 1208 |
auto syntax = new BaseEnkiParser(); |
|---|
| 1209 |
syntax.createSyntax(lines); |
|---|
| 1210 |
syntax.semanticPass(); |
|---|
| 1211 |
|
|---|
| 1212 |
// create bnf file |
|---|
| 1213 |
File("enki/enki.bnf").write(syntax.toBNF()); |
|---|
| 1214 |
|
|---|
| 1215 |
// emit the code |
|---|
| 1216 |
File("enki/EnkiParser.d").write(syntax.render()); |
|---|
| 1217 |
} |
|---|