mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
Unified error handling in the lexer.
This commit is contained in:
parent
3cdee749c6
commit
19f77cfff5
2 changed files with 18 additions and 32 deletions
|
@ -28,7 +28,7 @@
|
|||
i += this.identifierToken() || this.commentToken() || this.whitespaceToken() || this.lineToken() || this.heredocToken() || this.stringToken() || this.numberToken() || this.regexToken() || this.jsToken() || this.literalToken();
|
||||
}
|
||||
this.closeIndentation();
|
||||
if (tag = this.ends.pop()) this.carp("missing " + tag);
|
||||
if (tag = this.ends.pop()) this.error("missing " + tag);
|
||||
if (opts.rewrite === false) return this.tokens;
|
||||
return (new Rewriter).rewrite(this.tokens);
|
||||
};
|
||||
|
@ -71,7 +71,7 @@
|
|||
id = new String(id);
|
||||
id.reserved = true;
|
||||
} else if (__indexOf.call(RESERVED, id) >= 0) {
|
||||
this.identifierError(id);
|
||||
this.error("Reserved word \"" + word + "\"");
|
||||
}
|
||||
}
|
||||
if (!forcedIdentifier) {
|
||||
|
@ -323,7 +323,7 @@
|
|||
prev = last(this.tokens);
|
||||
if (value === '=' && prev) {
|
||||
if (!prev[1].reserved && (_ref3 = prev[1], __indexOf.call(JS_FORBIDDEN, _ref3) >= 0)) {
|
||||
this.assignmentError();
|
||||
this.error("Reserved word \"" + (this.value()) + "\" can't be assigned");
|
||||
}
|
||||
if ((_ref4 = prev[1]) === '||' || _ref4 === '&&') {
|
||||
prev[0] = 'COMPOUND_ASSIGN';
|
||||
|
@ -376,7 +376,7 @@
|
|||
indent = options.indent, herecomment = options.herecomment;
|
||||
if (herecomment) {
|
||||
if (HEREDOC_ILLEGAL.test(doc)) {
|
||||
this.carp("block comment cannot contain \"*/\", starting");
|
||||
this.error("block comment cannot contain \"*/\", starting");
|
||||
}
|
||||
if (doc.indexOf('\n') <= 0) return doc;
|
||||
} else {
|
||||
|
@ -420,12 +420,6 @@
|
|||
Lexer.prototype.closeIndentation = function() {
|
||||
return this.outdentToken(this.indent);
|
||||
};
|
||||
Lexer.prototype.identifierError = function(word) {
|
||||
throw SyntaxError("Reserved word \"" + word + "\" on line " + (this.line + 1));
|
||||
};
|
||||
Lexer.prototype.assignmentError = function() {
|
||||
throw SyntaxError("Reserved word \"" + (this.value()) + "\" on line " + (this.line + 1) + " can't be assigned");
|
||||
};
|
||||
Lexer.prototype.balancedString = function(str, end) {
|
||||
var i, letter, match, prev, stack, _ref3;
|
||||
stack = [end];
|
||||
|
@ -451,7 +445,7 @@
|
|||
}
|
||||
prev = letter;
|
||||
}
|
||||
return this.carp("missing " + (stack.pop()) + ", starting");
|
||||
return this.error("missing " + (stack.pop()) + ", starting");
|
||||
};
|
||||
Lexer.prototype.interpolateString = function(str, options) {
|
||||
var expr, heredoc, i, inner, interpolated, len, letter, nested, pi, regex, tag, tokens, value, _len, _ref3, _ref4, _ref5;
|
||||
|
@ -510,7 +504,7 @@
|
|||
Lexer.prototype.pair = function(tag) {
|
||||
var size, wanted;
|
||||
if (tag !== (wanted = last(this.ends))) {
|
||||
if ('OUTDENT' !== wanted) this.carp("unmatched " + tag);
|
||||
if ('OUTDENT' !== wanted) this.error("unmatched " + tag);
|
||||
this.indent -= size = last(this.indents);
|
||||
this.outdentToken(size, true);
|
||||
return this.pair(tag);
|
||||
|
@ -547,7 +541,7 @@
|
|||
body = body.replace(RegExp("" + quote, "g"), '\\$&');
|
||||
return quote + this.escapeLines(body, heredoc) + quote;
|
||||
};
|
||||
Lexer.prototype.carp = function(message) {
|
||||
Lexer.prototype.error = function(message) {
|
||||
throw SyntaxError("" + message + " on line " + (this.line + 1));
|
||||
};
|
||||
return Lexer;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue