Use arrow syntax for bnf

This commit is contained in:
kpdecker
2013-07-24 21:57:30 -05:00
parent 163b3f9e51
commit f9ed0d3085
2 changed files with 88 additions and 86 deletions
+43 -43
View File
@@ -197,106 +197,106 @@ var $0 = $$.length - 1;
switch (yystate) {
case 1: return $$[$0-1];
break;
case 2: this.$ = new yy.ProgramNode([], $$[$0]);
case 2:this.$ = new yy.ProgramNode([], $$[$0]);
break;
case 3: this.$ = new yy.ProgramNode($$[$0-2], $$[$0]);
case 3:this.$ = new yy.ProgramNode($$[$0-2], $$[$0]);
break;
case 4: this.$ = new yy.ProgramNode($$[$0-1], []);
case 4:this.$ = new yy.ProgramNode($$[$0-1], []);
break;
case 5: this.$ = new yy.ProgramNode($$[$0]);
case 5:this.$ = new yy.ProgramNode($$[$0]);
break;
case 6: this.$ = new yy.ProgramNode([], []);
case 6:this.$ = new yy.ProgramNode([], []);
break;
case 7: this.$ = new yy.ProgramNode([]);
case 7:this.$ = new yy.ProgramNode([]);
break;
case 8: this.$ = [$$[$0]];
case 8:this.$ = [$$[$0]];
break;
case 9: $$[$0-1].push($$[$0]); this.$ = $$[$0-1];
break;
case 10: this.$ = new yy.BlockNode($$[$0-2], $$[$0-1].inverse, $$[$0-1], $$[$0]);
case 10:this.$ = new yy.BlockNode($$[$0-2], $$[$0-1].inverse, $$[$0-1], $$[$0]);
break;
case 11: this.$ = new yy.BlockNode($$[$0-2], $$[$0-1], $$[$0-1].inverse, $$[$0]);
case 11:this.$ = new yy.BlockNode($$[$0-2], $$[$0-1], $$[$0-1].inverse, $$[$0]);
break;
case 12: this.$ = $$[$0];
case 12:this.$ = $$[$0];
break;
case 13: this.$ = $$[$0];
case 13:this.$ = $$[$0];
break;
case 14: this.$ = new yy.ContentNode($$[$0]);
case 14:this.$ = new yy.ContentNode($$[$0]);
break;
case 15: this.$ = new yy.CommentNode($$[$0]);
case 15:this.$ = new yy.CommentNode($$[$0]);
break;
case 16: this.$ = new yy.MustacheNode($$[$0-1][0], $$[$0-1][1]);
case 16:this.$ = new yy.MustacheNode($$[$0-1][0], $$[$0-1][1]);
break;
case 17: this.$ = new yy.MustacheNode($$[$0-1][0], $$[$0-1][1]);
case 17:this.$ = new yy.MustacheNode($$[$0-1][0], $$[$0-1][1]);
break;
case 18: this.$ = $$[$0-1];
case 18:this.$ = $$[$0-1];
break;
case 19:
// Parsing out the '&' escape token at this level saves ~500 bytes after min due to the removal of one parser node.
this.$ = new yy.MustacheNode($$[$0-1][0], $$[$0-1][1], $$[$0-2][2] === '&');
break;
case 20: this.$ = new yy.MustacheNode($$[$0-1][0], $$[$0-1][1], true);
case 20:this.$ = new yy.MustacheNode($$[$0-1][0], $$[$0-1][1], true);
break;
case 21: this.$ = new yy.PartialNode($$[$0-1]);
case 21:this.$ = new yy.PartialNode($$[$0-1]);
break;
case 22: this.$ = new yy.PartialNode($$[$0-2], $$[$0-1]);
case 22:this.$ = new yy.PartialNode($$[$0-2], $$[$0-1]);
break;
case 23:
break;
case 24: this.$ = [[$$[$0-2]].concat($$[$0-1]), $$[$0]];
case 24:this.$ = [[$$[$0-2]].concat($$[$0-1]), $$[$0]];
break;
case 25: this.$ = [[$$[$0-1]].concat($$[$0]), null];
case 25:this.$ = [[$$[$0-1]].concat($$[$0]), null];
break;
case 26: this.$ = [[$$[$0-1]], $$[$0]];
case 26:this.$ = [[$$[$0-1]], $$[$0]];
break;
case 27: this.$ = [[$$[$0]], null];
case 27:this.$ = [[$$[$0]], null];
break;
case 28: this.$ = [[$$[$0]], null];
case 28:this.$ = [[$$[$0]], null];
break;
case 29: $$[$0-1].push($$[$0]); this.$ = $$[$0-1];
break;
case 30: this.$ = [$$[$0]];
case 30:this.$ = [$$[$0]];
break;
case 31: this.$ = $$[$0];
case 31:this.$ = $$[$0];
break;
case 32: this.$ = new yy.StringNode($$[$0]);
case 32:this.$ = new yy.StringNode($$[$0]);
break;
case 33: this.$ = new yy.IntegerNode($$[$0]);
case 33:this.$ = new yy.IntegerNode($$[$0]);
break;
case 34: this.$ = new yy.BooleanNode($$[$0]);
case 34:this.$ = new yy.BooleanNode($$[$0]);
break;
case 35: this.$ = $$[$0];
case 35:this.$ = $$[$0];
break;
case 36: this.$ = new yy.HashNode($$[$0]);
case 36:this.$ = new yy.HashNode($$[$0]);
break;
case 37: $$[$0-1].push($$[$0]); this.$ = $$[$0-1];
break;
case 38: this.$ = [$$[$0]];
case 38:this.$ = [$$[$0]];
break;
case 39: this.$ = [$$[$0-2], $$[$0]];
case 39:this.$ = [$$[$0-2], $$[$0]];
break;
case 40: this.$ = [$$[$0-2], new yy.StringNode($$[$0])];
case 40:this.$ = [$$[$0-2], new yy.StringNode($$[$0])];
break;
case 41: this.$ = [$$[$0-2], new yy.IntegerNode($$[$0])];
case 41:this.$ = [$$[$0-2], new yy.IntegerNode($$[$0])];
break;
case 42: this.$ = [$$[$0-2], new yy.BooleanNode($$[$0])];
case 42:this.$ = [$$[$0-2], new yy.BooleanNode($$[$0])];
break;
case 43: this.$ = [$$[$0-2], $$[$0]];
case 43:this.$ = [$$[$0-2], $$[$0]];
break;
case 44: this.$ = new yy.PartialNameNode($$[$0]);
case 44:this.$ = new yy.PartialNameNode($$[$0]);
break;
case 45: this.$ = new yy.PartialNameNode(new yy.StringNode($$[$0]));
case 45:this.$ = new yy.PartialNameNode(new yy.StringNode($$[$0]));
break;
case 46: this.$ = new yy.PartialNameNode(new yy.IntegerNode($$[$0]));
case 46:this.$ = new yy.PartialNameNode(new yy.IntegerNode($$[$0]));
break;
case 47: this.$ = new yy.DataNode($$[$0]);
case 47:this.$ = new yy.DataNode($$[$0]);
break;
case 48: this.$ = new yy.IdNode($$[$0]);
case 48:this.$ = new yy.IdNode($$[$0]);
break;
case 49: $$[$0-2].push({part: $$[$0], separator: $$[$0-1]}); this.$ = $$[$0-2];
break;
case 50: this.$ = [{part: $$[$0]}];
case 50:this.$ = [{part: $$[$0]}];
break;
}
},
+45 -43
View File
@@ -1,5 +1,7 @@
%start root
%ebnf
%%
root
@@ -7,38 +9,38 @@ root
;
program
: simpleInverse statements { $$ = new yy.ProgramNode([], $2); }
| statements simpleInverse statements { $$ = new yy.ProgramNode($1, $3); }
| statements simpleInverse { $$ = new yy.ProgramNode($1, []); }
| statements { $$ = new yy.ProgramNode($1); }
| simpleInverse { $$ = new yy.ProgramNode([], []); }
| "" { $$ = new yy.ProgramNode([]); }
: simpleInverse statements -> new yy.ProgramNode([], $2)
| statements simpleInverse statements -> new yy.ProgramNode($1, $3)
| statements simpleInverse -> new yy.ProgramNode($1, [])
| statements -> new yy.ProgramNode($1)
| simpleInverse -> new yy.ProgramNode([], [])
| "" -> new yy.ProgramNode([])
;
statements
: statement { $$ = [$1]; }
: statement -> [$1]
| statements statement { $1.push($2); $$ = $1; }
;
statement
: openInverse program closeBlock { $$ = new yy.BlockNode($1, $2.inverse, $2, $3); }
| openBlock program closeBlock { $$ = new yy.BlockNode($1, $2, $2.inverse, $3); }
| mustache { $$ = $1; }
| partial { $$ = $1; }
| CONTENT { $$ = new yy.ContentNode($1); }
| COMMENT { $$ = new yy.CommentNode($1); }
: openInverse program closeBlock -> new yy.BlockNode($1, $2.inverse, $2, $3)
| openBlock program closeBlock -> new yy.BlockNode($1, $2, $2.inverse, $3)
| mustache -> $1
| partial -> $1
| CONTENT -> new yy.ContentNode($1)
| COMMENT -> new yy.CommentNode($1)
;
openBlock
: OPEN_BLOCK inMustache CLOSE { $$ = new yy.MustacheNode($2[0], $2[1]); }
: OPEN_BLOCK inMustache CLOSE -> new yy.MustacheNode($2[0], $2[1])
;
openInverse
: OPEN_INVERSE inMustache CLOSE { $$ = new yy.MustacheNode($2[0], $2[1]); }
: OPEN_INVERSE inMustache CLOSE -> new yy.MustacheNode($2[0], $2[1])
;
closeBlock
: OPEN_ENDBLOCK path CLOSE { $$ = $2; }
: OPEN_ENDBLOCK path CLOSE -> $2
;
mustache
@@ -46,13 +48,13 @@ mustache
// Parsing out the '&' escape token at this level saves ~500 bytes after min due to the removal of one parser node.
$$ = new yy.MustacheNode($2[0], $2[1], $1[2] === '&');
}
| OPEN_UNESCAPED inMustache CLOSE_UNESCAPED { $$ = new yy.MustacheNode($2[0], $2[1], true); }
| OPEN_UNESCAPED inMustache CLOSE_UNESCAPED -> new yy.MustacheNode($2[0], $2[1], true)
;
partial
: OPEN_PARTIAL partialName CLOSE { $$ = new yy.PartialNode($2); }
| OPEN_PARTIAL partialName path CLOSE { $$ = new yy.PartialNode($2, $3); }
: OPEN_PARTIAL partialName CLOSE -> new yy.PartialNode($2)
| OPEN_PARTIAL partialName path CLOSE -> new yy.PartialNode($2, $3)
;
simpleInverse
@@ -60,59 +62,59 @@ simpleInverse
;
inMustache
: path params hash { $$ = [[$1].concat($2), $3]; }
| path params { $$ = [[$1].concat($2), null]; }
| path hash { $$ = [[$1], $2]; }
| path { $$ = [[$1], null]; }
| dataName { $$ = [[$1], null]; }
: path params hash -> [[$1].concat($2), $3]
| path params -> [[$1].concat($2), null]
| path hash -> [[$1], $2]
| path -> [[$1], null]
| dataName -> [[$1], null]
;
params
: params param { $1.push($2); $$ = $1; }
| param { $$ = [$1]; }
| param -> [$1]
;
param
: path { $$ = $1; }
| STRING { $$ = new yy.StringNode($1); }
| INTEGER { $$ = new yy.IntegerNode($1); }
| BOOLEAN { $$ = new yy.BooleanNode($1); }
| dataName { $$ = $1; }
: path -> $1
| STRING -> new yy.StringNode($1)
| INTEGER -> new yy.IntegerNode($1)
| BOOLEAN -> new yy.BooleanNode($1)
| dataName -> $1
;
hash
: hashSegments { $$ = new yy.HashNode($1); }
: hashSegments -> new yy.HashNode($1)
;
hashSegments
: hashSegments hashSegment { $1.push($2); $$ = $1; }
| hashSegment { $$ = [$1]; }
| hashSegment -> [$1]
;
hashSegment
: ID EQUALS path { $$ = [$1, $3]; }
| ID EQUALS STRING { $$ = [$1, new yy.StringNode($3)]; }
| ID EQUALS INTEGER { $$ = [$1, new yy.IntegerNode($3)]; }
| ID EQUALS BOOLEAN { $$ = [$1, new yy.BooleanNode($3)]; }
| ID EQUALS dataName { $$ = [$1, $3]; }
: ID EQUALS path -> [$1, $3]
| ID EQUALS STRING -> [$1, new yy.StringNode($3)]
| ID EQUALS INTEGER -> [$1, new yy.IntegerNode($3)]
| ID EQUALS BOOLEAN -> [$1, new yy.BooleanNode($3)]
| ID EQUALS dataName -> [$1, $3]
;
partialName
: path { $$ = new yy.PartialNameNode($1); }
| STRING { $$ = new yy.PartialNameNode(new yy.StringNode($1)); }
| INTEGER { $$ = new yy.PartialNameNode(new yy.IntegerNode($1)); }
: path -> new yy.PartialNameNode($1)
| STRING -> new yy.PartialNameNode(new yy.StringNode($1))
| INTEGER -> new yy.PartialNameNode(new yy.IntegerNode($1))
;
dataName
: DATA path { $$ = new yy.DataNode($2); }
: DATA path -> new yy.DataNode($2)
;
path
: pathSegments { $$ = new yy.IdNode($1); }
: pathSegments -> new yy.IdNode($1)
;
pathSegments
: pathSegments SEP ID { $1.push({part: $3, separator: $2}); $$ = $1; }
| ID { $$ = [{part: $1}]; }
| ID -> [{part: $1}]
;