merged stan's interpolation_3, a couple of tweaks
This commit is contained in:
parent
6cac2d57ba
commit
121f01c06f
|
@ -33,7 +33,7 @@
|
|||
Lexer.prototype.tokenize = function tokenize(code, options) {
|
||||
var o;
|
||||
o = options || {};
|
||||
this.code = code;
|
||||
this.code = code || '';
|
||||
// The remainder of the source code.
|
||||
this.i = 0;
|
||||
// Current character position we're parsing.
|
||||
|
@ -176,6 +176,9 @@
|
|||
// JavaScript and Ruby.
|
||||
Lexer.prototype.regex_token = function regex_token() {
|
||||
var _a, _b, _c, _d, _e, each, flags, i, index, interp_tokens, merge, regex, str, supress;
|
||||
if (!(starts(this.chunk, '/'))) {
|
||||
return false;
|
||||
}
|
||||
if (!((regex = this.balanced_token((supress = true), ['/', '/'])))) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@
|
|||
Rewriter.prototype.remove_leading_newlines = function remove_leading_newlines() {
|
||||
var _a;
|
||||
_a = [];
|
||||
while (this.tokens[0][0] === 'TERMINATOR') {
|
||||
while (this.tokens[0] && this.tokens[0][0] === 'TERMINATOR') {
|
||||
_a.push(this.tokens.shift());
|
||||
}
|
||||
return _a;
|
||||
|
|
|
@ -36,7 +36,7 @@ exports.Lexer: class Lexer
|
|||
# unless explicitly asked not to.
|
||||
tokenize: (code, options) ->
|
||||
o : options or {}
|
||||
@code : code # The remainder of the source code.
|
||||
@code : code or '' # The remainder of the source code.
|
||||
@i : 0 # Current character position we're parsing.
|
||||
@line : o.line or 0 # The current line.
|
||||
@indent : 0 # The current indentation level.
|
||||
|
@ -126,6 +126,7 @@ exports.Lexer: class Lexer
|
|||
# to distinguish from division, so we borrow some basic heuristics from
|
||||
# JavaScript and Ruby.
|
||||
regex_token: ->
|
||||
return false unless starts @chunk, '/'
|
||||
return false unless regex: @balanced_token supress: true, ['/', '/']
|
||||
return false if regex.length < 3 or regex.match /^\/\s+|\n/
|
||||
return false if include NOT_REGEX, @tag()
|
||||
|
|
|
@ -62,7 +62,7 @@ exports.Rewriter: class Rewriter
|
|||
# Leading newlines would introduce an ambiguity in the grammar, so we
|
||||
# dispatch them here.
|
||||
remove_leading_newlines: ->
|
||||
@tokens.shift() while @tokens[0][0] is 'TERMINATOR'
|
||||
@tokens.shift() while @tokens[0] and @tokens[0][0] is 'TERMINATOR'
|
||||
|
||||
# Some blocks occur in the middle of expressions -- when we're expecting
|
||||
# this, remove their trailing newlines.
|
||||
|
|
Loading…
Reference in New Issue