made simple strings shortcut
This commit is contained in:
parent
f051d0880e
commit
d457423c24
32
lib/lexer.js
32
lib/lexer.js
|
@ -1,5 +1,5 @@
|
||||||
(function() {
|
(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;
|
var __slice = Array.prototype.slice;
|
||||||
_ref = require('./rewriter');
|
_ref = require('./rewriter');
|
||||||
Rewriter = _ref.Rewriter;
|
Rewriter = _ref.Rewriter;
|
||||||
|
@ -96,14 +96,23 @@
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
Lexer.prototype.stringToken = function() {
|
Lexer.prototype.stringToken = function() {
|
||||||
var _ref2, string;
|
var string;
|
||||||
if (!(("'" === (_ref2 = this.chunk.charAt(0)) || '"' === _ref2))) {
|
switch (this.chunk.charAt(0)) {
|
||||||
return false;
|
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.line += count(string, '\n');
|
||||||
this.i += string.length;
|
this.i += string.length;
|
||||||
return true;
|
return true;
|
||||||
|
@ -146,10 +155,7 @@
|
||||||
};
|
};
|
||||||
Lexer.prototype.jsToken = function() {
|
Lexer.prototype.jsToken = function() {
|
||||||
var script;
|
var script;
|
||||||
if (this.chunk.charAt(0) !== '`') {
|
if (!(this.chunk.charAt(0) === '`' && (script = this.match(JSTOKEN)))) {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!(script = this.balancedToken(['`', '`']))) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
this.token('JS', script.slice(1, -1));
|
this.token('JS', script.slice(1, -1));
|
||||||
|
@ -590,6 +596,8 @@
|
||||||
COMMENT = /^###([^#][\s\S]*?)(?:###[ \t]*\n|(?:###)?$)|^(?:\s*#(?!##[^#])[^\n]*)+/;
|
COMMENT = /^###([^#][\s\S]*?)(?:###[ \t]*\n|(?:###)?$)|^(?:\s*#(?!##[^#])[^\n]*)+/;
|
||||||
CODE = /^[-=]>/;
|
CODE = /^[-=]>/;
|
||||||
MULTI_DENT = /^(?:\n[ \t]*)+/;
|
MULTI_DENT = /^(?:\n[ \t]*)+/;
|
||||||
|
SIMPLESTR = /^'[^\\']*(?:\\.[^\\']*)*'/;
|
||||||
|
JSTOKEN = /^`[^\\`]*(?:\\.[^\\`]*)*`/;
|
||||||
REGEX_START = /^\/([^\/])/;
|
REGEX_START = /^\/([^\/])/;
|
||||||
REGEX_INTERPOLATION = /[^\\]#\{.*[^\\]\}/;
|
REGEX_INTERPOLATION = /[^\\]#\{.*[^\\]\}/;
|
||||||
REGEX_END = /^[imgy]{0,4}(?![a-zA-Z])/;
|
REGEX_END = /^[imgy]{0,4}(?![a-zA-Z])/;
|
||||||
|
|
|
@ -118,11 +118,15 @@ exports.Lexer = class Lexer
|
||||||
# Matches strings, including multi-line strings. Ensures that quotation marks
|
# Matches strings, including multi-line strings. Ensures that quotation marks
|
||||||
# are balanced within the string's contents, and within nested interpolations.
|
# are balanced within the string's contents, and within nested interpolations.
|
||||||
stringToken: ->
|
stringToken: ->
|
||||||
return false unless @chunk.charAt(0) in ["'", '"']
|
switch @chunk.charAt 0
|
||||||
return false unless string =
|
when "'"
|
||||||
@balancedToken(['"', '"'], ['#{', '}']) or
|
return false unless string = @match SIMPLESTR
|
||||||
@balancedToken ["'", "'"]
|
@token 'STRING', string.replace MULTILINER, '\\\n'
|
||||||
@interpolateString string.replace MULTILINER, '\\\n'
|
when '"'
|
||||||
|
return false unless string = @balancedToken ['"', '"'], ['#{', '}']
|
||||||
|
@interpolateString string.replace MULTILINER, '\\\n'
|
||||||
|
else
|
||||||
|
return false
|
||||||
@line += count string, '\n'
|
@line += count string, '\n'
|
||||||
@i += string.length
|
@i += string.length
|
||||||
true
|
true
|
||||||
|
@ -153,8 +157,7 @@ exports.Lexer = class Lexer
|
||||||
|
|
||||||
# Matches JavaScript interpolated directly into the source via backticks.
|
# Matches JavaScript interpolated directly into the source via backticks.
|
||||||
jsToken: ->
|
jsToken: ->
|
||||||
return false unless @chunk.charAt(0) is '`'
|
return false unless @chunk.charAt(0) is '`' and script = @match JSTOKEN
|
||||||
return false unless script = @balancedToken ['`', '`']
|
|
||||||
@token 'JS', script.slice 1, -1
|
@token 'JS', script.slice 1, -1
|
||||||
@i += script.length
|
@i += script.length
|
||||||
true
|
true
|
||||||
|
@ -537,6 +540,8 @@ WHITESPACE = /^[ \t]+/
|
||||||
COMMENT = /^###([^#][\s\S]*?)(?:###[ \t]*\n|(?:###)?$)|^(?:\s*#(?!##[^#])[^\n]*)+/
|
COMMENT = /^###([^#][\s\S]*?)(?:###[ \t]*\n|(?:###)?$)|^(?:\s*#(?!##[^#])[^\n]*)+/
|
||||||
CODE = /^[-=]>/
|
CODE = /^[-=]>/
|
||||||
MULTI_DENT = /^(?:\n[ \t]*)+/
|
MULTI_DENT = /^(?:\n[ \t]*)+/
|
||||||
|
SIMPLESTR = /^'[^\\']*(?:\\.[^\\']*)*'/
|
||||||
|
JSTOKEN = /^`[^\\`]*(?:\\.[^\\`]*)*`/
|
||||||
|
|
||||||
# Regex-matching-regexes.
|
# Regex-matching-regexes.
|
||||||
REGEX_START = /^\/([^\/])/
|
REGEX_START = /^\/([^\/])/
|
||||||
|
|
Loading…
Reference in New Issue