mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-19 03:44:23 -05:00
made simple strings shortcut
This commit is contained in:
32
lib/lexer.js
32
lib/lexer.js
@@ -1,5 +1,5 @@
|
||||
(function() {
|
||||
var ASSIGNED, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, CONVERSIONS, HEREDOC, HEREDOC_INDENT, IDENTIFIER, JS_FORBIDDEN, JS_KEYWORDS, LINE_BREAK, LOGIC, Lexer, MATH, MULTILINER, MULTI_DENT, NEXT_CHARACTER, NOT_REGEX, NO_NEWLINE, NUMBER, OPERATOR, REGEX_END, REGEX_ESCAPE, REGEX_INTERPOLATION, REGEX_START, RESERVED, Rewriter, SHIFT, UNARY, WHITESPACE, _ref, compact, count, include, starts;
|
||||
var ASSIGNED, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, CONVERSIONS, HEREDOC, HEREDOC_INDENT, IDENTIFIER, JSTOKEN, JS_FORBIDDEN, JS_KEYWORDS, LINE_BREAK, LOGIC, Lexer, MATH, MULTILINER, MULTI_DENT, NEXT_CHARACTER, NOT_REGEX, NO_NEWLINE, NUMBER, OPERATOR, REGEX_END, REGEX_ESCAPE, REGEX_INTERPOLATION, REGEX_START, RESERVED, Rewriter, SHIFT, SIMPLESTR, UNARY, WHITESPACE, _ref, compact, count, include, starts;
|
||||
var __slice = Array.prototype.slice;
|
||||
_ref = require('./rewriter');
|
||||
Rewriter = _ref.Rewriter;
|
||||
@@ -96,14 +96,23 @@
|
||||
return true;
|
||||
};
|
||||
Lexer.prototype.stringToken = function() {
|
||||
var _ref2, string;
|
||||
if (!(("'" === (_ref2 = this.chunk.charAt(0)) || '"' === _ref2))) {
|
||||
return false;
|
||||
var string;
|
||||
switch (this.chunk.charAt(0)) {
|
||||
case "'":
|
||||
if (!(string = this.match(SIMPLESTR))) {
|
||||
return false;
|
||||
}
|
||||
this.token('STRING', string.replace(MULTILINER, '\\\n'));
|
||||
break;
|
||||
case '"':
|
||||
if (!(string = this.balancedToken(['"', '"'], ['#{', '}']))) {
|
||||
return false;
|
||||
}
|
||||
this.interpolateString(string.replace(MULTILINER, '\\\n'));
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
if (!(string = this.balancedToken(['"', '"'], ['#{', '}']) || this.balancedToken(["'", "'"]))) {
|
||||
return false;
|
||||
}
|
||||
this.interpolateString(string.replace(MULTILINER, '\\\n'));
|
||||
this.line += count(string, '\n');
|
||||
this.i += string.length;
|
||||
return true;
|
||||
@@ -146,10 +155,7 @@
|
||||
};
|
||||
Lexer.prototype.jsToken = function() {
|
||||
var script;
|
||||
if (this.chunk.charAt(0) !== '`') {
|
||||
return false;
|
||||
}
|
||||
if (!(script = this.balancedToken(['`', '`']))) {
|
||||
if (!(this.chunk.charAt(0) === '`' && (script = this.match(JSTOKEN)))) {
|
||||
return false;
|
||||
}
|
||||
this.token('JS', script.slice(1, -1));
|
||||
@@ -590,6 +596,8 @@
|
||||
COMMENT = /^###([^#][\s\S]*?)(?:###[ \t]*\n|(?:###)?$)|^(?:\s*#(?!##[^#])[^\n]*)+/;
|
||||
CODE = /^[-=]>/;
|
||||
MULTI_DENT = /^(?:\n[ \t]*)+/;
|
||||
SIMPLESTR = /^'[^\\']*(?:\\.[^\\']*)*'/;
|
||||
JSTOKEN = /^`[^\\`]*(?:\\.[^\\`]*)*`/;
|
||||
REGEX_START = /^\/([^\/])/;
|
||||
REGEX_INTERPOLATION = /[^\\]#\{.*[^\\]\}/;
|
||||
REGEX_END = /^[imgy]{0,4}(?![a-zA-Z])/;
|
||||
|
||||
Reference in New Issue
Block a user