making balanced_string accept an array of delimiters, in hope of using it in the Rewriter
This commit is contained in:
parent
b6c3b743f0
commit
4932d25540
11
lib/lexer.js
11
lib/lexer.js
|
@ -32,8 +32,8 @@
|
|||
// unless explicitly asked not to.
|
||||
Lexer.prototype.tokenize = function tokenize(code, options) {
|
||||
var o;
|
||||
o = options || {};
|
||||
code = code.replace(/\r/g, '');
|
||||
o = options || {};
|
||||
this.code = code;
|
||||
// The remainder of the source code.
|
||||
this.i = 0;
|
||||
|
@ -203,7 +203,7 @@
|
|||
Lexer.prototype.balanced_token = function balanced_token() {
|
||||
var delimited;
|
||||
delimited = Array.prototype.slice.call(arguments, 0);
|
||||
return this.balanced_string.apply(this, [this.chunk].concat(delimited));
|
||||
return this.balanced_string(this.chunk, delimited);
|
||||
};
|
||||
// Matches and conumes comments. We pass through comments into JavaScript,
|
||||
// so they're treated as real tokens, like any other part of the language.
|
||||
|
@ -407,9 +407,8 @@
|
|||
// a series of delimiters, all of which must be nested correctly within the
|
||||
// contents of the string. This method allows us to have strings within
|
||||
// interpolations within strings etc...
|
||||
Lexer.prototype.balanced_string = function balanced_string(str) {
|
||||
var _a, _b, _c, _d, close, delimited, i, levels, open, pair, slash;
|
||||
delimited = Array.prototype.slice.call(arguments, 1);
|
||||
Lexer.prototype.balanced_string = function balanced_string(str, delimited) {
|
||||
var _a, _b, _c, _d, close, i, levels, open, pair, slash;
|
||||
slash = delimited[0][0] === '/';
|
||||
levels = [];
|
||||
i = 0;
|
||||
|
@ -485,7 +484,7 @@
|
|||
tokens.push(['IDENTIFIER', interp]);
|
||||
i += group.length - 1;
|
||||
pi = i + 1;
|
||||
} else if (((expr = this.balanced_string(str.substring(i), ['${', '}'])))) {
|
||||
} else if (((expr = this.balanced_string(str.substring(i), [['${', '}']])))) {
|
||||
if (pi < i) {
|
||||
tokens.push(['STRING', '' + quote + (str.substring(pi, i)) + quote]);
|
||||
}
|
||||
|
|
|
@ -146,7 +146,7 @@ exports.Lexer: class Lexer
|
|||
# Matches a token in which which the passed delimiter pairs must be correctly
|
||||
# balanced (ie. strings, JS literals).
|
||||
balanced_token: (delimited...) ->
|
||||
@balanced_string @chunk, delimited...
|
||||
@balanced_string @chunk, delimited
|
||||
|
||||
# Matches and conumes comments. We pass through comments into JavaScript,
|
||||
# so they're treated as real tokens, like any other part of the language.
|
||||
|
@ -308,7 +308,7 @@ exports.Lexer: class Lexer
|
|||
# a series of delimiters, all of which must be nested correctly within the
|
||||
# contents of the string. This method allows us to have strings within
|
||||
# interpolations within strings etc...
|
||||
balanced_string: (str, delimited...) ->
|
||||
balanced_string: (str, delimited) ->
|
||||
slash: delimited[0][0] is '/'
|
||||
levels: []
|
||||
i: 0
|
||||
|
@ -362,7 +362,7 @@ exports.Lexer: class Lexer
|
|||
tokens.push ['IDENTIFIER', interp]
|
||||
i += group.length - 1
|
||||
pi: i + 1
|
||||
else if (expr: @balanced_string str.substring(i), ['${', '}'])
|
||||
else if (expr: @balanced_string str.substring(i), [['${', '}']])
|
||||
tokens.push ['STRING', "$quote${ str.substring(pi, i) }$quote"] if pi < i
|
||||
inner: expr.substring(2, expr.length - 1)
|
||||
if inner.length
|
||||
|
|
Loading…
Reference in New Issue