2010-07-25 07:15:12 +00:00
|
|
|
(function() {
|
2010-06-27 16:59:54 +00:00
|
|
|
var BALANCED_PAIRS, EXPRESSION_CLOSE, EXPRESSION_END, EXPRESSION_START, IMPLICIT_BLOCK, IMPLICIT_CALL, IMPLICIT_END, IMPLICIT_FUNC, INVERSES, Rewriter, SINGLE_CLOSERS, SINGLE_LINERS, _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, helpers, include, pair;
|
2010-07-25 07:15:12 +00:00
|
|
|
var __bind = function(func, context) {
|
|
|
|
return function(){ return func.apply(context, arguments); };
|
|
|
|
}, __hasProp = Object.prototype.hasOwnProperty;
|
2010-08-07 12:13:36 +00:00
|
|
|
if ((typeof process !== "undefined" && process !== null)) {
|
2010-05-01 02:04:57 +00:00
|
|
|
_a = require('./helpers');
|
|
|
|
helpers = _a.helpers;
|
2010-03-17 03:18:54 +00:00
|
|
|
} else {
|
|
|
|
this.exports = this;
|
|
|
|
helpers = this.helpers;
|
|
|
|
}
|
2010-05-01 02:04:57 +00:00
|
|
|
_b = helpers;
|
|
|
|
include = _b.include;
|
2010-02-28 00:46:45 +00:00
|
|
|
exports.Rewriter = (function() {
|
2010-07-22 21:08:07 +00:00
|
|
|
Rewriter = function() {};
|
2010-05-15 03:40:04 +00:00
|
|
|
Rewriter.prototype.rewrite = function(tokens) {
|
2010-02-28 00:46:45 +00:00
|
|
|
this.tokens = tokens;
|
2010-07-02 01:26:33 +00:00
|
|
|
this.adjustComments();
|
2010-06-12 23:05:13 +00:00
|
|
|
this.removeLeadingNewlines();
|
|
|
|
this.removeMidExpressionNewlines();
|
2010-08-08 21:37:28 +00:00
|
|
|
this.closeOpenCalls();
|
|
|
|
this.closeOpenIndexes();
|
2010-06-12 23:05:13 +00:00
|
|
|
this.addImplicitIndentation();
|
2010-07-25 06:42:37 +00:00
|
|
|
this.addImplicitBraces();
|
2010-06-12 23:05:13 +00:00
|
|
|
this.addImplicitParentheses();
|
|
|
|
this.ensureBalance(BALANCED_PAIRS);
|
|
|
|
this.rewriteClosingParens();
|
2010-02-28 00:46:45 +00:00
|
|
|
return this.tokens;
|
|
|
|
};
|
2010-06-12 23:05:13 +00:00
|
|
|
Rewriter.prototype.scanTokens = function(block) {
|
2010-02-28 00:46:45 +00:00
|
|
|
var i, move;
|
|
|
|
i = 0;
|
|
|
|
while (true) {
|
|
|
|
if (!(this.tokens[i])) {
|
|
|
|
break;
|
2010-01-30 22:24:48 +00:00
|
|
|
}
|
2010-02-28 00:46:45 +00:00
|
|
|
move = block(this.tokens[i - 1], this.tokens[i], this.tokens[i + 1], i);
|
|
|
|
i += move;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
2010-08-08 21:37:28 +00:00
|
|
|
Rewriter.prototype.detectEnd = function(i, condition, action) {
|
2010-08-08 21:41:10 +00:00
|
|
|
var levels, token;
|
2010-08-08 21:37:28 +00:00
|
|
|
levels = 0;
|
|
|
|
while (true) {
|
2010-08-11 01:46:46 +00:00
|
|
|
token = this.tokens[i];
|
2010-08-11 01:13:30 +00:00
|
|
|
if (levels === 0 && condition(token, i)) {
|
2010-08-08 21:37:28 +00:00
|
|
|
return action(token, i);
|
|
|
|
}
|
2010-08-11 01:46:46 +00:00
|
|
|
if (!token || levels < 0) {
|
2010-08-11 01:13:30 +00:00
|
|
|
return action(token, i - 1);
|
|
|
|
}
|
2010-08-08 21:41:10 +00:00
|
|
|
if (include(EXPRESSION_START, token[0])) {
|
2010-08-08 21:37:28 +00:00
|
|
|
levels += 1;
|
|
|
|
}
|
2010-08-08 21:41:10 +00:00
|
|
|
if (include(EXPRESSION_END, token[0])) {
|
2010-08-08 21:37:28 +00:00
|
|
|
levels -= 1;
|
|
|
|
}
|
|
|
|
i += 1;
|
|
|
|
}
|
|
|
|
return i - 1;
|
|
|
|
};
|
2010-07-02 01:26:33 +00:00
|
|
|
Rewriter.prototype.adjustComments = function() {
|
2010-07-25 07:15:12 +00:00
|
|
|
return this.scanTokens(__bind(function(prev, token, post, i) {
|
|
|
|
var _c, _d, after, before;
|
|
|
|
if (!(token[0] === 'HERECOMMENT')) {
|
2010-07-02 01:26:33 +00:00
|
|
|
return 1;
|
2010-07-24 05:34:56 +00:00
|
|
|
}
|
2010-07-25 07:15:12 +00:00
|
|
|
_c = [this.tokens[i - 2], this.tokens[i + 2]];
|
|
|
|
before = _c[0];
|
|
|
|
after = _c[1];
|
|
|
|
if (after && after[0] === 'INDENT') {
|
|
|
|
this.tokens.splice(i + 2, 1);
|
|
|
|
before && before[0] === 'OUTDENT' && post && (prev[0] === post[0]) && (post[0] === 'TERMINATOR') ? this.tokens.splice(i - 2, 1) : this.tokens.splice(i, 0, after);
|
|
|
|
} else if (prev && !('TERMINATOR' === (_d = prev[0]) || 'INDENT' === _d || 'OUTDENT' === _d)) {
|
|
|
|
if (post && post[0] === 'TERMINATOR' && after && after[0] === 'OUTDENT') {
|
|
|
|
this.tokens.splice.apply(this.tokens, [i + 2, 0].concat(this.tokens.splice(i, 2)));
|
|
|
|
this.tokens[i + 2][0] !== 'TERMINATOR' ? this.tokens.splice(i + 2, 0, ['TERMINATOR', "\n", prev[2]]) : null;
|
|
|
|
} else {
|
|
|
|
this.tokens.splice(i, 0, ['TERMINATOR', "\n", prev[2]]);
|
|
|
|
}
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}, this));
|
2010-07-02 01:26:33 +00:00
|
|
|
};
|
2010-06-12 23:05:13 +00:00
|
|
|
Rewriter.prototype.removeLeadingNewlines = function() {
|
2010-05-01 02:04:57 +00:00
|
|
|
var _c;
|
|
|
|
_c = [];
|
2010-03-09 00:43:12 +00:00
|
|
|
while (this.tokens[0] && this.tokens[0][0] === 'TERMINATOR') {
|
2010-05-01 02:04:57 +00:00
|
|
|
_c.push(this.tokens.shift());
|
2010-02-28 00:46:45 +00:00
|
|
|
}
|
2010-05-01 02:04:57 +00:00
|
|
|
return _c;
|
2010-02-28 00:46:45 +00:00
|
|
|
};
|
2010-06-12 23:05:13 +00:00
|
|
|
Rewriter.prototype.removeMidExpressionNewlines = function() {
|
2010-07-25 07:15:12 +00:00
|
|
|
return this.scanTokens(__bind(function(prev, token, post, i) {
|
|
|
|
if (!(post && include(EXPRESSION_CLOSE, post[0]) && token[0] === 'TERMINATOR')) {
|
|
|
|
return 1;
|
2010-07-24 05:34:56 +00:00
|
|
|
}
|
2010-07-25 07:15:12 +00:00
|
|
|
this.tokens.splice(i, 1);
|
|
|
|
return 0;
|
|
|
|
}, this));
|
2010-02-28 00:46:45 +00:00
|
|
|
};
|
2010-08-08 21:37:28 +00:00
|
|
|
Rewriter.prototype.closeOpenCalls = function() {
|
2010-07-25 07:15:12 +00:00
|
|
|
return this.scanTokens(__bind(function(prev, token, post, i) {
|
2010-08-08 21:37:28 +00:00
|
|
|
var action, condition;
|
|
|
|
if (token[0] === 'CALL_START') {
|
2010-08-11 01:13:30 +00:00
|
|
|
condition = function(token, i) {
|
|
|
|
var _c;
|
|
|
|
return (')' === (_c = token[0]) || 'CALL_END' === _c);
|
|
|
|
};
|
|
|
|
action = function(token, i) {
|
|
|
|
return (token[0] = 'CALL_END');
|
|
|
|
};
|
2010-08-08 21:37:28 +00:00
|
|
|
this.detectEnd(i + 1, condition, action);
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}, this));
|
|
|
|
};
|
|
|
|
Rewriter.prototype.closeOpenIndexes = function() {
|
|
|
|
return this.scanTokens(__bind(function(prev, token, post, i) {
|
|
|
|
var action, condition;
|
|
|
|
if (token[0] === 'INDEX_START') {
|
2010-08-11 01:13:30 +00:00
|
|
|
condition = function(token, i) {
|
|
|
|
var _c;
|
|
|
|
return (']' === (_c = token[0]) || 'INDEX_END' === _c);
|
|
|
|
};
|
|
|
|
action = function(token, i) {
|
|
|
|
return (token[0] = 'INDEX_END');
|
|
|
|
};
|
2010-08-08 21:37:28 +00:00
|
|
|
this.detectEnd(i + 1, condition, action);
|
2010-07-24 05:34:56 +00:00
|
|
|
}
|
2010-07-25 07:15:12 +00:00
|
|
|
return 1;
|
|
|
|
}, this));
|
2010-02-28 00:46:45 +00:00
|
|
|
};
|
2010-07-25 06:42:37 +00:00
|
|
|
Rewriter.prototype.addImplicitBraces = function() {
|
2010-08-11 01:13:30 +00:00
|
|
|
var stack;
|
|
|
|
stack = [];
|
2010-07-25 07:15:12 +00:00
|
|
|
return this.scanTokens(__bind(function(prev, token, post, i) {
|
2010-08-11 01:13:30 +00:00
|
|
|
var action, before, condition, idx, last;
|
|
|
|
include(EXPRESSION_START, token[0]) ? stack.push((token[0] === 'INDENT' && (prev && prev[0] === '{')) ? '{' : token[0]) : null;
|
|
|
|
include(EXPRESSION_END, token[0]) ? stack.pop() : null;
|
|
|
|
last = stack[stack.length - 1];
|
2010-07-25 07:15:12 +00:00
|
|
|
before = this.tokens[i - 2];
|
2010-08-11 01:13:30 +00:00
|
|
|
if (token[0] === ':' && (!last || last[0] !== '{')) {
|
|
|
|
stack.push('{');
|
|
|
|
idx = before[0] === '@' ? i - 2 : i - 1;
|
2010-07-25 07:15:12 +00:00
|
|
|
this.tokens.splice(idx, 0, ['{', '{', token[2]]);
|
2010-08-11 01:13:30 +00:00
|
|
|
condition = __bind(function(token, i) {
|
|
|
|
var _c, _d, _e, one, three, two;
|
|
|
|
_c = this.tokens.slice(i + 1, i + 4);
|
|
|
|
one = _c[0];
|
|
|
|
two = _c[1];
|
|
|
|
three = _c[2];
|
|
|
|
return ((('TERMINATOR' === (_d = token[0]) || 'OUTDENT' === _d)) && !((two && two[0] === ':') || (one && one[0] === '@' && three && three[0] === ':'))) || (token[0] === ',' && one && (!('IDENTIFIER' === (_e = one[0]) || 'STRING' === _e || '@' === _e || 'TERMINATOR' === _e || 'OUTDENT' === _e)));
|
|
|
|
}, this);
|
|
|
|
action = __bind(function(token, i) {
|
|
|
|
return this.tokens.splice(i, 0, ['}', '}', token[2]]);
|
|
|
|
}, this);
|
|
|
|
this.detectEnd(i + 2, condition, action);
|
2010-07-25 07:15:12 +00:00
|
|
|
return 2;
|
2010-07-25 06:42:37 +00:00
|
|
|
}
|
2010-07-25 07:15:12 +00:00
|
|
|
return 1;
|
|
|
|
}, this));
|
2010-07-25 06:42:37 +00:00
|
|
|
};
|
2010-06-12 23:05:13 +00:00
|
|
|
Rewriter.prototype.addImplicitParentheses = function() {
|
2010-07-25 07:15:12 +00:00
|
|
|
return this.scanTokens(__bind(function(prev, token, post, i) {
|
2010-08-11 01:46:46 +00:00
|
|
|
var _c, action, condition;
|
|
|
|
if (prev && prev.spaced && include(IMPLICIT_FUNC, prev[0]) && include(IMPLICIT_CALL, token[0]) && !(token[0] === '!' && (('IN' === (_c = post[0]) || 'OF' === _c)))) {
|
2010-07-25 07:15:12 +00:00
|
|
|
this.tokens.splice(i, 0, ['CALL_START', '(', token[2]]);
|
2010-08-11 01:46:46 +00:00
|
|
|
condition = __bind(function(token, i) {
|
|
|
|
var _c, before;
|
|
|
|
_c = this.tokens.slice(i - 2, i + 1);
|
|
|
|
before = _c[0];
|
|
|
|
prev = _c[1];
|
|
|
|
return (!token.generated && this.tokens[i - 1][0] !== ',' && include(IMPLICIT_END, token[0]) && !(token[0] === 'INDENT' && (include(IMPLICIT_BLOCK, prev[0]) || before[0] === 'CLASS'))) || token[0] === 'PROPERTY_ACCESS' && prev[0] === 'OUTDENT';
|
|
|
|
}, this);
|
|
|
|
action = __bind(function(token, i) {
|
|
|
|
var idx;
|
|
|
|
idx = token[0] === 'OUTDENT' ? i + 1 : i;
|
|
|
|
return this.tokens.splice(idx, 0, ['CALL_END', ')', token[2]]);
|
|
|
|
}, this);
|
|
|
|
this.detectEnd(i + 1, condition, action);
|
2010-07-25 07:15:12 +00:00
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}, this));
|
2010-02-28 00:46:45 +00:00
|
|
|
};
|
2010-06-12 23:05:13 +00:00
|
|
|
Rewriter.prototype.addImplicitIndentation = function() {
|
2010-07-25 07:15:12 +00:00
|
|
|
return this.scanTokens(__bind(function(prev, token, post, i) {
|
|
|
|
var _c, idx, indent, insertion, outdent, parens, pre, starter, tok;
|
|
|
|
if (token[0] === 'ELSE' && prev[0] !== 'OUTDENT') {
|
|
|
|
this.tokens.splice.apply(this.tokens, [i, 0].concat(this.indentation(token)));
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
if (token[0] === 'CATCH' && (this.tokens[i + 2][0] === 'TERMINATOR' || this.tokens[i + 2][0] === 'FINALLY')) {
|
|
|
|
this.tokens.splice.apply(this.tokens, [i + 2, 0].concat(this.indentation(token)));
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
if (!(include(SINGLE_LINERS, token[0]) && post[0] !== 'INDENT' && !(token[0] === 'ELSE' && post[0] === 'IF'))) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
starter = token[0];
|
|
|
|
_c = this.indentation(token);
|
|
|
|
indent = _c[0];
|
|
|
|
outdent = _c[1];
|
|
|
|
indent.generated = (outdent.generated = true);
|
|
|
|
this.tokens.splice(i + 1, 0, indent);
|
|
|
|
idx = i + 1;
|
|
|
|
parens = 0;
|
|
|
|
while (true) {
|
|
|
|
idx += 1;
|
|
|
|
tok = this.tokens[idx];
|
|
|
|
pre = this.tokens[idx - 1];
|
|
|
|
if ((!tok || (include(SINGLE_CLOSERS, tok[0]) && tok[1] !== ';' && parens === 0) || (tok[0] === ')' && parens === 0)) && !(tok[0] === 'ELSE' && !('IF' === starter || 'THEN' === starter))) {
|
|
|
|
insertion = pre[0] === "," ? idx - 1 : idx;
|
|
|
|
this.tokens.splice(insertion, 0, outdent);
|
|
|
|
break;
|
2010-06-27 17:19:23 +00:00
|
|
|
}
|
2010-07-25 07:15:12 +00:00
|
|
|
if (tok[0] === '(') {
|
|
|
|
parens += 1;
|
2010-07-04 16:50:04 +00:00
|
|
|
}
|
2010-07-25 07:15:12 +00:00
|
|
|
if (tok[0] === ')') {
|
|
|
|
parens -= 1;
|
2010-01-30 23:29:53 +00:00
|
|
|
}
|
2010-07-24 05:34:56 +00:00
|
|
|
}
|
2010-07-25 07:15:12 +00:00
|
|
|
if (!(token[0] === 'THEN')) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
this.tokens.splice(i, 1);
|
|
|
|
return 0;
|
|
|
|
}, this));
|
2010-02-28 00:46:45 +00:00
|
|
|
};
|
2010-06-12 23:05:13 +00:00
|
|
|
Rewriter.prototype.ensureBalance = function(pairs) {
|
|
|
|
var _c, _d, key, levels, line, open, openLine, unclosed, value;
|
2010-02-28 00:46:45 +00:00
|
|
|
levels = {};
|
2010-06-12 23:05:13 +00:00
|
|
|
openLine = {};
|
2010-07-25 07:15:12 +00:00
|
|
|
this.scanTokens(__bind(function(prev, token, post, i) {
|
|
|
|
var _c, _d, _e, _f, close, open, pair;
|
|
|
|
_d = pairs;
|
|
|
|
for (_c = 0, _e = _d.length; _c < _e; _c++) {
|
|
|
|
pair = _d[_c];
|
|
|
|
_f = pair;
|
|
|
|
open = _f[0];
|
|
|
|
close = _f[1];
|
|
|
|
levels[open] = levels[open] || 0;
|
|
|
|
if (token[0] === open) {
|
|
|
|
if (levels[open] === 0) {
|
|
|
|
openLine[open] = token[2];
|
2010-02-28 00:46:45 +00:00
|
|
|
}
|
2010-07-25 07:15:12 +00:00
|
|
|
levels[open] += 1;
|
|
|
|
}
|
|
|
|
if (token[0] === close) {
|
|
|
|
levels[open] -= 1;
|
|
|
|
}
|
|
|
|
if (levels[open] < 0) {
|
|
|
|
throw new Error(("too many " + (token[1]) + " on line " + (token[2] + 1)));
|
2010-01-30 23:29:53 +00:00
|
|
|
}
|
2010-07-24 05:34:56 +00:00
|
|
|
}
|
2010-07-25 07:15:12 +00:00
|
|
|
return 1;
|
|
|
|
}, this));
|
2010-02-28 00:46:45 +00:00
|
|
|
unclosed = (function() {
|
2010-05-01 02:04:57 +00:00
|
|
|
_c = []; _d = levels;
|
2010-07-17 02:31:36 +00:00
|
|
|
for (key in _d) {
|
|
|
|
if (!__hasProp.call(_d, key)) continue;
|
2010-05-01 02:04:57 +00:00
|
|
|
value = _d[key];
|
|
|
|
value > 0 ? _c.push(key) : null;
|
2010-07-17 02:31:36 +00:00
|
|
|
}
|
2010-05-01 02:04:57 +00:00
|
|
|
return _c;
|
2010-04-10 18:40:05 +00:00
|
|
|
})();
|
2010-02-28 00:46:45 +00:00
|
|
|
if (unclosed.length) {
|
2010-03-12 03:55:35 +00:00
|
|
|
open = unclosed[0];
|
2010-06-12 23:05:13 +00:00
|
|
|
line = openLine[open] + 1;
|
2010-08-07 12:02:16 +00:00
|
|
|
throw new Error(("unclosed " + (open) + " on line " + (line)));
|
2010-02-28 00:46:45 +00:00
|
|
|
}
|
|
|
|
};
|
2010-06-12 23:05:13 +00:00
|
|
|
Rewriter.prototype.rewriteClosingParens = function() {
|
2010-05-01 02:04:57 +00:00
|
|
|
var _c, debt, key, stack, val;
|
2010-02-28 00:46:45 +00:00
|
|
|
stack = [];
|
|
|
|
debt = {};
|
2010-05-01 02:04:57 +00:00
|
|
|
_c = INVERSES;
|
2010-07-17 02:31:36 +00:00
|
|
|
for (key in _c) {
|
|
|
|
if (!__hasProp.call(_c, key)) continue;
|
2010-05-01 02:04:57 +00:00
|
|
|
val = _c[key];
|
2010-03-23 04:18:50 +00:00
|
|
|
(debt[key] = 0);
|
2010-07-17 02:31:36 +00:00
|
|
|
}
|
2010-07-25 07:15:12 +00:00
|
|
|
return this.scanTokens(__bind(function(prev, token, post, i) {
|
|
|
|
var inv, match, mtag, oppos, tag;
|
|
|
|
tag = token[0];
|
|
|
|
inv = INVERSES[token[0]];
|
|
|
|
if (include(EXPRESSION_START, tag)) {
|
|
|
|
stack.push(token);
|
|
|
|
return 1;
|
|
|
|
} else if (include(EXPRESSION_END, tag)) {
|
|
|
|
if (debt[inv] > 0) {
|
|
|
|
debt[inv] -= 1;
|
|
|
|
this.tokens.splice(i, 1);
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
match = stack.pop();
|
|
|
|
mtag = match[0];
|
|
|
|
oppos = INVERSES[mtag];
|
|
|
|
if (tag === oppos) {
|
2010-03-07 19:41:52 +00:00
|
|
|
return 1;
|
2010-01-30 23:29:53 +00:00
|
|
|
}
|
2010-07-25 07:15:12 +00:00
|
|
|
debt[mtag] += 1;
|
|
|
|
val = [oppos, mtag === 'INDENT' ? match[1] : oppos];
|
|
|
|
if ((this.tokens[i + 2] == undefined ? undefined : this.tokens[i + 2][0]) === mtag) {
|
|
|
|
this.tokens.splice(i + 3, 0, val);
|
|
|
|
stack.push(match);
|
|
|
|
} else {
|
|
|
|
this.tokens.splice(i, 0, val);
|
|
|
|
}
|
2010-02-28 00:46:45 +00:00
|
|
|
return 1;
|
2010-01-30 23:29:53 +00:00
|
|
|
}
|
2010-07-25 07:15:12 +00:00
|
|
|
} else {
|
|
|
|
return 1;
|
2010-07-24 05:34:56 +00:00
|
|
|
}
|
2010-07-25 07:15:12 +00:00
|
|
|
}, this));
|
2010-02-28 00:46:45 +00:00
|
|
|
};
|
2010-07-04 16:50:04 +00:00
|
|
|
Rewriter.prototype.indentation = function(token) {
|
|
|
|
return [['INDENT', 2, token[2]], ['OUTDENT', 2, token[2]]];
|
|
|
|
};
|
2010-02-28 00:46:45 +00:00
|
|
|
return Rewriter;
|
2010-05-31 18:42:30 +00:00
|
|
|
})();
|
2010-06-01 02:32:43 +00:00
|
|
|
BALANCED_PAIRS = [['(', ')'], ['[', ']'], ['{', '}'], ['INDENT', 'OUTDENT'], ['PARAM_START', 'PARAM_END'], ['CALL_START', 'CALL_END'], ['INDEX_START', 'INDEX_END']];
|
2010-03-07 19:41:52 +00:00
|
|
|
INVERSES = {};
|
2010-05-01 02:04:57 +00:00
|
|
|
_d = BALANCED_PAIRS;
|
|
|
|
for (_c = 0, _e = _d.length; _c < _e; _c++) {
|
|
|
|
pair = _d[_c];
|
2010-03-07 19:41:52 +00:00
|
|
|
INVERSES[pair[0]] = pair[1];
|
|
|
|
INVERSES[pair[1]] = pair[0];
|
|
|
|
}
|
|
|
|
EXPRESSION_START = (function() {
|
2010-05-01 02:04:57 +00:00
|
|
|
_f = []; _h = BALANCED_PAIRS;
|
|
|
|
for (_g = 0, _i = _h.length; _g < _i; _g++) {
|
|
|
|
pair = _h[_g];
|
|
|
|
_f.push(pair[0]);
|
2010-03-07 19:41:52 +00:00
|
|
|
}
|
2010-05-01 02:04:57 +00:00
|
|
|
return _f;
|
2010-04-10 18:40:05 +00:00
|
|
|
})();
|
2010-03-07 19:41:52 +00:00
|
|
|
EXPRESSION_END = (function() {
|
2010-05-01 02:04:57 +00:00
|
|
|
_j = []; _l = BALANCED_PAIRS;
|
|
|
|
for (_k = 0, _m = _l.length; _k < _m; _k++) {
|
|
|
|
pair = _l[_k];
|
|
|
|
_j.push(pair[1]);
|
2010-03-07 19:41:52 +00:00
|
|
|
}
|
2010-05-01 02:04:57 +00:00
|
|
|
return _j;
|
2010-04-10 18:40:05 +00:00
|
|
|
})();
|
2010-03-07 19:41:52 +00:00
|
|
|
EXPRESSION_CLOSE = ['CATCH', 'WHEN', 'ELSE', 'FINALLY'].concat(EXPRESSION_END);
|
2010-06-12 15:00:56 +00:00
|
|
|
IMPLICIT_FUNC = ['IDENTIFIER', 'SUPER', ')', 'CALL_END', ']', 'INDEX_END', '@'];
|
2010-07-27 11:03:44 +00:00
|
|
|
IMPLICIT_CALL = ['IDENTIFIER', 'NUMBER', 'STRING', 'JS', 'REGEX', 'NEW', 'PARAM_START', 'CLASS', 'TRY', 'DELETE', 'TYPEOF', 'SWITCH', 'THIS', 'NULL', 'TRUE', 'FALSE', 'YES', 'NO', 'ON', 'OFF', '!', '!!', '@', '->', '=>', '[', '(', '{'];
|
2010-03-07 19:41:52 +00:00
|
|
|
IMPLICIT_BLOCK = ['->', '=>', '{', '[', ','];
|
2010-08-11 01:46:46 +00:00
|
|
|
IMPLICIT_END = ['IF', 'UNLESS', 'FOR', 'WHILE', 'UNTIL', 'LOOP', 'TERMINATOR', 'INDENT'];
|
2010-03-07 19:41:52 +00:00
|
|
|
SINGLE_LINERS = ['ELSE', "->", "=>", 'TRY', 'FINALLY', 'THEN'];
|
|
|
|
SINGLE_CLOSERS = ['TERMINATOR', 'CATCH', 'FINALLY', 'ELSE', 'OUTDENT', 'LEADING_WHEN'];
|
2010-02-24 23:56:32 +00:00
|
|
|
})();
|