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

Making #1050 a syntax error.

This commit is contained in:
Jeremy Ashkenas 2011-01-18 23:10:09 -05:00
parent 7ae284f432
commit 4b78790096
3 changed files with 22 additions and 9 deletions

View file

@ -1,5 +1,5 @@
(function() { (function() {
var ASSIGNED, BOOL, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, HEREDOC, HEREDOC_INDENT, HEREGEX, HEREGEX_OMIT, IDENTIFIER, INDEXABLE, JSTOKEN, JS_FORBIDDEN, JS_KEYWORDS, LINE_BREAK, LINE_CONTINUER, LOGIC, Lexer, MATH, MULTILINER, MULTI_DENT, NOT_REGEX, NOT_SPACED_REGEX, NO_NEWLINE, NUMBER, OPERATOR, REGEX, RELATION, RESERVED, Rewriter, SHIFT, SIMPLESTR, TRAILING_SPACES, UNARY, WHITESPACE, compact, count, last, op, starts, _ref; var ASSIGNED, BOOL, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, HEREDOC, HEREDOC_ILLEGAL, HEREDOC_INDENT, HEREGEX, HEREGEX_OMIT, IDENTIFIER, INDEXABLE, JSTOKEN, JS_FORBIDDEN, JS_KEYWORDS, LINE_BREAK, LINE_CONTINUER, LOGIC, Lexer, MATH, MULTILINER, MULTI_DENT, NOT_REGEX, NOT_SPACED_REGEX, NO_NEWLINE, NUMBER, OPERATOR, REGEX, RELATION, RESERVED, Rewriter, SHIFT, SIMPLESTR, TRAILING_SPACES, UNARY, WHITESPACE, compact, count, last, op, starts, _ref;
var __indexOf = Array.prototype.indexOf || function(item) { var __indexOf = Array.prototype.indexOf || function(item) {
for (var i = 0, l = this.length; i < l; i++) { for (var i = 0, l = this.length; i < l; i++) {
if (this[i] === item) return i; if (this[i] === item) return i;
@ -175,7 +175,6 @@
return 0; return 0;
} }
comment = match[0], here = match[1]; comment = match[0], here = match[1];
this.line += count(comment, '\n');
if (here) { if (here) {
this.token('HERECOMMENT', this.sanitizeHeredoc(here, { this.token('HERECOMMENT', this.sanitizeHeredoc(here, {
herecomment: true, herecomment: true,
@ -183,6 +182,7 @@
})); }));
this.token('TERMINATOR', '\n'); this.token('TERMINATOR', '\n');
} }
this.line += count(comment, '\n');
return comment.length; return comment.length;
}; };
Lexer.prototype.jsToken = function() { Lexer.prototype.jsToken = function() {
@ -398,10 +398,14 @@
Lexer.prototype.sanitizeHeredoc = function(doc, options) { Lexer.prototype.sanitizeHeredoc = function(doc, options) {
var attempt, herecomment, indent, match, _ref; var attempt, herecomment, indent, match, _ref;
indent = options.indent, herecomment = options.herecomment; indent = options.indent, herecomment = options.herecomment;
if (herecomment && 0 > doc.indexOf('\n')) { if (herecomment) {
return doc; if (HEREDOC_ILLEGAL.test(doc)) {
} throw new Error("block comment cannot contain \"*/\", starting on line " + (this.line + 1));
if (!herecomment) { }
if (doc.indexOf('\n') <= 0) {
return doc;
}
} else {
while (match = HEREDOC_INDENT.exec(doc)) { while (match = HEREDOC_INDENT.exec(doc)) {
attempt = match[1]; attempt = match[1];
if (indent === null || (0 < (_ref = attempt.length) && _ref < indent.length)) { if (indent === null || (0 < (_ref = attempt.length) && _ref < indent.length)) {
@ -618,6 +622,7 @@
HEREGEX_OMIT = /\s+(?:#.*)?/g; HEREGEX_OMIT = /\s+(?:#.*)?/g;
MULTILINER = /\n/g; MULTILINER = /\n/g;
HEREDOC_INDENT = /\n+([^\n\S]*)/g; HEREDOC_INDENT = /\n+([^\n\S]*)/g;
HEREDOC_ILLEGAL = /\*\//;
ASSIGNED = /^\s*@?([$A-Za-z_][$\w\x7f-\uffff]*|['"].*['"])[^\n\S]*?[:=][^:=>]/; ASSIGNED = /^\s*@?([$A-Za-z_][$\w\x7f-\uffff]*|['"].*['"])[^\n\S]*?[:=][^:=>]/;
LINE_CONTINUER = /^\s*(?:,|\??\.(?!\.)|::)/; LINE_CONTINUER = /^\s*(?:,|\??\.(?!\.)|::)/;
TRAILING_SPACES = /\s+$/; TRAILING_SPACES = /\s+$/;

View file

@ -170,11 +170,11 @@ exports.Lexer = class Lexer
commentToken: -> commentToken: ->
return 0 unless match = @chunk.match COMMENT return 0 unless match = @chunk.match COMMENT
[comment, here] = match [comment, here] = match
@line += count comment, '\n'
if here if here
@token 'HERECOMMENT', @sanitizeHeredoc here, @token 'HERECOMMENT', @sanitizeHeredoc here,
herecomment: true, indent: Array(@indent + 1).join(' ') herecomment: true, indent: Array(@indent + 1).join(' ')
@token 'TERMINATOR', '\n' @token 'TERMINATOR', '\n'
@line += count comment, '\n'
comment.length comment.length
# Matches JavaScript interpolated directly into the source via backticks. # Matches JavaScript interpolated directly into the source via backticks.
@ -343,8 +343,11 @@ exports.Lexer = class Lexer
# erasing all external indentation on the left-hand side. # erasing all external indentation on the left-hand side.
sanitizeHeredoc: (doc, options) -> sanitizeHeredoc: (doc, options) ->
{indent, herecomment} = options {indent, herecomment} = options
return doc if herecomment and 0 > doc.indexOf '\n' if herecomment
unless herecomment if HEREDOC_ILLEGAL.test doc
throw new Error "block comment cannot contain \"*/\", starting on line #{@line + 1}"
return doc if doc.indexOf('\n') <= 0
else
while match = HEREDOC_INDENT.exec doc while match = HEREDOC_INDENT.exec doc
attempt = match[1] attempt = match[1]
indent = attempt if indent is null or 0 < attempt.length < indent.length indent = attempt if indent is null or 0 < attempt.length < indent.length
@ -593,6 +596,8 @@ MULTILINER = /\n/g
HEREDOC_INDENT = /\n+([^\n\S]*)/g HEREDOC_INDENT = /\n+([^\n\S]*)/g
HEREDOC_ILLEGAL = /\*\//
ASSIGNED = /^\s*@?([$A-Za-z_][$\w\x7f-\uffff]*|['"].*['"])[^\n\S]*?[:=][^:=>]/ ASSIGNED = /^\s*@?([$A-Za-z_][$\w\x7f-\uffff]*|['"].*['"])[^\n\S]*?[:=][^:=>]/
LINE_CONTINUER = /// ^ \s* (?: , | \??\.(?!\.) | :: ) /// LINE_CONTINUER = /// ^ \s* (?: , | \??\.(?!\.) | :: ) ///

View file

@ -55,3 +55,6 @@ test "#1026", ->
else else
d d
''' '''
test "#1050", ->
cantCompile "### */ ###"