mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
Add CompilationError.fromLocationData
This commit is contained in:
parent
1db89d1589
commit
5115fcb162
7 changed files with 16 additions and 12 deletions
|
@ -169,11 +169,10 @@
|
|||
parser.yy = require('./nodes');
|
||||
|
||||
parser.yy.parseError = function(message, _arg) {
|
||||
var first_column, first_line, last_column, last_line, token, _ref;
|
||||
var token;
|
||||
token = _arg.token;
|
||||
message = "unexpected " + token;
|
||||
_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);
|
||||
throw CompilerError.fromLocationData(message, parser.lexer.yylloc);
|
||||
};
|
||||
|
||||
}).call(this);
|
||||
|
|
|
@ -23,6 +23,12 @@
|
|||
}
|
||||
}
|
||||
|
||||
CompilerError.fromLocationData = function(message, _arg) {
|
||||
var first_column, first_line, last_column, last_line;
|
||||
first_line = _arg.first_line, first_column = _arg.first_column, last_line = _arg.last_line, last_column = _arg.last_column;
|
||||
return new CompilerError(message, first_line, first_column, last_line, last_column);
|
||||
};
|
||||
|
||||
CompilerError.prototype.prettyMessage = function(fileName, code) {
|
||||
var errorLength, errorLine, marker, message;
|
||||
message = "" + fileName + ":" + (this.startLine + 1) + ":" + (this.startColumn + 1) + ": error: " + this.message;
|
||||
|
|
|
@ -199,9 +199,7 @@
|
|||
};
|
||||
|
||||
Base.prototype.error = function(message) {
|
||||
var first_column, first_line, last_column, last_line, _ref2;
|
||||
_ref2 = this.locationData, first_line = _ref2.first_line, first_column = _ref2.first_column, last_line = _ref2.last_line, last_column = _ref2.last_column;
|
||||
throw new CompilerError(message, first_line, first_column, last_line, last_column);
|
||||
throw CompilerError.fromLocationData(message, this.locationData);
|
||||
};
|
||||
|
||||
return Base;
|
||||
|
|
|
@ -140,10 +140,8 @@ parser.yy = require './nodes'
|
|||
parser.yy.parseError = (message, {token}) ->
|
||||
# Disregard Jison's message, it contains redundant line numer information.
|
||||
message = "unexpected #{token}"
|
||||
|
||||
# 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
|
||||
throw CompilerError.fromLocationData message, parser.lexer.yylloc
|
|
@ -10,6 +10,10 @@ exports.CompilerError = class CompilerError extends Error
|
|||
# Add a stack trace in V8.
|
||||
Error.captureStackTrace? @, CompilerError
|
||||
|
||||
# Creates a CompilerError from a given locationData.
|
||||
@fromLocationData = (message, {first_line, first_column, last_line, last_column}) ->
|
||||
new CompilerError message, first_line, first_column, last_line, last_column
|
||||
|
||||
# Creates a nice error message like, following the "standard" format
|
||||
# <filename>:<line>:<col>: <message> plus the line with the error and a marker
|
||||
# showing where the error is.
|
||||
|
|
|
@ -13,7 +13,7 @@ exports.ends = (string, literal, back) ->
|
|||
|
||||
# Repeat a string `n` times.
|
||||
exports.repeat = (str, n) ->
|
||||
# Use clever algorithm to have O(lon(n)) string concatenation operations
|
||||
# Use clever algorithm to have O(log(n)) string concatenation operations.
|
||||
res = ''
|
||||
while n > 0
|
||||
res += str if n & 1
|
||||
|
|
|
@ -163,8 +163,7 @@ exports.Base = class Base
|
|||
|
||||
# Throw a compiler error associated with this node's location.
|
||||
error: (message) ->
|
||||
{first_line, first_column, last_line, last_column} = @locationData
|
||||
throw new CompilerError message, first_line, first_column, last_line, last_column
|
||||
throw CompilerError.fromLocationData message, @locationData
|
||||
|
||||
#### Block
|
||||
|
||||
|
|
Loading…
Reference in a new issue