2014-01-30 00:19:36 -05:00
|
|
|
// Generated by CoffeeScript 1.7.1
|
2010-07-25 03:15:12 -04:00
|
|
|
(function() {
|
2014-01-24 13:40:28 -05:00
|
|
|
var BOM, BOOL, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_ALIAS_MAP, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, HEREDOC, HEREDOC_ILLEGAL, HEREDOC_INDENT, HEREGEX, HEREGEX_OMIT, IDENTIFIER, INDENTABLE_CLOSERS, INDEXABLE, INVERSES, JSTOKEN, JS_FORBIDDEN, JS_KEYWORDS, LINE_BREAK, LINE_CONTINUER, LOGIC, Lexer, MATH, MULTILINER, MULTI_DENT, NOT_REGEX, NOT_SPACED_REGEX, NUMBER, OPERATOR, REGEX, RELATION, RESERVED, Rewriter, SHIFT, SIMPLESTR, STRICT_PROSCRIBED, TRAILING_SPACES, UNARY, UNARY_MATH, WHITESPACE, compact, count, invertLiterate, key, last, locationDataToString, repeat, starts, throwSyntaxError, _ref, _ref1,
|
2012-01-10 17:00:06 -05:00
|
|
|
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2011-09-16 19:26:04 -04:00
|
|
|
_ref = require('./rewriter'), Rewriter = _ref.Rewriter, INVERSES = _ref.INVERSES;
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2013-04-27 18:56:44 -04:00
|
|
|
_ref1 = require('./helpers'), count = _ref1.count, starts = _ref1.starts, compact = _ref1.compact, last = _ref1.last, repeat = _ref1.repeat, invertLiterate = _ref1.invertLiterate, locationDataToString = _ref1.locationDataToString, throwSyntaxError = _ref1.throwSyntaxError;
|
2013-02-25 12:41:34 -05:00
|
|
|
|
2010-12-23 13:50:52 -05:00
|
|
|
exports.Lexer = Lexer = (function() {
|
2010-11-11 21:48:08 -05:00
|
|
|
function Lexer() {}
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-11-05 00:04:52 -04:00
|
|
|
Lexer.prototype.tokenize = function(code, opts) {
|
2012-11-16 19:09:56 -05:00
|
|
|
var consumed, i, tag, _ref2;
|
2012-04-10 14:57:45 -04:00
|
|
|
if (opts == null) {
|
|
|
|
opts = {};
|
|
|
|
}
|
2012-09-25 20:15:40 -04:00
|
|
|
this.literate = opts.literate;
|
2010-02-27 19:40:53 -05:00
|
|
|
this.indent = 0;
|
2013-06-13 18:21:47 -04:00
|
|
|
this.baseIndent = 0;
|
2010-09-08 22:46:13 -04:00
|
|
|
this.indebt = 0;
|
2010-06-01 23:32:46 -04:00
|
|
|
this.outdebt = 0;
|
2010-02-27 19:40:53 -05:00
|
|
|
this.indents = [];
|
2011-09-16 19:26:04 -04:00
|
|
|
this.ends = [];
|
2010-02-27 19:40:53 -05:00
|
|
|
this.tokens = [];
|
2013-01-14 14:26:06 -05:00
|
|
|
this.chunkLine = opts.line || 0;
|
|
|
|
this.chunkColumn = opts.column || 0;
|
2013-03-01 13:38:55 -05:00
|
|
|
code = this.clean(code);
|
2010-10-22 10:47:40 -04:00
|
|
|
i = 0;
|
|
|
|
while (this.chunk = code.slice(i)) {
|
2012-11-16 19:09:56 -05:00
|
|
|
consumed = this.identifierToken() || this.commentToken() || this.whitespaceToken() || this.lineToken() || this.heredocToken() || this.stringToken() || this.numberToken() || this.regexToken() || this.jsToken() || this.literalToken();
|
|
|
|
_ref2 = this.getLineAndColumnFromChunk(consumed), this.chunkLine = _ref2[0], this.chunkColumn = _ref2[1];
|
|
|
|
i += consumed;
|
2010-02-27 19:40:53 -05:00
|
|
|
}
|
2010-06-12 19:05:13 -04:00
|
|
|
this.closeIndentation();
|
2012-04-10 14:57:45 -04:00
|
|
|
if (tag = this.ends.pop()) {
|
|
|
|
this.error("missing " + tag);
|
|
|
|
}
|
|
|
|
if (opts.rewrite === false) {
|
|
|
|
return this.tokens;
|
|
|
|
}
|
2010-09-25 04:39:19 -04:00
|
|
|
return (new Rewriter).rewrite(this.tokens);
|
2010-02-27 19:40:53 -05:00
|
|
|
};
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2012-09-25 20:15:40 -04:00
|
|
|
Lexer.prototype.clean = function(code) {
|
2013-01-06 23:56:58 -05:00
|
|
|
if (code.charCodeAt(0) === BOM) {
|
|
|
|
code = code.slice(1);
|
|
|
|
}
|
2013-03-01 13:38:55 -05:00
|
|
|
code = code.replace(/\r/g, '').replace(TRAILING_SPACES, '');
|
2012-09-25 20:15:40 -04:00
|
|
|
if (WHITESPACE.test(code)) {
|
|
|
|
code = "\n" + code;
|
2013-03-01 13:38:55 -05:00
|
|
|
this.chunkLine--;
|
2012-09-25 20:15:40 -04:00
|
|
|
}
|
|
|
|
if (this.literate) {
|
2013-03-04 21:45:57 -05:00
|
|
|
code = invertLiterate(code);
|
2012-09-25 20:15:40 -04:00
|
|
|
}
|
|
|
|
return code;
|
|
|
|
};
|
|
|
|
|
2010-06-12 19:05:13 -04:00
|
|
|
Lexer.prototype.identifierToken = function() {
|
2012-11-16 19:09:56 -05:00
|
|
|
var colon, colonOffset, forcedIdentifier, id, idLength, input, match, poppedToken, prev, tag, tagToken, _ref2, _ref3, _ref4;
|
2012-04-10 14:57:45 -04:00
|
|
|
if (!(match = IDENTIFIER.exec(this.chunk))) {
|
|
|
|
return 0;
|
|
|
|
}
|
2010-10-10 20:17:31 -04:00
|
|
|
input = match[0], id = match[1], colon = match[2];
|
2012-11-16 19:09:56 -05:00
|
|
|
idLength = id.length;
|
|
|
|
poppedToken = void 0;
|
2010-11-28 18:33:43 -05:00
|
|
|
if (id === 'own' && this.tag() === 'FOR') {
|
|
|
|
this.token('OWN', id);
|
2010-10-22 10:47:40 -04:00
|
|
|
return id.length;
|
2010-07-15 21:18:35 -04:00
|
|
|
}
|
2013-03-04 04:07:47 -05:00
|
|
|
forcedIdentifier = colon || (prev = last(this.tokens)) && (((_ref2 = prev[0]) === '.' || _ref2 === '?.' || _ref2 === '::' || _ref2 === '?::') || !prev.spaced && prev[0] === '@');
|
2010-02-27 19:40:53 -05:00
|
|
|
tag = 'IDENTIFIER';
|
2011-06-19 04:49:41 -04:00
|
|
|
if (!forcedIdentifier && (__indexOf.call(JS_KEYWORDS, id) >= 0 || __indexOf.call(COFFEE_KEYWORDS, id) >= 0)) {
|
2010-02-27 19:40:53 -05:00
|
|
|
tag = id.toUpperCase();
|
2012-02-29 23:46:03 -05:00
|
|
|
if (tag === 'WHEN' && (_ref3 = this.tag(), __indexOf.call(LINE_BREAK, _ref3) >= 0)) {
|
2010-09-23 01:14:18 -04:00
|
|
|
tag = 'LEADING_WHEN';
|
2010-10-05 15:46:17 -04:00
|
|
|
} else if (tag === 'FOR') {
|
|
|
|
this.seenFor = true;
|
2010-12-20 22:50:49 -05:00
|
|
|
} else if (tag === 'UNLESS') {
|
|
|
|
tag = 'IF';
|
2010-10-19 23:27:15 -04:00
|
|
|
} else if (__indexOf.call(UNARY, tag) >= 0) {
|
2010-09-25 03:00:07 -04:00
|
|
|
tag = 'UNARY';
|
2010-10-19 23:27:15 -04:00
|
|
|
} else if (__indexOf.call(RELATION, tag) >= 0) {
|
2010-10-05 15:46:17 -04:00
|
|
|
if (tag !== 'INSTANCEOF' && this.seenFor) {
|
|
|
|
tag = 'FOR' + tag;
|
2010-12-24 11:59:30 -05:00
|
|
|
this.seenFor = false;
|
2010-10-05 15:46:17 -04:00
|
|
|
} else {
|
|
|
|
tag = 'RELATION';
|
|
|
|
if (this.value() === '!') {
|
2012-11-16 19:09:56 -05:00
|
|
|
poppedToken = this.tokens.pop();
|
2010-10-05 15:46:17 -04:00
|
|
|
id = '!' + id;
|
|
|
|
}
|
|
|
|
}
|
2010-09-23 01:14:18 -04:00
|
|
|
}
|
2010-08-11 22:24:43 -04:00
|
|
|
}
|
2012-01-11 18:04:14 -05:00
|
|
|
if (__indexOf.call(JS_FORBIDDEN, id) >= 0) {
|
2010-06-15 00:54:02 -04:00
|
|
|
if (forcedIdentifier) {
|
2010-10-06 20:07:19 -04:00
|
|
|
tag = 'IDENTIFIER';
|
|
|
|
id = new String(id);
|
|
|
|
id.reserved = true;
|
2010-10-19 23:27:15 -04:00
|
|
|
} else if (__indexOf.call(RESERVED, id) >= 0) {
|
2011-11-25 08:49:51 -05:00
|
|
|
this.error("reserved word \"" + id + "\"");
|
2010-06-15 00:54:02 -04:00
|
|
|
}
|
|
|
|
}
|
2010-10-07 07:05:22 -04:00
|
|
|
if (!forcedIdentifier) {
|
2012-04-10 14:57:45 -04:00
|
|
|
if (__indexOf.call(COFFEE_ALIASES, id) >= 0) {
|
|
|
|
id = COFFEE_ALIAS_MAP[id];
|
|
|
|
}
|
2010-12-23 13:50:52 -05:00
|
|
|
tag = (function() {
|
2010-11-05 00:04:52 -04:00
|
|
|
switch (id) {
|
|
|
|
case '!':
|
|
|
|
return 'UNARY';
|
|
|
|
case '==':
|
|
|
|
case '!=':
|
|
|
|
return 'COMPARE';
|
|
|
|
case '&&':
|
|
|
|
case '||':
|
|
|
|
return 'LOGIC';
|
|
|
|
case 'true':
|
|
|
|
case 'false':
|
|
|
|
return 'BOOL';
|
2010-11-14 15:15:13 -05:00
|
|
|
case 'break':
|
|
|
|
case 'continue':
|
|
|
|
return 'STATEMENT';
|
2010-11-05 00:04:52 -04:00
|
|
|
default:
|
|
|
|
return tag;
|
|
|
|
}
|
2010-12-23 13:50:52 -05:00
|
|
|
})();
|
2010-03-21 21:46:06 -04:00
|
|
|
}
|
2012-11-16 19:09:56 -05:00
|
|
|
tagToken = this.token(tag, id, 0, idLength);
|
|
|
|
if (poppedToken) {
|
2013-01-14 15:20:35 -05:00
|
|
|
_ref4 = [poppedToken[2].first_line, poppedToken[2].first_column], tagToken[2].first_line = _ref4[0], tagToken[2].first_column = _ref4[1];
|
2012-11-16 19:09:56 -05:00
|
|
|
}
|
2012-04-10 14:57:45 -04:00
|
|
|
if (colon) {
|
2012-11-16 19:09:56 -05:00
|
|
|
colonOffset = input.lastIndexOf(':');
|
|
|
|
this.token(':', ':', colonOffset, colon.length);
|
2012-04-10 14:57:45 -04:00
|
|
|
}
|
2010-10-22 10:47:40 -04:00
|
|
|
return input.length;
|
2010-02-27 19:40:53 -05:00
|
|
|
};
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-06-12 19:05:13 -04:00
|
|
|
Lexer.prototype.numberToken = function() {
|
2012-01-20 17:23:50 -05:00
|
|
|
var binaryLiteral, lexedLength, match, number, octalLiteral;
|
2012-04-10 14:57:45 -04:00
|
|
|
if (!(match = NUMBER.exec(this.chunk))) {
|
|
|
|
return 0;
|
|
|
|
}
|
2010-09-25 18:06:14 -04:00
|
|
|
number = match[0];
|
2012-03-27 21:31:20 -04:00
|
|
|
if (/^0[BOX]/.test(number)) {
|
2012-03-08 14:44:47 -05:00
|
|
|
this.error("radix prefix '" + number + "' must be lowercase");
|
2012-03-27 21:31:20 -04:00
|
|
|
} else if (/E/.test(number) && !/^0x/.test(number)) {
|
|
|
|
this.error("exponential notation '" + number + "' must be indicated with a lowercase 'e'");
|
|
|
|
} else if (/^0\d*[89]/.test(number)) {
|
2012-03-08 14:44:47 -05:00
|
|
|
this.error("decimal literal '" + number + "' must not be prefixed with '0'");
|
2012-03-27 21:31:20 -04:00
|
|
|
} else if (/^0\d+/.test(number)) {
|
2012-03-08 14:44:47 -05:00
|
|
|
this.error("octal literal '" + number + "' must be prefixed with '0o'");
|
2012-01-12 15:32:14 -05:00
|
|
|
}
|
2012-01-20 17:23:50 -05:00
|
|
|
lexedLength = number.length;
|
2012-03-27 21:31:48 -04:00
|
|
|
if (octalLiteral = /^0o([0-7]+)/.exec(number)) {
|
2013-04-27 18:56:44 -04:00
|
|
|
number = '0x' + parseInt(octalLiteral[1], 8).toString(16);
|
2012-01-12 15:32:14 -05:00
|
|
|
}
|
2012-03-27 21:31:48 -04:00
|
|
|
if (binaryLiteral = /^0b([01]+)/.exec(number)) {
|
2013-04-27 18:56:44 -04:00
|
|
|
number = '0x' + parseInt(binaryLiteral[1], 2).toString(16);
|
2011-10-24 14:51:41 -04:00
|
|
|
}
|
2012-11-16 19:09:56 -05:00
|
|
|
this.token('NUMBER', number, 0, lexedLength);
|
2011-10-24 14:51:41 -04:00
|
|
|
return lexedLength;
|
2010-02-27 19:40:53 -05:00
|
|
|
};
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-06-12 19:05:13 -04:00
|
|
|
Lexer.prototype.stringToken = function() {
|
2013-11-27 15:29:45 -05:00
|
|
|
var octalEsc, quote, string, trimmed;
|
|
|
|
switch (quote = this.chunk.charAt(0)) {
|
2010-09-24 09:38:28 -04:00
|
|
|
case "'":
|
2014-02-17 18:37:10 -05:00
|
|
|
string = (SIMPLESTR.exec(this.chunk) || [])[0];
|
2010-09-24 09:38:28 -04:00
|
|
|
break;
|
|
|
|
case '"':
|
2013-11-27 15:29:45 -05:00
|
|
|
string = this.balancedString(this.chunk, '"');
|
|
|
|
}
|
|
|
|
if (!string) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
trimmed = this.removeNewlines(string.slice(1, -1));
|
|
|
|
if (quote === '"' && 0 < string.indexOf('#{', 1)) {
|
|
|
|
this.interpolateString(trimmed, {
|
|
|
|
strOffset: 1,
|
|
|
|
lexedLength: string.length
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.token('STRING', quote + this.escapeLines(trimmed) + quote, 0, string.length);
|
2010-02-27 19:40:53 -05:00
|
|
|
}
|
2012-04-20 18:29:40 -04:00
|
|
|
if (octalEsc = /^(?:\\.|[^\\])*\\(?:0[0-7]|[1-7])/.test(string)) {
|
2012-01-11 18:04:14 -05:00
|
|
|
this.error("octal escape sequences " + string + " are not allowed");
|
|
|
|
}
|
2010-10-22 10:47:40 -04:00
|
|
|
return string.length;
|
2010-02-27 19:40:53 -05:00
|
|
|
};
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-06-12 19:05:13 -04:00
|
|
|
Lexer.prototype.heredocToken = function() {
|
2010-09-23 01:14:18 -04:00
|
|
|
var doc, heredoc, match, quote;
|
2012-04-10 14:57:45 -04:00
|
|
|
if (!(match = HEREDOC.exec(this.chunk))) {
|
|
|
|
return 0;
|
|
|
|
}
|
2010-09-23 01:14:18 -04:00
|
|
|
heredoc = match[0];
|
|
|
|
quote = heredoc.charAt(0);
|
|
|
|
doc = this.sanitizeHeredoc(match[2], {
|
2010-09-25 18:06:14 -04:00
|
|
|
quote: quote,
|
|
|
|
indent: null
|
2010-05-12 20:56:44 -04:00
|
|
|
});
|
2010-10-19 20:42:12 -04:00
|
|
|
if (quote === '"' && 0 <= doc.indexOf('#{')) {
|
2010-10-04 14:30:48 -04:00
|
|
|
this.interpolateString(doc, {
|
2012-11-16 19:09:56 -05:00
|
|
|
heredoc: true,
|
2012-11-20 12:05:59 -05:00
|
|
|
strOffset: 3,
|
|
|
|
lexedLength: heredoc.length
|
2010-10-02 18:45:23 -04:00
|
|
|
});
|
|
|
|
} else {
|
2012-11-16 19:09:56 -05:00
|
|
|
this.token('STRING', this.makeString(doc, quote, true), 0, heredoc.length);
|
2010-10-02 18:45:23 -04:00
|
|
|
}
|
2010-10-22 10:47:40 -04:00
|
|
|
return heredoc.length;
|
2010-02-27 19:40:53 -05:00
|
|
|
};
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-06-12 19:05:13 -04:00
|
|
|
Lexer.prototype.commentToken = function() {
|
2010-10-10 20:17:31 -04:00
|
|
|
var comment, here, match;
|
2012-04-10 14:57:45 -04:00
|
|
|
if (!(match = this.chunk.match(COMMENT))) {
|
|
|
|
return 0;
|
|
|
|
}
|
2010-10-10 20:17:31 -04:00
|
|
|
comment = match[0], here = match[1];
|
2010-09-23 01:14:18 -04:00
|
|
|
if (here) {
|
|
|
|
this.token('HERECOMMENT', this.sanitizeHeredoc(here, {
|
2010-08-23 21:00:47 -04:00
|
|
|
herecomment: true,
|
2013-04-27 18:56:44 -04:00
|
|
|
indent: repeat(' ', this.indent)
|
2012-11-16 19:09:56 -05:00
|
|
|
}), 0, comment.length);
|
2010-07-01 21:26:33 -04:00
|
|
|
}
|
2010-10-22 10:47:40 -04:00
|
|
|
return comment.length;
|
2010-05-12 20:56:44 -04:00
|
|
|
};
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-06-12 19:05:13 -04:00
|
|
|
Lexer.prototype.jsToken = function() {
|
2010-09-25 18:06:14 -04:00
|
|
|
var match, script;
|
2011-08-08 12:55:22 -04:00
|
|
|
if (!(this.chunk.charAt(0) === '`' && (match = JSTOKEN.exec(this.chunk)))) {
|
|
|
|
return 0;
|
|
|
|
}
|
2012-11-16 19:09:56 -05:00
|
|
|
this.token('JS', (script = match[0]).slice(1, -1), 0, script.length);
|
2010-10-22 10:47:40 -04:00
|
|
|
return script.length;
|
2010-02-27 19:40:53 -05:00
|
|
|
};
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-06-12 19:05:13 -04:00
|
|
|
Lexer.prototype.regexToken = function() {
|
2012-02-29 23:46:03 -05:00
|
|
|
var flags, length, match, prev, regex, _ref2, _ref3;
|
2012-04-10 14:57:45 -04:00
|
|
|
if (this.chunk.charAt(0) !== '/') {
|
|
|
|
return 0;
|
|
|
|
}
|
2013-03-25 02:19:05 -04:00
|
|
|
if (length = this.heregexToken()) {
|
2011-05-19 13:59:58 -04:00
|
|
|
return length;
|
2010-03-08 19:43:12 -05:00
|
|
|
}
|
2010-11-09 22:39:15 -05:00
|
|
|
prev = last(this.tokens);
|
2012-02-29 23:46:03 -05:00
|
|
|
if (prev && (_ref2 = prev[0], __indexOf.call((prev.spaced ? NOT_REGEX : NOT_SPACED_REGEX), _ref2) >= 0)) {
|
2011-08-08 12:27:53 -04:00
|
|
|
return 0;
|
2011-08-08 12:55:22 -04:00
|
|
|
}
|
2012-04-10 14:57:45 -04:00
|
|
|
if (!(match = REGEX.exec(this.chunk))) {
|
|
|
|
return 0;
|
|
|
|
}
|
2012-02-29 23:46:03 -05:00
|
|
|
_ref3 = match, match = _ref3[0], regex = _ref3[1], flags = _ref3[2];
|
2013-03-25 02:19:05 -04:00
|
|
|
if (regex === '//') {
|
|
|
|
return 0;
|
|
|
|
}
|
2011-10-03 03:47:24 -04:00
|
|
|
if (regex.slice(0, 2) === '/*') {
|
2011-09-22 04:09:58 -04:00
|
|
|
this.error('regular expressions cannot begin with `*`');
|
|
|
|
}
|
2012-11-16 19:09:56 -05:00
|
|
|
this.token('REGEX', "" + regex + flags, 0, match.length);
|
2011-10-03 03:47:24 -04:00
|
|
|
return match.length;
|
2010-02-27 19:40:53 -05:00
|
|
|
};
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2013-03-25 02:19:05 -04:00
|
|
|
Lexer.prototype.heregexToken = function() {
|
|
|
|
var body, flags, flagsOffset, heregex, match, plusToken, prev, re, tag, token, tokens, value, _i, _len, _ref2, _ref3, _ref4;
|
|
|
|
if (!(match = HEREGEX.exec(this.chunk))) {
|
|
|
|
return 0;
|
|
|
|
}
|
2010-10-10 20:17:31 -04:00
|
|
|
heregex = match[0], body = match[1], flags = match[2];
|
2010-10-04 14:30:48 -04:00
|
|
|
if (0 > body.indexOf('#{')) {
|
2013-10-23 18:36:46 -04:00
|
|
|
re = this.escapeLines(body.replace(HEREGEX_OMIT, '$1$2').replace(/\//g, '\\/'), true);
|
2011-09-22 04:39:13 -04:00
|
|
|
if (re.match(/^\*/)) {
|
|
|
|
this.error('regular expressions cannot begin with `*`');
|
|
|
|
}
|
2012-11-16 19:09:56 -05:00
|
|
|
this.token('REGEX', "/" + (re || '(?:)') + "/" + flags, 0, heregex.length);
|
2010-10-22 10:47:40 -04:00
|
|
|
return heregex.length;
|
2010-05-14 09:14:41 -04:00
|
|
|
}
|
2012-11-16 19:09:56 -05:00
|
|
|
this.token('IDENTIFIER', 'RegExp', 0, 0);
|
|
|
|
this.token('CALL_START', '(', 0, 0);
|
2010-10-04 08:50:50 -04:00
|
|
|
tokens = [];
|
2012-02-29 23:46:03 -05:00
|
|
|
_ref2 = this.interpolateString(body, {
|
2010-10-21 21:51:06 -04:00
|
|
|
regex: true
|
2010-11-20 16:25:22 -05:00
|
|
|
});
|
2012-02-29 23:46:03 -05:00
|
|
|
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
2012-11-16 19:09:56 -05:00
|
|
|
token = _ref2[_i];
|
|
|
|
tag = token[0], value = token[1];
|
2010-10-04 08:50:50 -04:00
|
|
|
if (tag === 'TOKENS') {
|
|
|
|
tokens.push.apply(tokens, value);
|
2012-11-16 19:09:56 -05:00
|
|
|
} else if (tag === 'NEOSTRING') {
|
2013-10-21 15:52:36 -04:00
|
|
|
if (!(value = value.replace(HEREGEX_OMIT, '$1$2'))) {
|
2012-04-10 14:57:45 -04:00
|
|
|
continue;
|
|
|
|
}
|
2010-10-04 14:30:48 -04:00
|
|
|
value = value.replace(/\\/g, '\\\\');
|
2012-11-16 19:09:56 -05:00
|
|
|
token[0] = 'STRING';
|
|
|
|
token[1] = this.makeString(value, '"', true);
|
|
|
|
tokens.push(token);
|
|
|
|
} else {
|
|
|
|
this.error("Unexpected " + tag);
|
2010-07-21 13:32:36 -04:00
|
|
|
}
|
2012-11-16 19:09:56 -05:00
|
|
|
prev = last(this.tokens);
|
|
|
|
plusToken = ['+', '+'];
|
2013-01-14 15:20:35 -05:00
|
|
|
plusToken[2] = prev[2];
|
2012-11-16 19:09:56 -05:00
|
|
|
tokens.push(plusToken);
|
2010-03-08 13:05:02 -05:00
|
|
|
}
|
2010-10-04 08:50:50 -04:00
|
|
|
tokens.pop();
|
2012-11-16 19:09:56 -05:00
|
|
|
if (((_ref3 = tokens[0]) != null ? _ref3[0] : void 0) !== 'STRING') {
|
|
|
|
this.token('STRING', '""', 0, 0);
|
|
|
|
this.token('+', '+', 0, 0);
|
2011-08-08 12:55:22 -04:00
|
|
|
}
|
2012-11-16 19:09:56 -05:00
|
|
|
(_ref4 = this.tokens).push.apply(_ref4, tokens);
|
2012-04-10 14:57:45 -04:00
|
|
|
if (flags) {
|
2012-11-16 19:09:56 -05:00
|
|
|
flagsOffset = heregex.lastIndexOf(flags);
|
|
|
|
this.token(',', ',', flagsOffset, 0);
|
|
|
|
this.token('STRING', '"' + flags + '"', flagsOffset, flags.length);
|
2012-04-10 14:57:45 -04:00
|
|
|
}
|
2012-11-16 19:09:56 -05:00
|
|
|
this.token(')', ')', heregex.length - 1, 0);
|
2010-10-22 10:47:40 -04:00
|
|
|
return heregex.length;
|
2010-02-27 19:40:53 -05:00
|
|
|
};
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-06-12 19:05:13 -04:00
|
|
|
Lexer.prototype.lineToken = function() {
|
2012-06-06 20:39:17 -04:00
|
|
|
var diff, indent, match, noNewlines, size;
|
2012-04-10 14:57:45 -04:00
|
|
|
if (!(match = MULTI_DENT.exec(this.chunk))) {
|
|
|
|
return 0;
|
|
|
|
}
|
2010-09-25 18:06:14 -04:00
|
|
|
indent = match[0];
|
2011-09-20 23:28:07 -04:00
|
|
|
this.seenFor = false;
|
2010-09-23 01:14:18 -04:00
|
|
|
size = indent.length - 1 - indent.lastIndexOf('\n');
|
2010-10-25 14:56:02 -04:00
|
|
|
noNewlines = this.unfinished();
|
2010-09-08 22:46:13 -04:00
|
|
|
if (size - this.indebt === this.indent) {
|
2010-06-12 19:05:13 -04:00
|
|
|
if (noNewlines) {
|
2010-10-22 10:47:40 -04:00
|
|
|
this.suppressNewlines();
|
|
|
|
} else {
|
2012-11-16 19:09:56 -05:00
|
|
|
this.newlineToken(0);
|
2010-02-28 12:49:37 -05:00
|
|
|
}
|
2010-10-22 10:47:40 -04:00
|
|
|
return indent.length;
|
|
|
|
}
|
|
|
|
if (size > this.indent) {
|
2010-06-12 19:05:13 -04:00
|
|
|
if (noNewlines) {
|
2010-09-08 22:46:13 -04:00
|
|
|
this.indebt = size - this.indent;
|
2010-10-22 10:47:40 -04:00
|
|
|
this.suppressNewlines();
|
|
|
|
return indent.length;
|
2010-02-28 12:49:37 -05:00
|
|
|
}
|
2013-06-13 18:21:47 -04:00
|
|
|
if (!this.tokens.length) {
|
|
|
|
this.baseIndent = this.indent = size;
|
|
|
|
return indent.length;
|
|
|
|
}
|
2010-08-21 12:13:43 -04:00
|
|
|
diff = size - this.indent + this.outdebt;
|
2013-03-04 18:03:08 -05:00
|
|
|
this.token('INDENT', diff, indent.length - size, size);
|
2010-02-27 19:40:53 -05:00
|
|
|
this.indents.push(diff);
|
2011-09-16 19:26:04 -04:00
|
|
|
this.ends.push('OUTDENT');
|
2010-10-20 13:29:06 -04:00
|
|
|
this.outdebt = this.indebt = 0;
|
2014-01-22 13:30:13 -05:00
|
|
|
this.indent = size;
|
2013-06-13 18:21:47 -04:00
|
|
|
} else if (size < this.baseIndent) {
|
|
|
|
this.error('missing indentation', indent.length);
|
2010-02-27 19:40:53 -05:00
|
|
|
} else {
|
2010-09-08 22:46:13 -04:00
|
|
|
this.indebt = 0;
|
2012-11-16 19:09:56 -05:00
|
|
|
this.outdentToken(this.indent - size, noNewlines, indent.length);
|
2010-02-27 19:40:53 -05:00
|
|
|
}
|
2010-10-22 10:47:40 -04:00
|
|
|
return indent.length;
|
2010-02-27 19:40:53 -05:00
|
|
|
};
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2012-11-16 19:09:56 -05:00
|
|
|
Lexer.prototype.outdentToken = function(moveOut, noNewlines, outdentLength) {
|
2014-01-22 13:30:13 -05:00
|
|
|
var decreasedIndent, dent, lastIndent, _ref2;
|
|
|
|
decreasedIndent = this.indent - moveOut;
|
2010-07-30 22:06:22 -04:00
|
|
|
while (moveOut > 0) {
|
2014-01-22 13:30:13 -05:00
|
|
|
lastIndent = this.indents[this.indents.length - 1];
|
|
|
|
if (!lastIndent) {
|
2010-07-30 22:06:22 -04:00
|
|
|
moveOut = 0;
|
2014-01-22 13:30:13 -05:00
|
|
|
} else if (lastIndent === this.outdebt) {
|
2010-07-30 22:06:22 -04:00
|
|
|
moveOut -= this.outdebt;
|
|
|
|
this.outdebt = 0;
|
2014-01-22 13:30:13 -05:00
|
|
|
} else if (lastIndent < this.outdebt) {
|
|
|
|
this.outdebt -= lastIndent;
|
|
|
|
moveOut -= lastIndent;
|
2010-07-30 22:06:22 -04:00
|
|
|
} else {
|
2013-02-24 22:12:57 -05:00
|
|
|
dent = this.indents.pop() + this.outdebt;
|
2014-01-22 13:30:13 -05:00
|
|
|
if (outdentLength && (_ref2 = this.chunk[outdentLength], __indexOf.call(INDENTABLE_CLOSERS, _ref2) >= 0)) {
|
|
|
|
decreasedIndent -= dent - moveOut;
|
|
|
|
moveOut = dent;
|
|
|
|
}
|
2010-07-30 22:06:22 -04:00
|
|
|
this.outdebt = 0;
|
2011-09-16 19:26:04 -04:00
|
|
|
this.pair('OUTDENT');
|
2014-01-22 13:30:13 -05:00
|
|
|
this.token('OUTDENT', moveOut, 0, outdentLength);
|
|
|
|
moveOut -= dent;
|
2010-06-01 23:32:46 -04:00
|
|
|
}
|
|
|
|
}
|
2012-04-10 14:57:45 -04:00
|
|
|
if (dent) {
|
|
|
|
this.outdebt -= moveOut;
|
|
|
|
}
|
2011-09-04 12:18:22 -04:00
|
|
|
while (this.value() === ';') {
|
|
|
|
this.tokens.pop();
|
|
|
|
}
|
2011-08-08 12:55:22 -04:00
|
|
|
if (!(this.tag() === 'TERMINATOR' || noNewlines)) {
|
2012-11-16 19:09:56 -05:00
|
|
|
this.token('TERMINATOR', '\n', outdentLength, 0);
|
2011-08-08 12:55:22 -04:00
|
|
|
}
|
2014-01-23 15:52:26 -05:00
|
|
|
this.indent = decreasedIndent;
|
2010-10-22 10:47:40 -04:00
|
|
|
return this;
|
2010-02-27 19:40:53 -05:00
|
|
|
};
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-06-12 19:05:13 -04:00
|
|
|
Lexer.prototype.whitespaceToken = function() {
|
2010-10-20 21:37:58 -04:00
|
|
|
var match, nline, prev;
|
2011-08-08 12:55:22 -04:00
|
|
|
if (!((match = WHITESPACE.exec(this.chunk)) || (nline = this.chunk.charAt(0) === '\n'))) {
|
|
|
|
return 0;
|
|
|
|
}
|
2010-09-28 08:52:51 -04:00
|
|
|
prev = last(this.tokens);
|
2012-04-10 14:57:45 -04:00
|
|
|
if (prev) {
|
|
|
|
prev[match ? 'spaced' : 'newLine'] = true;
|
|
|
|
}
|
2010-11-08 23:07:51 -05:00
|
|
|
if (match) {
|
|
|
|
return match[0].length;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
2010-02-27 19:40:53 -05:00
|
|
|
};
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2012-11-16 19:09:56 -05:00
|
|
|
Lexer.prototype.newlineToken = function(offset) {
|
2011-09-04 12:18:22 -04:00
|
|
|
while (this.value() === ';') {
|
|
|
|
this.tokens.pop();
|
|
|
|
}
|
2012-04-10 14:57:45 -04:00
|
|
|
if (this.tag() !== 'TERMINATOR') {
|
2012-11-16 19:09:56 -05:00
|
|
|
this.token('TERMINATOR', '\n', offset, 0);
|
2012-04-10 14:57:45 -04:00
|
|
|
}
|
2010-10-22 10:47:40 -04:00
|
|
|
return this;
|
2010-02-27 19:40:53 -05:00
|
|
|
};
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-06-12 19:05:13 -04:00
|
|
|
Lexer.prototype.suppressNewlines = function() {
|
2012-04-10 14:57:45 -04:00
|
|
|
if (this.value() === '\\') {
|
|
|
|
this.tokens.pop();
|
|
|
|
}
|
2010-10-22 10:47:40 -04:00
|
|
|
return this;
|
2010-02-27 19:40:53 -05:00
|
|
|
};
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-06-12 19:05:13 -04:00
|
|
|
Lexer.prototype.literalToken = function() {
|
2012-02-29 23:46:03 -05:00
|
|
|
var match, prev, tag, value, _ref2, _ref3, _ref4, _ref5;
|
2010-10-05 10:31:48 -04:00
|
|
|
if (match = OPERATOR.exec(this.chunk)) {
|
|
|
|
value = match[0];
|
2012-04-10 14:57:45 -04:00
|
|
|
if (CODE.test(value)) {
|
|
|
|
this.tagParameters();
|
|
|
|
}
|
2010-09-23 01:14:18 -04:00
|
|
|
} else {
|
|
|
|
value = this.chunk.charAt(0);
|
2010-02-27 19:40:53 -05:00
|
|
|
}
|
|
|
|
tag = value;
|
2010-10-07 22:22:33 -04:00
|
|
|
prev = last(this.tokens);
|
2010-10-12 06:30:10 -04:00
|
|
|
if (value === '=' && prev) {
|
2012-02-29 23:46:03 -05:00
|
|
|
if (!prev[1].reserved && (_ref2 = prev[1], __indexOf.call(JS_FORBIDDEN, _ref2) >= 0)) {
|
2011-09-22 04:09:58 -04:00
|
|
|
this.error("reserved word \"" + (this.value()) + "\" can't be assigned");
|
2011-08-08 12:55:22 -04:00
|
|
|
}
|
2012-02-29 23:46:03 -05:00
|
|
|
if ((_ref3 = prev[1]) === '||' || _ref3 === '&&') {
|
2010-10-05 10:31:48 -04:00
|
|
|
prev[0] = 'COMPOUND_ASSIGN';
|
2010-10-11 06:10:30 -04:00
|
|
|
prev[1] += '=';
|
2010-10-22 10:47:40 -04:00
|
|
|
return value.length;
|
2010-07-25 01:36:50 -04:00
|
|
|
}
|
2010-07-25 01:23:37 -04:00
|
|
|
}
|
2010-10-19 22:04:38 -04:00
|
|
|
if (value === ';') {
|
2011-09-21 00:21:46 -04:00
|
|
|
this.seenFor = false;
|
2010-02-27 19:40:53 -05:00
|
|
|
tag = 'TERMINATOR';
|
2010-10-19 23:27:15 -04:00
|
|
|
} else if (__indexOf.call(MATH, value) >= 0) {
|
2010-08-11 22:24:43 -04:00
|
|
|
tag = 'MATH';
|
2010-10-19 23:27:15 -04:00
|
|
|
} else if (__indexOf.call(COMPARE, value) >= 0) {
|
2010-08-11 22:24:43 -04:00
|
|
|
tag = 'COMPARE';
|
2010-10-19 23:27:15 -04:00
|
|
|
} else if (__indexOf.call(COMPOUND_ASSIGN, value) >= 0) {
|
2010-08-11 22:24:43 -04:00
|
|
|
tag = 'COMPOUND_ASSIGN';
|
2010-10-19 23:27:15 -04:00
|
|
|
} else if (__indexOf.call(UNARY, value) >= 0) {
|
2010-08-11 22:24:43 -04:00
|
|
|
tag = 'UNARY';
|
2013-03-24 23:05:04 -04:00
|
|
|
} else if (__indexOf.call(UNARY_MATH, value) >= 0) {
|
|
|
|
tag = 'UNARY_MATH';
|
2010-10-19 23:27:15 -04:00
|
|
|
} else if (__indexOf.call(SHIFT, value) >= 0) {
|
2010-08-11 22:24:43 -04:00
|
|
|
tag = 'SHIFT';
|
2010-10-27 22:50:20 -04:00
|
|
|
} else if (__indexOf.call(LOGIC, value) >= 0 || value === '?' && (prev != null ? prev.spaced : void 0)) {
|
2010-10-07 22:22:33 -04:00
|
|
|
tag = 'LOGIC';
|
2010-10-12 06:30:10 -04:00
|
|
|
} else if (prev && !prev.spaced) {
|
2012-02-29 23:46:03 -05:00
|
|
|
if (value === '(' && (_ref4 = prev[0], __indexOf.call(CALLABLE, _ref4) >= 0)) {
|
2012-04-10 14:57:45 -04:00
|
|
|
if (prev[0] === '?') {
|
|
|
|
prev[0] = 'FUNC_EXIST';
|
|
|
|
}
|
2010-02-27 19:40:53 -05:00
|
|
|
tag = 'CALL_START';
|
2012-02-29 23:46:03 -05:00
|
|
|
} else if (value === '[' && (_ref5 = prev[0], __indexOf.call(INDEXABLE, _ref5) >= 0)) {
|
2010-02-27 19:40:53 -05:00
|
|
|
tag = 'INDEX_START';
|
2010-10-07 22:22:33 -04:00
|
|
|
switch (prev[0]) {
|
2010-09-23 01:14:18 -04:00
|
|
|
case '?':
|
2010-10-05 10:31:48 -04:00
|
|
|
prev[0] = 'INDEX_SOAK';
|
2010-05-31 22:32:43 -04:00
|
|
|
}
|
2010-02-27 19:40:53 -05:00
|
|
|
}
|
|
|
|
}
|
2011-09-16 19:26:04 -04:00
|
|
|
switch (value) {
|
|
|
|
case '(':
|
|
|
|
case '{':
|
|
|
|
case '[':
|
|
|
|
this.ends.push(INVERSES[value]);
|
|
|
|
break;
|
|
|
|
case ')':
|
|
|
|
case '}':
|
|
|
|
case ']':
|
|
|
|
this.pair(value);
|
|
|
|
}
|
2010-03-21 23:24:24 -04:00
|
|
|
this.token(tag, value);
|
2010-10-22 10:47:40 -04:00
|
|
|
return value.length;
|
2010-02-27 19:40:53 -05:00
|
|
|
};
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-06-12 19:05:13 -04:00
|
|
|
Lexer.prototype.sanitizeHeredoc = function(doc, options) {
|
2012-02-29 23:46:03 -05:00
|
|
|
var attempt, herecomment, indent, match, _ref2;
|
2010-10-10 20:17:31 -04:00
|
|
|
indent = options.indent, herecomment = options.herecomment;
|
2011-01-18 23:10:09 -05:00
|
|
|
if (herecomment) {
|
2011-08-08 12:55:22 -04:00
|
|
|
if (HEREDOC_ILLEGAL.test(doc)) {
|
2011-09-17 21:39:24 -04:00
|
|
|
this.error("block comment cannot contain \"*/\", starting");
|
2011-08-08 12:55:22 -04:00
|
|
|
}
|
2012-09-25 20:35:02 -04:00
|
|
|
if (doc.indexOf('\n') < 0) {
|
2012-04-10 14:57:45 -04:00
|
|
|
return doc;
|
|
|
|
}
|
2011-01-18 23:10:09 -05:00
|
|
|
} else {
|
2010-10-04 14:30:48 -04:00
|
|
|
while (match = HEREDOC_INDENT.exec(doc)) {
|
2010-09-25 18:06:14 -04:00
|
|
|
attempt = match[1];
|
2012-02-29 23:46:03 -05:00
|
|
|
if (indent === null || (0 < (_ref2 = attempt.length) && _ref2 < indent.length)) {
|
2011-08-08 12:27:53 -04:00
|
|
|
indent = attempt;
|
2011-08-08 12:55:22 -04:00
|
|
|
}
|
2010-05-12 21:47:31 -04:00
|
|
|
}
|
|
|
|
}
|
2012-04-10 14:57:45 -04:00
|
|
|
if (indent) {
|
|
|
|
doc = doc.replace(RegExp("\\n" + indent, "g"), '\n');
|
|
|
|
}
|
|
|
|
if (!herecomment) {
|
|
|
|
doc = doc.replace(/^\n/, '');
|
|
|
|
}
|
2010-09-25 18:06:14 -04:00
|
|
|
return doc;
|
2010-02-28 13:34:52 -05:00
|
|
|
};
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-06-12 19:05:13 -04:00
|
|
|
Lexer.prototype.tagParameters = function() {
|
2010-10-26 00:09:46 -04:00
|
|
|
var i, stack, tok, tokens;
|
2012-04-10 14:57:45 -04:00
|
|
|
if (this.tag() !== ')') {
|
|
|
|
return this;
|
|
|
|
}
|
2010-10-26 00:09:46 -04:00
|
|
|
stack = [];
|
|
|
|
tokens = this.tokens;
|
|
|
|
i = tokens.length;
|
|
|
|
tokens[--i][0] = 'PARAM_END';
|
|
|
|
while (tok = tokens[--i]) {
|
2010-09-15 23:46:01 -04:00
|
|
|
switch (tok[0]) {
|
2010-09-21 23:58:05 -04:00
|
|
|
case ')':
|
2010-10-26 00:09:46 -04:00
|
|
|
stack.push(tok);
|
2010-09-21 23:58:05 -04:00
|
|
|
break;
|
|
|
|
case '(':
|
2011-02-22 19:20:01 -05:00
|
|
|
case 'CALL_START':
|
2010-10-26 00:09:46 -04:00
|
|
|
if (stack.length) {
|
|
|
|
stack.pop();
|
2011-02-22 19:20:01 -05:00
|
|
|
} else if (tok[0] === '(') {
|
2010-10-26 00:09:46 -04:00
|
|
|
tok[0] = 'PARAM_START';
|
|
|
|
return this;
|
2011-06-07 03:58:36 -04:00
|
|
|
} else {
|
|
|
|
return this;
|
2010-10-26 00:09:46 -04:00
|
|
|
}
|
2010-02-28 20:44:33 -05:00
|
|
|
}
|
|
|
|
}
|
2010-10-22 10:47:40 -04:00
|
|
|
return this;
|
2010-02-28 20:44:33 -05:00
|
|
|
};
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-06-12 19:05:13 -04:00
|
|
|
Lexer.prototype.closeIndentation = function() {
|
|
|
|
return this.outdentToken(this.indent);
|
2010-02-28 20:44:33 -05:00
|
|
|
};
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-12-18 14:48:44 -05:00
|
|
|
Lexer.prototype.balancedString = function(str, end) {
|
2012-02-29 23:46:03 -05:00
|
|
|
var continueCount, i, letter, match, prev, stack, _i, _ref2;
|
2011-12-21 14:06:34 -05:00
|
|
|
continueCount = 0;
|
2010-12-18 13:20:14 -05:00
|
|
|
stack = [end];
|
2012-02-29 23:46:03 -05:00
|
|
|
for (i = _i = 1, _ref2 = str.length; 1 <= _ref2 ? _i < _ref2 : _i > _ref2; i = 1 <= _ref2 ? ++_i : --_i) {
|
2011-12-21 14:06:34 -05:00
|
|
|
if (continueCount) {
|
|
|
|
--continueCount;
|
|
|
|
continue;
|
|
|
|
}
|
2010-12-18 13:20:14 -05:00
|
|
|
switch (letter = str.charAt(i)) {
|
2010-11-15 23:59:52 -05:00
|
|
|
case '\\':
|
2011-12-21 14:06:34 -05:00
|
|
|
++continueCount;
|
2010-11-15 23:59:52 -05:00
|
|
|
continue;
|
2010-12-18 13:20:14 -05:00
|
|
|
case end:
|
2010-11-15 23:59:52 -05:00
|
|
|
stack.pop();
|
2012-04-10 14:57:45 -04:00
|
|
|
if (!stack.length) {
|
2012-05-20 16:32:10 -04:00
|
|
|
return str.slice(0, +i + 1 || 9e9);
|
2012-04-10 14:57:45 -04:00
|
|
|
}
|
2010-12-18 13:20:14 -05:00
|
|
|
end = stack[stack.length - 1];
|
2010-11-15 23:59:52 -05:00
|
|
|
continue;
|
2010-06-28 00:19:58 -04:00
|
|
|
}
|
2011-06-17 11:53:48 -04:00
|
|
|
if (end === '}' && (letter === '"' || letter === "'")) {
|
2010-12-18 13:20:14 -05:00
|
|
|
stack.push(end = letter);
|
2011-06-19 13:01:01 -04:00
|
|
|
} else if (end === '}' && letter === '/' && (match = HEREGEX.exec(str.slice(i)) || REGEX.exec(str.slice(i)))) {
|
2011-12-21 14:06:34 -05:00
|
|
|
continueCount += match[0].length - 1;
|
2010-12-18 13:20:14 -05:00
|
|
|
} else if (end === '}' && letter === '{') {
|
|
|
|
stack.push(end = '}');
|
|
|
|
} else if (end === '"' && prev === '#' && letter === '{') {
|
|
|
|
stack.push(end = '}');
|
2010-06-28 00:19:58 -04:00
|
|
|
}
|
2010-12-18 13:20:14 -05:00
|
|
|
prev = letter;
|
2010-06-28 00:19:58 -04:00
|
|
|
}
|
2011-09-17 21:39:24 -04:00
|
|
|
return this.error("missing " + (stack.pop()) + ", starting");
|
2010-06-28 00:19:58 -04:00
|
|
|
};
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-07-22 12:38:26 -04:00
|
|
|
Lexer.prototype.interpolateString = function(str, options) {
|
2014-01-21 21:44:50 -05:00
|
|
|
var column, errorToken, expr, heredoc, i, inner, interpolated, len, letter, lexedLength, line, locationToken, nested, offsetInChunk, pi, plusToken, popped, regex, rparen, strOffset, tag, token, tokens, value, _i, _len, _ref2, _ref3, _ref4;
|
2012-04-10 14:57:45 -04:00
|
|
|
if (options == null) {
|
|
|
|
options = {};
|
|
|
|
}
|
2012-11-20 12:05:59 -05:00
|
|
|
heredoc = options.heredoc, regex = options.regex, offsetInChunk = options.offsetInChunk, strOffset = options.strOffset, lexedLength = options.lexedLength;
|
2014-01-21 21:44:50 -05:00
|
|
|
offsetInChunk || (offsetInChunk = 0);
|
|
|
|
strOffset || (strOffset = 0);
|
|
|
|
lexedLength || (lexedLength = str.length);
|
2010-09-25 18:06:14 -04:00
|
|
|
tokens = [];
|
2010-10-04 14:30:48 -04:00
|
|
|
pi = 0;
|
|
|
|
i = -1;
|
2010-10-05 00:11:28 -04:00
|
|
|
while (letter = str.charAt(i += 1)) {
|
|
|
|
if (letter === '\\') {
|
2010-09-25 18:06:14 -04:00
|
|
|
i += 1;
|
2010-10-03 19:22:42 -04:00
|
|
|
continue;
|
|
|
|
}
|
2011-08-08 12:55:22 -04:00
|
|
|
if (!(letter === '#' && str.charAt(i + 1) === '{' && (expr = this.balancedString(str.slice(i + 1), '}')))) {
|
2011-08-08 12:27:53 -04:00
|
|
|
continue;
|
2011-08-08 12:55:22 -04:00
|
|
|
}
|
2012-04-10 14:57:45 -04:00
|
|
|
if (pi < i) {
|
2012-11-20 12:05:59 -05:00
|
|
|
tokens.push(this.makeToken('NEOSTRING', str.slice(pi, i), strOffset + pi));
|
2012-04-10 14:57:45 -04:00
|
|
|
}
|
2014-01-21 21:44:50 -05:00
|
|
|
if (!errorToken) {
|
|
|
|
errorToken = this.makeToken('', 'string interpolation', offsetInChunk + i + 1, 2);
|
|
|
|
}
|
2010-11-20 20:47:43 -05:00
|
|
|
inner = expr.slice(1, -1);
|
2010-10-03 19:22:42 -04:00
|
|
|
if (inner.length) {
|
2014-06-12 16:03:10 -04:00
|
|
|
_ref2 = this.getLineAndColumnFromChunk(strOffset + i + 2), line = _ref2[0], column = _ref2[1];
|
2010-10-04 14:30:48 -04:00
|
|
|
nested = new Lexer().tokenize(inner, {
|
2012-11-16 19:09:56 -05:00
|
|
|
line: line,
|
|
|
|
column: column,
|
2010-10-04 14:30:48 -04:00
|
|
|
rewrite: false
|
2010-10-03 19:22:42 -04:00
|
|
|
});
|
2012-11-16 19:09:56 -05:00
|
|
|
popped = nested.pop();
|
|
|
|
if (((_ref3 = nested[0]) != null ? _ref3[0] : void 0) === 'TERMINATOR') {
|
|
|
|
popped = nested.shift();
|
2011-08-08 12:55:22 -04:00
|
|
|
}
|
2011-01-15 10:57:50 -05:00
|
|
|
if (len = nested.length) {
|
|
|
|
if (len > 1) {
|
2012-11-20 12:05:59 -05:00
|
|
|
nested.unshift(this.makeToken('(', '(', strOffset + i + 1, 0));
|
|
|
|
nested.push(this.makeToken(')', ')', strOffset + i + 1 + inner.length, 0));
|
2011-01-15 10:57:50 -05:00
|
|
|
}
|
|
|
|
tokens.push(['TOKENS', nested]);
|
2010-03-08 13:05:02 -05:00
|
|
|
}
|
2010-03-05 17:30:49 -05:00
|
|
|
}
|
2010-10-03 19:22:42 -04:00
|
|
|
i += expr.length;
|
|
|
|
pi = i + 1;
|
2010-09-25 18:06:14 -04:00
|
|
|
}
|
2012-04-10 14:57:45 -04:00
|
|
|
if ((i > pi && pi < str.length)) {
|
2012-11-20 12:05:59 -05:00
|
|
|
tokens.push(this.makeToken('NEOSTRING', str.slice(pi), strOffset + pi));
|
2012-04-10 14:57:45 -04:00
|
|
|
}
|
|
|
|
if (regex) {
|
|
|
|
return tokens;
|
|
|
|
}
|
|
|
|
if (!tokens.length) {
|
2012-11-20 12:05:59 -05:00
|
|
|
return this.token('STRING', '""', offsetInChunk, lexedLength);
|
2012-04-10 14:57:45 -04:00
|
|
|
}
|
|
|
|
if (tokens[0][0] !== 'NEOSTRING') {
|
2012-11-20 12:05:59 -05:00
|
|
|
tokens.unshift(this.makeToken('NEOSTRING', '', offsetInChunk));
|
2012-04-10 14:57:45 -04:00
|
|
|
}
|
|
|
|
if (interpolated = tokens.length > 1) {
|
2014-01-21 21:44:50 -05:00
|
|
|
this.token('(', '(', offsetInChunk, 0, errorToken);
|
2012-04-10 14:57:45 -04:00
|
|
|
}
|
2011-12-21 14:06:34 -05:00
|
|
|
for (i = _i = 0, _len = tokens.length; _i < _len; i = ++_i) {
|
2012-11-16 19:09:56 -05:00
|
|
|
token = tokens[i];
|
|
|
|
tag = token[0], value = token[1];
|
2012-04-10 14:57:45 -04:00
|
|
|
if (i) {
|
2012-11-19 17:37:46 -05:00
|
|
|
if (i) {
|
|
|
|
plusToken = this.token('+', '+');
|
|
|
|
}
|
|
|
|
locationToken = tag === 'TOKENS' ? value[0] : token;
|
2013-01-14 15:20:35 -05:00
|
|
|
plusToken[2] = {
|
|
|
|
first_line: locationToken[2].first_line,
|
|
|
|
first_column: locationToken[2].first_column,
|
|
|
|
last_line: locationToken[2].first_line,
|
|
|
|
last_column: locationToken[2].first_column
|
2012-11-19 17:37:46 -05:00
|
|
|
};
|
2012-04-10 14:57:45 -04:00
|
|
|
}
|
2010-09-25 18:06:14 -04:00
|
|
|
if (tag === 'TOKENS') {
|
2012-02-29 23:46:03 -05:00
|
|
|
(_ref4 = this.tokens).push.apply(_ref4, value);
|
2012-11-16 19:09:56 -05:00
|
|
|
} else if (tag === 'NEOSTRING') {
|
|
|
|
token[0] = 'STRING';
|
|
|
|
token[1] = this.makeString(value, '"', heredoc);
|
|
|
|
this.tokens.push(token);
|
2010-09-25 18:06:14 -04:00
|
|
|
} else {
|
2012-11-16 19:09:56 -05:00
|
|
|
this.error("Unexpected " + tag);
|
2010-04-04 02:59:44 -04:00
|
|
|
}
|
2010-03-05 17:30:49 -05:00
|
|
|
}
|
2012-04-10 14:57:45 -04:00
|
|
|
if (interpolated) {
|
2013-03-05 03:28:29 -05:00
|
|
|
rparen = this.makeToken(')', ')', offsetInChunk + lexedLength, 0);
|
|
|
|
rparen.stringEnd = true;
|
|
|
|
this.tokens.push(rparen);
|
2012-04-10 14:57:45 -04:00
|
|
|
}
|
2010-09-25 18:06:14 -04:00
|
|
|
return tokens;
|
2010-03-05 17:30:49 -05:00
|
|
|
};
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2011-09-16 19:26:04 -04:00
|
|
|
Lexer.prototype.pair = function(tag) {
|
2014-01-22 13:30:13 -05:00
|
|
|
var wanted;
|
2011-09-16 19:26:04 -04:00
|
|
|
if (tag !== (wanted = last(this.ends))) {
|
2012-04-10 14:57:45 -04:00
|
|
|
if ('OUTDENT' !== wanted) {
|
|
|
|
this.error("unmatched " + tag);
|
|
|
|
}
|
2014-01-22 13:30:13 -05:00
|
|
|
this.outdentToken(last(this.indents), true);
|
2011-09-16 19:26:04 -04:00
|
|
|
return this.pair(tag);
|
|
|
|
}
|
|
|
|
return this.ends.pop();
|
|
|
|
};
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2012-11-16 19:09:56 -05:00
|
|
|
Lexer.prototype.getLineAndColumnFromChunk = function(offset) {
|
|
|
|
var column, lineCount, lines, string;
|
|
|
|
if (offset === 0) {
|
|
|
|
return [this.chunkLine, this.chunkColumn];
|
|
|
|
}
|
|
|
|
if (offset >= this.chunk.length) {
|
|
|
|
string = this.chunk;
|
|
|
|
} else {
|
|
|
|
string = this.chunk.slice(0, +(offset - 1) + 1 || 9e9);
|
|
|
|
}
|
|
|
|
lineCount = count(string, '\n');
|
|
|
|
column = this.chunkColumn;
|
|
|
|
if (lineCount > 0) {
|
|
|
|
lines = string.split('\n');
|
2013-04-27 18:56:44 -04:00
|
|
|
column = last(lines).length;
|
2012-11-16 19:09:56 -05:00
|
|
|
} else {
|
|
|
|
column += string.length;
|
|
|
|
}
|
|
|
|
return [this.chunkLine + lineCount, column];
|
|
|
|
};
|
|
|
|
|
|
|
|
Lexer.prototype.makeToken = function(tag, value, offsetInChunk, length) {
|
2013-01-14 17:11:07 -05:00
|
|
|
var lastCharacter, locationData, token, _ref2, _ref3;
|
2013-02-25 08:44:56 -05:00
|
|
|
if (offsetInChunk == null) {
|
|
|
|
offsetInChunk = 0;
|
|
|
|
}
|
|
|
|
if (length == null) {
|
2012-11-16 19:09:56 -05:00
|
|
|
length = value.length;
|
|
|
|
}
|
|
|
|
locationData = {};
|
|
|
|
_ref2 = this.getLineAndColumnFromChunk(offsetInChunk), locationData.first_line = _ref2[0], locationData.first_column = _ref2[1];
|
2013-02-25 08:44:56 -05:00
|
|
|
lastCharacter = Math.max(0, length - 1);
|
2013-03-04 18:01:17 -05:00
|
|
|
_ref3 = this.getLineAndColumnFromChunk(offsetInChunk + lastCharacter), locationData.last_line = _ref3[0], locationData.last_column = _ref3[1];
|
2013-01-14 15:20:35 -05:00
|
|
|
token = [tag, value, locationData];
|
2012-11-16 19:09:56 -05:00
|
|
|
return token;
|
|
|
|
};
|
|
|
|
|
2014-01-21 21:44:50 -05:00
|
|
|
Lexer.prototype.token = function(tag, value, offsetInChunk, length, origin) {
|
2012-11-16 19:09:56 -05:00
|
|
|
var token;
|
|
|
|
token = this.makeToken(tag, value, offsetInChunk, length);
|
2014-01-21 21:44:50 -05:00
|
|
|
if (origin) {
|
|
|
|
token.origin = origin;
|
|
|
|
}
|
2012-11-16 19:09:56 -05:00
|
|
|
this.tokens.push(token);
|
|
|
|
return token;
|
2010-02-27 19:40:53 -05:00
|
|
|
};
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-10-05 10:31:48 -04:00
|
|
|
Lexer.prototype.tag = function(index, tag) {
|
2010-02-27 19:40:53 -05:00
|
|
|
var tok;
|
2010-11-05 00:04:52 -04:00
|
|
|
return (tok = last(this.tokens, index)) && (tag ? tok[0] = tag : tok[0]);
|
2010-02-27 19:40:53 -05:00
|
|
|
};
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-05-14 23:40:04 -04:00
|
|
|
Lexer.prototype.value = function(index, val) {
|
2010-02-27 19:40:53 -05:00
|
|
|
var tok;
|
2010-11-05 00:04:52 -04:00
|
|
|
return (tok = last(this.tokens, index)) && (val ? tok[1] = val : tok[1]);
|
2010-02-27 19:40:53 -05:00
|
|
|
};
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-05-14 23:40:04 -04:00
|
|
|
Lexer.prototype.unfinished = function() {
|
2012-02-29 23:46:03 -05:00
|
|
|
var _ref2;
|
2013-03-25 19:41:14 -04:00
|
|
|
return LINE_CONTINUER.test(this.chunk) || ((_ref2 = this.tag()) === '\\' || _ref2 === '.' || _ref2 === '?.' || _ref2 === '?::' || _ref2 === 'UNARY' || _ref2 === 'MATH' || _ref2 === 'UNARY_MATH' || _ref2 === '+' || _ref2 === '-' || _ref2 === '**' || _ref2 === 'SHIFT' || _ref2 === 'RELATION' || _ref2 === 'COMPARE' || _ref2 === 'LOGIC' || _ref2 === 'THROW' || _ref2 === 'EXTENDS');
|
2010-09-25 18:06:14 -04:00
|
|
|
};
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2013-11-27 15:29:45 -05:00
|
|
|
Lexer.prototype.removeNewlines = function(str) {
|
|
|
|
return str.replace(/^\s*\n\s*/, '').replace(/([^\\]|\\\\)\s*\n\s*$/, '$1');
|
|
|
|
};
|
|
|
|
|
2010-09-26 10:57:03 -04:00
|
|
|
Lexer.prototype.escapeLines = function(str, heredoc) {
|
2013-11-24 13:37:11 -05:00
|
|
|
str = str.replace(/\\[^\S\n]*(\n|\\)\s*/g, function(escaped, character) {
|
|
|
|
if (character === '\n') {
|
|
|
|
return '';
|
|
|
|
} else {
|
|
|
|
return escaped;
|
|
|
|
}
|
|
|
|
});
|
2013-11-17 23:32:15 -05:00
|
|
|
if (heredoc) {
|
|
|
|
return str.replace(MULTILINER, '\\n');
|
|
|
|
} else {
|
2013-11-27 15:29:45 -05:00
|
|
|
return str.replace(/\s*\n\s*/g, ' ');
|
2013-11-17 23:32:15 -05:00
|
|
|
}
|
2010-03-20 00:58:25 -04:00
|
|
|
};
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-10-04 14:30:48 -04:00
|
|
|
Lexer.prototype.makeString = function(body, quote, heredoc) {
|
2012-04-10 14:57:45 -04:00
|
|
|
if (!body) {
|
|
|
|
return quote + quote;
|
|
|
|
}
|
2013-11-24 13:37:11 -05:00
|
|
|
body = body.replace(RegExp("\\\\(" + quote + "|\\\\)", "g"), function(match, contents) {
|
|
|
|
if (contents === quote) {
|
2010-11-08 23:07:51 -05:00
|
|
|
return contents;
|
|
|
|
} else {
|
|
|
|
return match;
|
|
|
|
}
|
2010-10-04 14:30:48 -04:00
|
|
|
});
|
|
|
|
body = body.replace(RegExp("" + quote, "g"), '\\$&');
|
|
|
|
return quote + this.escapeLines(body, heredoc) + quote;
|
|
|
|
};
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2013-06-13 18:21:47 -04:00
|
|
|
Lexer.prototype.error = function(message, offset) {
|
|
|
|
var first_column, first_line, _ref2;
|
|
|
|
if (offset == null) {
|
|
|
|
offset = 0;
|
|
|
|
}
|
|
|
|
_ref2 = this.getLineAndColumnFromChunk(offset), first_line = _ref2[0], first_column = _ref2[1];
|
2013-03-04 23:13:46 -05:00
|
|
|
return throwSyntaxError(message, {
|
2013-06-13 18:21:47 -04:00
|
|
|
first_line: first_line,
|
|
|
|
first_column: first_column
|
2013-03-04 23:13:46 -05:00
|
|
|
});
|
2011-09-16 19:26:04 -04:00
|
|
|
};
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-02-27 19:40:53 -05:00
|
|
|
return Lexer;
|
2011-12-14 10:39:20 -05:00
|
|
|
|
2010-12-23 13:50:52 -05:00
|
|
|
})();
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-12-24 11:59:30 -05:00
|
|
|
JS_KEYWORDS = ['true', 'false', 'null', 'this', 'new', 'delete', 'typeof', 'in', 'instanceof', 'return', 'throw', 'break', 'continue', 'debugger', 'if', 'else', 'switch', 'for', 'while', 'do', 'try', 'catch', 'finally', 'class', 'extends', 'super'];
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-10-27 22:50:20 -04:00
|
|
|
COFFEE_KEYWORDS = ['undefined', 'then', 'unless', 'until', 'loop', 'of', 'by', 'when'];
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2011-04-30 10:35:56 -04:00
|
|
|
COFFEE_ALIAS_MAP = {
|
2010-10-05 15:46:17 -04:00
|
|
|
and: '&&',
|
|
|
|
or: '||',
|
|
|
|
is: '==',
|
|
|
|
isnt: '!=',
|
2010-10-07 11:56:01 -04:00
|
|
|
not: '!',
|
2010-10-23 14:24:30 -04:00
|
|
|
yes: 'true',
|
|
|
|
no: 'false',
|
|
|
|
on: 'true',
|
|
|
|
off: 'false'
|
2011-04-30 10:35:56 -04:00
|
|
|
};
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2011-04-30 10:35:56 -04:00
|
|
|
COFFEE_ALIASES = (function() {
|
|
|
|
var _results;
|
|
|
|
_results = [];
|
|
|
|
for (key in COFFEE_ALIAS_MAP) {
|
|
|
|
_results.push(key);
|
|
|
|
}
|
|
|
|
return _results;
|
|
|
|
})();
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2011-04-30 10:35:56 -04:00
|
|
|
COFFEE_KEYWORDS = COFFEE_KEYWORDS.concat(COFFEE_ALIASES);
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2012-06-12 16:15:59 -04:00
|
|
|
RESERVED = ['case', 'default', 'function', 'var', 'void', 'with', 'const', 'let', 'enum', 'export', 'import', 'native', '__hasProp', '__extends', '__slice', '__bind', '__indexOf', 'implements', 'interface', 'package', 'private', 'protected', 'public', 'static', 'yield'];
|
2012-01-11 18:04:14 -05:00
|
|
|
|
|
|
|
STRICT_PROSCRIBED = ['arguments', 'eval'];
|
|
|
|
|
|
|
|
JS_FORBIDDEN = JS_KEYWORDS.concat(RESERVED).concat(STRICT_PROSCRIBED);
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2012-01-11 18:04:14 -05:00
|
|
|
exports.RESERVED = RESERVED.concat(JS_KEYWORDS).concat(COFFEE_KEYWORDS).concat(STRICT_PROSCRIBED);
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2012-01-11 18:04:14 -05:00
|
|
|
exports.STRICT_PROSCRIBED = STRICT_PROSCRIBED;
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2013-01-06 23:56:58 -05:00
|
|
|
BOM = 65279;
|
|
|
|
|
2010-12-28 20:42:20 -05:00
|
|
|
IDENTIFIER = /^([$A-Za-z_\x7f-\uffff][$\w\x7f-\uffff]*)([^\n\S]*:(?!:))?/;
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2012-01-20 17:23:50 -05:00
|
|
|
NUMBER = /^0b[01]+|^0o[0-7]+|^0x[\da-f]+|^\d*\.?\d+(?:e[+-]?\d+)?/i;
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2013-11-28 10:46:00 -05:00
|
|
|
HEREDOC = /^("""|''')((?:\\[\s\S]|[^\\])*?)(?:\n[^\n\S]*)?\1/;
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2013-03-25 02:19:05 -04:00
|
|
|
OPERATOR = /^(?:[-=]>|[-+*\/%<>&|^!?=]=|>>>=?|([-+:])\1|([&|<>*\/%])\2=?|\?(\.|::)|\.{2,3})/;
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-11-09 08:25:48 -05:00
|
|
|
WHITESPACE = /^[^\n\S]+/;
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2013-11-26 14:29:13 -05:00
|
|
|
COMMENT = /^###([^#][\s\S]*?)(?:###[^\n\S]*|###$)|^(?:\s*#(?!##[^#]).*)+/;
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-09-23 01:14:18 -04:00
|
|
|
CODE = /^[-=]>/;
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-11-09 08:25:48 -05:00
|
|
|
MULTI_DENT = /^(?:\n[^\n\S]*)+/;
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2013-11-18 10:13:40 -05:00
|
|
|
SIMPLESTR = /^'[^\\']*(?:\\[\s\S][^\\']*)*'/;
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-09-24 09:38:28 -04:00
|
|
|
JSTOKEN = /^`[^\\`]*(?:\\.[^\\`]*)*`/;
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2011-10-03 03:47:24 -04:00
|
|
|
REGEX = /^(\/(?![\s=])[^[\/\n\\]*(?:(?:\\[\s\S]|\[[^\]\n\\]*(?:\\[\s\S][^\]\n\\]*)*])[^[\/\n\\]*)*\/)([imgy]{0,4})(?!\w)/;
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2013-10-21 15:52:36 -04:00
|
|
|
HEREGEX = /^\/{3}((?:\\?[\s\S])+?)\/{3}([imgy]{0,4})(?!\w)/;
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2013-10-23 18:36:46 -04:00
|
|
|
HEREGEX_OMIT = /((?:\\\\)+)|\\(\s|\/)|\s+(?:#.*)?/g;
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-03-07 14:41:52 -05:00
|
|
|
MULTILINER = /\n/g;
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-11-09 08:25:48 -05:00
|
|
|
HEREDOC_INDENT = /\n+([^\n\S]*)/g;
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2011-01-18 23:10:09 -05:00
|
|
|
HEREDOC_ILLEGAL = /\*\//;
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2011-02-27 02:11:35 -05:00
|
|
|
LINE_CONTINUER = /^\s*(?:,|\??\.(?![.\d])|::)/;
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-10-03 19:22:42 -04:00
|
|
|
TRAILING_SPACES = /\s+$/;
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2013-03-25 02:19:05 -04:00
|
|
|
COMPOUND_ASSIGN = ['-=', '+=', '/=', '*=', '%=', '||=', '&&=', '?=', '<<=', '>>=', '>>>=', '&=', '^=', '|=', '**=', '//=', '%%='];
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2013-03-24 23:05:04 -04:00
|
|
|
UNARY = ['NEW', 'TYPEOF', 'DELETE', 'DO'];
|
|
|
|
|
|
|
|
UNARY_MATH = ['!', '~'];
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-10-23 14:24:30 -04:00
|
|
|
LOGIC = ['&&', '||', '&', '|', '^'];
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-08-11 22:24:43 -04:00
|
|
|
SHIFT = ['<<', '>>', '>>>'];
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-10-23 14:24:30 -04:00
|
|
|
COMPARE = ['==', '!=', '<', '>', '<=', '>='];
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2013-03-25 02:19:05 -04:00
|
|
|
MATH = ['*', '/', '%', '//', '%%'];
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-10-05 11:43:44 -04:00
|
|
|
RELATION = ['IN', 'OF', 'INSTANCEOF'];
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2012-05-08 16:11:23 -04:00
|
|
|
BOOL = ['TRUE', 'FALSE'];
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2013-04-21 06:27:30 -04:00
|
|
|
NOT_REGEX = ['NUMBER', 'REGEX', 'BOOL', 'NULL', 'UNDEFINED', '++', '--'];
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2013-04-21 06:27:30 -04:00
|
|
|
NOT_SPACED_REGEX = NOT_REGEX.concat(')', '}', 'THIS', 'IDENTIFIER', 'STRING', ']');
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-10-12 06:30:10 -04:00
|
|
|
CALLABLE = ['IDENTIFIER', 'STRING', 'REGEX', ')', ']', '}', '?', '::', '@', 'THIS', 'SUPER'];
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2012-05-08 16:11:23 -04:00
|
|
|
INDEXABLE = CALLABLE.concat('NUMBER', 'BOOL', 'NULL', 'UNDEFINED');
|
2011-09-18 18:16:39 -04:00
|
|
|
|
2010-03-20 00:58:25 -04:00
|
|
|
LINE_BREAK = ['INDENT', 'OUTDENT', 'TERMINATOR'];
|
2011-12-14 10:39:20 -05:00
|
|
|
|
2014-01-22 13:30:13 -05:00
|
|
|
INDENTABLE_CLOSERS = [')', '}', ']'];
|
|
|
|
|
2010-09-21 03:53:58 -04:00
|
|
|
}).call(this);
|