2010-07-25 03:15:12 -04:00
|
|
|
(function() {
|
2010-10-19 23:27:15 -04:00
|
|
|
var ASSIGNED, BOOL, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, HEREDOC, HEREDOC_INDENT, HEREGEX, HEREGEX_OMIT, IDENTIFIER, INDEXABLE, JSTOKEN, JS_FORBIDDEN, JS_KEYWORDS, LEADING_SPACES, LINE_BREAK, LOGIC, Lexer, MATH, MULTILINER, MULTI_DENT, NEXT_CHARACTER, NEXT_ELLIPSIS, NOT_REGEX, NO_NEWLINE, NUMBER, OPERATOR, REGEX, RELATION, RESERVED, Rewriter, SHIFT, SIMPLESTR, TRAILING_SPACES, UNARY, WHITESPACE, _ref, compact, count, last, op, starts;
|
|
|
|
var __indexOf = Array.prototype.indexOf || function(item) {
|
|
|
|
for (var i = 0, l = this.length; i < l; i++) if (this[i] === item) return i;
|
|
|
|
return -1;
|
|
|
|
};
|
2010-09-28 16:47:12 -04:00
|
|
|
Rewriter = require('./rewriter').Rewriter;
|
2010-10-19 23:27:15 -04:00
|
|
|
_ref = require('./helpers'), count = _ref.count, starts = _ref.starts, compact = _ref.compact, last = _ref.last;
|
2010-02-27 19:40:53 -05:00
|
|
|
exports.Lexer = (function() {
|
2010-10-04 23:21:16 -04:00
|
|
|
Lexer = (function() {
|
2010-10-19 03:39:58 -04:00
|
|
|
function Lexer() {
|
|
|
|
return this;
|
|
|
|
};
|
2010-10-11 12:13:01 -04:00
|
|
|
return Lexer;
|
2010-10-04 23:21:16 -04:00
|
|
|
})();
|
2010-05-14 23:40:04 -04:00
|
|
|
Lexer.prototype.tokenize = function(code, options) {
|
2010-03-06 16:06:47 -05:00
|
|
|
var o;
|
2010-10-03 19:22:42 -04:00
|
|
|
code = code.replace(/\r/g, '').replace(TRAILING_SPACES, '');
|
2010-03-09 20:53:56 -05:00
|
|
|
o = options || {};
|
2010-03-08 23:07:26 -05:00
|
|
|
this.code = code;
|
2010-02-27 19:40:53 -05:00
|
|
|
this.i = 0;
|
2010-03-06 16:06:47 -05:00
|
|
|
this.line = o.line || 0;
|
2010-02-27 19:40:53 -05:00
|
|
|
this.indent = 0;
|
2010-09-08 22:46:13 -04:00
|
|
|
this.indebt = 0;
|
2010-06-01 23:32:46 -04:00
|
|
|
this.outdebt = 0;
|
2010-10-05 15:46:17 -04:00
|
|
|
this.seenFor = false;
|
2010-02-27 19:40:53 -05:00
|
|
|
this.indents = [];
|
|
|
|
this.tokens = [];
|
2010-10-11 08:06:27 -04:00
|
|
|
while (this.chunk = code.slice(this.i)) {
|
2010-09-25 18:06:14 -04:00
|
|
|
this.identifierToken() || this.commentToken() || this.whitespaceToken() || this.lineToken() || this.heredocToken() || this.stringToken() || this.numberToken() || this.regexToken() || this.jsToken() || this.literalToken();
|
2010-02-27 19:40:53 -05:00
|
|
|
}
|
2010-06-12 19:05:13 -04:00
|
|
|
this.closeIndentation();
|
2010-04-11 09:26:21 -04:00
|
|
|
if (o.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
|
|
|
};
|
2010-06-12 19:05:13 -04:00
|
|
|
Lexer.prototype.identifierToken = function() {
|
2010-10-19 23:27:15 -04:00
|
|
|
var _ref2, colon, forcedIdentifier, id, input, match, tag;
|
2010-09-25 18:06:14 -04:00
|
|
|
if (!(match = IDENTIFIER.exec(this.chunk))) {
|
2010-02-27 19:40:53 -05:00
|
|
|
return false;
|
|
|
|
}
|
2010-10-10 20:17:31 -04:00
|
|
|
input = match[0], id = match[1], colon = match[2];
|
2010-10-11 06:10:30 -04:00
|
|
|
this.i += input.length;
|
2010-07-15 21:18:35 -04:00
|
|
|
if (id === 'all' && this.tag() === 'FOR') {
|
2010-09-25 03:00:07 -04:00
|
|
|
this.token('ALL', id);
|
|
|
|
return true;
|
2010-07-15 21:18:35 -04:00
|
|
|
}
|
2010-10-11 06:10:30 -04:00
|
|
|
forcedIdentifier = colon || this.tagAccessor();
|
2010-02-27 19:40:53 -05:00
|
|
|
tag = 'IDENTIFIER';
|
2010-10-19 23:27:15 -04:00
|
|
|
if ((__indexOf.call(JS_KEYWORDS, id) >= 0) || !forcedIdentifier && (__indexOf.call(COFFEE_KEYWORDS, id) >= 0)) {
|
2010-02-27 19:40:53 -05:00
|
|
|
tag = id.toUpperCase();
|
2010-10-19 23:27:15 -04:00
|
|
|
if (tag === 'WHEN' && (_ref2 = this.tag(), __indexOf.call(LINE_BREAK, _ref2) >= 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-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) {
|
|
|
|
this.seenFor = false;
|
|
|
|
tag = 'FOR' + tag;
|
|
|
|
} else {
|
|
|
|
tag = 'RELATION';
|
|
|
|
if (this.value() === '!') {
|
|
|
|
this.tokens.pop();
|
|
|
|
id = '!' + id;
|
|
|
|
}
|
|
|
|
}
|
2010-09-23 01:14:18 -04:00
|
|
|
}
|
2010-08-11 22:24:43 -04:00
|
|
|
}
|
2010-10-19 23:27:15 -04: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) {
|
2010-06-15 00:54:02 -04:00
|
|
|
this.identifierError(id);
|
|
|
|
}
|
|
|
|
}
|
2010-10-07 07:05:22 -04:00
|
|
|
if (!forcedIdentifier) {
|
2010-10-05 15:46:17 -04:00
|
|
|
if (COFFEE_ALIASES.hasOwnProperty(id)) {
|
2010-10-20 13:29:06 -04:00
|
|
|
tag = id = COFFEE_ALIASES[id];
|
2010-03-21 23:24:24 -04:00
|
|
|
}
|
2010-08-11 22:24:43 -04:00
|
|
|
if (id === '!') {
|
|
|
|
tag = 'UNARY';
|
2010-10-19 23:27:15 -04:00
|
|
|
} else if (__indexOf.call(LOGIC, id) >= 0) {
|
2010-09-23 01:14:18 -04:00
|
|
|
tag = 'LOGIC';
|
2010-10-19 23:27:15 -04:00
|
|
|
} else if (__indexOf.call(BOOL, tag) >= 0) {
|
2010-10-11 04:05:50 -04:00
|
|
|
id = tag.toLowerCase();
|
|
|
|
tag = 'BOOL';
|
2010-08-11 22:24:43 -04:00
|
|
|
}
|
2010-03-21 21:46:06 -04:00
|
|
|
}
|
|
|
|
this.token(tag, id);
|
2010-10-11 06:10:30 -04:00
|
|
|
if (colon) {
|
|
|
|
this.token(':', ':');
|
|
|
|
}
|
2010-02-27 19:40:53 -05:00
|
|
|
return true;
|
|
|
|
};
|
2010-06-12 19:05:13 -04:00
|
|
|
Lexer.prototype.numberToken = function() {
|
2010-09-25 18:06:14 -04:00
|
|
|
var match, number;
|
|
|
|
if (!(match = NUMBER.exec(this.chunk))) {
|
2010-02-27 19:40:53 -05:00
|
|
|
return false;
|
|
|
|
}
|
2010-09-25 18:06:14 -04:00
|
|
|
number = match[0];
|
2010-09-23 01:14:18 -04:00
|
|
|
if (this.tag() === '.' && number.charAt(0) === '.') {
|
2010-05-31 13:40:03 -04:00
|
|
|
return false;
|
2010-05-19 17:20:33 -04:00
|
|
|
}
|
2010-05-31 13:40:03 -04:00
|
|
|
this.i += number.length;
|
2010-05-19 17:20:33 -04:00
|
|
|
this.token('NUMBER', number);
|
2010-02-27 19:40:53 -05:00
|
|
|
return true;
|
|
|
|
};
|
2010-06-12 19:05:13 -04:00
|
|
|
Lexer.prototype.stringToken = function() {
|
2010-09-25 18:06:14 -04:00
|
|
|
var match, string;
|
2010-09-24 09:38:28 -04:00
|
|
|
switch (this.chunk.charAt(0)) {
|
|
|
|
case "'":
|
2010-09-25 18:06:14 -04:00
|
|
|
if (!(match = SIMPLESTR.exec(this.chunk))) {
|
2010-09-24 09:38:28 -04:00
|
|
|
return false;
|
|
|
|
}
|
2010-09-25 18:06:14 -04:00
|
|
|
this.token('STRING', (string = match[0]).replace(MULTILINER, '\\\n'));
|
2010-09-24 09:38:28 -04:00
|
|
|
break;
|
|
|
|
case '"':
|
2010-10-03 19:22:42 -04:00
|
|
|
if (!(string = this.balancedString(this.chunk, [['"', '"'], ['#{', '}']]))) {
|
2010-09-24 09:38:28 -04:00
|
|
|
return false;
|
|
|
|
}
|
2010-10-04 14:30:48 -04:00
|
|
|
if (0 < string.indexOf('#{', 1)) {
|
|
|
|
this.interpolateString(string.slice(1, -1));
|
2010-10-03 19:22:42 -04:00
|
|
|
} else {
|
|
|
|
this.token('STRING', this.escapeLines(string));
|
|
|
|
}
|
2010-09-24 09:38:28 -04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
2010-02-27 19:40:53 -05:00
|
|
|
}
|
2010-09-23 01:14:18 -04:00
|
|
|
this.line += count(string, '\n');
|
2010-02-27 19:40:53 -05:00
|
|
|
this.i += string.length;
|
|
|
|
return true;
|
|
|
|
};
|
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;
|
2010-10-03 19:22:42 -04:00
|
|
|
if (!(match = HEREDOC.exec(this.chunk))) {
|
2010-02-27 19:40:53 -05:00
|
|
|
return false;
|
|
|
|
}
|
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, {
|
2010-10-02 18:45:23 -04:00
|
|
|
heredoc: true
|
|
|
|
});
|
|
|
|
} else {
|
2010-10-04 14:30:48 -04:00
|
|
|
this.token('STRING', this.makeString(doc, quote, true));
|
2010-10-02 18:45:23 -04:00
|
|
|
}
|
2010-09-23 01:14:18 -04:00
|
|
|
this.line += count(heredoc, '\n');
|
|
|
|
this.i += heredoc.length;
|
2010-02-27 19:40:53 -05:00
|
|
|
return true;
|
|
|
|
};
|
2010-06-12 19:05:13 -04:00
|
|
|
Lexer.prototype.commentToken = function() {
|
2010-10-10 20:17:31 -04:00
|
|
|
var comment, here, match;
|
2010-05-12 20:56:44 -04:00
|
|
|
if (!(match = this.chunk.match(COMMENT))) {
|
|
|
|
return false;
|
|
|
|
}
|
2010-10-10 20:17:31 -04:00
|
|
|
comment = match[0], here = match[1];
|
2010-09-23 01:14:18 -04:00
|
|
|
this.line += count(comment, '\n');
|
|
|
|
this.i += comment.length;
|
|
|
|
if (here) {
|
|
|
|
this.token('HERECOMMENT', this.sanitizeHeredoc(here, {
|
2010-08-23 21:00:47 -04:00
|
|
|
herecomment: true,
|
2010-09-21 23:17:43 -04:00
|
|
|
indent: Array(this.indent + 1).join(' ')
|
2010-08-23 20:27:34 -04:00
|
|
|
}));
|
2010-07-01 21:26:33 -04:00
|
|
|
this.token('TERMINATOR', '\n');
|
|
|
|
}
|
2010-05-12 20:56:44 -04:00
|
|
|
return true;
|
|
|
|
};
|
2010-06-12 19:05:13 -04:00
|
|
|
Lexer.prototype.jsToken = function() {
|
2010-09-25 18:06:14 -04:00
|
|
|
var match, script;
|
|
|
|
if (!(this.chunk.charAt(0) === '`' && (match = JSTOKEN.exec(this.chunk)))) {
|
2010-03-07 12:47:03 -05:00
|
|
|
return false;
|
|
|
|
}
|
2010-09-25 18:06:14 -04:00
|
|
|
this.token('JS', (script = match[0]).slice(1, -1));
|
2010-02-27 19:40:53 -05:00
|
|
|
this.i += script.length;
|
|
|
|
return true;
|
|
|
|
};
|
2010-06-12 19:05:13 -04:00
|
|
|
Lexer.prototype.regexToken = function() {
|
2010-10-19 23:27:15 -04:00
|
|
|
var _ref2, match, regex;
|
2010-10-03 19:22:42 -04:00
|
|
|
if (this.chunk.charAt(0) !== '/') {
|
2010-08-12 20:24:53 -04:00
|
|
|
return false;
|
|
|
|
}
|
2010-10-03 19:22:42 -04:00
|
|
|
if (match = HEREGEX.exec(this.chunk)) {
|
|
|
|
return this.heregexToken(match);
|
2010-03-08 19:43:12 -05:00
|
|
|
}
|
2010-10-19 23:27:15 -04:00
|
|
|
if (_ref2 = this.tag(), __indexOf.call(NOT_REGEX, _ref2) >= 0) {
|
2010-03-08 13:05:02 -05:00
|
|
|
return false;
|
|
|
|
}
|
2010-10-04 08:50:50 -04:00
|
|
|
if (!(match = REGEX.exec(this.chunk))) {
|
2010-02-27 19:40:53 -05:00
|
|
|
return false;
|
|
|
|
}
|
2010-10-17 18:43:29 -04:00
|
|
|
regex = match[0];
|
|
|
|
this.token('REGEX', regex === '//' ? '/(?:)/' : regex);
|
|
|
|
this.i += regex.length;
|
2010-02-27 19:40:53 -05:00
|
|
|
return true;
|
|
|
|
};
|
2010-10-03 19:22:42 -04:00
|
|
|
Lexer.prototype.heregexToken = function(match) {
|
2010-10-19 11:07:10 -04:00
|
|
|
var _i, _len, _ref2, _ref3, _ref4, _this, body, flags, heregex, re, tag, tokens, value;
|
2010-10-10 20:17:31 -04:00
|
|
|
heregex = match[0], body = match[1], flags = match[2];
|
2010-10-03 19:22:42 -04:00
|
|
|
this.i += heregex.length;
|
2010-10-04 14:30:48 -04:00
|
|
|
if (0 > body.indexOf('#{')) {
|
2010-10-03 22:55:49 -04:00
|
|
|
re = body.replace(HEREGEX_OMIT, '').replace(/\//g, '\\/');
|
2010-10-04 08:50:50 -04:00
|
|
|
this.token('REGEX', "/" + (re || '(?:)') + "/" + flags);
|
2010-10-03 19:22:42 -04:00
|
|
|
return true;
|
2010-05-14 09:14:41 -04:00
|
|
|
}
|
2010-10-03 19:22:42 -04:00
|
|
|
this.token('IDENTIFIER', 'RegExp');
|
|
|
|
this.tokens.push(['CALL_START', '(']);
|
2010-10-04 08:50:50 -04:00
|
|
|
tokens = [];
|
2010-10-10 20:17:31 -04:00
|
|
|
for (_i = 0, _len = (_ref2 = this.interpolateString(body, {
|
2010-10-04 08:50:50 -04:00
|
|
|
regex: true
|
2010-10-06 23:24:32 -04:00
|
|
|
})).length; _i < _len; _i++) {
|
2010-10-10 20:17:31 -04:00
|
|
|
_ref3 = _ref2[_i], tag = _ref3[0], value = _ref3[1];
|
2010-10-04 08:50:50 -04:00
|
|
|
if (tag === 'TOKENS') {
|
|
|
|
tokens.push.apply(tokens, value);
|
|
|
|
} else {
|
2010-10-04 14:30:48 -04:00
|
|
|
if (!(value = value.replace(HEREGEX_OMIT, ''))) {
|
2010-10-04 08:50:50 -04:00
|
|
|
continue;
|
|
|
|
}
|
2010-10-04 14:30:48 -04:00
|
|
|
value = value.replace(/\\/g, '\\\\');
|
|
|
|
tokens.push(['STRING', this.makeString(value, '"', true)]);
|
2010-07-21 13:32:36 -04:00
|
|
|
}
|
2010-10-04 08:50:50 -04:00
|
|
|
tokens.push(['+', '+']);
|
2010-03-08 13:05:02 -05:00
|
|
|
}
|
2010-10-04 08:50:50 -04:00
|
|
|
tokens.pop();
|
2010-10-10 20:17:31 -04:00
|
|
|
if ((((_ref4 = tokens[0]) != null) ? _ref4[0] : undefined) !== 'STRING') {
|
2010-10-04 08:50:50 -04:00
|
|
|
this.tokens.push(['STRING', '""'], ['+', '+']);
|
|
|
|
}
|
|
|
|
(_this = this.tokens).push.apply(_this, tokens);
|
2010-10-03 19:22:42 -04:00
|
|
|
if (flags) {
|
|
|
|
this.tokens.push([',', ','], ['STRING', '"' + flags + '"']);
|
|
|
|
}
|
2010-10-12 06:30:10 -04:00
|
|
|
this.token(')', ')');
|
2010-02-27 19:40:53 -05:00
|
|
|
return true;
|
|
|
|
};
|
2010-06-12 19:05:13 -04:00
|
|
|
Lexer.prototype.lineToken = function() {
|
2010-10-11 16:34:16 -04:00
|
|
|
var diff, indent, match, nextCharacter, noNewlines, prev, size;
|
2010-09-25 18:06:14 -04:00
|
|
|
if (!(match = MULTI_DENT.exec(this.chunk))) {
|
2010-02-27 19:40:53 -05:00
|
|
|
return false;
|
|
|
|
}
|
2010-09-25 18:06:14 -04:00
|
|
|
indent = match[0];
|
2010-09-23 01:14:18 -04:00
|
|
|
this.line += count(indent, '\n');
|
2010-02-27 19:40:53 -05:00
|
|
|
this.i += indent.length;
|
2010-09-28 08:52:51 -04:00
|
|
|
prev = last(this.tokens, 1);
|
2010-09-23 01:14:18 -04:00
|
|
|
size = indent.length - 1 - indent.lastIndexOf('\n');
|
2010-09-25 18:06:14 -04:00
|
|
|
nextCharacter = NEXT_CHARACTER.exec(this.chunk)[1];
|
2010-10-13 12:10:36 -04:00
|
|
|
noNewlines = ((nextCharacter === '.' || nextCharacter === ',') && !NEXT_ELLIPSIS.test(this.chunk)) || 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) {
|
|
|
|
return this.suppressNewlines();
|
2010-02-28 12:49:37 -05:00
|
|
|
}
|
2010-06-12 19:05:13 -04:00
|
|
|
return this.newlineToken(indent);
|
2010-02-28 12:49:37 -05:00
|
|
|
} else 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-06-12 19:05:13 -04:00
|
|
|
return this.suppressNewlines();
|
2010-02-28 12:49:37 -05:00
|
|
|
}
|
2010-08-21 12:13:43 -04:00
|
|
|
diff = size - this.indent + this.outdebt;
|
2010-02-27 19:40:53 -05:00
|
|
|
this.token('INDENT', diff);
|
|
|
|
this.indents.push(diff);
|
2010-10-20 13:29:06 -04:00
|
|
|
this.outdebt = this.indebt = 0;
|
2010-02-27 19:40:53 -05:00
|
|
|
} else {
|
2010-09-08 22:46:13 -04:00
|
|
|
this.indebt = 0;
|
2010-06-12 19:05:13 -04:00
|
|
|
this.outdentToken(this.indent - size, noNewlines);
|
2010-02-27 19:40:53 -05:00
|
|
|
}
|
|
|
|
this.indent = size;
|
|
|
|
return true;
|
|
|
|
};
|
2010-07-30 22:06:22 -04:00
|
|
|
Lexer.prototype.outdentToken = function(moveOut, noNewlines, close) {
|
|
|
|
var dent, len;
|
|
|
|
while (moveOut > 0) {
|
|
|
|
len = this.indents.length - 1;
|
|
|
|
if (this.indents[len] === undefined) {
|
|
|
|
moveOut = 0;
|
|
|
|
} else if (this.indents[len] === this.outdebt) {
|
|
|
|
moveOut -= this.outdebt;
|
|
|
|
this.outdebt = 0;
|
|
|
|
} else if (this.indents[len] < this.outdebt) {
|
|
|
|
this.outdebt -= this.indents[len];
|
|
|
|
moveOut -= this.indents[len];
|
|
|
|
} else {
|
2010-10-12 06:30:10 -04:00
|
|
|
dent = this.indents.pop() - this.outdebt;
|
2010-07-30 22:06:22 -04:00
|
|
|
moveOut -= dent;
|
|
|
|
this.outdebt = 0;
|
|
|
|
this.token('OUTDENT', dent);
|
2010-06-01 23:32:46 -04:00
|
|
|
}
|
|
|
|
}
|
2010-07-30 22:06:22 -04:00
|
|
|
if (dent) {
|
|
|
|
this.outdebt -= moveOut;
|
2010-02-27 19:40:53 -05:00
|
|
|
}
|
2010-06-12 19:05:13 -04:00
|
|
|
if (!(this.tag() === 'TERMINATOR' || noNewlines)) {
|
2010-09-23 01:14:18 -04:00
|
|
|
this.token('TERMINATOR', '\n');
|
2010-02-27 19:40:53 -05:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
2010-06-12 19:05:13 -04:00
|
|
|
Lexer.prototype.whitespaceToken = function() {
|
2010-09-25 18:06:14 -04:00
|
|
|
var match, prev;
|
|
|
|
if (!(match = WHITESPACE.exec(this.chunk))) {
|
2010-02-27 19:40:53 -05:00
|
|
|
return false;
|
|
|
|
}
|
2010-09-28 08:52:51 -04:00
|
|
|
prev = last(this.tokens);
|
2010-02-27 19:40:53 -05:00
|
|
|
if (prev) {
|
|
|
|
prev.spaced = true;
|
|
|
|
}
|
2010-09-25 18:06:14 -04:00
|
|
|
this.i += match[0].length;
|
2010-02-27 19:40:53 -05:00
|
|
|
return true;
|
|
|
|
};
|
2010-06-12 19:05:13 -04:00
|
|
|
Lexer.prototype.newlineToken = function(newlines) {
|
2010-08-15 15:13:33 -04:00
|
|
|
if (this.tag() !== 'TERMINATOR') {
|
2010-09-23 01:14:18 -04:00
|
|
|
this.token('TERMINATOR', '\n');
|
2010-02-27 19:40:53 -05:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
2010-06-12 19:05:13 -04:00
|
|
|
Lexer.prototype.suppressNewlines = function() {
|
2010-09-23 01:14:18 -04:00
|
|
|
if (this.value() === '\\') {
|
2010-02-27 19:40:53 -05:00
|
|
|
this.tokens.pop();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
2010-06-12 19:05:13 -04:00
|
|
|
Lexer.prototype.literalToken = function() {
|
2010-10-19 23:27:15 -04:00
|
|
|
var _ref2, _ref3, _ref4, _ref5, match, prev, tag, value;
|
2010-10-05 10:31:48 -04:00
|
|
|
if (match = OPERATOR.exec(this.chunk)) {
|
|
|
|
value = match[0];
|
2010-09-23 01:14:18 -04:00
|
|
|
if (CODE.test(value)) {
|
|
|
|
this.tagParameters();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
value = this.chunk.charAt(0);
|
2010-02-27 19:40:53 -05:00
|
|
|
}
|
2010-07-25 01:36:50 -04:00
|
|
|
this.i += value.length;
|
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) {
|
2010-10-19 23:27:15 -04:00
|
|
|
if (!prev[1].reserved && (_ref2 = prev[1], __indexOf.call(JS_FORBIDDEN, _ref2) >= 0)) {
|
2010-07-25 01:36:50 -04:00
|
|
|
this.assignmentError();
|
|
|
|
}
|
2010-10-19 23:27:15 -04: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-08-11 22:24:43 -04:00
|
|
|
return true;
|
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 === ';') {
|
2010-02-27 19:40:53 -05:00
|
|
|
tag = 'TERMINATOR';
|
2010-10-19 23:27:15 -04:00
|
|
|
} else if (__indexOf.call(LOGIC, value) >= 0) {
|
2010-08-11 22:24:43 -04:00
|
|
|
tag = 'LOGIC';
|
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';
|
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-12 06:30:10 -04:00
|
|
|
} else if (value === '?' && ((prev != null) ? prev.spaced : undefined)) {
|
2010-10-07 22:22:33 -04:00
|
|
|
tag = 'LOGIC';
|
2010-10-12 06:30:10 -04:00
|
|
|
} else if (prev && !prev.spaced) {
|
2010-10-19 23:27:15 -04:00
|
|
|
if (value === '(' && (_ref4 = prev[0], __indexOf.call(CALLABLE, _ref4) >= 0)) {
|
2010-10-07 22:22:33 -04:00
|
|
|
if (prev[0] === '?') {
|
2010-08-25 14:31:56 -04:00
|
|
|
prev[0] = 'FUNC_EXIST';
|
|
|
|
}
|
2010-02-27 19:40:53 -05:00
|
|
|
tag = 'CALL_START';
|
2010-10-19 23:27:15 -04: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-09-23 01:14:18 -04:00
|
|
|
break;
|
|
|
|
case '::':
|
2010-10-05 10:31:48 -04:00
|
|
|
prev[0] = 'INDEX_PROTO';
|
2010-09-23 01:14:18 -04:00
|
|
|
break;
|
2010-05-31 22:32:43 -04:00
|
|
|
}
|
2010-02-27 19:40:53 -05:00
|
|
|
}
|
|
|
|
}
|
2010-03-21 23:24:24 -04:00
|
|
|
this.token(tag, value);
|
2010-02-27 19:40:53 -05:00
|
|
|
return true;
|
|
|
|
};
|
2010-06-12 19:05:13 -04:00
|
|
|
Lexer.prototype.tagAccessor = function() {
|
2010-10-11 06:10:30 -04:00
|
|
|
var prev;
|
2010-09-28 08:52:51 -04:00
|
|
|
if (!(prev = last(this.tokens)) || prev.spaced) {
|
2010-05-31 13:25:06 -04:00
|
|
|
return false;
|
2010-02-28 13:34:52 -05:00
|
|
|
}
|
2010-10-11 06:10:30 -04:00
|
|
|
if (prev[1] === '::') {
|
|
|
|
this.tag(0, 'PROTOTYPE_ACCESS');
|
|
|
|
} else if (prev[1] === '.' && this.value(1) !== '.') {
|
|
|
|
if (this.tag(1) === '?') {
|
|
|
|
this.tag(0, 'SOAK_ACCESS');
|
|
|
|
this.tokens.splice(-2, 1);
|
2010-02-28 13:34:52 -05:00
|
|
|
} else {
|
2010-10-11 06:10:30 -04:00
|
|
|
this.tag(0, 'PROPERTY_ACCESS');
|
2010-02-28 13:34:52 -05:00
|
|
|
}
|
2010-10-11 06:10:30 -04:00
|
|
|
} else {
|
|
|
|
return prev[0] === '@';
|
|
|
|
}
|
|
|
|
return true;
|
2010-02-28 13:34:52 -05:00
|
|
|
};
|
2010-06-12 19:05:13 -04:00
|
|
|
Lexer.prototype.sanitizeHeredoc = function(doc, options) {
|
2010-10-10 20:17:31 -04:00
|
|
|
var _ref2, attempt, herecomment, indent, match;
|
|
|
|
indent = options.indent, herecomment = options.herecomment;
|
2010-10-04 14:30:48 -04:00
|
|
|
if (herecomment && 0 > doc.indexOf('\n')) {
|
2010-08-23 21:00:47 -04:00
|
|
|
return doc;
|
|
|
|
}
|
2010-10-07 07:05:22 -04:00
|
|
|
if (!herecomment) {
|
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];
|
2010-10-20 06:53:41 -04:00
|
|
|
if (indent === null || 0 < (_ref2 = attempt.length) && _ref2 < indent.length) {
|
2010-08-23 21:00:47 -04:00
|
|
|
indent = attempt;
|
|
|
|
}
|
2010-05-12 21:47:31 -04:00
|
|
|
}
|
|
|
|
}
|
2010-09-25 18:06:14 -04:00
|
|
|
if (indent) {
|
2010-10-04 08:50:50 -04:00
|
|
|
doc = doc.replace(RegExp("\\n" + indent, "g"), '\n');
|
2010-09-25 18:06:14 -04:00
|
|
|
}
|
2010-10-07 07:05:22 -04:00
|
|
|
if (!herecomment) {
|
2010-10-04 14:30:48 -04:00
|
|
|
doc = doc.replace(/^\n/, '');
|
2010-09-25 18:06:14 -04:00
|
|
|
}
|
|
|
|
return doc;
|
2010-02-28 13:34:52 -05:00
|
|
|
};
|
2010-06-12 19:05:13 -04:00
|
|
|
Lexer.prototype.tagParameters = function() {
|
2010-09-15 23:46:01 -04:00
|
|
|
var i, tok;
|
2010-02-28 20:44:33 -05:00
|
|
|
if (this.tag() !== ')') {
|
2010-10-06 22:24:52 -04:00
|
|
|
return;
|
2010-02-28 20:44:33 -05:00
|
|
|
}
|
2010-09-28 08:52:51 -04:00
|
|
|
i = this.tokens.length;
|
2010-10-11 06:10:30 -04:00
|
|
|
while (tok = this.tokens[--i]) {
|
2010-09-15 23:46:01 -04:00
|
|
|
switch (tok[0]) {
|
2010-09-21 23:58:05 -04:00
|
|
|
case 'IDENTIFIER':
|
|
|
|
tok[0] = 'PARAM';
|
|
|
|
break;
|
|
|
|
case ')':
|
|
|
|
tok[0] = 'PARAM_END';
|
|
|
|
break;
|
|
|
|
case '(':
|
|
|
|
case 'CALL_START':
|
2010-10-11 06:10:30 -04:00
|
|
|
tok[0] = 'PARAM_START';
|
|
|
|
return true;
|
2010-02-28 20:44:33 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
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
|
|
|
};
|
2010-06-12 19:05:13 -04:00
|
|
|
Lexer.prototype.identifierError = function(word) {
|
2010-10-11 06:10:30 -04:00
|
|
|
throw SyntaxError("Reserved word \"" + word + "\" on line " + (this.line + 1));
|
2010-02-28 13:34:52 -05:00
|
|
|
};
|
2010-06-12 19:05:13 -04:00
|
|
|
Lexer.prototype.assignmentError = function() {
|
2010-10-11 06:10:30 -04:00
|
|
|
throw SyntaxError("Reserved word \"" + (this.value()) + "\" on line " + (this.line + 1) + " can't be assigned");
|
2010-02-28 13:34:52 -05:00
|
|
|
};
|
2010-06-28 00:19:58 -04:00
|
|
|
Lexer.prototype.balancedString = function(str, delimited, options) {
|
2010-10-19 11:07:10 -04:00
|
|
|
var _i, _len, close, i, levels, open, pair, slen;
|
2010-08-14 18:02:07 -04:00
|
|
|
options || (options = {});
|
2010-06-28 00:19:58 -04:00
|
|
|
levels = [];
|
|
|
|
i = 0;
|
2010-09-23 01:14:18 -04:00
|
|
|
slen = str.length;
|
|
|
|
while (i < slen) {
|
|
|
|
if (levels.length && str.charAt(i) === '\\') {
|
2010-06-28 00:19:58 -04:00
|
|
|
i += 1;
|
|
|
|
} else {
|
2010-10-01 18:26:37 -04:00
|
|
|
for (_i = 0, _len = delimited.length; _i < _len; _i++) {
|
|
|
|
pair = delimited[_i];
|
2010-10-10 20:17:31 -04:00
|
|
|
open = pair[0], close = pair[1];
|
2010-09-28 08:52:51 -04:00
|
|
|
if (levels.length && starts(str, close, i) && last(levels) === pair) {
|
2010-06-28 00:19:58 -04:00
|
|
|
levels.pop();
|
|
|
|
i += close.length - 1;
|
2010-10-07 07:05:22 -04:00
|
|
|
if (!levels.length) {
|
2010-06-28 00:19:58 -04:00
|
|
|
i += 1;
|
|
|
|
}
|
|
|
|
break;
|
2010-10-03 19:22:42 -04:00
|
|
|
}
|
|
|
|
if (starts(str, open, i)) {
|
2010-06-28 00:19:58 -04:00
|
|
|
levels.push(pair);
|
|
|
|
i += open.length - 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-10-04 08:50:50 -04:00
|
|
|
if (!levels.length) {
|
2010-06-28 00:19:58 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
i += 1;
|
|
|
|
}
|
|
|
|
if (levels.length) {
|
2010-10-12 03:23:28 -04:00
|
|
|
throw SyntaxError("Unterminated " + (levels.pop()[0]) + " starting on line " + (this.line + 1));
|
2010-06-28 00:19:58 -04:00
|
|
|
}
|
2010-09-23 01:14:18 -04:00
|
|
|
return !i ? false : str.slice(0, i);
|
2010-06-28 00:19:58 -04:00
|
|
|
};
|
2010-07-22 12:38:26 -04:00
|
|
|
Lexer.prototype.interpolateString = function(str, options) {
|
2010-10-19 11:07:10 -04:00
|
|
|
var _len, _ref2, _ref3, _this, expr, heredoc, i, inner, interpolated, letter, nested, pi, regex, tag, tokens, value;
|
2010-10-03 19:22:42 -04:00
|
|
|
_ref2 = options || (options = {}), heredoc = _ref2.heredoc, regex = _ref2.regex;
|
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;
|
|
|
|
}
|
2010-10-05 00:11:28 -04:00
|
|
|
if (!(letter === '#' && str.charAt(i + 1) === '{' && (expr = this.balancedString(str.slice(i + 1), [['{', '}']])))) {
|
2010-10-03 19:22:42 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (pi < i) {
|
2010-10-04 14:30:48 -04:00
|
|
|
tokens.push(['TO_BE_STRING', str.slice(pi, i)]);
|
2010-10-03 19:22:42 -04:00
|
|
|
}
|
|
|
|
inner = expr.slice(1, -1).replace(LEADING_SPACES, '').replace(TRAILING_SPACES, '');
|
|
|
|
if (inner.length) {
|
2010-10-04 14:30:48 -04:00
|
|
|
nested = new Lexer().tokenize(inner, {
|
|
|
|
line: this.line,
|
|
|
|
rewrite: false
|
2010-10-03 19:22:42 -04:00
|
|
|
});
|
|
|
|
nested.pop();
|
2010-10-04 14:30:48 -04:00
|
|
|
if (nested.length > 1) {
|
|
|
|
nested.unshift(['(', '(']);
|
|
|
|
nested.push([')', ')']);
|
2010-03-08 13:05:02 -05:00
|
|
|
}
|
2010-10-03 19:22:42 -04:00
|
|
|
tokens.push(['TOKENS', nested]);
|
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
|
|
|
}
|
2010-10-20 06:53:41 -04:00
|
|
|
if (i > pi && pi < str.length) {
|
2010-10-04 14:30:48 -04:00
|
|
|
tokens.push(['TO_BE_STRING', str.slice(pi)]);
|
2010-09-25 18:06:14 -04:00
|
|
|
}
|
2010-10-04 08:50:50 -04:00
|
|
|
if (regex) {
|
|
|
|
return tokens;
|
2010-09-25 18:06:14 -04:00
|
|
|
}
|
2010-10-07 07:05:22 -04:00
|
|
|
if (!tokens.length) {
|
2010-10-04 14:30:48 -04:00
|
|
|
return this.token('STRING', '""');
|
2010-09-25 18:06:14 -04:00
|
|
|
}
|
2010-10-12 06:30:10 -04:00
|
|
|
if (tokens[0][0] !== 'TO_BE_STRING') {
|
|
|
|
tokens.unshift(['', '']);
|
|
|
|
}
|
2010-10-04 14:30:48 -04:00
|
|
|
if (interpolated = tokens.length > 1) {
|
2010-09-25 18:06:14 -04:00
|
|
|
this.token('(', '(');
|
|
|
|
}
|
2010-10-01 18:26:37 -04:00
|
|
|
for (i = 0, _len = tokens.length; i < _len; i++) {
|
2010-10-06 20:54:08 -04:00
|
|
|
_ref3 = tokens[i], tag = _ref3[0], value = _ref3[1];
|
2010-10-03 19:22:42 -04:00
|
|
|
if (i) {
|
|
|
|
this.token('+', '+');
|
|
|
|
}
|
2010-09-25 18:06:14 -04:00
|
|
|
if (tag === 'TOKENS') {
|
2010-10-04 08:50:50 -04:00
|
|
|
(_this = this.tokens).push.apply(_this, value);
|
2010-09-25 18:06:14 -04:00
|
|
|
} else {
|
2010-10-04 14:30:48 -04:00
|
|
|
this.token('STRING', this.makeString(value, '"', heredoc));
|
2010-04-04 02:59:44 -04:00
|
|
|
}
|
2010-03-05 17:30:49 -05:00
|
|
|
}
|
2010-09-25 18:06:14 -04:00
|
|
|
if (interpolated) {
|
|
|
|
this.token(')', ')');
|
2010-03-05 17:30:49 -05:00
|
|
|
}
|
2010-09-25 18:06:14 -04:00
|
|
|
return tokens;
|
2010-03-05 17:30:49 -05:00
|
|
|
};
|
2010-05-14 23:40:04 -04:00
|
|
|
Lexer.prototype.token = function(tag, value) {
|
2010-02-27 19:40:53 -05:00
|
|
|
return this.tokens.push([tag, value, this.line]);
|
|
|
|
};
|
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-10-20 13:29:06 -04:00
|
|
|
return (tok = last(this.tokens, index)) && ((tag != null) ? tok[0] = tag : tok[0]);
|
2010-02-27 19:40:53 -05: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-10-20 13:29:06 -04:00
|
|
|
return (tok = last(this.tokens, index)) && ((val != null) ? tok[1] = val : tok[1]);
|
2010-02-27 19:40:53 -05:00
|
|
|
};
|
2010-05-14 23:40:04 -04:00
|
|
|
Lexer.prototype.unfinished = function() {
|
2010-09-23 01:14:18 -04:00
|
|
|
var prev, value;
|
2010-10-10 11:42:25 -04:00
|
|
|
return (prev = last(this.tokens, 1)) && prev[0] !== '.' && (value = this.value()) && !value.reserved && NO_NEWLINE.test(value) && !CODE.test(value) && !ASSIGNED.test(this.chunk);
|
2010-09-25 18:06:14 -04:00
|
|
|
};
|
2010-09-26 10:57:03 -04:00
|
|
|
Lexer.prototype.escapeLines = function(str, heredoc) {
|
2010-09-25 18:06:14 -04:00
|
|
|
return str.replace(MULTILINER, heredoc ? '\\n' : '');
|
2010-03-20 00:58:25 -04:00
|
|
|
};
|
2010-10-04 14:30:48 -04:00
|
|
|
Lexer.prototype.makeString = function(body, quote, heredoc) {
|
2010-10-12 06:30:10 -04:00
|
|
|
if (!body) {
|
|
|
|
return quote + quote;
|
|
|
|
}
|
2010-10-05 00:23:04 -04:00
|
|
|
body = body.replace(/\\([\s\S])/g, function(match, contents) {
|
2010-10-13 12:10:36 -04:00
|
|
|
return (contents === '\n' || contents === quote) ? contents : match;
|
2010-10-04 14:30:48 -04:00
|
|
|
});
|
|
|
|
body = body.replace(RegExp("" + quote, "g"), '\\$&');
|
|
|
|
return quote + this.escapeLines(body, heredoc) + quote;
|
|
|
|
};
|
2010-02-27 19:40:53 -05:00
|
|
|
return Lexer;
|
2010-06-26 13:36:31 -04:00
|
|
|
})();
|
2010-10-12 03:23:28 -04:00
|
|
|
JS_KEYWORDS = ['true', 'false', 'null', 'this', 'new', 'delete', 'typeof', 'in', 'instanceof', 'return', 'throw', 'break', 'continue', 'debugger', 'if', 'else', 'switch', 'for', 'while', 'try', 'catch', 'finally', 'class', 'extends', 'super'];
|
2010-10-07 11:56:01 -04:00
|
|
|
COFFEE_KEYWORDS = ['then', 'unless', 'until', 'loop', 'of', 'by', 'when'];
|
2010-10-07 02:31:40 -04:00
|
|
|
for (op in (COFFEE_ALIASES = {
|
2010-10-05 15:46:17 -04:00
|
|
|
and: '&&',
|
|
|
|
or: '||',
|
|
|
|
is: '==',
|
|
|
|
isnt: '!=',
|
2010-10-07 11:56:01 -04:00
|
|
|
not: '!',
|
|
|
|
yes: 'TRUE',
|
|
|
|
no: 'FALSE',
|
|
|
|
on: 'TRUE',
|
|
|
|
off: 'FALSE'
|
2010-10-07 02:31:40 -04:00
|
|
|
})) {
|
2010-10-05 15:46:17 -04:00
|
|
|
COFFEE_KEYWORDS.push(op);
|
|
|
|
}
|
2010-09-23 01:14:18 -04:00
|
|
|
RESERVED = ['case', 'default', 'do', 'function', 'var', 'void', 'with', 'const', 'let', 'enum', 'export', 'import', 'native', '__hasProp', '__extends', '__slice'];
|
2010-03-07 14:41:52 -05:00
|
|
|
JS_FORBIDDEN = JS_KEYWORDS.concat(RESERVED);
|
2010-10-11 06:10:30 -04:00
|
|
|
IDENTIFIER = /^([$A-Za-z_][$\w]*)([^\n\S]*:(?!:))?/;
|
2010-09-25 18:06:14 -04:00
|
|
|
NUMBER = /^0x[\da-f]+|^(?:\d+(\.\d+)?|\.\d+)(?:e[+-]?\d+)?/i;
|
2010-10-04 14:30:48 -04:00
|
|
|
HEREDOC = /^("""|''')([\s\S]*?)(?:\n[ \t]*)?\1/;
|
2010-10-10 12:34:22 -04:00
|
|
|
OPERATOR = /^(?:-[-=>]?|\+[+=]?|\.\.\.?|[*&|\/%=<>^:!?]+)/;
|
2010-09-23 01:14:18 -04:00
|
|
|
WHITESPACE = /^[ \t]+/;
|
2010-09-25 18:06:14 -04:00
|
|
|
COMMENT = /^###([^#][\s\S]*?)(?:###[ \t]*\n|(?:###)?$)|^(?:\s*#(?!##[^#]).*)+/;
|
2010-09-23 01:14:18 -04:00
|
|
|
CODE = /^[-=]>/;
|
|
|
|
MULTI_DENT = /^(?:\n[ \t]*)+/;
|
2010-09-24 09:38:28 -04:00
|
|
|
SIMPLESTR = /^'[^\\']*(?:\\.[^\\']*)*'/;
|
|
|
|
JSTOKEN = /^`[^\\`]*(?:\\.[^\\`]*)*`/;
|
2010-10-17 18:43:29 -04:00
|
|
|
REGEX = /^\/(?!\s)[^[\/\n\\]*(?:(?:\\[\s\S]|\[[^\]\n\\]*(?:\\[\s\S][^\]\n\\]*)*])[^[\/\n\\]*)*\/[imgy]{0,4}(?![A-Za-z])/;
|
2010-10-03 19:22:42 -04:00
|
|
|
HEREGEX = /^\/{3}([\s\S]+?)\/{3}([imgy]{0,4})(?![A-Za-z])/;
|
|
|
|
HEREGEX_OMIT = /\s+(?:#.*)?/g;
|
2010-03-07 14:41:52 -05:00
|
|
|
MULTILINER = /\n/g;
|
2010-09-25 18:06:14 -04:00
|
|
|
HEREDOC_INDENT = /\n+([ \t]*)/g;
|
2010-09-25 10:37:33 -04:00
|
|
|
ASSIGNED = /^\s*@?[$A-Za-z_][$\w]*[ \t]*?[:=][^:=>]/;
|
2010-09-25 18:06:14 -04:00
|
|
|
NEXT_CHARACTER = /^\s*(\S?)/;
|
2010-10-11 16:34:16 -04:00
|
|
|
NEXT_ELLIPSIS = /^\s*\.\.\.?/;
|
2010-10-03 19:22:42 -04:00
|
|
|
LEADING_SPACES = /^\s+/;
|
|
|
|
TRAILING_SPACES = /\s+$/;
|
2010-10-05 00:11:28 -04:00
|
|
|
NO_NEWLINE = /^(?:[-+*&|\/%=<>!.\\][<>=&|]*|and|or|is(?:nt)?|n(?:ot|ew)|delete|typeof|instanceof)$/;
|
2010-08-11 22:24:43 -04:00
|
|
|
COMPOUND_ASSIGN = ['-=', '+=', '/=', '*=', '%=', '||=', '&&=', '?=', '<<=', '>>=', '>>>=', '&=', '^=', '|='];
|
2010-09-25 04:39:19 -04:00
|
|
|
UNARY = ['UMINUS', 'UPLUS', '!', '!!', '~', 'NEW', 'TYPEOF', 'DELETE'];
|
2010-08-11 22:24:43 -04:00
|
|
|
LOGIC = ['&', '|', '^', '&&', '||'];
|
|
|
|
SHIFT = ['<<', '>>', '>>>'];
|
|
|
|
COMPARE = ['<=', '<', '>', '>='];
|
|
|
|
MATH = ['*', '/', '%'];
|
2010-10-05 11:43:44 -04:00
|
|
|
RELATION = ['IN', 'OF', 'INSTANCEOF'];
|
2010-10-11 04:05:50 -04:00
|
|
|
BOOL = ['TRUE', 'FALSE', 'NULL'];
|
|
|
|
NOT_REGEX = ['NUMBER', 'REGEX', 'BOOL', '++', '--', ']'];
|
2010-10-12 06:30:10 -04:00
|
|
|
CALLABLE = ['IDENTIFIER', 'STRING', 'REGEX', ')', ']', '}', '?', '::', '@', 'THIS', 'SUPER'];
|
|
|
|
INDEXABLE = CALLABLE.concat('NUMBER', 'BOOL');
|
2010-03-20 00:58:25 -04:00
|
|
|
LINE_BREAK = ['INDENT', 'OUTDENT', 'TERMINATOR'];
|
2010-09-21 03:53:58 -04:00
|
|
|
}).call(this);
|