Skip to content

Instantly share code, notes, and snippets.

Created November 25, 2010 08:59
Show Gist options
  • Save anonymous/715104 to your computer and use it in GitHub Desktop.
Save anonymous/715104 to your computer and use it in GitHub Desktop.
/* Jison generated parser */
var handlebars = (function(){
var parser = {trace: function trace() { },
yy: {},
symbols_: {"error":2,"root":3,"program":4,"statements":5,"simpleInverse":6,"statement":7,"openBlock":8,"closeBlock":9,"mustache":10,"partial":11,"CONTENT":12,"COMMENT":13,"OPEN_BLOCK":14,"inMustache":15,"CLOSE":16,"OPEN_ENDBLOCK":17,"id":18,"OPEN":19,"OPEN_PARTIAL":20,"OPEN_INVERSE":21,"params":22,"param":23,"STRING":24,"ID":25,"$accept":0,"$end":1},
terminals_: {"2":"error","12":"CONTENT","13":"COMMENT","14":"OPEN_BLOCK","16":"CLOSE","17":"OPEN_ENDBLOCK","19":"OPEN","20":"OPEN_PARTIAL","21":"OPEN_INVERSE","24":"STRING","25":"ID"},
productions_: [0,[3,1],[4,3],[4,1],[5,1],[5,2],[7,3],[7,1],[7,1],[7,1],[7,1],[8,3],[9,3],[10,3],[11,3],[6,2],[15,2],[15,1],[22,2],[22,1],[23,1],[23,1],[18,1]],
performAction: function anonymous(yytext,yyleng,yylineno,yy) {
var $$ = arguments[5],$0=arguments[5].length;
switch(arguments[4]) {
case 1: return $$[$0-1+1-1]
break;
case 2: this.$ = new yy.ProgramNode($$[$0-3+1-1], $$[$0-3+3-1])
break;
case 3: this.$ = new yy.ProgramNode($$[$0-1+1-1])
break;
case 4: this.$ = [$$[$0-1+1-1]]
break;
case 5: $$[$0-2+1-1].push($$[$0-2+2-1]); this.$ = $$[$0-2+1-1]
break;
case 6: this.$ = new yy.BlockNode($$[$0-3+1-1], $$[$0-3+2-1])
break;
case 7: this.$ = $$[$0-1+1-1]
break;
case 8: this.$ = $$[$0-1+1-1]
break;
case 9: this.$ = new yy.ContentNode($$[$0-1+1-1])
break;
case 10: this.$ = new yy.CommentNode($$[$0-1+1-1])
break;
case 11: this.$ = new yy.MustacheNode($$[$0-3+2-1])
break;
case 12:
break;
case 13: this.$ = new yy.MustacheNode($$[$0-3+2-1])
break;
case 14: this.$ = new yy.PartialNode($$[$0-3+2-1])
break;
case 15:
break;
case 16: this.$ = [$$[$0-2+1-1]].concat($$[$0-2+2-1])
break;
case 17: this.$ = [$$[$0-1+1-1]]
break;
case 18: $$[$0-2+1-1].push($$[$0-2+2-1]); this.$ = $$[$0-2+1-1];
break;
case 19: this.$ = [$$[$0-1+1-1]]
break;
case 20: this.$ = $$[$0-1+1-1]
break;
case 21: this.$ = new yy.StringNode($$[$0-1+1-1])
break;
case 22: this.$ = new yy.IdNode($$[$0-1+1-1])
break;
}
},
table: [{"3":1,"4":2,"5":3,"7":4,"8":5,"10":6,"11":7,"12":[1,8],"13":[1,9],"14":[1,10],"19":[1,11],"20":[1,12]},{"1":[3]},{"1":[2,1]},{"1":[2,3],"6":13,"7":14,"8":5,"10":6,"11":7,"12":[1,8],"13":[1,9],"14":[1,10],"17":[2,3],"19":[1,11],"20":[1,12],"21":[1,15]},{"1":[2,4],"12":[2,4],"13":[2,4],"14":[2,4],"17":[2,4],"19":[2,4],"20":[2,4],"21":[2,4]},{"4":16,"5":3,"7":4,"8":5,"10":6,"11":7,"12":[1,8],"13":[1,9],"14":[1,10],"19":[1,11],"20":[1,12]},{"1":[2,7],"12":[2,7],"13":[2,7],"14":[2,7],"17":[2,7],"19":[2,7],"20":[2,7],"21":[2,7]},{"1":[2,8],"12":[2,8],"13":[2,8],"14":[2,8],"17":[2,8],"19":[2,8],"20":[2,8],"21":[2,8]},{"1":[2,9],"12":[2,9],"13":[2,9],"14":[2,9],"17":[2,9],"19":[2,9],"20":[2,9],"21":[2,9]},{"1":[2,10],"12":[2,10],"13":[2,10],"14":[2,10],"17":[2,10],"19":[2,10],"20":[2,10],"21":[2,10]},{"15":17,"18":18,"25":[1,19]},{"15":20,"18":18,"25":[1,19]},{"18":21,"25":[1,19]},{"5":22,"7":4,"8":5,"10":6,"11":7,"12":[1,8],"13":[1,9],"14":[1,10],"19":[1,11],"20":[1,12]},{"1":[2,5],"12":[2,5],"13":[2,5],"14":[2,5],"17":[2,5],"19":[2,5],"20":[2,5],"21":[2,5]},{"16":[1,23]},{"9":24,"17":[1,25]},{"16":[1,26]},{"16":[2,17],"18":29,"22":27,"23":28,"24":[1,30],"25":[1,19]},{"16":[2,22],"24":[2,22],"25":[2,22]},{"16":[1,31]},{"16":[1,32]},{"1":[2,2],"7":14,"8":5,"10":6,"11":7,"12":[1,8],"13":[1,9],"14":[1,10],"17":[2,2],"19":[1,11],"20":[1,12]},{"12":[2,15],"13":[2,15],"14":[2,15],"19":[2,15],"20":[2,15]},{"1":[2,6],"12":[2,6],"13":[2,6],"14":[2,6],"17":[2,6],"19":[2,6],"20":[2,6],"21":[2,6]},{"18":33,"25":[1,19]},{"12":[2,11],"13":[2,11],"14":[2,11],"19":[2,11],"20":[2,11]},{"16":[2,16],"18":29,"23":34,"24":[1,30],"25":[1,19]},{"16":[2,19],"24":[2,19],"25":[2,19]},{"16":[2,20],"24":[2,20],"25":[2,20]},{"16":[2,21],"24":[2,21],"25":[2,21]},{"1":[2,13],"12":[2,13],"13":[2,13],"14":[2,13],"17":[2,13],"19":[2,13],"20":[2,13],"21":[2,13]},{"1":[2,14],"12":[2,14],"13":[2,14],"14":[2,14],"17":[2,14],"19":[2,14],"20":[2,14],"21":[2,14]},{"16":[1,35]},{"16":[2,18],"24":[2,18],"25":[2,18]},{"1":[2,12],"12":[2,12],"13":[2,12],"14":[2,12],"17":[2,12],"19":[2,12],"20":[2,12],"21":[2,12]}],
defaultActions: {"2":[2,1]},
parseError: function parseError(str, hash) {
throw new Error(str);
},
parse: function parse(input) {
var self = this,
stack = [0],
vstack = [null], // semantic value stack
table = this.table,
yytext = '',
yylineno = 0,
yyleng = 0,
shifts = 0,
reductions = 0,
recovering = 0,
TERROR = 2,
EOF = 1;
this.lexer.setInput(input);
this.lexer.yy = this.yy;
this.yy.lexer = this.lexer;
var parseError = this.yy.parseError = typeof this.yy.parseError == 'function' ? this.yy.parseError : this.parseError;
function popStack (n) {
stack.length = stack.length - 2*n;
vstack.length = vstack.length - n;
}
function lex() {
var token;
token = self.lexer.lex() || 1; // $end = 1
// if token isn't its numeric value, convert
if (typeof token !== 'number') {
token = self.symbols_[token] || token;
}
return token;
};
var symbol, preErrorSymbol, state, action, a, r, yyval={},p,len,newState, expected, recovered = false;
while (true) {
// retreive state number from top of stack
state = stack[stack.length-1];
// use default actions if available
if (this.defaultActions[state]) {
action = this.defaultActions[state];
} else {
if (symbol == null)
symbol = lex();
// read action for current state and first input
action = table[state] && table[state][symbol];
}
// handle parse error
if (typeof action === 'undefined' || !action.length || !action[0]) {
if (!recovering) {
// Report error
expected = [];
for (p in table[state]) if (this.terminals_[p] && p > 2) {
expected.push("'"+this.terminals_[p]+"'");
}
var errStr = '';
if (this.lexer.showPosition) {
errStr = 'Parse error on line '+(yylineno+1)+":\n"+this.lexer.showPosition()+'\nExpecting '+expected.join(', ');
} else {
errStr = 'Parse error on line '+(yylineno+1)+": Unexpected " +
(symbol == 1 /*EOF*/ ? "end of input" :
("'"+(this.terminals_[symbol] || symbol)+"'"));
}
parseError.call(this, errStr,
{text: this.lexer.match, token: this.terminals_[symbol] || symbol, line: this.lexer.yylineno, expected: expected});
}
// just recovered from another error
if (recovering == 3) {
if (symbol == EOF) {
throw new Error(errStr || 'Parsing halted.');
}
// discard current lookahead and grab another
yyleng = this.lexer.yyleng;
yytext = this.lexer.yytext;
yylineno = this.lexer.yylineno;
symbol = lex();
}
// try to recover from error
while (1) {
// check for error recovery rule in this state
if ((TERROR.toString()) in table[state]) {
break;
}
if (state == 0) {
throw new Error(errStr || 'Parsing halted.');
}
popStack(1);
state = stack[stack.length-1];
}
preErrorSymbol = symbol; // save the lookahead token
symbol = TERROR; // insert generic error symbol as new lookahead
state = stack[stack.length-1];
action = table[state] && table[state][TERROR];
recovering = 3; // allow 3 real symbols to be shifted before reporting a new error
}
// this shouldn't happen, unless resolve defaults are off
if (action[0] instanceof Array && action.length > 1) {
throw new Error('Parse Error: multiple actions possible at state: '+state+', token: '+symbol);
}
a = action;
switch (a[0]) {
case 1: // shift
shifts++;
stack.push(symbol);
vstack.push(this.lexer.yytext); // semantic values or junk only, no terminals
stack.push(a[1]); // push state
symbol = null;
if (!preErrorSymbol) { // normal execution/no error
yyleng = this.lexer.yyleng;
yytext = this.lexer.yytext;
yylineno = this.lexer.yylineno;
if (recovering > 0)
recovering--;
} else { // error just occurred, resume old lookahead f/ before error
symbol = preErrorSymbol;
preErrorSymbol = null;
}
break;
case 2: // reduce
reductions++;
len = this.productions_[a[1]][1];
// perform semantic action
yyval.$ = vstack[vstack.length-len]; // default to $$ = $1
r = this.performAction.call(yyval, yytext, yyleng, yylineno, this.yy, a[1], vstack);
if (typeof r !== 'undefined') {
return r;
}
// pop off stack
if (len) {
stack = stack.slice(0,-1*len*2);
vstack = vstack.slice(0, -1*len);
}
stack.push(this.productions_[a[1]][0]); // push nonterminal (reduce)
vstack.push(yyval.$);
// goto new state = table[STATE][NONTERMINAL]
newState = table[stack[stack.length-2]][stack[stack.length-1]];
stack.push(newState);
break;
case 3: // accept
this.reductionCount = reductions;
this.shiftCount = shifts;
return true;
}
}
return true;
}};
return parser;
})();
if (typeof require !== 'undefined') {
exports.parser = handlebars;
exports.parse = function () { return handlebars.parse.apply(handlebars, arguments); }
exports.main = function commonjsMain(args) {
if (!args[1])
throw new Error('Usage: '+args[0]+' FILE');
if (typeof process !== 'undefined') {
var source = require('fs').readFileSync(require('path').join(process.cwd(), args[1]), "utf8");
} else {
var cwd = require("file").path(require("file").cwd());
var source = cwd.join(args[1]).read({charset: "utf-8"});
}
return exports.parser.parse(source);
}
if (typeof module !== 'undefined' && require.main === module) {
exports.main(typeof process !== 'undefined' ? process.argv.slice(1) : require("system").args);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment