updating Jison

This commit is contained in:
Jeremy Ashkenas
2010-02-13 18:19:59 -05:00
parent 97fd126a7f
commit ecfa212189
3 changed files with 21 additions and 10 deletions

View File

@@ -919,7 +919,7 @@ lrGeneratorMixin.createParser = function createParser () {
table: this.table,
productions_: this.productions_,
symbols_: this.symbols_,
terminals_: this.terminals,
terminals_: this.terminals_,
performAction: this.performAction
});
@@ -984,8 +984,13 @@ parser.parse = function parse (input) {
for (p in table[state]) if (this.terminals_[p] && p != 1) {
expected.push("'"+this.terminals_[p]+"'");
}
parseError('Parse error on line '+(yylineno+1)+'. Expecting: '+expected.join(', ')+"\n"+(this.lexer.showPosition && this.lexer.showPosition()),
{text: this.lexer.match, token: symbol, line: this.lexer.yylineno});
if (this.lexer.showPosition) {
parseError('Parse error on line '+(yylineno+1)+":\n"+this.lexer.showPosition()+'\nExpecting '+expected.join(', '),
{text: this.lexer.match, token: this.terminals_[symbol], line: this.lexer.yylineno, expected: expected});
} else {
parseError('Parse error on line '+(yylineno+1)+": Unexpected '"+this.terminals_[symbol]+"'",
{text: this.lexer.match, token: this.terminals_[symbol], line: this.lexer.yylineno, expected: expected});
}
}
this.trace('action:',action);

View File

@@ -219,10 +219,11 @@ exports["test custom parse error method"] = function () {
result = hash;
throw str;
};
assert["throws"](function () {parser.parse("agb")});
assert.equal(result.text, "b", "parse error text should equal b");
assert["throws"](function () {parser.parse("agz")});
assert.equal(result.line, 0, "lexical error should have correct line");
assert["throws"](function () {parser.parse("aga")});
assert.strictEqual(result.text, "a", "parse error text should equal b");
assert.strictEqual(typeof result.token, 'string', "parse error token should be a string");
assert.strictEqual(result.line, 0, "hash should include line number");
};
exports["test jison grammar as string"] = function () {