jashkenas--coffeescript/lib/lexer.js

648 lines
22 KiB
JavaScript
Raw Normal View History

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