Skip to content

Commit

Permalink
Add "Unexpected" token type/value to errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tjvr committed Apr 17, 2017
1 parent ea9584f commit 93967e8
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/nearley.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ Parser.prototype.feed = function(chunk) {
if (nextColumn.states.length === 0) {
// No states at all! This is not good.
var message = this.lexer.formatError(token, "invalid syntax") + "\n";
message += "Unexpected " + (token.type ? token.type + " token: " : "");
message += JSON.stringify(token.value !== undefined ? token.value : token) + "\n";
var err = new Error(message);
err.offset = this.current;
throw err;
Expand Down

0 comments on commit 93967e8

Please sign in to comment.