jashkenas--coffeescript/lib/lexer.js

632 lines
21 KiB
JavaScript
Raw Normal View History

2010-07-25 07:15:12 +00:00
(function() {
2010-10-11 08:05:50 +00:00
var ASSIGNED, BOOL, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, HEREDOC, HEREDOC_INDENT, HEREGEX, HEREGEX_OMIT, IDENTIFIER, JSTOKEN, JS_FORBIDDEN, JS_KEYWORDS, LEADING_SPACES, LINE_BREAK, LOGIC, Lexer, MATH, MULTILINER, MULTI_DENT, NEXT_CHARACTER, NOT_REGEX, NO_NEWLINE, NUMBER, OPERATOR, REGEX, RELATION, RESERVED, Rewriter, SHIFT, SIMPLESTR, TRAILING_SPACES, UNARY, WHITESPACE, _ref, compact, count, include, last, op, starts;
Rewriter = require('./rewriter').Rewriter;
_ref = require('./helpers'), include = _ref.include, 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() {
return function Lexer() {};
})();
Lexer.prototype.tokenize = function(code, options) {
var o;
2010-10-03 23:22:42 +00:00
code = code.replace(/\r/g, '').replace(TRAILING_SPACES, '');
o = options || {};
this.code = code;
this.i = 0;
this.line = o.line || 0;
this.indent = 0;
this.indebt = 0;
this.outdebt = 0;
this.seenFor = false;
this.indents = [];
this.tokens = [];
2010-10-11 12:06:27 +00:00
while (this.chunk = code.slice(this.i)) {
this.identifierToken() || this.commentToken() || this.whitespaceToken() || this.lineToken() || this.heredocToken() || this.stringToken() || this.numberToken() || this.regexToken() || this.jsToken() || this.literalToken();
}
this.closeIndentation();
if (o.rewrite === false) {
return this.tokens;
}
return (new Rewriter).rewrite(this.tokens);
};
Lexer.prototype.identifierToken = function() {
var _ref2, colon, forcedIdentifier, id, input, match, tag;
if (!(match = IDENTIFIER.exec(this.chunk))) {
return false;
}
_ref2 = match, input = _ref2[0], id = _ref2[1], colon = _ref2[2];
this.i += input.length;
if (id === 'all' && this.tag() === 'FOR') {
this.token('ALL', id);
return true;
}
forcedIdentifier = colon || this.tagAccessor();
tag = 'IDENTIFIER';
2010-09-23 05:14:18 +00:00
if (include(JS_KEYWORDS, id) || !forcedIdentifier && include(COFFEE_KEYWORDS, id)) {
tag = id.toUpperCase();
2010-09-23 05:14:18 +00:00
if (tag === 'WHEN' && include(LINE_BREAK, this.tag())) {
tag = 'LEADING_WHEN';
} else if (tag === 'FOR') {
this.seenFor = true;
} else if (include(UNARY, tag)) {
tag = 'UNARY';
} else if (include(RELATION, tag)) {
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 (include(JS_FORBIDDEN, id)) {
if (forcedIdentifier) {
tag = 'IDENTIFIER';
id = new String(id);
id.reserved = true;
} else if (include(RESERVED, id)) {
this.identifierError(id);
}
}
2010-10-07 11:05:22 +00:00
if (!forcedIdentifier) {
if (COFFEE_ALIASES.hasOwnProperty(id)) {
tag = (id = COFFEE_ALIASES[id]);
}
if (id === '!') {
tag = 'UNARY';
2010-09-23 05:14:18 +00:00
} else if (include(LOGIC, id)) {
tag = 'LOGIC';
2010-10-11 08:05:50 +00:00
} else if (include(BOOL, tag)) {
id = tag.toLowerCase();
tag = 'BOOL';
}
2010-03-22 01:46:06 +00:00
}
this.token(tag, id);
if (colon) {
this.token(':', ':');
}
return true;
};
Lexer.prototype.numberToken = function() {
var match, number;
if (!(match = NUMBER.exec(this.chunk))) {
return false;
}
number = match[0];
2010-09-23 05:14:18 +00:00
if (this.tag() === '.' && number.charAt(0) === '.') {
return false;
}
this.i += number.length;
this.token('NUMBER', number);
return true;
};
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))) {
2010-09-24 13:38:28 +00:00
return false;
}
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, [['"', '"'], ['#{', '}']]))) {
2010-09-24 13:38:28 +00:00
return false;
}
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 false;
}
2010-09-23 05:14:18 +00:00
this.line += count(string, '\n');
this.i += string.length;
return true;
};
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 false;
}
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');
this.i += heredoc.length;
return true;
};
Lexer.prototype.commentToken = function() {
2010-09-23 05:14:18 +00:00
var _ref2, comment, here, match;
if (!(match = this.chunk.match(COMMENT))) {
return false;
}
_ref2 = match, comment = _ref2[0], here = _ref2[1];
2010-09-23 05:14:18 +00:00
this.line += count(comment, '\n');
this.i += comment.length;
if (here) {
this.token('HERECOMMENT', this.sanitizeHeredoc(here, {
herecomment: true,
indent: Array(this.indent + 1).join(' ')
}));
this.token('TERMINATOR', '\n');
}
return true;
};
Lexer.prototype.jsToken = function() {
var match, script;
if (!(this.chunk.charAt(0) === '`' && (match = JSTOKEN.exec(this.chunk)))) {
return false;
}
this.token('JS', (script = match[0]).slice(1, -1));
this.i += script.length;
return true;
};
Lexer.prototype.regexToken = function() {
var match;
2010-10-03 23:22:42 +00:00
if (this.chunk.charAt(0) !== '/') {
return false;
}
2010-10-03 23:22:42 +00:00
if (match = HEREGEX.exec(this.chunk)) {
return this.heregexToken(match);
}
if (include(NOT_REGEX, this.tag())) {
return false;
}
if (!(match = REGEX.exec(this.chunk))) {
return false;
}
this.token('REGEX', match[0]);
this.i += match[0].length;
return true;
};
2010-10-03 23:22:42 +00:00
Lexer.prototype.heregexToken = function(match) {
var _i, _len, _ref2, _ref3, _ref4, _ref5, _this, body, flags, heregex, re, tag, tokens, value;
2010-10-03 23:22:42 +00:00
_ref2 = match, heregex = _ref2[0], body = _ref2[1], flags = _ref2[2];
this.i += heregex.length;
if (0 > body.indexOf('#{')) {
re = body.replace(HEREGEX_OMIT, '').replace(/\//g, '\\/');
this.token('REGEX', "/" + (re || '(?:)') + "/" + flags);
2010-10-03 23:22:42 +00:00
return true;
}
2010-10-03 23:22:42 +00:00
this.token('IDENTIFIER', 'RegExp');
this.tokens.push(['CALL_START', '(']);
tokens = [];
for (_i = 0, _len = (_ref3 = this.interpolateString(body, {
regex: true
})).length; _i < _len; _i++) {
_ref4 = _ref3[_i], tag = _ref4[0], value = _ref4[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();
2010-10-10 15:33:03 +00:00
if ((((_ref5 = tokens[0]) != null) ? _ref5[0] : undefined) !== '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.tokens.push(['CALL_END', ')']);
return true;
};
Lexer.prototype.lineToken = function() {
var diff, indent, match, nextCharacter, noNewlines, prev, size;
if (!(match = MULTI_DENT.exec(this.chunk))) {
return false;
}
indent = match[0];
2010-09-23 05:14:18 +00:00
this.line += count(indent, '\n');
this.i += indent.length;
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');
nextCharacter = NEXT_CHARACTER.exec(this.chunk)[1];
noNewlines = ('.' === nextCharacter || ',' === nextCharacter) || this.unfinished();
if (size - this.indebt === this.indent) {
if (noNewlines) {
return this.suppressNewlines();
}
return this.newlineToken(indent);
} else if (size > this.indent) {
if (noNewlines) {
this.indebt = size - this.indent;
return this.suppressNewlines();
}
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 true;
};
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 {
dent = this.indents.pop();
dent -= 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 true;
};
Lexer.prototype.whitespaceToken = function() {
var match, prev;
if (!(match = WHITESPACE.exec(this.chunk))) {
return false;
}
2010-09-28 12:52:51 +00:00
prev = last(this.tokens);
if (prev) {
prev.spaced = true;
}
this.i += match[0].length;
return true;
};
Lexer.prototype.newlineToken = function(newlines) {
if (this.tag() !== 'TERMINATOR') {
2010-09-23 05:14:18 +00:00
this.token('TERMINATOR', '\n');
}
return true;
};
Lexer.prototype.suppressNewlines = function() {
2010-09-23 05:14:18 +00:00
if (this.value() === '\\') {
this.tokens.pop();
}
return true;
};
Lexer.prototype.literalToken = function() {
var _ref2, match, prev, tag, value;
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);
}
2010-07-25 05:36:50 +00:00
this.i += value.length;
tag = value;
prev = last(this.tokens);
2010-07-25 05:36:50 +00:00
if (value === '=') {
if (!prev[1].reserved && include(JS_FORBIDDEN, prev[1])) {
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 true;
2010-07-25 05:36:50 +00:00
}
2010-07-25 05:23:37 +00:00
}
2010-10-05 14:31:48 +00:00
if (';' === value) {
tag = 'TERMINATOR';
} else if (include(LOGIC, value)) {
tag = 'LOGIC';
} else if (include(MATH, value)) {
tag = 'MATH';
} else if (include(COMPARE, value)) {
tag = 'COMPARE';
} else if (include(COMPOUND_ASSIGN, value)) {
tag = 'COMPOUND_ASSIGN';
} else if (include(UNARY, value)) {
tag = 'UNARY';
} else if (include(SHIFT, value)) {
tag = 'SHIFT';
} else if (value === '?' && prev.spaced) {
tag = 'LOGIC';
} else if (prev && !prev.spaced && include(CALLABLE, prev[0])) {
2010-04-03 13:58:45 +00:00
if (value === '(') {
if (prev[0] === '?') {
2010-08-25 18:31:56 +00:00
prev[0] = 'FUNC_EXIST';
}
tag = 'CALL_START';
} else if (value === '[') {
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';
2010-09-23 05:14:18 +00:00
break;
}
}
}
this.token(tag, value);
return true;
};
Lexer.prototype.tagAccessor = function() {
var prev;
2010-09-28 12:52:51 +00:00
if (!(prev = last(this.tokens)) || prev.spaced) {
return false;
}
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);
} else {
this.tag(0, 'PROPERTY_ACCESS');
}
} else {
return prev[0] === '@';
}
return true;
};
Lexer.prototype.sanitizeHeredoc = function(doc, options) {
var _ref2, _ref3, attempt, herecomment, indent, match;
_ref2 = options, indent = _ref2.indent, herecomment = _ref2.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 < (_ref3 = attempt.length)) && (_ref3 < 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() {
var i, tok;
if (this.tag() !== ')') {
2010-10-07 02:24:52 +00:00
return;
}
2010-09-28 12:52:51 +00:00
i = this.tokens.length;
while (tok = this.tokens[--i]) {
switch (tok[0]) {
2010-09-22 03:58:05 +00:00
case 'IDENTIFIER':
tok[0] = 'PARAM';
break;
case ')':
tok[0] = 'PARAM_END';
break;
case '(':
case 'CALL_START':
tok[0] = 'PARAM_START';
return true;
}
}
return true;
};
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 _i, _len, _ref2, close, i, levels, open, pair, slen;
options || (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 {
2010-10-01 22:26:37 +00:00
for (_i = 0, _len = delimited.length; _i < _len; _i++) {
pair = delimited[_i];
_ref2 = pair, open = _ref2[0], close = _ref2[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) {
throw new Error("SyntaxError: Unterminated " + (levels.pop()[0]) + " starting on line " + (this.line + 1));
}
2010-09-23 05:14:18 +00:00
return !i ? false : str.slice(0, i);
};
Lexer.prototype.interpolateString = function(str, options) {
var _len, _ref2, _ref3, _this, expr, heredoc, i, inner, interpolated, letter, nested, pi, regex, tag, tokens, value;
2010-10-03 23:22:42 +00:00
_ref2 = options || (options = {}), heredoc = _ref2.heredoc, regex = _ref2.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) {
tokens.push(['TO_BE_STRING', 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;
}
if ((i > pi) && (pi < str.length)) {
tokens.push(['TO_BE_STRING', str.slice(pi)]);
}
if (regex) {
return tokens;
}
2010-10-07 11:05:22 +00:00
if (!tokens.length) {
return this.token('STRING', '""');
}
if (interpolated = tokens.length > 1) {
this.token('(', '(');
}
if (tokens[0][0] !== 'TO_BE_STRING') {
this.tokens.push(['STRING', '""'], ['+', '+']);
}
2010-10-01 22:26:37 +00:00
for (i = 0, _len = tokens.length; i < _len; i++) {
_ref3 = tokens[i], tag = _ref3[0], value = _ref3[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-10-05 14:31:48 +00:00
return (tok = last(this.tokens, index)) && ((tag != null) ? (tok[0] = tag) : tok[0]);
};
Lexer.prototype.value = function(index, val) {
var tok;
2010-10-05 14:31:48 +00:00
return (tok = last(this.tokens, index)) && ((val != null) ? (tok[1] = val) : tok[1]);
};
Lexer.prototype.unfinished = function() {
2010-09-23 05:14:18 +00:00
var prev, value;
return (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) {
body = body.replace(/\\([\s\S])/g, function(match, contents) {
return ('\n' === contents || quote === contents) ? contents : 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-09-23 05:14:18 +00:00
JS_KEYWORDS = ['if', 'else', 'true', 'false', 'new', 'return', 'try', 'catch', 'finally', 'throw', 'break', 'continue', 'for', 'in', 'while', 'delete', 'instanceof', 'typeof', 'switch', 'super', 'extends', 'class', 'this', 'null', 'debugger'];
COFFEE_KEYWORDS = ['then', 'unless', 'until', 'loop', 'of', 'by', 'when'];
2010-10-07 06:31:40 +00:00
for (op in (COFFEE_ALIASES = {
and: '&&',
or: '||',
is: '==',
isnt: '!=',
not: '!',
yes: 'TRUE',
no: 'FALSE',
on: 'TRUE',
off: 'FALSE'
2010-10-07 06:31:40 +00:00
})) {
COFFEE_KEYWORDS.push(op);
}
COFFEE_ALIASES['==='] = '==';
2010-09-23 05:14:18 +00:00
RESERVED = ['case', 'default', 'do', 'function', 'var', 'void', 'with', '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-05 14:31:48 +00:00
OPERATOR = /^(?:-[-=>]?|\+[+=]?|[*&|\/%=<>^:!?]+)/;
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-09 22:32:49 +00:00
REGEX = /^\/(?!\s)(?:[^[\/\n\\]+|\\[\s\S]|\[([^\]\n\\]+|\\[\s\S])*])+\/[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]*?[:=][^:=>]/;
NEXT_CHARACTER = /^\s*(\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 = ['-=', '+=', '/=', '*=', '%=', '||=', '&&=', '?=', '<<=', '>>=', '>>>=', '&=', '^=', '|='];
UNARY = ['UMINUS', 'UPLUS', '!', '!!', '~', 'NEW', 'TYPEOF', 'DELETE'];
LOGIC = ['&', '|', '^', '&&', '||'];
SHIFT = ['<<', '>>', '>>>'];
COMPARE = ['<=', '<', '>', '>='];
MATH = ['*', '/', '%'];
RELATION = ['IN', 'OF', 'INSTANCEOF'];
2010-10-11 08:05:50 +00:00
BOOL = ['TRUE', 'FALSE', 'NULL'];
NOT_REGEX = ['NUMBER', 'REGEX', 'BOOL', '++', '--', ']'];
CALLABLE = ['IDENTIFIER', 'SUPER', ')', ']', '}', 'STRING', '@', 'THIS', '?', '::'];
LINE_BREAK = ['INDENT', 'OUTDENT', 'TERMINATOR'];
}).call(this);