Comparing version 0.2.11 to 0.2.12
@@ -672,3 +672,3 @@ // Jison, an LR(0), SLR(1), LARL(1), LR(1) Parser Generator | ||
lrGeneratorMixin.canonicalCollection = function canonicalCollection () { | ||
var item1 = new this.Item(this.productions[0], 0, new Set(this.EOF)); | ||
var item1 = new this.Item(this.productions[0], 0, [this.EOF]); | ||
var firstState = this.closureOperation(new this.ItemSet(item1)), | ||
@@ -717,2 +717,3 @@ states = new Set(firstState), | ||
lrGeneratorMixin.parseTable = function parseTable (itemSets) { | ||
var NONASSOC = 0; | ||
var states = [], | ||
@@ -916,3 +917,22 @@ nonterminals = this.nonterminals, | ||
// returns parse function without error recovery code | ||
function removeErrorRecovery (fn) { | ||
var parseFn = String(fn); | ||
try { | ||
var JSONSelect = require('JSONSelect'); | ||
var Reflect = require('reflect'); | ||
var ast = Reflect.parse(parseFn); | ||
var labeled = JSONSelect.match(':has(:root > .label > .name:val("_handle_error"))', ast); | ||
labeled[0].body.consequent.body = [labeled[0].body.consequent.body[0]]; | ||
return Reflect.stringify(ast).replace(/_handle_error:\s?/,"").replace(/\\\\n/g,"\\n"); | ||
} catch (e) { | ||
return parseFn; | ||
} | ||
} | ||
lrGeneratorMixin.generateModule_ = function generateModule_ () { | ||
var parseFn = (this.hasErrorRecovery ? String : removeErrorRecovery)(parser.parse); | ||
var out = "{"; | ||
@@ -929,3 +949,3 @@ out += [ | ||
"parseError: " + String(this.parseError || (this.hasErrorRecovery ? traceParseError : parser.parseError)), | ||
"parse: " + String(parser.parse) | ||
"parse: " + parseFn | ||
].join(",\n"); | ||
@@ -1071,3 +1091,3 @@ out += "};"; | ||
return token; | ||
}; | ||
} | ||
@@ -1090,2 +1110,3 @@ var symbol, preErrorSymbol, state, action, a, r, yyval={},p,len,newState, expected; | ||
// handle parse error | ||
_handle_error: | ||
if (typeof action === 'undefined' || !action.length || !action[0]) { | ||
@@ -1101,3 +1122,3 @@ | ||
if (this.lexer.showPosition) { | ||
errStr = 'Parse error on line '+(yylineno+1)+":\n"+this.lexer.showPosition()+'\nExpecting '+expected.join(', '); | ||
errStr = 'Parse error on line '+(yylineno+1)+":\n"+this.lexer.showPosition()+"\nExpecting "+expected.join(', ') + ", got '" + this.terminals_[symbol]+ "'"; | ||
} else { | ||
@@ -1442,3 +1463,3 @@ errStr = 'Parse error on line '+(yylineno+1)+": Unexpected " + | ||
b = self.first(item.remainingHandle()); | ||
if (b.length === 0) b = item.follows; | ||
if (b.length === 0 || item.production.nullable) b = b.concat(item.follows); | ||
self.nonterminals[symbol].productions.forEach(function (production) { | ||
@@ -1445,0 +1466,0 @@ var newItem = new self.Item(production, 0, b); |
@@ -258,2 +258,8 @@ // Basic RegExp Lexer | ||
}, | ||
topState: function () { | ||
return this.conditionStack[this.conditionStack.length-2]; | ||
}, | ||
pushState: function begin (condition) { | ||
this.begin(condition); | ||
}, | ||
@@ -260,0 +266,0 @@ generate: function generate(opt) { |
@@ -8,3 +8,3 @@ /* Jison generated parser */ | ||
terminals_: {2:"error",5:"%%",7:"EOF",8:"CODE",10:"START",12:"LEX_BLOCK",14:"ACTION",17:"LEFT",18:"RIGHT",19:"NONASSOC",23:":",25:";",26:"|",31:"PREC",32:"STRING",33:"ID",34:"{",36:"}",37:"ARROW_ACTION",38:"ACTION_BODY"}, | ||
productions_: [0,[3,4],[3,5],[3,6],[4,2],[4,0],[9,2],[9,1],[9,1],[9,1],[13,2],[15,1],[15,1],[15,1],[16,2],[16,1],[6,1],[21,2],[21,1],[22,4],[24,3],[24,1],[27,3],[28,2],[28,0],[29,2],[29,0],[20,1],[20,1],[11,1],[30,3],[30,1],[30,1],[30,0],[35,0],[35,1],[35,5]], | ||
productions_: [0,[3,4],[3,5],[3,6],[4,2],[4,0],[9,2],[9,1],[9,1],[9,1],[13,2],[15,1],[15,1],[15,1],[16,2],[16,1],[6,1],[21,2],[21,1],[22,4],[24,3],[24,1],[27,3],[28,2],[28,0],[29,2],[29,0],[20,1],[20,1],[11,1],[30,3],[30,1],[30,1],[30,0],[35,0],[35,1],[35,5],[35,4]], | ||
performAction: function anonymous(yytext,yyleng,yylineno,yy,yystate,$$,_$) { | ||
@@ -92,5 +92,7 @@ | ||
break; | ||
case 37:this.$ = $$[$0-3]+$$[$0-2]+$$[$0-1]+$$[$0]; | ||
break; | ||
} | ||
}, | ||
table: [{3:1,4:2,5:[2,5],10:[2,5],12:[2,5],14:[2,5],17:[2,5],18:[2,5],19:[2,5]},{1:[3]},{5:[1,3],9:4,10:[1,5],12:[1,6],13:7,14:[1,8],15:9,17:[1,10],18:[1,11],19:[1,12]},{6:13,11:16,21:14,22:15,33:[1,17]},{5:[2,4],10:[2,4],12:[2,4],14:[2,4],17:[2,4],18:[2,4],19:[2,4]},{11:18,33:[1,17]},{5:[2,7],10:[2,7],12:[2,7],14:[2,7],17:[2,7],18:[2,7],19:[2,7]},{5:[2,8],10:[2,8],12:[2,8],14:[2,8],17:[2,8],18:[2,8],19:[2,8]},{5:[2,9],10:[2,9],12:[2,9],14:[2,9],17:[2,9],18:[2,9],19:[2,9]},{11:21,16:19,20:20,32:[1,22],33:[1,17]},{32:[2,11],33:[2,11]},{32:[2,12],33:[2,12]},{32:[2,13],33:[2,13]},{5:[1,24],7:[1,23]},{5:[2,16],7:[2,16],11:16,22:25,33:[1,17]},{5:[2,18],7:[2,18],33:[2,18]},{23:[1,26]},{5:[2,29],10:[2,29],12:[2,29],14:[2,29],17:[2,29],18:[2,29],19:[2,29],23:[2,29],25:[2,29],26:[2,29],31:[2,29],32:[2,29],33:[2,29],34:[2,29],37:[2,29]},{5:[2,6],10:[2,6],12:[2,6],14:[2,6],17:[2,6],18:[2,6],19:[2,6]},{5:[2,10],10:[2,10],11:21,12:[2,10],14:[2,10],17:[2,10],18:[2,10],19:[2,10],20:27,32:[1,22],33:[1,17]},{5:[2,15],10:[2,15],12:[2,15],14:[2,15],17:[2,15],18:[2,15],19:[2,15],32:[2,15],33:[2,15]},{5:[2,27],10:[2,27],12:[2,27],14:[2,27],17:[2,27],18:[2,27],19:[2,27],25:[2,27],26:[2,27],31:[2,27],32:[2,27],33:[2,27],34:[2,27],37:[2,27]},{5:[2,28],10:[2,28],12:[2,28],14:[2,28],17:[2,28],18:[2,28],19:[2,28],25:[2,28],26:[2,28],31:[2,28],32:[2,28],33:[2,28],34:[2,28],37:[2,28]},{1:[2,1]},{7:[1,28],8:[1,29]},{5:[2,17],7:[2,17],33:[2,17]},{14:[2,24],24:30,25:[2,24],26:[2,24],27:31,28:32,31:[2,24],32:[2,24],33:[2,24],34:[2,24],37:[2,24]},{5:[2,14],10:[2,14],12:[2,14],14:[2,14],17:[2,14],18:[2,14],19:[2,14],32:[2,14],33:[2,14]},{1:[2,2]},{7:[1,33]},{25:[1,34],26:[1,35]},{25:[2,21],26:[2,21]},{11:21,14:[2,26],20:37,25:[2,26],26:[2,26],29:36,31:[1,38],32:[1,22],33:[1,17],34:[2,26],37:[2,26]},{1:[2,3]},{5:[2,19],7:[2,19],33:[2,19]},{14:[2,24],25:[2,24],26:[2,24],27:39,28:32,31:[2,24],32:[2,24],33:[2,24],34:[2,24],37:[2,24]},{14:[1,42],25:[2,33],26:[2,33],30:40,34:[1,41],37:[1,43]},{14:[2,23],25:[2,23],26:[2,23],31:[2,23],32:[2,23],33:[2,23],34:[2,23],37:[2,23]},{11:21,20:44,32:[1,22],33:[1,17]},{25:[2,20],26:[2,20]},{25:[2,22],26:[2,22]},{34:[2,34],35:45,36:[2,34],38:[1,46]},{25:[2,31],26:[2,31]},{25:[2,32],26:[2,32]},{14:[2,25],25:[2,25],26:[2,25],34:[2,25],37:[2,25]},{34:[1,48],36:[1,47]},{34:[2,35],36:[2,35]},{25:[2,30],26:[2,30]},{34:[2,34],35:49,36:[2,34],38:[1,46]},{34:[1,48],36:[1,50]},{34:[2,34],35:51,36:[2,34],38:[1,46]},{34:[1,48],36:[2,36]}], | ||
table: [{3:1,4:2,5:[2,5],10:[2,5],12:[2,5],14:[2,5],17:[2,5],18:[2,5],19:[2,5]},{1:[3]},{5:[1,3],9:4,10:[1,5],12:[1,6],13:7,14:[1,8],15:9,17:[1,10],18:[1,11],19:[1,12]},{6:13,11:16,21:14,22:15,33:[1,17]},{5:[2,4],10:[2,4],12:[2,4],14:[2,4],17:[2,4],18:[2,4],19:[2,4]},{11:18,33:[1,17]},{5:[2,7],10:[2,7],12:[2,7],14:[2,7],17:[2,7],18:[2,7],19:[2,7]},{5:[2,8],10:[2,8],12:[2,8],14:[2,8],17:[2,8],18:[2,8],19:[2,8]},{5:[2,9],10:[2,9],12:[2,9],14:[2,9],17:[2,9],18:[2,9],19:[2,9]},{11:21,16:19,20:20,32:[1,22],33:[1,17]},{32:[2,11],33:[2,11]},{32:[2,12],33:[2,12]},{32:[2,13],33:[2,13]},{5:[1,24],7:[1,23]},{5:[2,16],7:[2,16],11:16,22:25,33:[1,17]},{5:[2,18],7:[2,18],33:[2,18]},{23:[1,26]},{5:[2,29],10:[2,29],12:[2,29],14:[2,29],17:[2,29],18:[2,29],19:[2,29],23:[2,29],25:[2,29],26:[2,29],31:[2,29],32:[2,29],33:[2,29],34:[2,29],37:[2,29]},{5:[2,6],10:[2,6],12:[2,6],14:[2,6],17:[2,6],18:[2,6],19:[2,6]},{5:[2,10],10:[2,10],11:21,12:[2,10],14:[2,10],17:[2,10],18:[2,10],19:[2,10],20:27,32:[1,22],33:[1,17]},{5:[2,15],10:[2,15],12:[2,15],14:[2,15],17:[2,15],18:[2,15],19:[2,15],32:[2,15],33:[2,15]},{5:[2,27],10:[2,27],12:[2,27],14:[2,27],17:[2,27],18:[2,27],19:[2,27],25:[2,27],26:[2,27],31:[2,27],32:[2,27],33:[2,27],34:[2,27],37:[2,27]},{5:[2,28],10:[2,28],12:[2,28],14:[2,28],17:[2,28],18:[2,28],19:[2,28],25:[2,28],26:[2,28],31:[2,28],32:[2,28],33:[2,28],34:[2,28],37:[2,28]},{1:[2,1]},{7:[1,28],8:[1,29]},{5:[2,17],7:[2,17],33:[2,17]},{14:[2,24],24:30,25:[2,24],26:[2,24],27:31,28:32,31:[2,24],32:[2,24],33:[2,24],34:[2,24],37:[2,24]},{5:[2,14],10:[2,14],12:[2,14],14:[2,14],17:[2,14],18:[2,14],19:[2,14],32:[2,14],33:[2,14]},{1:[2,2]},{7:[1,33]},{25:[1,34],26:[1,35]},{25:[2,21],26:[2,21]},{11:21,14:[2,26],20:37,25:[2,26],26:[2,26],29:36,31:[1,38],32:[1,22],33:[1,17],34:[2,26],37:[2,26]},{1:[2,3]},{5:[2,19],7:[2,19],33:[2,19]},{14:[2,24],25:[2,24],26:[2,24],27:39,28:32,31:[2,24],32:[2,24],33:[2,24],34:[2,24],37:[2,24]},{14:[1,42],25:[2,33],26:[2,33],30:40,34:[1,41],37:[1,43]},{14:[2,23],25:[2,23],26:[2,23],31:[2,23],32:[2,23],33:[2,23],34:[2,23],37:[2,23]},{11:21,20:44,32:[1,22],33:[1,17]},{25:[2,20],26:[2,20]},{25:[2,22],26:[2,22]},{34:[2,34],35:45,36:[2,34],38:[1,46]},{25:[2,31],26:[2,31]},{25:[2,32],26:[2,32]},{14:[2,25],25:[2,25],26:[2,25],34:[2,25],37:[2,25]},{34:[1,48],36:[1,47]},{34:[2,35],36:[2,35]},{25:[2,30],26:[2,30]},{34:[2,34],35:49,36:[2,34],38:[1,46]},{34:[1,48],36:[1,50]},{34:[2,37],36:[2,37],38:[1,51]},{34:[2,36],36:[2,36]}], | ||
defaultActions: {23:[2,1],28:[2,2],33:[2,3]}, | ||
@@ -101,49 +103,28 @@ parseError: function parseError(str, hash) { | ||
parse: function parse(input) { | ||
var self = this, | ||
stack = [0], | ||
vstack = [null], // semantic value stack | ||
lstack = [], // location stack | ||
table = this.table, | ||
yytext = '', | ||
yylineno = 0, | ||
yyleng = 0, | ||
recovering = 0, | ||
TERROR = 2, | ||
EOF = 1; | ||
//this.reductionCount = this.shiftCount = 0; | ||
var self = this, stack = [0], vstack = [null], lstack = [], table = this.table, yytext = "", yylineno = 0, yyleng = 0, recovering = 0, TERROR = 2, EOF = 1; | ||
this.lexer.setInput(input); | ||
this.lexer.yy = this.yy; | ||
this.yy.lexer = this.lexer; | ||
if (typeof this.lexer.yylloc == 'undefined') | ||
if (typeof this.lexer.yylloc == "undefined") | ||
this.lexer.yylloc = {}; | ||
var yyloc = this.lexer.yylloc; | ||
lstack.push(yyloc); | ||
if (typeof this.yy.parseError === 'function') | ||
if (typeof this.yy.parseError === "function") | ||
this.parseError = this.yy.parseError; | ||
function popStack (n) { | ||
stack.length = stack.length - 2*n; | ||
function popStack(n) { | ||
stack.length = stack.length - 2 * n; | ||
vstack.length = vstack.length - n; | ||
lstack.length = lstack.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.lexer.lex() || 1; | ||
if (typeof token !== "number") { | ||
token = self.symbols_[token] || token; | ||
} | ||
return token; | ||
}; | ||
var symbol, preErrorSymbol, state, action, a, r, yyval={},p,len,newState, expected; | ||
} | ||
var symbol, preErrorSymbol, state, action, a, r, yyval = {}, p, len, newState, expected; | ||
while (true) { | ||
// retreive state number from top of stack | ||
state = stack[stack.length-1]; | ||
// use default actions if available | ||
state = stack[stack.length - 1]; | ||
if (this.defaultActions[state]) { | ||
@@ -154,34 +135,31 @@ action = this.defaultActions[state]; | ||
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 (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 = ''; | ||
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(', '); | ||
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)+"'")); | ||
errStr = "Parse error on line " + (yylineno + 1) + ": Unexpected " + (symbol == 1?"end of input":"'" + (this.terminals_[symbol] || symbol) + "'"); | ||
} | ||
this.parseError(errStr, | ||
{text: this.lexer.match, token: this.terminals_[symbol] || symbol, line: this.lexer.yylineno, loc: yyloc, expected: expected}); | ||
this.parseError(errStr, {text: this.lexer.match, token: this.terminals_[symbol] || symbol, line: this.lexer.yylineno, loc: yyloc, 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 | ||
} | ||
if (action[0] instanceof Array && action.length > 1) { | ||
throw new Error("Parse Error: multiple actions possible at state: " + state + ", token: " + symbol); | ||
} | ||
switch (action[0]) { | ||
case 1: | ||
stack.push(symbol); | ||
vstack.push(this.lexer.yytext); | ||
lstack.push(this.lexer.yylloc); | ||
stack.push(action[1]); | ||
symbol = null; | ||
if (!preErrorSymbol) { | ||
yyleng = this.lexer.yyleng; | ||
@@ -191,96 +169,35 @@ yytext = this.lexer.yytext; | ||
yyloc = this.lexer.yylloc; | ||
symbol = lex(); | ||
if (recovering > 0) | ||
recovering--; | ||
} else { | ||
symbol = preErrorSymbol; | ||
preErrorSymbol = null; | ||
} | ||
// 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]; | ||
break; | ||
case 2: | ||
len = this.productions_[action[1]][1]; | ||
yyval.$ = vstack[vstack.length - len]; | ||
yyval._$ = {first_line: lstack[lstack.length - (len || 1)].first_line, last_line: lstack[lstack.length - 1].last_line, first_column: lstack[lstack.length - (len || 1)].first_column, last_column: lstack[lstack.length - 1].last_column}; | ||
r = this.performAction.call(yyval, yytext, yyleng, yylineno, this.yy, action[1], vstack, lstack); | ||
if (typeof r !== "undefined") { | ||
return r; | ||
} | ||
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 | ||
if (len) { | ||
stack = stack.slice(0, -1 * len * 2); | ||
vstack = vstack.slice(0, -1 * len); | ||
lstack = lstack.slice(0, -1 * len); | ||
} | ||
stack.push(this.productions_[action[1]][0]); | ||
vstack.push(yyval.$); | ||
lstack.push(yyval._$); | ||
newState = table[stack[stack.length - 2]][stack[stack.length - 1]]; | ||
stack.push(newState); | ||
break; | ||
case 3: | ||
return true; | ||
} | ||
// 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); | ||
} | ||
switch (action[0]) { | ||
case 1: // shift | ||
//this.shiftCount++; | ||
stack.push(symbol); | ||
vstack.push(this.lexer.yytext); | ||
lstack.push(this.lexer.yylloc); | ||
stack.push(action[1]); // push state | ||
symbol = null; | ||
if (!preErrorSymbol) { // normal execution/no error | ||
yyleng = this.lexer.yyleng; | ||
yytext = this.lexer.yytext; | ||
yylineno = this.lexer.yylineno; | ||
yyloc = this.lexer.yylloc; | ||
if (recovering > 0) | ||
recovering--; | ||
} else { // error just occurred, resume old lookahead f/ before error | ||
symbol = preErrorSymbol; | ||
preErrorSymbol = null; | ||
} | ||
break; | ||
case 2: // reduce | ||
//this.reductionCount++; | ||
len = this.productions_[action[1]][1]; | ||
// perform semantic action | ||
yyval.$ = vstack[vstack.length-len]; // default to $$ = $1 | ||
// default location, uses first token for firsts, last for lasts | ||
yyval._$ = { | ||
first_line: lstack[lstack.length-(len||1)].first_line, | ||
last_line: lstack[lstack.length-1].last_line, | ||
first_column: lstack[lstack.length-(len||1)].first_column, | ||
last_column: lstack[lstack.length-1].last_column | ||
}; | ||
r = this.performAction.call(yyval, yytext, yyleng, yylineno, this.yy, action[1], vstack, lstack); | ||
if (typeof r !== 'undefined') { | ||
return r; | ||
} | ||
// pop off stack | ||
if (len) { | ||
stack = stack.slice(0,-1*len*2); | ||
vstack = vstack.slice(0, -1*len); | ||
lstack = lstack.slice(0, -1*len); | ||
} | ||
stack.push(this.productions_[action[1]][0]); // push nonterminal (reduce) | ||
vstack.push(yyval.$); | ||
lstack.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 | ||
return true; | ||
} | ||
} | ||
return true; | ||
}};/* Jison generated lexer */ | ||
} | ||
};/* Jison generated lexer */ | ||
var lexer = (function(){ | ||
@@ -287,0 +204,0 @@ |
@@ -6,5 +6,5 @@ | ||
var fs = require('fs'); | ||
var sys = require('sys'); | ||
var util = require('util'); | ||
exports.p = sys.puts; | ||
exports.p = util.puts; | ||
exports.cwd = process.cwd; | ||
@@ -11,0 +11,0 @@ exports.join = require('path').join; |
@@ -126,49 +126,28 @@ /* Jison generated parser */ | ||
parse: function parse(input) { | ||
var self = this, | ||
stack = [0], | ||
vstack = [null], // semantic value stack | ||
lstack = [], // location stack | ||
table = this.table, | ||
yytext = '', | ||
yylineno = 0, | ||
yyleng = 0, | ||
recovering = 0, | ||
TERROR = 2, | ||
EOF = 1; | ||
//this.reductionCount = this.shiftCount = 0; | ||
var self = this, stack = [0], vstack = [null], lstack = [], table = this.table, yytext = "", yylineno = 0, yyleng = 0, recovering = 0, TERROR = 2, EOF = 1; | ||
this.lexer.setInput(input); | ||
this.lexer.yy = this.yy; | ||
this.yy.lexer = this.lexer; | ||
if (typeof this.lexer.yylloc == 'undefined') | ||
if (typeof this.lexer.yylloc == "undefined") | ||
this.lexer.yylloc = {}; | ||
var yyloc = this.lexer.yylloc; | ||
lstack.push(yyloc); | ||
if (typeof this.yy.parseError === 'function') | ||
if (typeof this.yy.parseError === "function") | ||
this.parseError = this.yy.parseError; | ||
function popStack (n) { | ||
stack.length = stack.length - 2*n; | ||
function popStack(n) { | ||
stack.length = stack.length - 2 * n; | ||
vstack.length = vstack.length - n; | ||
lstack.length = lstack.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.lexer.lex() || 1; | ||
if (typeof token !== "number") { | ||
token = self.symbols_[token] || token; | ||
} | ||
return token; | ||
}; | ||
var symbol, preErrorSymbol, state, action, a, r, yyval={},p,len,newState, expected; | ||
} | ||
var symbol, preErrorSymbol, state, action, a, r, yyval = {}, p, len, newState, expected; | ||
while (true) { | ||
// retreive state number from top of stack | ||
state = stack[stack.length-1]; | ||
// use default actions if available | ||
state = stack[stack.length - 1]; | ||
if (this.defaultActions[state]) { | ||
@@ -179,34 +158,31 @@ action = this.defaultActions[state]; | ||
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 (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 = ''; | ||
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(', '); | ||
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)+"'")); | ||
errStr = "Parse error on line " + (yylineno + 1) + ": Unexpected " + (symbol == 1?"end of input":"'" + (this.terminals_[symbol] || symbol) + "'"); | ||
} | ||
this.parseError(errStr, | ||
{text: this.lexer.match, token: this.terminals_[symbol] || symbol, line: this.lexer.yylineno, loc: yyloc, expected: expected}); | ||
this.parseError(errStr, {text: this.lexer.match, token: this.terminals_[symbol] || symbol, line: this.lexer.yylineno, loc: yyloc, 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 | ||
} | ||
if (action[0] instanceof Array && action.length > 1) { | ||
throw new Error("Parse Error: multiple actions possible at state: " + state + ", token: " + symbol); | ||
} | ||
switch (action[0]) { | ||
case 1: | ||
stack.push(symbol); | ||
vstack.push(this.lexer.yytext); | ||
lstack.push(this.lexer.yylloc); | ||
stack.push(action[1]); | ||
symbol = null; | ||
if (!preErrorSymbol) { | ||
yyleng = this.lexer.yyleng; | ||
@@ -216,96 +192,35 @@ yytext = this.lexer.yytext; | ||
yyloc = this.lexer.yylloc; | ||
symbol = lex(); | ||
if (recovering > 0) | ||
recovering--; | ||
} else { | ||
symbol = preErrorSymbol; | ||
preErrorSymbol = null; | ||
} | ||
// 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]; | ||
break; | ||
case 2: | ||
len = this.productions_[action[1]][1]; | ||
yyval.$ = vstack[vstack.length - len]; | ||
yyval._$ = {first_line: lstack[lstack.length - (len || 1)].first_line, last_line: lstack[lstack.length - 1].last_line, first_column: lstack[lstack.length - (len || 1)].first_column, last_column: lstack[lstack.length - 1].last_column}; | ||
r = this.performAction.call(yyval, yytext, yyleng, yylineno, this.yy, action[1], vstack, lstack); | ||
if (typeof r !== "undefined") { | ||
return r; | ||
} | ||
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 | ||
if (len) { | ||
stack = stack.slice(0, -1 * len * 2); | ||
vstack = vstack.slice(0, -1 * len); | ||
lstack = lstack.slice(0, -1 * len); | ||
} | ||
stack.push(this.productions_[action[1]][0]); | ||
vstack.push(yyval.$); | ||
lstack.push(yyval._$); | ||
newState = table[stack[stack.length - 2]][stack[stack.length - 1]]; | ||
stack.push(newState); | ||
break; | ||
case 3: | ||
return true; | ||
} | ||
// 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); | ||
} | ||
switch (action[0]) { | ||
case 1: // shift | ||
//this.shiftCount++; | ||
stack.push(symbol); | ||
vstack.push(this.lexer.yytext); | ||
lstack.push(this.lexer.yylloc); | ||
stack.push(action[1]); // push state | ||
symbol = null; | ||
if (!preErrorSymbol) { // normal execution/no error | ||
yyleng = this.lexer.yyleng; | ||
yytext = this.lexer.yytext; | ||
yylineno = this.lexer.yylineno; | ||
yyloc = this.lexer.yylloc; | ||
if (recovering > 0) | ||
recovering--; | ||
} else { // error just occurred, resume old lookahead f/ before error | ||
symbol = preErrorSymbol; | ||
preErrorSymbol = null; | ||
} | ||
break; | ||
case 2: // reduce | ||
//this.reductionCount++; | ||
len = this.productions_[action[1]][1]; | ||
// perform semantic action | ||
yyval.$ = vstack[vstack.length-len]; // default to $$ = $1 | ||
// default location, uses first token for firsts, last for lasts | ||
yyval._$ = { | ||
first_line: lstack[lstack.length-(len||1)].first_line, | ||
last_line: lstack[lstack.length-1].last_line, | ||
first_column: lstack[lstack.length-(len||1)].first_column, | ||
last_column: lstack[lstack.length-1].last_column | ||
}; | ||
r = this.performAction.call(yyval, yytext, yyleng, yylineno, this.yy, action[1], vstack, lstack); | ||
if (typeof r !== 'undefined') { | ||
return r; | ||
} | ||
// pop off stack | ||
if (len) { | ||
stack = stack.slice(0,-1*len*2); | ||
vstack = vstack.slice(0, -1*len); | ||
lstack = lstack.slice(0, -1*len); | ||
} | ||
stack.push(this.productions_[action[1]][0]); // push nonterminal (reduce) | ||
vstack.push(yyval.$); | ||
lstack.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 | ||
return true; | ||
} | ||
} | ||
return true; | ||
}};/* Jison generated lexer */ | ||
} | ||
};/* Jison generated lexer */ | ||
var lexer = (function(){ | ||
@@ -312,0 +227,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"description": "A parser generator with Bison's API", | ||
"version": "0.2.11", | ||
"version": "0.2.12", | ||
"keywords": [ | ||
@@ -34,5 +34,7 @@ "jison", | ||
"engines": { | ||
"node": "0.4 || 0.5" | ||
"node": ">=0.4" | ||
}, | ||
"dependencies": { | ||
"JSONSelect": "*", | ||
"reflect": "*", | ||
"nomnom": "0.4.3" | ||
@@ -52,18 +54,3 @@ }, | ||
}, | ||
"modules": { | ||
"jison.js": "lib/jison.js", | ||
"jison/bnf.js": "lib/jison/bnf.js", | ||
"jison/cli-wrapper.js": "lib/jison/cli-wrapper.js", | ||
"jison/jison2json.js": "lib/jison/jison2json.js", | ||
"jison/jisonlex.js": "lib/jison/jisonlex.js", | ||
"jison/json2jison.js": "lib/jison/json2jison.js", | ||
"jison/lexer.js": "lib/jison/lexer.js", | ||
"jison/util/bnf-parser.js": "lib/jison/util/bnf-parser.js", | ||
"jison/util/io.js": "lib/jison/util/io.js", | ||
"jison/util/lex-parser.js": "lib/jison/util/lex-parser.js", | ||
"jison/util/nomnom.js": "lib/jison/util/nomnom.js", | ||
"jison/util/set.js": "lib/jison/util/set.js", | ||
"jison/util/typal.js": "lib/jison/util/typal.js" | ||
}, | ||
"homepage": "http://jison.org" | ||
} |
@@ -120,1 +120,22 @@ var Jison = require("../setup").Jison, | ||
exports["test compilers test grammar"] = function () { | ||
var lexData = { | ||
rules: [ | ||
["x", "return 'x';"] | ||
] | ||
}; | ||
var grammar = { | ||
tokens: [ 'x' ], | ||
startSymbol: "S", | ||
bnf: { | ||
"S" :[ 'A' ], | ||
"A" :[ 'B A', '' ], | ||
"B" :[ '', 'x' ] | ||
} | ||
}; | ||
var parser = new Jison.Parser(grammar, {type: "lr"}); | ||
parser.lexer = new Lexer(lexData); | ||
assert.ok(parser.parse("xxx"), "parse"); | ||
}; |
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 2 instances in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
0
238960
3
5986
2
13
+ AddedJSONSelect@*
+ Addedreflect@*
+ AddedJSONSelect@0.4.0(transitive)
+ Addedreflect@0.1.3(transitive)