1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

Fix failing parser error message test

This commit is contained in:
Demian Ferreiro 2013-02-26 05:55:09 -03:00
parent 44e3a76881
commit fbc8417263
3 changed files with 10 additions and 11 deletions

View file

@ -169,10 +169,10 @@
parser.yy = require('./nodes');
parser.yy.parseError = function(message, _arg) {
var first_column, first_line, last_column, last_line, loc, token;
loc = _arg.loc, token = _arg.token;
var first_column, first_line, last_column, last_line, token, _ref;
token = _arg.token;
message = "unexpected " + token;
first_line = loc.first_line, first_column = loc.first_column, last_line = loc.last_line, last_column = loc.last_column;
_ref = parser.lexer.yylloc, first_line = _ref.first_line, first_column = _ref.first_column, last_line = _ref.last_line, last_column = _ref.last_column;
throw new CompilerError(message, first_line, first_column, last_line, last_column);
};

View file

@ -137,13 +137,13 @@ parser.lexer =
parser.yy = require './nodes'
# Override Jison's default error handling function.
parser.yy.parseError = (message, {loc, token}) ->
parser.yy.parseError = (message, {token}) ->
# Disregard Jison's message, it contains redundant line numer information.
message = "unexpected #{token}"
# FIXME The `loc` received does not correspond to the `token` token, but to
# the one before it instead. That's why the test in error_messages.coffee is
# failing. There should be a way to get the location data... maybe accessing
# the lexer's tokens?
{first_line, first_column, last_line, last_column} = loc
# The second argument has a `loc` property, which should have the location
# data for this token. Unfortunately, Jison seems to send an outdated `loc`
# (from the previous token), so we take the location information directly
# from the lexer.
{first_line, first_column, last_line, last_column} = parser.lexer.yylloc
throw new CompilerError message, first_line, first_column, last_line, last_column

View file

@ -20,13 +20,12 @@ test "lexer errors formating", ->
^
'''
# FIXME Test not passing. See "parser.yy.parseError" in coffee-script.coffee
test "parser error formating", ->
assertErrorFormat '''
foo in bar or in baz
''',
'''
test.coffee:1:12: error: unexpected RELATION
test.coffee:1:15: error: unexpected RELATION
foo in bar or in baz
^^
'''