2012-02-06 20:59:17 +00:00
|
|
|
"no use strict";
|
2013-12-30 15:00:16 +00:00
|
|
|
;(function(window) {
|
|
|
|
if (typeof window.window != "undefined" && window.document) {
|
|
|
|
return;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
window.console = function() {
|
|
|
|
var msgs = Array.prototype.slice.call(arguments, 0);
|
|
|
|
postMessage({type: "log", data: msgs});
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2013-12-30 15:00:16 +00:00
|
|
|
window.console.error =
|
|
|
|
window.console.warn =
|
|
|
|
window.console.log =
|
|
|
|
window.console.trace = window.console;
|
|
|
|
|
|
|
|
window.window = window;
|
|
|
|
window.ace = window;
|
|
|
|
|
|
|
|
window.onerror = function(message, file, line, col, err) {
|
|
|
|
console.error("Worker " + err.stack);
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
window.normalizeModule = function(parentId, moduleName) {
|
2012-02-06 20:59:17 +00:00
|
|
|
if (moduleName.indexOf("!") !== -1) {
|
|
|
|
var chunks = moduleName.split("!");
|
2013-12-30 15:00:16 +00:00
|
|
|
return window.normalizeModule(parentId, chunks[0]) + "!" + window.normalizeModule(parentId, chunks[1]);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
if (moduleName.charAt(0) == ".") {
|
|
|
|
var base = parentId.split("/").slice(0, -1).join("/");
|
2013-12-30 15:00:16 +00:00
|
|
|
moduleName = (base ? base + "/" : "") + moduleName;
|
2012-02-06 20:59:17 +00:00
|
|
|
|
|
|
|
while(moduleName.indexOf(".") !== -1 && previous != moduleName) {
|
|
|
|
var previous = moduleName;
|
2013-12-30 15:00:16 +00:00
|
|
|
moduleName = moduleName.replace(/^\.\//, "").replace(/\/\.\//, "/").replace(/[^\/]+\/\.\.\//, "");
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return moduleName;
|
|
|
|
};
|
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
window.require = function(parentId, id) {
|
|
|
|
if (!id) {
|
|
|
|
id = parentId
|
|
|
|
parentId = null;
|
|
|
|
}
|
|
|
|
if (!id.charAt)
|
|
|
|
throw new Error("worker.js require() accepts only (parentId, id) as arguments");
|
|
|
|
|
|
|
|
id = window.normalizeModule(parentId, id);
|
|
|
|
|
|
|
|
var module = window.require.modules[id];
|
2012-02-06 20:59:17 +00:00
|
|
|
if (module) {
|
|
|
|
if (!module.initialized) {
|
|
|
|
module.initialized = true;
|
2013-12-30 15:00:16 +00:00
|
|
|
module.exports = module.factory().exports;
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
return module.exports;
|
|
|
|
}
|
|
|
|
|
|
|
|
var chunks = id.split("/");
|
2013-12-30 15:00:16 +00:00
|
|
|
if (!window.require.tlns)
|
|
|
|
return console.log("unable to load " + id);
|
|
|
|
chunks[0] = window.require.tlns[chunks[0]] || chunks[0];
|
2012-02-06 20:59:17 +00:00
|
|
|
var path = chunks.join("/") + ".js";
|
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
window.require.id = id;
|
2012-02-06 20:59:17 +00:00
|
|
|
importScripts(path);
|
2013-12-30 15:00:16 +00:00
|
|
|
return window.require(parentId, id);
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2013-12-30 15:00:16 +00:00
|
|
|
window.require.modules = {};
|
|
|
|
window.require.tlns = {};
|
2012-02-06 20:59:17 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
window.define = function(id, deps, factory) {
|
2012-02-06 20:59:17 +00:00
|
|
|
if (arguments.length == 2) {
|
|
|
|
factory = deps;
|
2013-12-30 15:00:16 +00:00
|
|
|
if (typeof id != "string") {
|
|
|
|
deps = id;
|
|
|
|
id = window.require.id;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
} else if (arguments.length == 1) {
|
|
|
|
factory = id;
|
2013-12-30 15:00:16 +00:00
|
|
|
deps = []
|
|
|
|
id = window.require.id;
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
if (!deps.length)
|
|
|
|
deps = ['require', 'exports', 'module']
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
if (id.indexOf("text!") === 0)
|
|
|
|
return;
|
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
var req = function(childId) {
|
|
|
|
return window.require(id, childId);
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
window.require.modules[id] = {
|
|
|
|
exports: {},
|
2012-02-06 20:59:17 +00:00
|
|
|
factory: function() {
|
2013-12-30 15:00:16 +00:00
|
|
|
var module = this;
|
|
|
|
var returnExports = factory.apply(this, deps.map(function(dep) {
|
|
|
|
switch(dep) {
|
|
|
|
case 'require': return req
|
|
|
|
case 'exports': return module.exports
|
|
|
|
case 'module': return module
|
|
|
|
default: return req(dep)
|
|
|
|
}
|
|
|
|
}));
|
2012-02-06 20:59:17 +00:00
|
|
|
if (returnExports)
|
|
|
|
module.exports = returnExports;
|
|
|
|
return module;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
2013-12-30 15:00:16 +00:00
|
|
|
window.define.amd = {}
|
2012-02-06 20:59:17 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
window.initBaseUrls = function initBaseUrls(topLevelNamespaces) {
|
2012-02-06 20:59:17 +00:00
|
|
|
require.tlns = topLevelNamespaces;
|
|
|
|
}
|
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
window.initSender = function initSender() {
|
2012-02-06 20:59:17 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
var EventEmitter = window.require("ace/lib/event_emitter").EventEmitter;
|
|
|
|
var oop = window.require("ace/lib/oop");
|
2012-02-06 20:59:17 +00:00
|
|
|
|
|
|
|
var Sender = function() {};
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
|
|
|
oop.implement(this, EventEmitter);
|
|
|
|
|
|
|
|
this.callback = function(data, callbackId) {
|
|
|
|
postMessage({
|
|
|
|
type: "call",
|
|
|
|
id: callbackId,
|
|
|
|
data: data
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
this.emit = function(name, data) {
|
|
|
|
postMessage({
|
|
|
|
type: "event",
|
|
|
|
name: name,
|
|
|
|
data: data
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
}).call(Sender.prototype);
|
|
|
|
|
|
|
|
return new Sender();
|
|
|
|
}
|
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
window.main = null;
|
|
|
|
window.sender = null;
|
2012-02-06 20:59:17 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
window.onmessage = function(e) {
|
2012-02-06 20:59:17 +00:00
|
|
|
var msg = e.data;
|
|
|
|
if (msg.command) {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (main[msg.command])
|
|
|
|
main[msg.command].apply(main, msg.args);
|
|
|
|
else
|
|
|
|
throw new Error("Unknown command:" + msg.command);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
else if (msg.init) {
|
|
|
|
initBaseUrls(msg.tlns);
|
2013-12-30 15:00:16 +00:00
|
|
|
require("ace/lib/es5-shim");
|
2012-02-06 20:59:17 +00:00
|
|
|
sender = initSender();
|
2013-12-30 15:00:16 +00:00
|
|
|
var clazz = require(msg.module)[msg.classname];
|
2012-02-06 20:59:17 +00:00
|
|
|
main = new clazz(sender);
|
|
|
|
}
|
|
|
|
else if (msg.event && sender) {
|
|
|
|
sender._emit(msg.event, msg.data);
|
|
|
|
}
|
|
|
|
};
|
2013-12-30 15:00:16 +00:00
|
|
|
})(this);// https://github.com/kriskowal/es5-shim
|
2012-02-06 20:59:17 +00:00
|
|
|
|
|
|
|
define('ace/lib/es5-shim', ['require', 'exports', 'module' ], function(require, exports, module) {
|
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
function Empty() {}
|
2012-02-06 20:59:17 +00:00
|
|
|
|
|
|
|
if (!Function.prototype.bind) {
|
|
|
|
Function.prototype.bind = function bind(that) { // .length is 1
|
|
|
|
var target = this;
|
2013-12-30 15:00:16 +00:00
|
|
|
if (typeof target != "function") {
|
|
|
|
throw new TypeError("Function.prototype.bind called on incompatible " + target);
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
var args = slice.call(arguments, 1); // for normal call
|
|
|
|
var bound = function () {
|
|
|
|
|
|
|
|
if (this instanceof bound) {
|
|
|
|
|
|
|
|
var result = target.apply(
|
2013-12-30 15:00:16 +00:00
|
|
|
this,
|
2012-02-06 20:59:17 +00:00
|
|
|
args.concat(slice.call(arguments))
|
|
|
|
);
|
2013-12-30 15:00:16 +00:00
|
|
|
if (Object(result) === result) {
|
2012-02-06 20:59:17 +00:00
|
|
|
return result;
|
2013-12-30 15:00:16 +00:00
|
|
|
}
|
|
|
|
return this;
|
2012-02-06 20:59:17 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
return target.apply(
|
|
|
|
that,
|
|
|
|
args.concat(slice.call(arguments))
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
2013-12-30 15:00:16 +00:00
|
|
|
if(target.prototype) {
|
|
|
|
Empty.prototype = target.prototype;
|
|
|
|
bound.prototype = new Empty();
|
|
|
|
Empty.prototype = null;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
return bound;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
var call = Function.prototype.call;
|
|
|
|
var prototypeOfArray = Array.prototype;
|
|
|
|
var prototypeOfObject = Object.prototype;
|
|
|
|
var slice = prototypeOfArray.slice;
|
2013-12-30 15:00:16 +00:00
|
|
|
var _toString = call.bind(prototypeOfObject.toString);
|
2012-02-06 20:59:17 +00:00
|
|
|
var owns = call.bind(prototypeOfObject.hasOwnProperty);
|
|
|
|
var defineGetter;
|
|
|
|
var defineSetter;
|
|
|
|
var lookupGetter;
|
|
|
|
var lookupSetter;
|
|
|
|
var supportsAccessors;
|
|
|
|
if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) {
|
|
|
|
defineGetter = call.bind(prototypeOfObject.__defineGetter__);
|
|
|
|
defineSetter = call.bind(prototypeOfObject.__defineSetter__);
|
|
|
|
lookupGetter = call.bind(prototypeOfObject.__lookupGetter__);
|
|
|
|
lookupSetter = call.bind(prototypeOfObject.__lookupSetter__);
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
if ([1,2].splice(0).length != 2) {
|
|
|
|
if(function() { // test IE < 9 to splice bug - see issue #138
|
|
|
|
function makeArray(l) {
|
|
|
|
var a = new Array(l+2);
|
|
|
|
a[0] = a[1] = 0;
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
var array = [], lengthBefore;
|
|
|
|
|
|
|
|
array.splice.apply(array, makeArray(20));
|
|
|
|
array.splice.apply(array, makeArray(26));
|
|
|
|
|
|
|
|
lengthBefore = array.length; //46
|
|
|
|
array.splice(5, 0, "XXX"); // add one element
|
|
|
|
|
|
|
|
lengthBefore + 1 == array.length
|
|
|
|
|
|
|
|
if (lengthBefore + 1 == array.length) {
|
|
|
|
return true;// has right splice implementation without bugs
|
|
|
|
}
|
|
|
|
}()) {//IE 6/7
|
|
|
|
var array_splice = Array.prototype.splice;
|
|
|
|
Array.prototype.splice = function(start, deleteCount) {
|
|
|
|
if (!arguments.length) {
|
|
|
|
return [];
|
|
|
|
} else {
|
|
|
|
return array_splice.apply(this, [
|
|
|
|
start === void 0 ? 0 : start,
|
|
|
|
deleteCount === void 0 ? (this.length - start) : deleteCount
|
|
|
|
].concat(slice.call(arguments, 2)))
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} else {//IE8
|
|
|
|
Array.prototype.splice = function(pos, removeCount){
|
|
|
|
var length = this.length;
|
|
|
|
if (pos > 0) {
|
|
|
|
if (pos > length)
|
|
|
|
pos = length;
|
|
|
|
} else if (pos == void 0) {
|
|
|
|
pos = 0;
|
|
|
|
} else if (pos < 0) {
|
|
|
|
pos = Math.max(length + pos, 0);
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
if (!(pos+removeCount < length))
|
|
|
|
removeCount = length - pos;
|
2012-02-06 20:59:17 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
var removed = this.slice(pos, pos+removeCount);
|
|
|
|
var insert = slice.call(arguments, 2);
|
|
|
|
var add = insert.length;
|
|
|
|
if (pos === length) {
|
|
|
|
if (add) {
|
|
|
|
this.push.apply(this, insert);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
var remove = Math.min(removeCount, length - pos);
|
|
|
|
var tailOldPos = pos + remove;
|
|
|
|
var tailNewPos = tailOldPos + add - remove;
|
|
|
|
var tailCount = length - tailOldPos;
|
|
|
|
var lengthAfterRemove = length - remove;
|
|
|
|
|
|
|
|
if (tailNewPos < tailOldPos) { // case A
|
|
|
|
for (var i = 0; i < tailCount; ++i) {
|
|
|
|
this[tailNewPos+i] = this[tailOldPos+i];
|
|
|
|
}
|
|
|
|
} else if (tailNewPos > tailOldPos) { // case B
|
|
|
|
for (i = tailCount; i--; ) {
|
|
|
|
this[tailNewPos+i] = this[tailOldPos+i];
|
|
|
|
}
|
|
|
|
} // else, add == remove (nothing to do)
|
|
|
|
|
|
|
|
if (add && pos === lengthAfterRemove) {
|
|
|
|
this.length = lengthAfterRemove; // truncate array
|
|
|
|
this.push.apply(this, insert);
|
|
|
|
} else {
|
|
|
|
this.length = lengthAfterRemove + add; // reserves space
|
|
|
|
for (i = 0; i < add; ++i) {
|
|
|
|
this[pos+i] = insert[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return removed;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
if (!Array.isArray) {
|
|
|
|
Array.isArray = function isArray(obj) {
|
2013-12-30 15:00:16 +00:00
|
|
|
return _toString(obj) == "[object Array]";
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
var boxedString = Object("a"),
|
|
|
|
splitString = boxedString[0] != "a" || !(0 in boxedString);
|
2012-02-06 20:59:17 +00:00
|
|
|
|
|
|
|
if (!Array.prototype.forEach) {
|
|
|
|
Array.prototype.forEach = function forEach(fun /*, thisp*/) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var object = toObject(this),
|
|
|
|
self = splitString && _toString(this) == "[object String]" ?
|
|
|
|
this.split("") :
|
|
|
|
object,
|
2012-02-06 20:59:17 +00:00
|
|
|
thisp = arguments[1],
|
2013-12-30 15:00:16 +00:00
|
|
|
i = -1,
|
2012-02-06 20:59:17 +00:00
|
|
|
length = self.length >>> 0;
|
2013-12-30 15:00:16 +00:00
|
|
|
if (_toString(fun) != "[object Function]") {
|
2012-02-06 20:59:17 +00:00
|
|
|
throw new TypeError(); // TODO message
|
|
|
|
}
|
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
while (++i < length) {
|
2012-02-06 20:59:17 +00:00
|
|
|
if (i in self) {
|
2013-12-30 15:00:16 +00:00
|
|
|
fun.call(thisp, self[i], i, object);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (!Array.prototype.map) {
|
|
|
|
Array.prototype.map = function map(fun /*, thisp*/) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var object = toObject(this),
|
|
|
|
self = splitString && _toString(this) == "[object String]" ?
|
|
|
|
this.split("") :
|
|
|
|
object,
|
2012-02-06 20:59:17 +00:00
|
|
|
length = self.length >>> 0,
|
|
|
|
result = Array(length),
|
|
|
|
thisp = arguments[1];
|
2013-12-30 15:00:16 +00:00
|
|
|
if (_toString(fun) != "[object Function]") {
|
|
|
|
throw new TypeError(fun + " is not a function");
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0; i < length; i++) {
|
|
|
|
if (i in self)
|
2013-12-30 15:00:16 +00:00
|
|
|
result[i] = fun.call(thisp, self[i], i, object);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (!Array.prototype.filter) {
|
|
|
|
Array.prototype.filter = function filter(fun /*, thisp */) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var object = toObject(this),
|
|
|
|
self = splitString && _toString(this) == "[object String]" ?
|
|
|
|
this.split("") :
|
|
|
|
object,
|
2012-02-06 20:59:17 +00:00
|
|
|
length = self.length >>> 0,
|
|
|
|
result = [],
|
2013-12-30 15:00:16 +00:00
|
|
|
value,
|
2012-02-06 20:59:17 +00:00
|
|
|
thisp = arguments[1];
|
2013-12-30 15:00:16 +00:00
|
|
|
if (_toString(fun) != "[object Function]") {
|
|
|
|
throw new TypeError(fun + " is not a function");
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0; i < length; i++) {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (i in self) {
|
|
|
|
value = self[i];
|
|
|
|
if (fun.call(thisp, value, i, object)) {
|
|
|
|
result.push(value);
|
|
|
|
}
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (!Array.prototype.every) {
|
|
|
|
Array.prototype.every = function every(fun /*, thisp */) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var object = toObject(this),
|
|
|
|
self = splitString && _toString(this) == "[object String]" ?
|
|
|
|
this.split("") :
|
|
|
|
object,
|
2012-02-06 20:59:17 +00:00
|
|
|
length = self.length >>> 0,
|
|
|
|
thisp = arguments[1];
|
2013-12-30 15:00:16 +00:00
|
|
|
if (_toString(fun) != "[object Function]") {
|
|
|
|
throw new TypeError(fun + " is not a function");
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0; i < length; i++) {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (i in self && !fun.call(thisp, self[i], i, object)) {
|
2012-02-06 20:59:17 +00:00
|
|
|
return false;
|
2013-12-30 15:00:16 +00:00
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (!Array.prototype.some) {
|
|
|
|
Array.prototype.some = function some(fun /*, thisp */) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var object = toObject(this),
|
|
|
|
self = splitString && _toString(this) == "[object String]" ?
|
|
|
|
this.split("") :
|
|
|
|
object,
|
2012-02-06 20:59:17 +00:00
|
|
|
length = self.length >>> 0,
|
|
|
|
thisp = arguments[1];
|
2013-12-30 15:00:16 +00:00
|
|
|
if (_toString(fun) != "[object Function]") {
|
|
|
|
throw new TypeError(fun + " is not a function");
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0; i < length; i++) {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (i in self && fun.call(thisp, self[i], i, object)) {
|
2012-02-06 20:59:17 +00:00
|
|
|
return true;
|
2013-12-30 15:00:16 +00:00
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (!Array.prototype.reduce) {
|
|
|
|
Array.prototype.reduce = function reduce(fun /*, initial*/) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var object = toObject(this),
|
|
|
|
self = splitString && _toString(this) == "[object String]" ?
|
|
|
|
this.split("") :
|
|
|
|
object,
|
2012-02-06 20:59:17 +00:00
|
|
|
length = self.length >>> 0;
|
2013-12-30 15:00:16 +00:00
|
|
|
if (_toString(fun) != "[object Function]") {
|
|
|
|
throw new TypeError(fun + " is not a function");
|
|
|
|
}
|
|
|
|
if (!length && arguments.length == 1) {
|
|
|
|
throw new TypeError("reduce of empty array with no initial value");
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var i = 0;
|
|
|
|
var result;
|
|
|
|
if (arguments.length >= 2) {
|
|
|
|
result = arguments[1];
|
|
|
|
} else {
|
|
|
|
do {
|
|
|
|
if (i in self) {
|
|
|
|
result = self[i++];
|
|
|
|
break;
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
if (++i >= length) {
|
|
|
|
throw new TypeError("reduce of empty array with no initial value");
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
} while (true);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; i < length; i++) {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (i in self) {
|
|
|
|
result = fun.call(void 0, result, self[i], i, object);
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (!Array.prototype.reduceRight) {
|
|
|
|
Array.prototype.reduceRight = function reduceRight(fun /*, initial*/) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var object = toObject(this),
|
|
|
|
self = splitString && _toString(this) == "[object String]" ?
|
|
|
|
this.split("") :
|
|
|
|
object,
|
2012-02-06 20:59:17 +00:00
|
|
|
length = self.length >>> 0;
|
2013-12-30 15:00:16 +00:00
|
|
|
if (_toString(fun) != "[object Function]") {
|
|
|
|
throw new TypeError(fun + " is not a function");
|
|
|
|
}
|
|
|
|
if (!length && arguments.length == 1) {
|
|
|
|
throw new TypeError("reduceRight of empty array with no initial value");
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var result, i = length - 1;
|
|
|
|
if (arguments.length >= 2) {
|
|
|
|
result = arguments[1];
|
|
|
|
} else {
|
|
|
|
do {
|
|
|
|
if (i in self) {
|
|
|
|
result = self[i--];
|
|
|
|
break;
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
if (--i < 0) {
|
|
|
|
throw new TypeError("reduceRight of empty array with no initial value");
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
} while (true);
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (i in this) {
|
|
|
|
result = fun.call(void 0, result, self[i], i, object);
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
} while (i--);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
if (!Array.prototype.indexOf || ([0, 1].indexOf(1, 2) != -1)) {
|
2012-02-06 20:59:17 +00:00
|
|
|
Array.prototype.indexOf = function indexOf(sought /*, fromIndex */ ) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var self = splitString && _toString(this) == "[object String]" ?
|
|
|
|
this.split("") :
|
|
|
|
toObject(this),
|
2012-02-06 20:59:17 +00:00
|
|
|
length = self.length >>> 0;
|
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
if (!length) {
|
2012-02-06 20:59:17 +00:00
|
|
|
return -1;
|
2013-12-30 15:00:16 +00:00
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
|
|
|
|
var i = 0;
|
2013-12-30 15:00:16 +00:00
|
|
|
if (arguments.length > 1) {
|
2012-02-06 20:59:17 +00:00
|
|
|
i = toInteger(arguments[1]);
|
2013-12-30 15:00:16 +00:00
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
i = i >= 0 ? i : Math.max(0, length + i);
|
|
|
|
for (; i < length; i++) {
|
|
|
|
if (i in self && self[i] === sought) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
};
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
if (!Array.prototype.lastIndexOf || ([0, 1].lastIndexOf(0, -3) != -1)) {
|
2012-02-06 20:59:17 +00:00
|
|
|
Array.prototype.lastIndexOf = function lastIndexOf(sought /*, fromIndex */) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var self = splitString && _toString(this) == "[object String]" ?
|
|
|
|
this.split("") :
|
|
|
|
toObject(this),
|
2012-02-06 20:59:17 +00:00
|
|
|
length = self.length >>> 0;
|
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
if (!length) {
|
2012-02-06 20:59:17 +00:00
|
|
|
return -1;
|
2013-12-30 15:00:16 +00:00
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
var i = length - 1;
|
2013-12-30 15:00:16 +00:00
|
|
|
if (arguments.length > 1) {
|
2012-02-06 20:59:17 +00:00
|
|
|
i = Math.min(i, toInteger(arguments[1]));
|
2013-12-30 15:00:16 +00:00
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
i = i >= 0 ? i : length - Math.abs(i);
|
|
|
|
for (; i >= 0; i--) {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (i in self && sought === self[i]) {
|
2012-02-06 20:59:17 +00:00
|
|
|
return i;
|
2013-12-30 15:00:16 +00:00
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (!Object.getPrototypeOf) {
|
|
|
|
Object.getPrototypeOf = function getPrototypeOf(object) {
|
|
|
|
return object.__proto__ || (
|
|
|
|
object.constructor ?
|
|
|
|
object.constructor.prototype :
|
|
|
|
prototypeOfObject
|
|
|
|
);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (!Object.getOwnPropertyDescriptor) {
|
|
|
|
var ERR_NON_OBJECT = "Object.getOwnPropertyDescriptor called on a " +
|
|
|
|
"non-object: ";
|
|
|
|
Object.getOwnPropertyDescriptor = function getOwnPropertyDescriptor(object, property) {
|
|
|
|
if ((typeof object != "object" && typeof object != "function") || object === null)
|
|
|
|
throw new TypeError(ERR_NON_OBJECT + object);
|
|
|
|
if (!owns(object, property))
|
|
|
|
return;
|
|
|
|
|
|
|
|
var descriptor, getter, setter;
|
|
|
|
descriptor = { enumerable: true, configurable: true };
|
|
|
|
if (supportsAccessors) {
|
|
|
|
var prototype = object.__proto__;
|
|
|
|
object.__proto__ = prototypeOfObject;
|
|
|
|
|
|
|
|
var getter = lookupGetter(object, property);
|
|
|
|
var setter = lookupSetter(object, property);
|
|
|
|
object.__proto__ = prototype;
|
|
|
|
|
|
|
|
if (getter || setter) {
|
|
|
|
if (getter) descriptor.get = getter;
|
|
|
|
if (setter) descriptor.set = setter;
|
|
|
|
return descriptor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
descriptor.value = object[property];
|
|
|
|
return descriptor;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (!Object.getOwnPropertyNames) {
|
|
|
|
Object.getOwnPropertyNames = function getOwnPropertyNames(object) {
|
|
|
|
return Object.keys(object);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (!Object.create) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var createEmpty;
|
|
|
|
if (Object.prototype.__proto__ === null) {
|
|
|
|
createEmpty = function () {
|
|
|
|
return { "__proto__": null };
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
createEmpty = function () {
|
|
|
|
var empty = {};
|
|
|
|
for (var i in empty)
|
|
|
|
empty[i] = null;
|
|
|
|
empty.constructor =
|
|
|
|
empty.hasOwnProperty =
|
|
|
|
empty.propertyIsEnumerable =
|
|
|
|
empty.isPrototypeOf =
|
|
|
|
empty.toLocaleString =
|
|
|
|
empty.toString =
|
|
|
|
empty.valueOf =
|
|
|
|
empty.__proto__ = null;
|
|
|
|
return empty;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Object.create = function create(prototype, properties) {
|
|
|
|
var object;
|
|
|
|
if (prototype === null) {
|
2013-12-30 15:00:16 +00:00
|
|
|
object = createEmpty();
|
2012-02-06 20:59:17 +00:00
|
|
|
} else {
|
|
|
|
if (typeof prototype != "object")
|
|
|
|
throw new TypeError("typeof prototype["+(typeof prototype)+"] != 'object'");
|
|
|
|
var Type = function () {};
|
|
|
|
Type.prototype = prototype;
|
|
|
|
object = new Type();
|
|
|
|
object.__proto__ = prototype;
|
|
|
|
}
|
|
|
|
if (properties !== void 0)
|
|
|
|
Object.defineProperties(object, properties);
|
|
|
|
return object;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function doesDefinePropertyWork(object) {
|
|
|
|
try {
|
|
|
|
Object.defineProperty(object, "sentinel", {});
|
|
|
|
return "sentinel" in object;
|
|
|
|
} catch (exception) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Object.defineProperty) {
|
|
|
|
var definePropertyWorksOnObject = doesDefinePropertyWork({});
|
|
|
|
var definePropertyWorksOnDom = typeof document == "undefined" ||
|
|
|
|
doesDefinePropertyWork(document.createElement("div"));
|
|
|
|
if (!definePropertyWorksOnObject || !definePropertyWorksOnDom) {
|
|
|
|
var definePropertyFallback = Object.defineProperty;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Object.defineProperty || definePropertyFallback) {
|
|
|
|
var ERR_NON_OBJECT_DESCRIPTOR = "Property description must be an object: ";
|
|
|
|
var ERR_NON_OBJECT_TARGET = "Object.defineProperty called on non-object: "
|
|
|
|
var ERR_ACCESSORS_NOT_SUPPORTED = "getters & setters can not be defined " +
|
|
|
|
"on this javascript engine";
|
|
|
|
|
|
|
|
Object.defineProperty = function defineProperty(object, property, descriptor) {
|
|
|
|
if ((typeof object != "object" && typeof object != "function") || object === null)
|
|
|
|
throw new TypeError(ERR_NON_OBJECT_TARGET + object);
|
|
|
|
if ((typeof descriptor != "object" && typeof descriptor != "function") || descriptor === null)
|
|
|
|
throw new TypeError(ERR_NON_OBJECT_DESCRIPTOR + descriptor);
|
|
|
|
if (definePropertyFallback) {
|
|
|
|
try {
|
|
|
|
return definePropertyFallback.call(Object, object, property, descriptor);
|
|
|
|
} catch (exception) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (owns(descriptor, "value")) {
|
|
|
|
|
|
|
|
if (supportsAccessors && (lookupGetter(object, property) ||
|
|
|
|
lookupSetter(object, property)))
|
|
|
|
{
|
|
|
|
var prototype = object.__proto__;
|
|
|
|
object.__proto__ = prototypeOfObject;
|
|
|
|
delete object[property];
|
|
|
|
object[property] = descriptor.value;
|
|
|
|
object.__proto__ = prototype;
|
|
|
|
} else {
|
|
|
|
object[property] = descriptor.value;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!supportsAccessors)
|
|
|
|
throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
|
|
|
|
if (owns(descriptor, "get"))
|
|
|
|
defineGetter(object, property, descriptor.get);
|
|
|
|
if (owns(descriptor, "set"))
|
|
|
|
defineSetter(object, property, descriptor.set);
|
|
|
|
}
|
|
|
|
|
|
|
|
return object;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (!Object.defineProperties) {
|
|
|
|
Object.defineProperties = function defineProperties(object, properties) {
|
|
|
|
for (var property in properties) {
|
|
|
|
if (owns(properties, property))
|
|
|
|
Object.defineProperty(object, property, properties[property]);
|
|
|
|
}
|
|
|
|
return object;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (!Object.seal) {
|
|
|
|
Object.seal = function seal(object) {
|
|
|
|
return object;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (!Object.freeze) {
|
|
|
|
Object.freeze = function freeze(object) {
|
|
|
|
return object;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
Object.freeze(function () {});
|
|
|
|
} catch (exception) {
|
|
|
|
Object.freeze = (function freeze(freezeObject) {
|
|
|
|
return function freeze(object) {
|
|
|
|
if (typeof object == "function") {
|
|
|
|
return object;
|
|
|
|
} else {
|
|
|
|
return freezeObject(object);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
})(Object.freeze);
|
|
|
|
}
|
|
|
|
if (!Object.preventExtensions) {
|
|
|
|
Object.preventExtensions = function preventExtensions(object) {
|
|
|
|
return object;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (!Object.isSealed) {
|
|
|
|
Object.isSealed = function isSealed(object) {
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (!Object.isFrozen) {
|
|
|
|
Object.isFrozen = function isFrozen(object) {
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (!Object.isExtensible) {
|
|
|
|
Object.isExtensible = function isExtensible(object) {
|
|
|
|
if (Object(object) === object) {
|
|
|
|
throw new TypeError(); // TODO message
|
|
|
|
}
|
|
|
|
var name = '';
|
|
|
|
while (owns(object, name)) {
|
|
|
|
name += '?';
|
|
|
|
}
|
|
|
|
object[name] = true;
|
|
|
|
var returnValue = owns(object, name);
|
|
|
|
delete object[name];
|
|
|
|
return returnValue;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (!Object.keys) {
|
|
|
|
var hasDontEnumBug = true,
|
|
|
|
dontEnums = [
|
|
|
|
"toString",
|
|
|
|
"toLocaleString",
|
|
|
|
"valueOf",
|
|
|
|
"hasOwnProperty",
|
|
|
|
"isPrototypeOf",
|
|
|
|
"propertyIsEnumerable",
|
|
|
|
"constructor"
|
|
|
|
],
|
|
|
|
dontEnumsLength = dontEnums.length;
|
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
for (var key in {"toString": null}) {
|
2012-02-06 20:59:17 +00:00
|
|
|
hasDontEnumBug = false;
|
2013-12-30 15:00:16 +00:00
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
|
|
|
|
Object.keys = function keys(object) {
|
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
if (
|
|
|
|
(typeof object != "object" && typeof object != "function") ||
|
|
|
|
object === null
|
|
|
|
) {
|
2012-02-06 20:59:17 +00:00
|
|
|
throw new TypeError("Object.keys called on a non-object");
|
2013-12-30 15:00:16 +00:00
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
|
|
|
|
var keys = [];
|
|
|
|
for (var name in object) {
|
|
|
|
if (owns(object, name)) {
|
|
|
|
keys.push(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasDontEnumBug) {
|
|
|
|
for (var i = 0, ii = dontEnumsLength; i < ii; i++) {
|
|
|
|
var dontEnum = dontEnums[i];
|
|
|
|
if (owns(object, dontEnum)) {
|
|
|
|
keys.push(dontEnum);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return keys;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
if (!Date.now) {
|
|
|
|
Date.now = function now() {
|
|
|
|
return new Date().getTime();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
var ws = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003" +
|
|
|
|
"\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028" +
|
|
|
|
"\u2029\uFEFF";
|
|
|
|
if (!String.prototype.trim || ws.trim()) {
|
|
|
|
ws = "[" + ws + "]";
|
|
|
|
var trimBeginRegexp = new RegExp("^" + ws + ws + "*"),
|
|
|
|
trimEndRegexp = new RegExp(ws + ws + "*$");
|
|
|
|
String.prototype.trim = function trim() {
|
|
|
|
return String(this).replace(trimBeginRegexp, "").replace(trimEndRegexp, "");
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
function toInteger(n) {
|
2012-02-06 20:59:17 +00:00
|
|
|
n = +n;
|
2013-12-30 15:00:16 +00:00
|
|
|
if (n !== n) { // isNaN
|
2012-02-06 20:59:17 +00:00
|
|
|
n = 0;
|
2013-12-30 15:00:16 +00:00
|
|
|
} else if (n !== 0 && n !== (1/0) && n !== -(1/0)) {
|
2012-02-06 20:59:17 +00:00
|
|
|
n = (n > 0 || -1) * Math.floor(Math.abs(n));
|
2013-12-30 15:00:16 +00:00
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
return n;
|
2013-12-30 15:00:16 +00:00
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
function isPrimitive(input) {
|
|
|
|
var type = typeof input;
|
|
|
|
return (
|
|
|
|
input === null ||
|
|
|
|
type === "undefined" ||
|
|
|
|
type === "boolean" ||
|
|
|
|
type === "number" ||
|
|
|
|
type === "string"
|
|
|
|
);
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
function toPrimitive(input) {
|
|
|
|
var val, valueOf, toString;
|
|
|
|
if (isPrimitive(input)) {
|
|
|
|
return input;
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
valueOf = input.valueOf;
|
|
|
|
if (typeof valueOf === "function") {
|
|
|
|
val = valueOf.call(input);
|
|
|
|
if (isPrimitive(val)) {
|
|
|
|
return val;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
toString = input.toString;
|
|
|
|
if (typeof toString === "function") {
|
|
|
|
val = toString.call(input);
|
|
|
|
if (isPrimitive(val)) {
|
|
|
|
return val;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
throw new TypeError();
|
|
|
|
}
|
|
|
|
var toObject = function (o) {
|
|
|
|
if (o == null) { // this matches both null and undefined
|
|
|
|
throw new TypeError("can't convert "+o+" to object");
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
return Object(o);
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
});
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
define('ace/mode/coffee_worker', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/worker/mirror', 'ace/mode/coffee/coffee-script'], function(require, exports, module) {
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
var oop = require("../lib/oop");
|
|
|
|
var Mirror = require("../worker/mirror").Mirror;
|
|
|
|
var coffee = require("../mode/coffee/coffee-script");
|
|
|
|
|
|
|
|
window.addEventListener = function() {};
|
|
|
|
|
|
|
|
|
|
|
|
var Worker = exports.Worker = function(sender) {
|
|
|
|
Mirror.call(this, sender);
|
2013-12-30 15:00:16 +00:00
|
|
|
this.setTimeout(250);
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
oop.inherits(Worker, Mirror);
|
|
|
|
|
|
|
|
(function() {
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
this.onUpdate = function() {
|
|
|
|
var value = this.doc.getValue();
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
try {
|
2013-12-30 15:00:16 +00:00
|
|
|
coffee.parse(value).compile();
|
2012-02-06 20:59:17 +00:00
|
|
|
} catch(e) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var loc = e.location;
|
|
|
|
if (loc) {
|
2012-02-06 20:59:17 +00:00
|
|
|
this.sender.emit("error", {
|
2013-12-30 15:00:16 +00:00
|
|
|
row: loc.first_line,
|
|
|
|
column: loc.first_column,
|
|
|
|
endRow: loc.last_line,
|
|
|
|
endColumn: loc.last_column,
|
|
|
|
text: e.message,
|
2012-02-06 20:59:17 +00:00
|
|
|
type: "error"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.sender.emit("ok");
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
}).call(Worker.prototype);
|
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
define('ace/lib/oop', ['require', 'exports', 'module' ], function(require, exports, module) {
|
|
|
|
|
|
|
|
|
|
|
|
exports.inherits = function(ctor, superCtor) {
|
|
|
|
ctor.super_ = superCtor;
|
|
|
|
ctor.prototype = Object.create(superCtor.prototype, {
|
|
|
|
constructor: {
|
|
|
|
value: ctor,
|
|
|
|
enumerable: false,
|
|
|
|
writable: true,
|
|
|
|
configurable: true
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.mixin = function(obj, mixin) {
|
|
|
|
for (var key in mixin) {
|
|
|
|
obj[key] = mixin[key];
|
|
|
|
}
|
|
|
|
return obj;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.implement = function(proto, mixin) {
|
|
|
|
exports.mixin(proto, mixin);
|
|
|
|
};
|
|
|
|
|
2012-07-05 06:37:09 +00:00
|
|
|
});
|
|
|
|
define('ace/worker/mirror', ['require', 'exports', 'module' , 'ace/document', 'ace/lib/lang'], function(require, exports, module) {
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
|
|
|
|
var Document = require("../document").Document;
|
|
|
|
var lang = require("../lib/lang");
|
|
|
|
|
|
|
|
var Mirror = exports.Mirror = function(sender) {
|
|
|
|
this.sender = sender;
|
|
|
|
var doc = this.doc = new Document("");
|
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
var deferredUpdate = this.deferredUpdate = lang.delayedCall(this.onUpdate.bind(this));
|
2012-02-06 20:59:17 +00:00
|
|
|
|
|
|
|
var _self = this;
|
|
|
|
sender.on("change", function(e) {
|
2013-12-30 15:00:16 +00:00
|
|
|
doc.applyDeltas(e.data);
|
|
|
|
if (_self.$timeout)
|
|
|
|
return deferredUpdate.schedule(_self.$timeout);
|
|
|
|
_self.onUpdate();
|
2012-02-06 20:59:17 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
|
|
|
this.$timeout = 500;
|
|
|
|
|
|
|
|
this.setTimeout = function(timeout) {
|
|
|
|
this.$timeout = timeout;
|
|
|
|
};
|
|
|
|
|
|
|
|
this.setValue = function(value) {
|
|
|
|
this.doc.setValue(value);
|
|
|
|
this.deferredUpdate.schedule(this.$timeout);
|
|
|
|
};
|
|
|
|
|
|
|
|
this.getValue = function(callbackId) {
|
|
|
|
this.sender.callback(this.doc.getValue(), callbackId);
|
|
|
|
};
|
|
|
|
|
|
|
|
this.onUpdate = function() {
|
2013-12-30 15:00:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
this.isPending = function() {
|
|
|
|
return this.deferredUpdate.isPending();
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}).call(Mirror.prototype);
|
|
|
|
|
2012-07-05 06:37:09 +00:00
|
|
|
});
|
2012-02-06 20:59:17 +00:00
|
|
|
|
|
|
|
define('ace/document', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/event_emitter', 'ace/range', 'ace/anchor'], function(require, exports, module) {
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
|
|
|
|
var oop = require("./lib/oop");
|
|
|
|
var EventEmitter = require("./lib/event_emitter").EventEmitter;
|
|
|
|
var Range = require("./range").Range;
|
|
|
|
var Anchor = require("./anchor").Anchor;
|
|
|
|
|
|
|
|
var Document = function(text) {
|
|
|
|
this.$lines = [];
|
2012-07-05 06:37:09 +00:00
|
|
|
if (text.length == 0) {
|
2012-02-06 20:59:17 +00:00
|
|
|
this.$lines = [""];
|
2012-07-05 06:37:09 +00:00
|
|
|
} else if (Array.isArray(text)) {
|
2013-12-30 15:00:16 +00:00
|
|
|
this._insertLines(0, text);
|
2012-02-06 20:59:17 +00:00
|
|
|
} else {
|
|
|
|
this.insert({row: 0, column:0}, text);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
|
|
|
oop.implement(this, EventEmitter);
|
|
|
|
this.setValue = function(text) {
|
|
|
|
var len = this.getLength();
|
|
|
|
this.remove(new Range(0, 0, len, this.getLine(len-1).length));
|
|
|
|
this.insert({row: 0, column:0}, text);
|
|
|
|
};
|
|
|
|
this.getValue = function() {
|
|
|
|
return this.getAllLines().join(this.getNewLineCharacter());
|
|
|
|
};
|
|
|
|
this.createAnchor = function(row, column) {
|
|
|
|
return new Anchor(this, row, column);
|
|
|
|
};
|
|
|
|
if ("aaa".split(/a/).length == 0)
|
|
|
|
this.$split = function(text) {
|
|
|
|
return text.replace(/\r\n|\r/g, "\n").split("\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
this.$split = function(text) {
|
|
|
|
return text.split(/\r\n|\r|\n/);
|
|
|
|
};
|
2013-12-30 15:00:16 +00:00
|
|
|
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
this.$detectNewLine = function(text) {
|
|
|
|
var match = text.match(/^.*?(\r\n|\r|\n)/m);
|
2013-12-30 15:00:16 +00:00
|
|
|
this.$autoNewLine = match ? match[1] : "\n";
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
|
|
|
this.getNewLineCharacter = function() {
|
2013-12-30 15:00:16 +00:00
|
|
|
switch (this.$newLineMode) {
|
2012-02-06 20:59:17 +00:00
|
|
|
case "windows":
|
2013-12-30 15:00:16 +00:00
|
|
|
return "\r\n";
|
2012-02-06 20:59:17 +00:00
|
|
|
case "unix":
|
2013-12-30 15:00:16 +00:00
|
|
|
return "\n";
|
|
|
|
default:
|
|
|
|
return this.$autoNewLine;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
this.$autoNewLine = "\n";
|
|
|
|
this.$newLineMode = "auto";
|
|
|
|
this.setNewLineMode = function(newLineMode) {
|
|
|
|
if (this.$newLineMode === newLineMode)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this.$newLineMode = newLineMode;
|
|
|
|
};
|
|
|
|
this.getNewLineMode = function() {
|
|
|
|
return this.$newLineMode;
|
|
|
|
};
|
|
|
|
this.isNewLine = function(text) {
|
|
|
|
return (text == "\r\n" || text == "\r" || text == "\n");
|
|
|
|
};
|
|
|
|
this.getLine = function(row) {
|
|
|
|
return this.$lines[row] || "";
|
|
|
|
};
|
|
|
|
this.getLines = function(firstRow, lastRow) {
|
|
|
|
return this.$lines.slice(firstRow, lastRow + 1);
|
|
|
|
};
|
|
|
|
this.getAllLines = function() {
|
|
|
|
return this.getLines(0, this.getLength());
|
|
|
|
};
|
|
|
|
this.getLength = function() {
|
|
|
|
return this.$lines.length;
|
|
|
|
};
|
|
|
|
this.getTextRange = function(range) {
|
|
|
|
if (range.start.row == range.end.row) {
|
2013-12-30 15:00:16 +00:00
|
|
|
return this.getLine(range.start.row)
|
|
|
|
.substring(range.start.column, range.end.column);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
var lines = this.getLines(range.start.row, range.end.row);
|
|
|
|
lines[0] = (lines[0] || "").substring(range.start.column);
|
|
|
|
var l = lines.length - 1;
|
|
|
|
if (range.end.row - range.start.row == l)
|
|
|
|
lines[l] = lines[l].substring(0, range.end.column);
|
|
|
|
return lines.join(this.getNewLineCharacter());
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2013-12-30 15:00:16 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
this.$clipPosition = function(position) {
|
|
|
|
var length = this.getLength();
|
|
|
|
if (position.row >= length) {
|
|
|
|
position.row = Math.max(0, length - 1);
|
|
|
|
position.column = this.getLine(length-1).length;
|
2013-12-30 15:00:16 +00:00
|
|
|
} else if (position.row < 0)
|
|
|
|
position.row = 0;
|
2012-02-06 20:59:17 +00:00
|
|
|
return position;
|
|
|
|
};
|
|
|
|
this.insert = function(position, text) {
|
2012-07-05 06:37:09 +00:00
|
|
|
if (!text || text.length === 0)
|
2012-02-06 20:59:17 +00:00
|
|
|
return position;
|
|
|
|
|
|
|
|
position = this.$clipPosition(position);
|
|
|
|
if (this.getLength() <= 1)
|
|
|
|
this.$detectNewLine(text);
|
|
|
|
|
|
|
|
var lines = this.$split(text);
|
|
|
|
var firstLine = lines.splice(0, 1)[0];
|
|
|
|
var lastLine = lines.length == 0 ? null : lines.splice(lines.length - 1, 1)[0];
|
|
|
|
|
|
|
|
position = this.insertInLine(position, firstLine);
|
|
|
|
if (lastLine !== null) {
|
|
|
|
position = this.insertNewLine(position); // terminate first line
|
2013-12-30 15:00:16 +00:00
|
|
|
position = this._insertLines(position.row, lines);
|
2012-02-06 20:59:17 +00:00
|
|
|
position = this.insertInLine(position, lastLine || "");
|
|
|
|
}
|
|
|
|
return position;
|
|
|
|
};
|
|
|
|
this.insertLines = function(row, lines) {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (row >= this.getLength())
|
|
|
|
return this.insert({row: row, column: 0}, "\n" + lines.join("\n"));
|
|
|
|
return this._insertLines(Math.max(row, 0), lines);
|
|
|
|
};
|
|
|
|
this._insertLines = function(row, lines) {
|
2012-02-06 20:59:17 +00:00
|
|
|
if (lines.length == 0)
|
|
|
|
return {row: row, column: 0};
|
2012-07-05 06:37:09 +00:00
|
|
|
if (lines.length > 0xFFFF) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var end = this._insertLines(row, lines.slice(0xFFFF));
|
2012-07-05 06:37:09 +00:00
|
|
|
lines = lines.slice(0, 0xFFFF);
|
|
|
|
}
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
var args = [row, 0];
|
|
|
|
args.push.apply(args, lines);
|
|
|
|
this.$lines.splice.apply(this.$lines, args);
|
|
|
|
|
|
|
|
var range = new Range(row, 0, row + lines.length, 0);
|
|
|
|
var delta = {
|
|
|
|
action: "insertLines",
|
|
|
|
range: range,
|
|
|
|
lines: lines
|
|
|
|
};
|
|
|
|
this._emit("change", { data: delta });
|
2012-07-05 06:37:09 +00:00
|
|
|
return end || range.end;
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
|
|
|
this.insertNewLine = function(position) {
|
|
|
|
position = this.$clipPosition(position);
|
|
|
|
var line = this.$lines[position.row] || "";
|
|
|
|
|
|
|
|
this.$lines[position.row] = line.substring(0, position.column);
|
|
|
|
this.$lines.splice(position.row + 1, 0, line.substring(position.column, line.length));
|
|
|
|
|
|
|
|
var end = {
|
|
|
|
row : position.row + 1,
|
|
|
|
column : 0
|
|
|
|
};
|
|
|
|
|
|
|
|
var delta = {
|
|
|
|
action: "insertText",
|
|
|
|
range: Range.fromPoints(position, end),
|
|
|
|
text: this.getNewLineCharacter()
|
|
|
|
};
|
|
|
|
this._emit("change", { data: delta });
|
|
|
|
|
|
|
|
return end;
|
|
|
|
};
|
|
|
|
this.insertInLine = function(position, text) {
|
|
|
|
if (text.length == 0)
|
|
|
|
return position;
|
|
|
|
|
|
|
|
var line = this.$lines[position.row] || "";
|
|
|
|
|
|
|
|
this.$lines[position.row] = line.substring(0, position.column) + text
|
|
|
|
+ line.substring(position.column);
|
|
|
|
|
|
|
|
var end = {
|
|
|
|
row : position.row,
|
|
|
|
column : position.column + text.length
|
|
|
|
};
|
|
|
|
|
|
|
|
var delta = {
|
|
|
|
action: "insertText",
|
|
|
|
range: Range.fromPoints(position, end),
|
|
|
|
text: text
|
|
|
|
};
|
|
|
|
this._emit("change", { data: delta });
|
|
|
|
|
|
|
|
return end;
|
|
|
|
};
|
|
|
|
this.remove = function(range) {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (!range instanceof Range)
|
|
|
|
range = Range.fromPoints(range.start, range.end);
|
2012-02-06 20:59:17 +00:00
|
|
|
range.start = this.$clipPosition(range.start);
|
|
|
|
range.end = this.$clipPosition(range.end);
|
|
|
|
|
|
|
|
if (range.isEmpty())
|
|
|
|
return range.start;
|
|
|
|
|
|
|
|
var firstRow = range.start.row;
|
|
|
|
var lastRow = range.end.row;
|
|
|
|
|
|
|
|
if (range.isMultiLine()) {
|
|
|
|
var firstFullRow = range.start.column == 0 ? firstRow : firstRow + 1;
|
|
|
|
var lastFullRow = lastRow - 1;
|
|
|
|
|
|
|
|
if (range.end.column > 0)
|
|
|
|
this.removeInLine(lastRow, 0, range.end.column);
|
|
|
|
|
|
|
|
if (lastFullRow >= firstFullRow)
|
2013-12-30 15:00:16 +00:00
|
|
|
this._removeLines(firstFullRow, lastFullRow);
|
2012-02-06 20:59:17 +00:00
|
|
|
|
|
|
|
if (firstFullRow != firstRow) {
|
|
|
|
this.removeInLine(firstRow, range.start.column, this.getLine(firstRow).length);
|
|
|
|
this.removeNewLine(range.start.row);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.removeInLine(firstRow, range.start.column, range.end.column);
|
|
|
|
}
|
|
|
|
return range.start;
|
|
|
|
};
|
|
|
|
this.removeInLine = function(row, startColumn, endColumn) {
|
|
|
|
if (startColumn == endColumn)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var range = new Range(row, startColumn, row, endColumn);
|
|
|
|
var line = this.getLine(row);
|
|
|
|
var removed = line.substring(startColumn, endColumn);
|
|
|
|
var newLine = line.substring(0, startColumn) + line.substring(endColumn, line.length);
|
|
|
|
this.$lines.splice(row, 1, newLine);
|
|
|
|
|
|
|
|
var delta = {
|
|
|
|
action: "removeText",
|
|
|
|
range: range,
|
|
|
|
text: removed
|
|
|
|
};
|
|
|
|
this._emit("change", { data: delta });
|
|
|
|
return range.start;
|
|
|
|
};
|
|
|
|
this.removeLines = function(firstRow, lastRow) {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (firstRow < 0 || lastRow >= this.getLength())
|
|
|
|
return this.remove(new Range(firstRow, 0, lastRow + 1, 0));
|
|
|
|
return this._removeLines(firstRow, lastRow);
|
|
|
|
};
|
|
|
|
|
|
|
|
this._removeLines = function(firstRow, lastRow) {
|
2012-02-06 20:59:17 +00:00
|
|
|
var range = new Range(firstRow, 0, lastRow + 1, 0);
|
|
|
|
var removed = this.$lines.splice(firstRow, lastRow - firstRow + 1);
|
|
|
|
|
|
|
|
var delta = {
|
|
|
|
action: "removeLines",
|
|
|
|
range: range,
|
|
|
|
nl: this.getNewLineCharacter(),
|
|
|
|
lines: removed
|
|
|
|
};
|
|
|
|
this._emit("change", { data: delta });
|
|
|
|
return removed;
|
|
|
|
};
|
|
|
|
this.removeNewLine = function(row) {
|
|
|
|
var firstLine = this.getLine(row);
|
|
|
|
var secondLine = this.getLine(row+1);
|
|
|
|
|
|
|
|
var range = new Range(row, firstLine.length, row+1, 0);
|
|
|
|
var line = firstLine + secondLine;
|
|
|
|
|
|
|
|
this.$lines.splice(row, 2, line);
|
|
|
|
|
|
|
|
var delta = {
|
|
|
|
action: "removeText",
|
|
|
|
range: range,
|
|
|
|
text: this.getNewLineCharacter()
|
|
|
|
};
|
|
|
|
this._emit("change", { data: delta });
|
|
|
|
};
|
|
|
|
this.replace = function(range, text) {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (!range instanceof Range)
|
|
|
|
range = Range.fromPoints(range.start, range.end);
|
2012-02-06 20:59:17 +00:00
|
|
|
if (text.length == 0 && range.isEmpty())
|
|
|
|
return range.start;
|
2013-12-30 15:00:16 +00:00
|
|
|
if (text == this.getTextRange(range))
|
|
|
|
return range.end;
|
|
|
|
|
|
|
|
this.remove(range);
|
|
|
|
if (text) {
|
|
|
|
var end = this.insert(range.start, text);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
end = range.start;
|
|
|
|
}
|
|
|
|
|
|
|
|
return end;
|
|
|
|
};
|
|
|
|
this.applyDeltas = function(deltas) {
|
|
|
|
for (var i=0; i<deltas.length; i++) {
|
|
|
|
var delta = deltas[i];
|
|
|
|
var range = Range.fromPoints(delta.range.start, delta.range.end);
|
|
|
|
|
|
|
|
if (delta.action == "insertLines")
|
|
|
|
this.insertLines(range.start.row, delta.lines);
|
|
|
|
else if (delta.action == "insertText")
|
|
|
|
this.insert(range.start, delta.text);
|
|
|
|
else if (delta.action == "removeLines")
|
|
|
|
this._removeLines(range.start.row, range.end.row - 1);
|
|
|
|
else if (delta.action == "removeText")
|
|
|
|
this.remove(range);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
this.revertDeltas = function(deltas) {
|
|
|
|
for (var i=deltas.length-1; i>=0; i--) {
|
|
|
|
var delta = deltas[i];
|
|
|
|
|
|
|
|
var range = Range.fromPoints(delta.range.start, delta.range.end);
|
|
|
|
|
|
|
|
if (delta.action == "insertLines")
|
|
|
|
this._removeLines(range.start.row, range.end.row - 1);
|
|
|
|
else if (delta.action == "insertText")
|
|
|
|
this.remove(range);
|
|
|
|
else if (delta.action == "removeLines")
|
|
|
|
this._insertLines(range.start.row, delta.lines);
|
|
|
|
else if (delta.action == "removeText")
|
|
|
|
this.insert(range.start, delta.text);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
this.indexToPosition = function(index, startRow) {
|
|
|
|
var lines = this.$lines || this.getAllLines();
|
|
|
|
var newlineLength = this.getNewLineCharacter().length;
|
|
|
|
for (var i = startRow || 0, l = lines.length; i < l; i++) {
|
|
|
|
index -= lines[i].length + newlineLength;
|
|
|
|
if (index < 0)
|
|
|
|
return {row: i, column: index + lines[i].length + newlineLength};
|
|
|
|
}
|
|
|
|
return {row: l-1, column: lines[l-1].length};
|
|
|
|
};
|
|
|
|
this.positionToIndex = function(pos, startRow) {
|
|
|
|
var lines = this.$lines || this.getAllLines();
|
|
|
|
var newlineLength = this.getNewLineCharacter().length;
|
|
|
|
var index = 0;
|
|
|
|
var row = Math.min(pos.row, lines.length);
|
|
|
|
for (var i = startRow || 0; i < row; ++i)
|
|
|
|
index += lines[i].length + newlineLength;
|
|
|
|
|
|
|
|
return index + pos.column;
|
|
|
|
};
|
|
|
|
|
|
|
|
}).call(Document.prototype);
|
|
|
|
|
|
|
|
exports.Document = Document;
|
|
|
|
});
|
|
|
|
|
|
|
|
define('ace/lib/event_emitter', ['require', 'exports', 'module' ], function(require, exports, module) {
|
|
|
|
|
|
|
|
|
|
|
|
var EventEmitter = {};
|
|
|
|
var stopPropagation = function() { this.propagationStopped = true; };
|
|
|
|
var preventDefault = function() { this.defaultPrevented = true; };
|
|
|
|
|
|
|
|
EventEmitter._emit =
|
|
|
|
EventEmitter._dispatchEvent = function(eventName, e) {
|
|
|
|
this._eventRegistry || (this._eventRegistry = {});
|
|
|
|
this._defaultHandlers || (this._defaultHandlers = {});
|
|
|
|
|
|
|
|
var listeners = this._eventRegistry[eventName] || [];
|
|
|
|
var defaultHandler = this._defaultHandlers[eventName];
|
|
|
|
if (!listeners.length && !defaultHandler)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (typeof e != "object" || !e)
|
|
|
|
e = {};
|
|
|
|
|
|
|
|
if (!e.type)
|
|
|
|
e.type = eventName;
|
|
|
|
if (!e.stopPropagation)
|
|
|
|
e.stopPropagation = stopPropagation;
|
|
|
|
if (!e.preventDefault)
|
|
|
|
e.preventDefault = preventDefault;
|
|
|
|
|
|
|
|
listeners = listeners.slice();
|
|
|
|
for (var i=0; i<listeners.length; i++) {
|
|
|
|
listeners[i](e, this);
|
|
|
|
if (e.propagationStopped)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defaultHandler && !e.defaultPrevented)
|
|
|
|
return defaultHandler(e, this);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
EventEmitter._signal = function(eventName, e) {
|
|
|
|
var listeners = (this._eventRegistry || {})[eventName];
|
|
|
|
if (!listeners)
|
|
|
|
return;
|
|
|
|
listeners = listeners.slice();
|
|
|
|
for (var i=0; i<listeners.length; i++)
|
|
|
|
listeners[i](e, this);
|
|
|
|
};
|
|
|
|
|
|
|
|
EventEmitter.once = function(eventName, callback) {
|
|
|
|
var _self = this;
|
|
|
|
callback && this.addEventListener(eventName, function newCallback() {
|
|
|
|
_self.removeEventListener(eventName, newCallback);
|
|
|
|
callback.apply(null, arguments);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
EventEmitter.setDefaultHandler = function(eventName, callback) {
|
|
|
|
var handlers = this._defaultHandlers
|
|
|
|
if (!handlers)
|
|
|
|
handlers = this._defaultHandlers = {_disabled_: {}};
|
|
|
|
|
|
|
|
if (handlers[eventName]) {
|
|
|
|
var old = handlers[eventName];
|
|
|
|
var disabled = handlers._disabled_[eventName];
|
|
|
|
if (!disabled)
|
|
|
|
handlers._disabled_[eventName] = disabled = [];
|
|
|
|
disabled.push(old);
|
|
|
|
var i = disabled.indexOf(callback);
|
|
|
|
if (i != -1)
|
|
|
|
disabled.splice(i, 1);
|
|
|
|
}
|
|
|
|
handlers[eventName] = callback;
|
|
|
|
};
|
|
|
|
EventEmitter.removeDefaultHandler = function(eventName, callback) {
|
|
|
|
var handlers = this._defaultHandlers
|
|
|
|
if (!handlers)
|
|
|
|
return;
|
|
|
|
var disabled = handlers._disabled_[eventName];
|
|
|
|
|
|
|
|
if (handlers[eventName] == callback) {
|
|
|
|
var old = handlers[eventName];
|
|
|
|
if (disabled)
|
|
|
|
this.setDefaultHandler(eventName, disabled.pop());
|
|
|
|
} else if (disabled) {
|
|
|
|
var i = disabled.indexOf(callback);
|
|
|
|
if (i != -1)
|
|
|
|
disabled.splice(i, 1);
|
|
|
|
}
|
|
|
|
};
|
2012-02-06 20:59:17 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
EventEmitter.on =
|
|
|
|
EventEmitter.addEventListener = function(eventName, callback, capturing) {
|
|
|
|
this._eventRegistry = this._eventRegistry || {};
|
2012-02-06 20:59:17 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
var listeners = this._eventRegistry[eventName];
|
|
|
|
if (!listeners)
|
|
|
|
listeners = this._eventRegistry[eventName] = [];
|
2012-02-06 20:59:17 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
if (listeners.indexOf(callback) == -1)
|
|
|
|
listeners[capturing ? "unshift" : "push"](callback);
|
|
|
|
return callback;
|
|
|
|
};
|
2012-02-06 20:59:17 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
EventEmitter.off =
|
|
|
|
EventEmitter.removeListener =
|
|
|
|
EventEmitter.removeEventListener = function(eventName, callback) {
|
|
|
|
this._eventRegistry = this._eventRegistry || {};
|
2012-02-06 20:59:17 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
var listeners = this._eventRegistry[eventName];
|
|
|
|
if (!listeners)
|
|
|
|
return;
|
2012-02-06 20:59:17 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
var index = listeners.indexOf(callback);
|
|
|
|
if (index !== -1)
|
|
|
|
listeners.splice(index, 1);
|
|
|
|
};
|
2012-02-06 20:59:17 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
EventEmitter.removeAllListeners = function(eventName) {
|
|
|
|
if (this._eventRegistry) this._eventRegistry[eventName] = [];
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.EventEmitter = EventEmitter;
|
2012-02-06 20:59:17 +00:00
|
|
|
|
|
|
|
});
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
define('ace/range', ['require', 'exports', 'module' ], function(require, exports, module) {
|
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
var comparePoints = function(p1, p2) {
|
|
|
|
return p1.row - p2.row || p1.column - p2.column;
|
|
|
|
};
|
2012-02-06 20:59:17 +00:00
|
|
|
var Range = function(startRow, startColumn, endRow, endColumn) {
|
|
|
|
this.start = {
|
|
|
|
row: startRow,
|
|
|
|
column: startColumn
|
|
|
|
};
|
|
|
|
|
|
|
|
this.end = {
|
|
|
|
row: endRow,
|
|
|
|
column: endColumn
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
(function() {
|
2012-07-05 06:37:09 +00:00
|
|
|
this.isEqual = function(range) {
|
2013-12-30 15:00:16 +00:00
|
|
|
return this.start.row === range.start.row &&
|
|
|
|
this.end.row === range.end.row &&
|
|
|
|
this.start.column === range.start.column &&
|
|
|
|
this.end.column === range.end.column;
|
|
|
|
};
|
2012-02-06 20:59:17 +00:00
|
|
|
this.toString = function() {
|
|
|
|
return ("Range: [" + this.start.row + "/" + this.start.column +
|
|
|
|
"] -> [" + this.end.row + "/" + this.end.column + "]");
|
2013-12-30 15:00:16 +00:00
|
|
|
};
|
2012-02-06 20:59:17 +00:00
|
|
|
|
|
|
|
this.contains = function(row, column) {
|
|
|
|
return this.compare(row, column) == 0;
|
2013-12-30 15:00:16 +00:00
|
|
|
};
|
2012-02-06 20:59:17 +00:00
|
|
|
this.compareRange = function(range) {
|
|
|
|
var cmp,
|
|
|
|
end = range.end,
|
|
|
|
start = range.start;
|
|
|
|
|
|
|
|
cmp = this.compare(end.row, end.column);
|
|
|
|
if (cmp == 1) {
|
|
|
|
cmp = this.compare(start.row, start.column);
|
|
|
|
if (cmp == 1) {
|
|
|
|
return 2;
|
|
|
|
} else if (cmp == 0) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} else if (cmp == -1) {
|
|
|
|
return -2;
|
|
|
|
} else {
|
|
|
|
cmp = this.compare(start.row, start.column);
|
|
|
|
if (cmp == -1) {
|
|
|
|
return -1;
|
|
|
|
} else if (cmp == 1) {
|
|
|
|
return 42;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
};
|
2012-02-06 20:59:17 +00:00
|
|
|
this.comparePoint = function(p) {
|
|
|
|
return this.compare(p.row, p.column);
|
2013-12-30 15:00:16 +00:00
|
|
|
};
|
2012-02-06 20:59:17 +00:00
|
|
|
this.containsRange = function(range) {
|
|
|
|
return this.comparePoint(range.start) == 0 && this.comparePoint(range.end) == 0;
|
2013-12-30 15:00:16 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
this.intersects = function(range) {
|
|
|
|
var cmp = this.compareRange(range);
|
|
|
|
return (cmp == -1 || cmp == 0 || cmp == 1);
|
2013-12-30 15:00:16 +00:00
|
|
|
};
|
2012-02-06 20:59:17 +00:00
|
|
|
this.isEnd = function(row, column) {
|
|
|
|
return this.end.row == row && this.end.column == column;
|
2013-12-30 15:00:16 +00:00
|
|
|
};
|
2012-02-06 20:59:17 +00:00
|
|
|
this.isStart = function(row, column) {
|
|
|
|
return this.start.row == row && this.start.column == column;
|
2013-12-30 15:00:16 +00:00
|
|
|
};
|
2012-02-06 20:59:17 +00:00
|
|
|
this.setStart = function(row, column) {
|
|
|
|
if (typeof row == "object") {
|
|
|
|
this.start.column = row.column;
|
|
|
|
this.start.row = row.row;
|
|
|
|
} else {
|
|
|
|
this.start.row = row;
|
|
|
|
this.start.column = column;
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
};
|
2012-02-06 20:59:17 +00:00
|
|
|
this.setEnd = function(row, column) {
|
|
|
|
if (typeof row == "object") {
|
|
|
|
this.end.column = row.column;
|
|
|
|
this.end.row = row.row;
|
|
|
|
} else {
|
|
|
|
this.end.row = row;
|
|
|
|
this.end.column = column;
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
};
|
2012-02-06 20:59:17 +00:00
|
|
|
this.inside = function(row, column) {
|
|
|
|
if (this.compare(row, column) == 0) {
|
|
|
|
if (this.isEnd(row, column) || this.isStart(row, column)) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2013-12-30 15:00:16 +00:00
|
|
|
};
|
2012-02-06 20:59:17 +00:00
|
|
|
this.insideStart = function(row, column) {
|
|
|
|
if (this.compare(row, column) == 0) {
|
|
|
|
if (this.isEnd(row, column)) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2013-12-30 15:00:16 +00:00
|
|
|
};
|
2012-02-06 20:59:17 +00:00
|
|
|
this.insideEnd = function(row, column) {
|
|
|
|
if (this.compare(row, column) == 0) {
|
|
|
|
if (this.isStart(row, column)) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2013-12-30 15:00:16 +00:00
|
|
|
};
|
2012-02-06 20:59:17 +00:00
|
|
|
this.compare = function(row, column) {
|
|
|
|
if (!this.isMultiLine()) {
|
|
|
|
if (row === this.start.row) {
|
|
|
|
return column < this.start.column ? -1 : (column > this.end.column ? 1 : 0);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (row < this.start.row)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (row > this.end.row)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (this.start.row === row)
|
|
|
|
return column >= this.start.column ? 0 : -1;
|
|
|
|
|
|
|
|
if (this.end.row === row)
|
|
|
|
return column <= this.end.column ? 0 : 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
this.compareStart = function(row, column) {
|
|
|
|
if (this.start.row == row && this.start.column == column) {
|
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
return this.compare(row, column);
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
};
|
2012-02-06 20:59:17 +00:00
|
|
|
this.compareEnd = function(row, column) {
|
|
|
|
if (this.end.row == row && this.end.column == column) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return this.compare(row, column);
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
};
|
2012-02-06 20:59:17 +00:00
|
|
|
this.compareInside = function(row, column) {
|
|
|
|
if (this.end.row == row && this.end.column == column) {
|
|
|
|
return 1;
|
|
|
|
} else if (this.start.row == row && this.start.column == column) {
|
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
return this.compare(row, column);
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
};
|
2012-02-06 20:59:17 +00:00
|
|
|
this.clipRows = function(firstRow, lastRow) {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (this.end.row > lastRow)
|
|
|
|
var end = {row: lastRow + 1, column: 0};
|
|
|
|
else if (this.end.row < firstRow)
|
|
|
|
var end = {row: firstRow, column: 0};
|
2012-02-06 20:59:17 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
if (this.start.row > lastRow)
|
|
|
|
var start = {row: lastRow + 1, column: 0};
|
|
|
|
else if (this.start.row < firstRow)
|
|
|
|
var start = {row: firstRow, column: 0};
|
2012-02-06 20:59:17 +00:00
|
|
|
|
|
|
|
return Range.fromPoints(start || this.start, end || this.end);
|
|
|
|
};
|
|
|
|
this.extend = function(row, column) {
|
|
|
|
var cmp = this.compare(row, column);
|
|
|
|
|
|
|
|
if (cmp == 0)
|
|
|
|
return this;
|
|
|
|
else if (cmp == -1)
|
|
|
|
var start = {row: row, column: column};
|
|
|
|
else
|
|
|
|
var end = {row: row, column: column};
|
|
|
|
|
|
|
|
return Range.fromPoints(start || this.start, end || this.end);
|
|
|
|
};
|
|
|
|
|
|
|
|
this.isEmpty = function() {
|
2013-12-30 15:00:16 +00:00
|
|
|
return (this.start.row === this.end.row && this.start.column === this.end.column);
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
|
|
|
this.isMultiLine = function() {
|
|
|
|
return (this.start.row !== this.end.row);
|
|
|
|
};
|
|
|
|
this.clone = function() {
|
|
|
|
return Range.fromPoints(this.start, this.end);
|
|
|
|
};
|
|
|
|
this.collapseRows = function() {
|
|
|
|
if (this.end.column == 0)
|
|
|
|
return new Range(this.start.row, 0, Math.max(this.start.row, this.end.row-1), 0)
|
|
|
|
else
|
|
|
|
return new Range(this.start.row, 0, this.end.row, 0)
|
|
|
|
};
|
|
|
|
this.toScreenRange = function(session) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var screenPosStart = session.documentToScreenPosition(this.start);
|
|
|
|
var screenPosEnd = session.documentToScreenPosition(this.end);
|
2012-02-06 20:59:17 +00:00
|
|
|
|
|
|
|
return new Range(
|
|
|
|
screenPosStart.row, screenPosStart.column,
|
|
|
|
screenPosEnd.row, screenPosEnd.column
|
|
|
|
);
|
|
|
|
};
|
2013-12-30 15:00:16 +00:00
|
|
|
this.moveBy = function(row, column) {
|
|
|
|
this.start.row += row;
|
|
|
|
this.start.column += column;
|
|
|
|
this.end.row += row;
|
|
|
|
this.end.column += column;
|
|
|
|
};
|
2012-02-06 20:59:17 +00:00
|
|
|
|
|
|
|
}).call(Range.prototype);
|
|
|
|
Range.fromPoints = function(start, end) {
|
|
|
|
return new Range(start.row, start.column, end.row, end.column);
|
|
|
|
};
|
2013-12-30 15:00:16 +00:00
|
|
|
Range.comparePoints = comparePoints;
|
|
|
|
|
|
|
|
Range.comparePoints = function(p1, p2) {
|
|
|
|
return p1.row - p2.row || p1.column - p2.column;
|
|
|
|
};
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
|
|
|
|
exports.Range = Range;
|
|
|
|
});
|
|
|
|
|
|
|
|
define('ace/anchor', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/event_emitter'], function(require, exports, module) {
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
|
|
|
|
var oop = require("./lib/oop");
|
|
|
|
var EventEmitter = require("./lib/event_emitter").EventEmitter;
|
|
|
|
|
|
|
|
var Anchor = exports.Anchor = function(doc, row, column) {
|
2013-12-30 15:00:16 +00:00
|
|
|
this.$onChange = this.onChange.bind(this);
|
|
|
|
this.attach(doc);
|
2012-02-06 20:59:17 +00:00
|
|
|
|
|
|
|
if (typeof column == "undefined")
|
|
|
|
this.setPosition(row.row, row.column);
|
|
|
|
else
|
|
|
|
this.setPosition(row, column);
|
|
|
|
};
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
|
|
|
oop.implement(this, EventEmitter);
|
|
|
|
this.getPosition = function() {
|
|
|
|
return this.$clipPositionToDocument(this.row, this.column);
|
|
|
|
};
|
|
|
|
this.getDocument = function() {
|
|
|
|
return this.document;
|
|
|
|
};
|
2013-12-30 15:00:16 +00:00
|
|
|
this.$insertRight = false;
|
2012-02-06 20:59:17 +00:00
|
|
|
this.onChange = function(e) {
|
|
|
|
var delta = e.data;
|
|
|
|
var range = delta.range;
|
2013-12-30 15:00:16 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
if (range.start.row == range.end.row && range.start.row != this.row)
|
|
|
|
return;
|
2013-12-30 15:00:16 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
if (range.start.row > this.row)
|
|
|
|
return;
|
2013-12-30 15:00:16 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
if (range.start.row == this.row && range.start.column > this.column)
|
|
|
|
return;
|
2013-12-30 15:00:16 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
var row = this.row;
|
|
|
|
var column = this.column;
|
2013-12-30 15:00:16 +00:00
|
|
|
var start = range.start;
|
|
|
|
var end = range.end;
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
if (delta.action === "insertText") {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (start.row === row && start.column <= column) {
|
|
|
|
if (start.column === column && this.$insertRight) {
|
|
|
|
} else if (start.row === end.row) {
|
|
|
|
column += end.column - start.column;
|
|
|
|
} else {
|
|
|
|
column -= start.column;
|
|
|
|
row += end.row - start.row;
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
} else if (start.row !== end.row && start.row < row) {
|
|
|
|
row += end.row - start.row;
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
} else if (delta.action === "insertLines") {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (start.row <= row) {
|
|
|
|
row += end.row - start.row;
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
} else if (delta.action === "removeText") {
|
|
|
|
if (start.row === row && start.column < column) {
|
|
|
|
if (end.column >= column)
|
|
|
|
column = start.column;
|
2012-02-06 20:59:17 +00:00
|
|
|
else
|
2013-12-30 15:00:16 +00:00
|
|
|
column = Math.max(0, column - (end.column - start.column));
|
|
|
|
|
|
|
|
} else if (start.row !== end.row && start.row < row) {
|
|
|
|
if (end.row === row)
|
|
|
|
column = Math.max(0, column - end.column) + start.column;
|
|
|
|
row -= (end.row - start.row);
|
|
|
|
} else if (end.row === row) {
|
|
|
|
row -= end.row - start.row;
|
|
|
|
column = Math.max(0, column - end.column) + start.column;
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
} else if (delta.action == "removeLines") {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (start.row <= row) {
|
|
|
|
if (end.row <= row)
|
|
|
|
row -= end.row - start.row;
|
2012-02-06 20:59:17 +00:00
|
|
|
else {
|
2013-12-30 15:00:16 +00:00
|
|
|
row = start.row;
|
2012-02-06 20:59:17 +00:00
|
|
|
column = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setPosition(row, column, true);
|
|
|
|
};
|
|
|
|
this.setPosition = function(row, column, noClip) {
|
|
|
|
var pos;
|
|
|
|
if (noClip) {
|
|
|
|
pos = {
|
|
|
|
row: row,
|
|
|
|
column: column
|
|
|
|
};
|
2013-12-30 15:00:16 +00:00
|
|
|
} else {
|
2012-02-06 20:59:17 +00:00
|
|
|
pos = this.$clipPositionToDocument(row, column);
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
if (this.row == pos.row && this.column == pos.column)
|
|
|
|
return;
|
2013-12-30 15:00:16 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
var old = {
|
|
|
|
row: this.row,
|
|
|
|
column: this.column
|
|
|
|
};
|
2013-12-30 15:00:16 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
this.row = pos.row;
|
|
|
|
this.column = pos.column;
|
|
|
|
this._emit("change", {
|
|
|
|
old: old,
|
|
|
|
value: pos
|
|
|
|
});
|
|
|
|
};
|
|
|
|
this.detach = function() {
|
|
|
|
this.document.removeEventListener("change", this.$onChange);
|
|
|
|
};
|
2013-12-30 15:00:16 +00:00
|
|
|
this.attach = function(doc) {
|
|
|
|
this.document = doc || this.document;
|
|
|
|
this.document.on("change", this.$onChange);
|
|
|
|
};
|
2012-02-06 20:59:17 +00:00
|
|
|
this.$clipPositionToDocument = function(row, column) {
|
|
|
|
var pos = {};
|
2013-12-30 15:00:16 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
if (row >= this.document.getLength()) {
|
|
|
|
pos.row = Math.max(0, this.document.getLength() - 1);
|
|
|
|
pos.column = this.document.getLine(pos.row).length;
|
|
|
|
}
|
|
|
|
else if (row < 0) {
|
|
|
|
pos.row = 0;
|
|
|
|
pos.column = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pos.row = row;
|
|
|
|
pos.column = Math.min(this.document.getLine(pos.row).length, Math.max(0, column));
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
if (column < 0)
|
|
|
|
pos.column = 0;
|
2013-12-30 15:00:16 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
return pos;
|
|
|
|
};
|
2013-12-30 15:00:16 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
}).call(Anchor.prototype);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
define('ace/lib/lang', ['require', 'exports', 'module' ], function(require, exports, module) {
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
|
|
|
|
exports.stringReverse = function(string) {
|
|
|
|
return string.split("").reverse().join("");
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.stringRepeat = function (string, count) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var result = '';
|
|
|
|
while (count > 0) {
|
|
|
|
if (count & 1)
|
|
|
|
result += string;
|
|
|
|
|
|
|
|
if (count >>= 1)
|
|
|
|
string += string;
|
|
|
|
}
|
|
|
|
return result;
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
var trimBeginRegexp = /^\s\s*/;
|
|
|
|
var trimEndRegexp = /\s\s*$/;
|
|
|
|
|
|
|
|
exports.stringTrimLeft = function (string) {
|
|
|
|
return string.replace(trimBeginRegexp, '');
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.stringTrimRight = function (string) {
|
|
|
|
return string.replace(trimEndRegexp, '');
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.copyObject = function(obj) {
|
|
|
|
var copy = {};
|
|
|
|
for (var key in obj) {
|
|
|
|
copy[key] = obj[key];
|
|
|
|
}
|
|
|
|
return copy;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.copyArray = function(array){
|
|
|
|
var copy = [];
|
|
|
|
for (var i=0, l=array.length; i<l; i++) {
|
|
|
|
if (array[i] && typeof array[i] == "object")
|
|
|
|
copy[i] = this.copyObject( array[i] );
|
|
|
|
else
|
|
|
|
copy[i] = array[i];
|
|
|
|
}
|
|
|
|
return copy;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.deepCopy = function (obj) {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (typeof obj !== "object" || !obj)
|
|
|
|
return obj;
|
|
|
|
var cons = obj.constructor;
|
|
|
|
if (cons === RegExp)
|
2012-02-06 20:59:17 +00:00
|
|
|
return obj;
|
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
var copy = cons();
|
2012-02-06 20:59:17 +00:00
|
|
|
for (var key in obj) {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (typeof obj[key] === "object") {
|
|
|
|
copy[key] = exports.deepCopy(obj[key]);
|
2012-02-06 20:59:17 +00:00
|
|
|
} else {
|
|
|
|
copy[key] = obj[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return copy;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.arrayToMap = function(arr) {
|
|
|
|
var map = {};
|
|
|
|
for (var i=0; i<arr.length; i++) {
|
|
|
|
map[arr[i]] = 1;
|
|
|
|
}
|
|
|
|
return map;
|
|
|
|
|
|
|
|
};
|
2013-12-30 15:00:16 +00:00
|
|
|
|
|
|
|
exports.createMap = function(props) {
|
|
|
|
var map = Object.create(null);
|
|
|
|
for (var i in props) {
|
|
|
|
map[i] = props[i];
|
|
|
|
}
|
|
|
|
return map;
|
|
|
|
};
|
2012-02-06 20:59:17 +00:00
|
|
|
exports.arrayRemove = function(array, value) {
|
|
|
|
for (var i = 0; i <= array.length; i++) {
|
|
|
|
if (value === array[i]) {
|
|
|
|
array.splice(i, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.escapeRegExp = function(str) {
|
|
|
|
return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1');
|
|
|
|
};
|
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
exports.escapeHTML = function(str) {
|
|
|
|
return str.replace(/&/g, "&").replace(/"/g, """).replace(/'/g, "'").replace(/</g, "<");
|
|
|
|
};
|
|
|
|
|
2012-07-05 06:37:09 +00:00
|
|
|
exports.getMatchOffsets = function(string, regExp) {
|
|
|
|
var matches = [];
|
|
|
|
|
|
|
|
string.replace(regExp, function(str) {
|
|
|
|
matches.push({
|
|
|
|
offset: arguments[arguments.length-2],
|
|
|
|
length: str.length
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return matches;
|
|
|
|
};
|
2012-02-06 20:59:17 +00:00
|
|
|
exports.deferredCall = function(fcn) {
|
|
|
|
|
|
|
|
var timer = null;
|
|
|
|
var callback = function() {
|
|
|
|
timer = null;
|
|
|
|
fcn();
|
|
|
|
};
|
|
|
|
|
|
|
|
var deferred = function(timeout) {
|
|
|
|
deferred.cancel();
|
|
|
|
timer = setTimeout(callback, timeout || 0);
|
|
|
|
return deferred;
|
|
|
|
};
|
|
|
|
|
|
|
|
deferred.schedule = deferred;
|
|
|
|
|
|
|
|
deferred.call = function() {
|
|
|
|
this.cancel();
|
|
|
|
fcn();
|
|
|
|
return deferred;
|
|
|
|
};
|
|
|
|
|
|
|
|
deferred.cancel = function() {
|
|
|
|
clearTimeout(timer);
|
|
|
|
timer = null;
|
|
|
|
return deferred;
|
|
|
|
};
|
2013-12-30 15:00:16 +00:00
|
|
|
|
|
|
|
deferred.isPending = function() {
|
|
|
|
return timer;
|
|
|
|
};
|
2012-02-06 20:59:17 +00:00
|
|
|
|
|
|
|
return deferred;
|
|
|
|
};
|
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
|
|
|
|
exports.delayedCall = function(fcn, defaultTimeout) {
|
|
|
|
var timer = null;
|
|
|
|
var callback = function() {
|
|
|
|
timer = null;
|
|
|
|
fcn();
|
|
|
|
};
|
|
|
|
|
|
|
|
var _self = function(timeout) {
|
|
|
|
if (timer == null)
|
|
|
|
timer = setTimeout(callback, timeout || defaultTimeout);
|
|
|
|
};
|
|
|
|
|
|
|
|
_self.delay = function(timeout) {
|
|
|
|
timer && clearTimeout(timer);
|
|
|
|
timer = setTimeout(callback, timeout || defaultTimeout);
|
|
|
|
};
|
|
|
|
_self.schedule = _self;
|
|
|
|
|
|
|
|
_self.call = function() {
|
|
|
|
this.cancel();
|
|
|
|
fcn();
|
|
|
|
};
|
|
|
|
|
|
|
|
_self.cancel = function() {
|
|
|
|
timer && clearTimeout(timer);
|
|
|
|
timer = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
_self.isPending = function() {
|
|
|
|
return timer;
|
|
|
|
};
|
|
|
|
|
|
|
|
return _self;
|
|
|
|
};
|
2012-02-06 20:59:17 +00:00
|
|
|
});
|
2013-12-30 15:00:16 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
define('ace/mode/coffee/coffee-script', ['require', 'exports', 'module' , 'ace/mode/coffee/lexer', 'ace/mode/coffee/parser', 'ace/mode/coffee/nodes'], function(require, exports, module) {
|
2013-12-30 15:00:16 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
var Lexer = require("./lexer").Lexer;
|
|
|
|
var parser = require("./parser");
|
|
|
|
|
|
|
|
var lexer = new Lexer();
|
|
|
|
parser.lexer = {
|
|
|
|
lex: function() {
|
2013-12-30 15:00:16 +00:00
|
|
|
var tag, token;
|
|
|
|
token = this.tokens[this.pos++];
|
|
|
|
if (token) {
|
|
|
|
tag = token[0], this.yytext = token[1], this.yylloc = token[2];
|
|
|
|
this.yylineno = this.yylloc.first_line;
|
|
|
|
} else {
|
|
|
|
tag = '';
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
return tag;
|
|
|
|
},
|
|
|
|
setInput: function(tokens) {
|
|
|
|
this.tokens = tokens;
|
|
|
|
return this.pos = 0;
|
|
|
|
},
|
|
|
|
upcomingInput: function() {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
parser.yy = require('./nodes');
|
2013-12-30 15:00:16 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
exports.parse = function(code) {
|
|
|
|
return parser.parse(lexer.tokenize(code));
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
});
|
2012-02-06 20:59:17 +00:00
|
|
|
|
|
|
|
define('ace/mode/coffee/lexer', ['require', 'exports', 'module' , 'ace/mode/coffee/rewriter', 'ace/mode/coffee/helpers'], function(require, exports, module) {
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
var BOM, BOOL, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_ALIAS_MAP, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, HEREDOC, HEREDOC_ILLEGAL, HEREDOC_INDENT, HEREGEX, HEREGEX_OMIT, IDENTIFIER, INDEXABLE, INVERSES, JSTOKEN, JS_FORBIDDEN, JS_KEYWORDS, LINE_BREAK, LINE_CONTINUER, LOGIC, Lexer, MATH, MULTILINER, MULTI_DENT, NOT_REGEX, NOT_SPACED_REGEX, NUMBER, OPERATOR, REGEX, RELATION, RESERVED, Rewriter, SHIFT, SIMPLESTR, STRICT_PROSCRIBED, TRAILING_SPACES, UNARY, WHITESPACE, compact, count, invertLiterate, key, last, locationDataToString, repeat, starts, throwSyntaxError, _ref, _ref1,
|
2012-07-05 06:37:09 +00:00
|
|
|
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
|
|
|
|
|
|
|
_ref = require('./rewriter'), Rewriter = _ref.Rewriter, INVERSES = _ref.INVERSES;
|
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
_ref1 = require('./helpers'), count = _ref1.count, starts = _ref1.starts, compact = _ref1.compact, last = _ref1.last, repeat = _ref1.repeat, invertLiterate = _ref1.invertLiterate, locationDataToString = _ref1.locationDataToString, throwSyntaxError = _ref1.throwSyntaxError;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
exports.Lexer = Lexer = (function() {
|
|
|
|
function Lexer() {}
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Lexer.prototype.tokenize = function(code, opts) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var consumed, i, tag, _ref2;
|
|
|
|
if (opts == null) {
|
|
|
|
opts = {};
|
|
|
|
}
|
|
|
|
this.literate = opts.literate;
|
2012-02-06 20:59:17 +00:00
|
|
|
this.indent = 0;
|
2013-12-30 15:00:16 +00:00
|
|
|
this.baseIndent = 0;
|
2012-02-06 20:59:17 +00:00
|
|
|
this.indebt = 0;
|
|
|
|
this.outdebt = 0;
|
|
|
|
this.indents = [];
|
2012-07-05 06:37:09 +00:00
|
|
|
this.ends = [];
|
2012-02-06 20:59:17 +00:00
|
|
|
this.tokens = [];
|
2013-12-30 15:00:16 +00:00
|
|
|
this.chunkLine = opts.line || 0;
|
|
|
|
this.chunkColumn = opts.column || 0;
|
|
|
|
code = this.clean(code);
|
2012-02-06 20:59:17 +00:00
|
|
|
i = 0;
|
|
|
|
while (this.chunk = code.slice(i)) {
|
2013-12-30 15:00:16 +00:00
|
|
|
consumed = this.identifierToken() || this.commentToken() || this.whitespaceToken() || this.lineToken() || this.heredocToken() || this.stringToken() || this.numberToken() || this.regexToken() || this.jsToken() || this.literalToken();
|
|
|
|
_ref2 = this.getLineAndColumnFromChunk(consumed), this.chunkLine = _ref2[0], this.chunkColumn = _ref2[1];
|
|
|
|
i += consumed;
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
this.closeIndentation();
|
2013-12-30 15:00:16 +00:00
|
|
|
if (tag = this.ends.pop()) {
|
|
|
|
this.error("missing " + tag);
|
|
|
|
}
|
|
|
|
if (opts.rewrite === false) {
|
|
|
|
return this.tokens;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
return (new Rewriter).rewrite(this.tokens);
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
Lexer.prototype.clean = function(code) {
|
|
|
|
if (code.charCodeAt(0) === BOM) {
|
|
|
|
code = code.slice(1);
|
|
|
|
}
|
|
|
|
code = code.replace(/\r/g, '').replace(TRAILING_SPACES, '');
|
|
|
|
if (WHITESPACE.test(code)) {
|
|
|
|
code = "\n" + code;
|
|
|
|
this.chunkLine--;
|
|
|
|
}
|
|
|
|
if (this.literate) {
|
|
|
|
code = invertLiterate(code);
|
|
|
|
}
|
|
|
|
return code;
|
|
|
|
};
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Lexer.prototype.identifierToken = function() {
|
2013-12-30 15:00:16 +00:00
|
|
|
var colon, colonOffset, forcedIdentifier, id, idLength, input, match, poppedToken, prev, tag, tagToken, _ref2, _ref3, _ref4;
|
|
|
|
if (!(match = IDENTIFIER.exec(this.chunk))) {
|
|
|
|
return 0;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
input = match[0], id = match[1], colon = match[2];
|
2013-12-30 15:00:16 +00:00
|
|
|
idLength = id.length;
|
|
|
|
poppedToken = void 0;
|
2012-02-06 20:59:17 +00:00
|
|
|
if (id === 'own' && this.tag() === 'FOR') {
|
|
|
|
this.token('OWN', id);
|
|
|
|
return id.length;
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
forcedIdentifier = colon || (prev = last(this.tokens)) && (((_ref2 = prev[0]) === '.' || _ref2 === '?.' || _ref2 === '::' || _ref2 === '?::') || !prev.spaced && prev[0] === '@');
|
2012-02-06 20:59:17 +00:00
|
|
|
tag = 'IDENTIFIER';
|
2012-07-05 06:37:09 +00:00
|
|
|
if (!forcedIdentifier && (__indexOf.call(JS_KEYWORDS, id) >= 0 || __indexOf.call(COFFEE_KEYWORDS, id) >= 0)) {
|
2012-02-06 20:59:17 +00:00
|
|
|
tag = id.toUpperCase();
|
|
|
|
if (tag === 'WHEN' && (_ref3 = this.tag(), __indexOf.call(LINE_BREAK, _ref3) >= 0)) {
|
|
|
|
tag = 'LEADING_WHEN';
|
|
|
|
} else if (tag === 'FOR') {
|
|
|
|
this.seenFor = true;
|
|
|
|
} else if (tag === 'UNLESS') {
|
|
|
|
tag = 'IF';
|
|
|
|
} else if (__indexOf.call(UNARY, tag) >= 0) {
|
|
|
|
tag = 'UNARY';
|
|
|
|
} else if (__indexOf.call(RELATION, tag) >= 0) {
|
|
|
|
if (tag !== 'INSTANCEOF' && this.seenFor) {
|
|
|
|
tag = 'FOR' + tag;
|
|
|
|
this.seenFor = false;
|
|
|
|
} else {
|
|
|
|
tag = 'RELATION';
|
|
|
|
if (this.value() === '!') {
|
2013-12-30 15:00:16 +00:00
|
|
|
poppedToken = this.tokens.pop();
|
2012-02-06 20:59:17 +00:00
|
|
|
id = '!' + id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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) {
|
2012-07-05 06:37:09 +00:00
|
|
|
this.error("reserved word \"" + id + "\"");
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!forcedIdentifier) {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (__indexOf.call(COFFEE_ALIASES, id) >= 0) {
|
|
|
|
id = COFFEE_ALIAS_MAP[id];
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
tag = (function() {
|
|
|
|
switch (id) {
|
|
|
|
case '!':
|
|
|
|
return 'UNARY';
|
|
|
|
case '==':
|
|
|
|
case '!=':
|
|
|
|
return 'COMPARE';
|
|
|
|
case '&&':
|
|
|
|
case '||':
|
|
|
|
return 'LOGIC';
|
|
|
|
case 'true':
|
|
|
|
case 'false':
|
|
|
|
return 'BOOL';
|
|
|
|
case 'break':
|
|
|
|
case 'continue':
|
|
|
|
return 'STATEMENT';
|
|
|
|
default:
|
|
|
|
return tag;
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
tagToken = this.token(tag, id, 0, idLength);
|
|
|
|
if (poppedToken) {
|
|
|
|
_ref4 = [poppedToken[2].first_line, poppedToken[2].first_column], tagToken[2].first_line = _ref4[0], tagToken[2].first_column = _ref4[1];
|
|
|
|
}
|
|
|
|
if (colon) {
|
|
|
|
colonOffset = input.lastIndexOf(':');
|
|
|
|
this.token(':', ':', colonOffset, colon.length);
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
return input.length;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Lexer.prototype.numberToken = function() {
|
2012-07-05 06:37:09 +00:00
|
|
|
var binaryLiteral, lexedLength, match, number, octalLiteral;
|
2013-12-30 15:00:16 +00:00
|
|
|
if (!(match = NUMBER.exec(this.chunk))) {
|
|
|
|
return 0;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
number = match[0];
|
2013-12-30 15:00:16 +00:00
|
|
|
if (/^0[BOX]/.test(number)) {
|
2012-07-05 06:37:09 +00:00
|
|
|
this.error("radix prefix '" + number + "' must be lowercase");
|
2013-12-30 15:00:16 +00:00
|
|
|
} else if (/E/.test(number) && !/^0x/.test(number)) {
|
|
|
|
this.error("exponential notation '" + number + "' must be indicated with a lowercase 'e'");
|
|
|
|
} else if (/^0\d*[89]/.test(number)) {
|
2012-07-05 06:37:09 +00:00
|
|
|
this.error("decimal literal '" + number + "' must not be prefixed with '0'");
|
2013-12-30 15:00:16 +00:00
|
|
|
} else if (/^0\d+/.test(number)) {
|
2012-07-05 06:37:09 +00:00
|
|
|
this.error("octal literal '" + number + "' must be prefixed with '0o'");
|
|
|
|
}
|
|
|
|
lexedLength = number.length;
|
2013-12-30 15:00:16 +00:00
|
|
|
if (octalLiteral = /^0o([0-7]+)/.exec(number)) {
|
|
|
|
number = '0x' + parseInt(octalLiteral[1], 8).toString(16);
|
2012-07-05 06:37:09 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
if (binaryLiteral = /^0b([01]+)/.exec(number)) {
|
|
|
|
number = '0x' + parseInt(binaryLiteral[1], 2).toString(16);
|
2012-07-05 06:37:09 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
this.token('NUMBER', number, 0, lexedLength);
|
2012-07-05 06:37:09 +00:00
|
|
|
return lexedLength;
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Lexer.prototype.stringToken = function() {
|
2013-12-30 15:00:16 +00:00
|
|
|
var octalEsc, quote, string, trimmed;
|
|
|
|
switch (quote = this.chunk.charAt(0)) {
|
2012-02-06 20:59:17 +00:00
|
|
|
case "'":
|
2013-12-30 15:00:16 +00:00
|
|
|
string = SIMPLESTR.exec(this.chunk)[0];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
|
|
|
case '"':
|
2013-12-30 15:00:16 +00:00
|
|
|
string = this.balancedString(this.chunk, '"');
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
if (!string) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
trimmed = this.removeNewlines(string.slice(1, -1));
|
|
|
|
if (quote === '"' && 0 < string.indexOf('#{', 1)) {
|
|
|
|
this.interpolateString(trimmed, {
|
|
|
|
strOffset: 1,
|
|
|
|
lexedLength: string.length
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.token('STRING', quote + this.escapeLines(trimmed) + quote, 0, string.length);
|
|
|
|
}
|
|
|
|
if (octalEsc = /^(?:\\.|[^\\])*\\(?:0[0-7]|[1-7])/.test(string)) {
|
2012-07-05 06:37:09 +00:00
|
|
|
this.error("octal escape sequences " + string + " are not allowed");
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
return string.length;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Lexer.prototype.heredocToken = function() {
|
|
|
|
var doc, heredoc, match, quote;
|
2013-12-30 15:00:16 +00:00
|
|
|
if (!(match = HEREDOC.exec(this.chunk))) {
|
|
|
|
return 0;
|
|
|
|
}
|
2012-02-06 20:59:17 +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, {
|
2013-12-30 15:00:16 +00:00
|
|
|
heredoc: true,
|
|
|
|
strOffset: 3,
|
|
|
|
lexedLength: heredoc.length
|
2012-02-06 20:59:17 +00:00
|
|
|
});
|
|
|
|
} else {
|
2013-12-30 15:00:16 +00:00
|
|
|
this.token('STRING', this.makeString(doc, quote, true), 0, heredoc.length);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
return heredoc.length;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Lexer.prototype.commentToken = function() {
|
|
|
|
var comment, here, match;
|
2013-12-30 15:00:16 +00:00
|
|
|
if (!(match = this.chunk.match(COMMENT))) {
|
|
|
|
return 0;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
comment = match[0], here = match[1];
|
|
|
|
if (here) {
|
|
|
|
this.token('HERECOMMENT', this.sanitizeHeredoc(here, {
|
|
|
|
herecomment: true,
|
2013-12-30 15:00:16 +00:00
|
|
|
indent: repeat(' ', this.indent)
|
|
|
|
}), 0, comment.length);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
return comment.length;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Lexer.prototype.jsToken = function() {
|
|
|
|
var match, script;
|
|
|
|
if (!(this.chunk.charAt(0) === '`' && (match = JSTOKEN.exec(this.chunk)))) {
|
|
|
|
return 0;
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
this.token('JS', (script = match[0]).slice(1, -1), 0, script.length);
|
2012-02-06 20:59:17 +00:00
|
|
|
return script.length;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Lexer.prototype.regexToken = function() {
|
2012-07-05 06:37:09 +00:00
|
|
|
var flags, length, match, prev, regex, _ref2, _ref3;
|
2013-12-30 15:00:16 +00:00
|
|
|
if (this.chunk.charAt(0) !== '/') {
|
|
|
|
return 0;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
if (match = HEREGEX.exec(this.chunk)) {
|
2012-07-05 06:37:09 +00:00
|
|
|
length = this.heregexToken(match);
|
|
|
|
return length;
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
prev = last(this.tokens);
|
|
|
|
if (prev && (_ref2 = prev[0], __indexOf.call((prev.spaced ? NOT_REGEX : NOT_SPACED_REGEX), _ref2) >= 0)) {
|
|
|
|
return 0;
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
if (!(match = REGEX.exec(this.chunk))) {
|
|
|
|
return 0;
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
_ref3 = match, match = _ref3[0], regex = _ref3[1], flags = _ref3[2];
|
|
|
|
if (regex.slice(0, 2) === '/*') {
|
|
|
|
this.error('regular expressions cannot begin with `*`');
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
if (regex === '//') {
|
|
|
|
regex = '/(?:)/';
|
|
|
|
}
|
|
|
|
this.token('REGEX', "" + regex + flags, 0, match.length);
|
2012-07-05 06:37:09 +00:00
|
|
|
return match.length;
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Lexer.prototype.heregexToken = function(match) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var body, flags, flagsOffset, heregex, plusToken, prev, re, tag, token, tokens, value, _i, _len, _ref2, _ref3, _ref4;
|
2012-02-06 20:59:17 +00:00
|
|
|
heregex = match[0], body = match[1], flags = match[2];
|
|
|
|
if (0 > body.indexOf('#{')) {
|
2013-12-30 15:00:16 +00:00
|
|
|
re = this.escapeLines(body.replace(HEREGEX_OMIT, '$1$2').replace(/\//g, '\\/'), true);
|
2012-07-05 06:37:09 +00:00
|
|
|
if (re.match(/^\*/)) {
|
|
|
|
this.error('regular expressions cannot begin with `*`');
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
this.token('REGEX', "/" + (re || '(?:)') + "/" + flags, 0, heregex.length);
|
2012-02-06 20:59:17 +00:00
|
|
|
return heregex.length;
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
this.token('IDENTIFIER', 'RegExp', 0, 0);
|
|
|
|
this.token('CALL_START', '(', 0, 0);
|
2012-02-06 20:59:17 +00:00
|
|
|
tokens = [];
|
|
|
|
_ref2 = this.interpolateString(body, {
|
|
|
|
regex: true
|
|
|
|
});
|
|
|
|
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
2013-12-30 15:00:16 +00:00
|
|
|
token = _ref2[_i];
|
|
|
|
tag = token[0], value = token[1];
|
2012-02-06 20:59:17 +00:00
|
|
|
if (tag === 'TOKENS') {
|
|
|
|
tokens.push.apply(tokens, value);
|
2013-12-30 15:00:16 +00:00
|
|
|
} else if (tag === 'NEOSTRING') {
|
|
|
|
if (!(value = value.replace(HEREGEX_OMIT, '$1$2'))) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
value = value.replace(/\\/g, '\\\\');
|
2013-12-30 15:00:16 +00:00
|
|
|
token[0] = 'STRING';
|
|
|
|
token[1] = this.makeString(value, '"', true);
|
|
|
|
tokens.push(token);
|
|
|
|
} else {
|
|
|
|
this.error("Unexpected " + tag);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
prev = last(this.tokens);
|
|
|
|
plusToken = ['+', '+'];
|
|
|
|
plusToken[2] = prev[2];
|
|
|
|
tokens.push(plusToken);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
tokens.pop();
|
2013-12-30 15:00:16 +00:00
|
|
|
if (((_ref3 = tokens[0]) != null ? _ref3[0] : void 0) !== 'STRING') {
|
|
|
|
this.token('STRING', '""', 0, 0);
|
|
|
|
this.token('+', '+', 0, 0);
|
|
|
|
}
|
|
|
|
(_ref4 = this.tokens).push.apply(_ref4, tokens);
|
|
|
|
if (flags) {
|
|
|
|
flagsOffset = heregex.lastIndexOf(flags);
|
|
|
|
this.token(',', ',', flagsOffset, 0);
|
|
|
|
this.token('STRING', '"' + flags + '"', flagsOffset, flags.length);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
this.token(')', ')', heregex.length - 1, 0);
|
2012-02-06 20:59:17 +00:00
|
|
|
return heregex.length;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Lexer.prototype.lineToken = function() {
|
2013-12-30 15:00:16 +00:00
|
|
|
var diff, indent, match, noNewlines, size;
|
|
|
|
if (!(match = MULTI_DENT.exec(this.chunk))) {
|
|
|
|
return 0;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
indent = match[0];
|
2012-07-05 06:37:09 +00:00
|
|
|
this.seenFor = false;
|
2012-02-06 20:59:17 +00:00
|
|
|
size = indent.length - 1 - indent.lastIndexOf('\n');
|
|
|
|
noNewlines = this.unfinished();
|
|
|
|
if (size - this.indebt === this.indent) {
|
|
|
|
if (noNewlines) {
|
|
|
|
this.suppressNewlines();
|
|
|
|
} else {
|
2013-12-30 15:00:16 +00:00
|
|
|
this.newlineToken(0);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
return indent.length;
|
|
|
|
}
|
|
|
|
if (size > this.indent) {
|
|
|
|
if (noNewlines) {
|
|
|
|
this.indebt = size - this.indent;
|
|
|
|
this.suppressNewlines();
|
|
|
|
return indent.length;
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
if (!this.tokens.length) {
|
|
|
|
this.baseIndent = this.indent = size;
|
|
|
|
return indent.length;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
diff = size - this.indent + this.outdebt;
|
2013-12-30 15:00:16 +00:00
|
|
|
this.token('INDENT', diff, indent.length - size, size);
|
2012-02-06 20:59:17 +00:00
|
|
|
this.indents.push(diff);
|
2012-07-05 06:37:09 +00:00
|
|
|
this.ends.push('OUTDENT');
|
2012-02-06 20:59:17 +00:00
|
|
|
this.outdebt = this.indebt = 0;
|
2013-12-30 15:00:16 +00:00
|
|
|
} else if (size < this.baseIndent) {
|
|
|
|
this.error('missing indentation', indent.length);
|
2012-02-06 20:59:17 +00:00
|
|
|
} else {
|
|
|
|
this.indebt = 0;
|
2013-12-30 15:00:16 +00:00
|
|
|
this.outdentToken(this.indent - size, noNewlines, indent.length);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
this.indent = size;
|
|
|
|
return indent.length;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
Lexer.prototype.outdentToken = function(moveOut, noNewlines, outdentLength) {
|
2012-02-06 20:59:17 +00:00
|
|
|
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 {
|
2013-12-30 15:00:16 +00:00
|
|
|
dent = this.indents.pop() + this.outdebt;
|
2012-02-06 20:59:17 +00:00
|
|
|
moveOut -= dent;
|
|
|
|
this.outdebt = 0;
|
2012-07-05 06:37:09 +00:00
|
|
|
this.pair('OUTDENT');
|
2013-12-30 15:00:16 +00:00
|
|
|
this.token('OUTDENT', dent, 0, outdentLength);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
if (dent) {
|
|
|
|
this.outdebt -= moveOut;
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
while (this.value() === ';') {
|
|
|
|
this.tokens.pop();
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
if (!(this.tag() === 'TERMINATOR' || noNewlines)) {
|
2013-12-30 15:00:16 +00:00
|
|
|
this.token('TERMINATOR', '\n', outdentLength, 0);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
return this;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Lexer.prototype.whitespaceToken = function() {
|
|
|
|
var match, nline, prev;
|
|
|
|
if (!((match = WHITESPACE.exec(this.chunk)) || (nline = this.chunk.charAt(0) === '\n'))) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
prev = last(this.tokens);
|
2013-12-30 15:00:16 +00:00
|
|
|
if (prev) {
|
|
|
|
prev[match ? 'spaced' : 'newLine'] = true;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
if (match) {
|
|
|
|
return match[0].length;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
Lexer.prototype.newlineToken = function(offset) {
|
2012-07-05 06:37:09 +00:00
|
|
|
while (this.value() === ';') {
|
|
|
|
this.tokens.pop();
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
if (this.tag() !== 'TERMINATOR') {
|
|
|
|
this.token('TERMINATOR', '\n', offset, 0);
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
return this;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Lexer.prototype.suppressNewlines = function() {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (this.value() === '\\') {
|
|
|
|
this.tokens.pop();
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
return this;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Lexer.prototype.literalToken = function() {
|
|
|
|
var match, prev, tag, value, _ref2, _ref3, _ref4, _ref5;
|
|
|
|
if (match = OPERATOR.exec(this.chunk)) {
|
|
|
|
value = match[0];
|
2013-12-30 15:00:16 +00:00
|
|
|
if (CODE.test(value)) {
|
|
|
|
this.tagParameters();
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
} else {
|
|
|
|
value = this.chunk.charAt(0);
|
|
|
|
}
|
|
|
|
tag = value;
|
|
|
|
prev = last(this.tokens);
|
|
|
|
if (value === '=' && prev) {
|
|
|
|
if (!prev[1].reserved && (_ref2 = prev[1], __indexOf.call(JS_FORBIDDEN, _ref2) >= 0)) {
|
2012-07-05 06:37:09 +00:00
|
|
|
this.error("reserved word \"" + (this.value()) + "\" can't be assigned");
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
if ((_ref3 = prev[1]) === '||' || _ref3 === '&&') {
|
|
|
|
prev[0] = 'COMPOUND_ASSIGN';
|
|
|
|
prev[1] += '=';
|
|
|
|
return value.length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (value === ';') {
|
2012-07-05 06:37:09 +00:00
|
|
|
this.seenFor = false;
|
2012-02-06 20:59:17 +00:00
|
|
|
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 === '(' && (_ref4 = prev[0], __indexOf.call(CALLABLE, _ref4) >= 0)) {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (prev[0] === '?') {
|
|
|
|
prev[0] = 'FUNC_EXIST';
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
tag = 'CALL_START';
|
|
|
|
} else if (value === '[' && (_ref5 = prev[0], __indexOf.call(INDEXABLE, _ref5) >= 0)) {
|
|
|
|
tag = 'INDEX_START';
|
|
|
|
switch (prev[0]) {
|
|
|
|
case '?':
|
|
|
|
prev[0] = 'INDEX_SOAK';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
switch (value) {
|
|
|
|
case '(':
|
|
|
|
case '{':
|
|
|
|
case '[':
|
|
|
|
this.ends.push(INVERSES[value]);
|
|
|
|
break;
|
|
|
|
case ')':
|
|
|
|
case '}':
|
|
|
|
case ']':
|
|
|
|
this.pair(value);
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
this.token(tag, value);
|
|
|
|
return value.length;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Lexer.prototype.sanitizeHeredoc = function(doc, options) {
|
|
|
|
var attempt, herecomment, indent, match, _ref2;
|
|
|
|
indent = options.indent, herecomment = options.herecomment;
|
|
|
|
if (herecomment) {
|
|
|
|
if (HEREDOC_ILLEGAL.test(doc)) {
|
2012-07-05 06:37:09 +00:00
|
|
|
this.error("block comment cannot contain \"*/\", starting");
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
if (doc.indexOf('\n') < 0) {
|
|
|
|
return doc;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
} else {
|
|
|
|
while (match = HEREDOC_INDENT.exec(doc)) {
|
|
|
|
attempt = match[1];
|
|
|
|
if (indent === null || (0 < (_ref2 = attempt.length) && _ref2 < indent.length)) {
|
|
|
|
indent = attempt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
if (indent) {
|
|
|
|
doc = doc.replace(RegExp("\\n" + indent, "g"), '\n');
|
|
|
|
}
|
|
|
|
if (!herecomment) {
|
|
|
|
doc = doc.replace(/^\n/, '');
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
return doc;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Lexer.prototype.tagParameters = function() {
|
|
|
|
var i, stack, tok, tokens;
|
2013-12-30 15:00:16 +00:00
|
|
|
if (this.tag() !== ')') {
|
|
|
|
return this;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
stack = [];
|
|
|
|
tokens = this.tokens;
|
|
|
|
i = tokens.length;
|
|
|
|
tokens[--i][0] = 'PARAM_END';
|
|
|
|
while (tok = tokens[--i]) {
|
|
|
|
switch (tok[0]) {
|
|
|
|
case ')':
|
|
|
|
stack.push(tok);
|
|
|
|
break;
|
|
|
|
case '(':
|
|
|
|
case 'CALL_START':
|
|
|
|
if (stack.length) {
|
|
|
|
stack.pop();
|
|
|
|
} else if (tok[0] === '(') {
|
|
|
|
tok[0] = 'PARAM_START';
|
|
|
|
return this;
|
2012-07-05 06:37:09 +00:00
|
|
|
} else {
|
|
|
|
return this;
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Lexer.prototype.closeIndentation = function() {
|
|
|
|
return this.outdentToken(this.indent);
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Lexer.prototype.balancedString = function(str, end) {
|
2012-07-05 06:37:09 +00:00
|
|
|
var continueCount, i, letter, match, prev, stack, _i, _ref2;
|
|
|
|
continueCount = 0;
|
2012-02-06 20:59:17 +00:00
|
|
|
stack = [end];
|
2012-07-05 06:37:09 +00:00
|
|
|
for (i = _i = 1, _ref2 = str.length; 1 <= _ref2 ? _i < _ref2 : _i > _ref2; i = 1 <= _ref2 ? ++_i : --_i) {
|
|
|
|
if (continueCount) {
|
|
|
|
--continueCount;
|
|
|
|
continue;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
switch (letter = str.charAt(i)) {
|
|
|
|
case '\\':
|
2012-07-05 06:37:09 +00:00
|
|
|
++continueCount;
|
2012-02-06 20:59:17 +00:00
|
|
|
continue;
|
|
|
|
case end:
|
|
|
|
stack.pop();
|
2013-12-30 15:00:16 +00:00
|
|
|
if (!stack.length) {
|
|
|
|
return str.slice(0, +i + 1 || 9e9);
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
end = stack[stack.length - 1];
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (end === '}' && (letter === '"' || letter === "'")) {
|
|
|
|
stack.push(end = letter);
|
2012-07-05 06:37:09 +00:00
|
|
|
} else if (end === '}' && letter === '/' && (match = HEREGEX.exec(str.slice(i)) || REGEX.exec(str.slice(i)))) {
|
|
|
|
continueCount += match[0].length - 1;
|
2012-02-06 20:59:17 +00:00
|
|
|
} else if (end === '}' && letter === '{') {
|
|
|
|
stack.push(end = '}');
|
|
|
|
} else if (end === '"' && prev === '#' && letter === '{') {
|
|
|
|
stack.push(end = '}');
|
|
|
|
}
|
|
|
|
prev = letter;
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
return this.error("missing " + (stack.pop()) + ", starting");
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Lexer.prototype.interpolateString = function(str, options) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var column, expr, heredoc, i, inner, interpolated, len, letter, lexedLength, line, locationToken, nested, offsetInChunk, pi, plusToken, popped, regex, rparen, strOffset, tag, token, tokens, value, _i, _len, _ref2, _ref3, _ref4;
|
|
|
|
if (options == null) {
|
|
|
|
options = {};
|
|
|
|
}
|
|
|
|
heredoc = options.heredoc, regex = options.regex, offsetInChunk = options.offsetInChunk, strOffset = options.strOffset, lexedLength = options.lexedLength;
|
|
|
|
offsetInChunk = offsetInChunk || 0;
|
|
|
|
strOffset = strOffset || 0;
|
|
|
|
lexedLength = lexedLength || str.length;
|
2012-02-06 20:59:17 +00:00
|
|
|
tokens = [];
|
|
|
|
pi = 0;
|
|
|
|
i = -1;
|
|
|
|
while (letter = str.charAt(i += 1)) {
|
|
|
|
if (letter === '\\') {
|
|
|
|
i += 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!(letter === '#' && str.charAt(i + 1) === '{' && (expr = this.balancedString(str.slice(i + 1), '}')))) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
if (pi < i) {
|
|
|
|
tokens.push(this.makeToken('NEOSTRING', str.slice(pi, i), strOffset + pi));
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
inner = expr.slice(1, -1);
|
|
|
|
if (inner.length) {
|
2013-12-30 15:00:16 +00:00
|
|
|
_ref2 = this.getLineAndColumnFromChunk(strOffset + i + 1), line = _ref2[0], column = _ref2[1];
|
2012-02-06 20:59:17 +00:00
|
|
|
nested = new Lexer().tokenize(inner, {
|
2013-12-30 15:00:16 +00:00
|
|
|
line: line,
|
|
|
|
column: column,
|
2012-02-06 20:59:17 +00:00
|
|
|
rewrite: false
|
|
|
|
});
|
2013-12-30 15:00:16 +00:00
|
|
|
popped = nested.pop();
|
|
|
|
if (((_ref3 = nested[0]) != null ? _ref3[0] : void 0) === 'TERMINATOR') {
|
|
|
|
popped = nested.shift();
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
if (len = nested.length) {
|
|
|
|
if (len > 1) {
|
2013-12-30 15:00:16 +00:00
|
|
|
nested.unshift(this.makeToken('(', '(', strOffset + i + 1, 0));
|
|
|
|
nested.push(this.makeToken(')', ')', strOffset + i + 1 + inner.length, 0));
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
tokens.push(['TOKENS', nested]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
i += expr.length;
|
|
|
|
pi = i + 1;
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
if ((i > pi && pi < str.length)) {
|
|
|
|
tokens.push(this.makeToken('NEOSTRING', str.slice(pi), strOffset + pi));
|
|
|
|
}
|
|
|
|
if (regex) {
|
|
|
|
return tokens;
|
|
|
|
}
|
|
|
|
if (!tokens.length) {
|
|
|
|
return this.token('STRING', '""', offsetInChunk, lexedLength);
|
|
|
|
}
|
|
|
|
if (tokens[0][0] !== 'NEOSTRING') {
|
|
|
|
tokens.unshift(this.makeToken('NEOSTRING', '', offsetInChunk));
|
|
|
|
}
|
|
|
|
if (interpolated = tokens.length > 1) {
|
|
|
|
this.token('(', '(', offsetInChunk, 0);
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
for (i = _i = 0, _len = tokens.length; _i < _len; i = ++_i) {
|
2013-12-30 15:00:16 +00:00
|
|
|
token = tokens[i];
|
|
|
|
tag = token[0], value = token[1];
|
|
|
|
if (i) {
|
|
|
|
if (i) {
|
|
|
|
plusToken = this.token('+', '+');
|
|
|
|
}
|
|
|
|
locationToken = tag === 'TOKENS' ? value[0] : token;
|
|
|
|
plusToken[2] = {
|
|
|
|
first_line: locationToken[2].first_line,
|
|
|
|
first_column: locationToken[2].first_column,
|
|
|
|
last_line: locationToken[2].first_line,
|
|
|
|
last_column: locationToken[2].first_column
|
|
|
|
};
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
if (tag === 'TOKENS') {
|
|
|
|
(_ref4 = this.tokens).push.apply(_ref4, value);
|
2013-12-30 15:00:16 +00:00
|
|
|
} else if (tag === 'NEOSTRING') {
|
|
|
|
token[0] = 'STRING';
|
|
|
|
token[1] = this.makeString(value, '"', heredoc);
|
|
|
|
this.tokens.push(token);
|
2012-02-06 20:59:17 +00:00
|
|
|
} else {
|
2013-12-30 15:00:16 +00:00
|
|
|
this.error("Unexpected " + tag);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
if (interpolated) {
|
|
|
|
rparen = this.makeToken(')', ')', offsetInChunk + lexedLength, 0);
|
|
|
|
rparen.stringEnd = true;
|
|
|
|
this.tokens.push(rparen);
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
return tokens;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
Lexer.prototype.pair = function(tag) {
|
|
|
|
var size, wanted;
|
|
|
|
if (tag !== (wanted = last(this.ends))) {
|
2013-12-30 15:00:16 +00:00
|
|
|
if ('OUTDENT' !== wanted) {
|
|
|
|
this.error("unmatched " + tag);
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
this.indent -= size = last(this.indents);
|
|
|
|
this.outdentToken(size, true);
|
|
|
|
return this.pair(tag);
|
|
|
|
}
|
|
|
|
return this.ends.pop();
|
|
|
|
};
|
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
Lexer.prototype.getLineAndColumnFromChunk = function(offset) {
|
|
|
|
var column, lineCount, lines, string;
|
|
|
|
if (offset === 0) {
|
|
|
|
return [this.chunkLine, this.chunkColumn];
|
|
|
|
}
|
|
|
|
if (offset >= this.chunk.length) {
|
|
|
|
string = this.chunk;
|
|
|
|
} else {
|
|
|
|
string = this.chunk.slice(0, +(offset - 1) + 1 || 9e9);
|
|
|
|
}
|
|
|
|
lineCount = count(string, '\n');
|
|
|
|
column = this.chunkColumn;
|
|
|
|
if (lineCount > 0) {
|
|
|
|
lines = string.split('\n');
|
|
|
|
column = last(lines).length;
|
|
|
|
} else {
|
|
|
|
column += string.length;
|
|
|
|
}
|
|
|
|
return [this.chunkLine + lineCount, column];
|
|
|
|
};
|
|
|
|
|
|
|
|
Lexer.prototype.makeToken = function(tag, value, offsetInChunk, length) {
|
|
|
|
var lastCharacter, locationData, token, _ref2, _ref3;
|
|
|
|
if (offsetInChunk == null) {
|
|
|
|
offsetInChunk = 0;
|
|
|
|
}
|
|
|
|
if (length == null) {
|
|
|
|
length = value.length;
|
|
|
|
}
|
|
|
|
locationData = {};
|
|
|
|
_ref2 = this.getLineAndColumnFromChunk(offsetInChunk), locationData.first_line = _ref2[0], locationData.first_column = _ref2[1];
|
|
|
|
lastCharacter = Math.max(0, length - 1);
|
|
|
|
_ref3 = this.getLineAndColumnFromChunk(offsetInChunk + lastCharacter), locationData.last_line = _ref3[0], locationData.last_column = _ref3[1];
|
|
|
|
token = [tag, value, locationData];
|
|
|
|
return token;
|
|
|
|
};
|
|
|
|
|
|
|
|
Lexer.prototype.token = function(tag, value, offsetInChunk, length) {
|
|
|
|
var token;
|
|
|
|
token = this.makeToken(tag, value, offsetInChunk, length);
|
|
|
|
this.tokens.push(token);
|
|
|
|
return token;
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Lexer.prototype.tag = function(index, tag) {
|
|
|
|
var tok;
|
|
|
|
return (tok = last(this.tokens, index)) && (tag ? tok[0] = tag : tok[0]);
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Lexer.prototype.value = function(index, val) {
|
|
|
|
var tok;
|
|
|
|
return (tok = last(this.tokens, index)) && (val ? tok[1] = val : tok[1]);
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Lexer.prototype.unfinished = function() {
|
2012-07-05 06:37:09 +00:00
|
|
|
var _ref2;
|
2013-12-30 15:00:16 +00:00
|
|
|
return LINE_CONTINUER.test(this.chunk) || ((_ref2 = this.tag()) === '\\' || _ref2 === '.' || _ref2 === '?.' || _ref2 === '?::' || _ref2 === 'UNARY' || _ref2 === 'MATH' || _ref2 === '+' || _ref2 === '-' || _ref2 === 'SHIFT' || _ref2 === 'RELATION' || _ref2 === 'COMPARE' || _ref2 === 'LOGIC' || _ref2 === 'THROW' || _ref2 === 'EXTENDS');
|
|
|
|
};
|
|
|
|
|
|
|
|
Lexer.prototype.removeNewlines = function(str) {
|
|
|
|
return str.replace(/^\s*\n\s*/, '').replace(/([^\\]|\\\\)\s*\n\s*$/, '$1');
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Lexer.prototype.escapeLines = function(str, heredoc) {
|
2013-12-30 15:00:16 +00:00
|
|
|
str = str.replace(/\\[^\S\n]*(\n|\\)\s*/g, function(escaped, character) {
|
|
|
|
if (character === '\n') {
|
|
|
|
return '';
|
|
|
|
} else {
|
|
|
|
return escaped;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (heredoc) {
|
|
|
|
return str.replace(MULTILINER, '\\n');
|
|
|
|
} else {
|
|
|
|
return str.replace(/\s*\n\s*/g, ' ');
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Lexer.prototype.makeString = function(body, quote, heredoc) {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (!body) {
|
|
|
|
return quote + quote;
|
|
|
|
}
|
|
|
|
body = body.replace(RegExp("\\\\(" + quote + "|\\\\)", "g"), function(match, contents) {
|
|
|
|
if (contents === quote) {
|
2012-02-06 20:59:17 +00:00
|
|
|
return contents;
|
|
|
|
} else {
|
|
|
|
return match;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
body = body.replace(RegExp("" + quote, "g"), '\\$&');
|
|
|
|
return quote + this.escapeLines(body, heredoc) + quote;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
Lexer.prototype.error = function(message, offset) {
|
|
|
|
var first_column, first_line, _ref2;
|
|
|
|
if (offset == null) {
|
|
|
|
offset = 0;
|
|
|
|
}
|
|
|
|
_ref2 = this.getLineAndColumnFromChunk(offset), first_line = _ref2[0], first_column = _ref2[1];
|
|
|
|
return throwSyntaxError(message, {
|
|
|
|
first_line: first_line,
|
|
|
|
first_column: first_column
|
|
|
|
});
|
2012-07-05 06:37:09 +00:00
|
|
|
};
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
return Lexer;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
})();
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
JS_KEYWORDS = ['true', 'false', 'null', 'this', 'new', 'delete', 'typeof', 'in', 'instanceof', 'return', 'throw', 'break', 'continue', 'debugger', 'if', 'else', 'switch', 'for', 'while', 'do', 'try', 'catch', 'finally', 'class', 'extends', 'super'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
COFFEE_KEYWORDS = ['undefined', 'then', 'unless', 'until', 'loop', 'of', 'by', 'when'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
COFFEE_ALIAS_MAP = {
|
|
|
|
and: '&&',
|
|
|
|
or: '||',
|
|
|
|
is: '==',
|
|
|
|
isnt: '!=',
|
|
|
|
not: '!',
|
|
|
|
yes: 'true',
|
|
|
|
no: 'false',
|
|
|
|
on: 'true',
|
|
|
|
off: 'false'
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
COFFEE_ALIASES = (function() {
|
|
|
|
var _results;
|
|
|
|
_results = [];
|
|
|
|
for (key in COFFEE_ALIAS_MAP) {
|
|
|
|
_results.push(key);
|
|
|
|
}
|
|
|
|
return _results;
|
|
|
|
})();
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
COFFEE_KEYWORDS = COFFEE_KEYWORDS.concat(COFFEE_ALIASES);
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
RESERVED = ['case', 'default', 'function', 'var', 'void', 'with', 'const', 'let', 'enum', 'export', 'import', 'native', '__hasProp', '__extends', '__slice', '__bind', '__indexOf', 'implements', 'interface', 'package', 'private', 'protected', 'public', 'static', 'yield'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
STRICT_PROSCRIBED = ['arguments', 'eval'];
|
|
|
|
|
|
|
|
JS_FORBIDDEN = JS_KEYWORDS.concat(RESERVED).concat(STRICT_PROSCRIBED);
|
|
|
|
|
|
|
|
exports.RESERVED = RESERVED.concat(JS_KEYWORDS).concat(COFFEE_KEYWORDS).concat(STRICT_PROSCRIBED);
|
|
|
|
|
|
|
|
exports.STRICT_PROSCRIBED = STRICT_PROSCRIBED;
|
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
BOM = 65279;
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
IDENTIFIER = /^([$A-Za-z_\x7f-\uffff][$\w\x7f-\uffff]*)([^\n\S]*:(?!:))?/;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
NUMBER = /^0b[01]+|^0o[0-7]+|^0x[\da-f]+|^\d*\.?\d+(?:e[+-]?\d+)?/i;
|
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
HEREDOC = /^("""|''')((?:\\[\s\S]|[^\\])*?)(?:\n[^\n\S]*)?\1/;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
OPERATOR = /^(?:[-=]>|[-+*\/%<>&|^!?=]=|>>>=?|([-+:])\1|([&|<>])\2=?|\?(\.|::)|\.{2,3})/;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
WHITESPACE = /^[^\n\S]+/;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
COMMENT = /^###([^#][\s\S]*?)(?:###[^\n\S]*|###$)|^(?:\s*#(?!##[^#]).*)+/;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
CODE = /^[-=]>/;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
MULTI_DENT = /^(?:\n[^\n\S]*)+/;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
SIMPLESTR = /^'[^\\']*(?:\\[\s\S][^\\']*)*'/;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
JSTOKEN = /^`[^\\`]*(?:\\.[^\\`]*)*`/;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
REGEX = /^(\/(?![\s=])[^[\/\n\\]*(?:(?:\\[\s\S]|\[[^\]\n\\]*(?:\\[\s\S][^\]\n\\]*)*])[^[\/\n\\]*)*\/)([imgy]{0,4})(?!\w)/;
|
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
HEREGEX = /^\/{3}((?:\\?[\s\S])+?)\/{3}([imgy]{0,4})(?!\w)/;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
HEREGEX_OMIT = /((?:\\\\)+)|\\(\s|\/)|\s+(?:#.*)?/g;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
MULTILINER = /\n/g;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
HEREDOC_INDENT = /\n+([^\n\S]*)/g;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
HEREDOC_ILLEGAL = /\*\//;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
LINE_CONTINUER = /^\s*(?:,|\??\.(?![.\d])|::)/;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
TRAILING_SPACES = /\s+$/;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
COMPOUND_ASSIGN = ['-=', '+=', '/=', '*=', '%=', '||=', '&&=', '?=', '<<=', '>>=', '>>>=', '&=', '^=', '|='];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
UNARY = ['!', '~', 'NEW', 'TYPEOF', 'DELETE', 'DO'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
LOGIC = ['&&', '||', '&', '|', '^'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
SHIFT = ['<<', '>>', '>>>'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
COMPARE = ['==', '!=', '<', '>', '<=', '>='];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
MATH = ['*', '/', '%'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
RELATION = ['IN', 'OF', 'INSTANCEOF'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
BOOL = ['TRUE', 'FALSE'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
NOT_REGEX = ['NUMBER', 'REGEX', 'BOOL', 'NULL', 'UNDEFINED', '++', '--'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
NOT_SPACED_REGEX = NOT_REGEX.concat(')', '}', 'THIS', 'IDENTIFIER', 'STRING', ']');
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
CALLABLE = ['IDENTIFIER', 'STRING', 'REGEX', ')', ']', '}', '?', '::', '@', 'THIS', 'SUPER'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
INDEXABLE = CALLABLE.concat('NUMBER', 'BOOL', 'NULL', 'UNDEFINED');
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
LINE_BREAK = ['INDENT', 'OUTDENT', 'TERMINATOR'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
define('ace/mode/coffee/rewriter', ['require', 'exports', 'module' ], function(require, exports, module) {
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
var BALANCED_PAIRS, CALL_CLOSERS, EXPRESSION_CLOSE, EXPRESSION_END, EXPRESSION_START, IMPLICIT_CALL, IMPLICIT_END, IMPLICIT_FUNC, IMPLICIT_UNSPACED_CALL, INVERSES, LINEBREAKS, SINGLE_CLOSERS, SINGLE_LINERS, generate, left, rite, _i, _len, _ref,
|
2012-07-05 06:37:09 +00:00
|
|
|
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
|
|
|
|
__slice = [].slice;
|
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
generate = function(tag, value) {
|
|
|
|
var tok;
|
|
|
|
tok = [tag, value];
|
|
|
|
tok.generated = true;
|
|
|
|
return tok;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
exports.Rewriter = (function() {
|
2012-02-06 20:59:17 +00:00
|
|
|
function Rewriter() {}
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Rewriter.prototype.rewrite = function(tokens) {
|
|
|
|
this.tokens = tokens;
|
|
|
|
this.removeLeadingNewlines();
|
|
|
|
this.closeOpenCalls();
|
|
|
|
this.closeOpenIndexes();
|
2013-12-30 15:00:16 +00:00
|
|
|
this.normalizeLines();
|
2012-02-06 20:59:17 +00:00
|
|
|
this.tagPostfixConditionals();
|
2013-12-30 15:00:16 +00:00
|
|
|
this.addImplicitBracesAndParens();
|
|
|
|
this.addLocationDataToGeneratedTokens();
|
2012-02-06 20:59:17 +00:00
|
|
|
return this.tokens;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Rewriter.prototype.scanTokens = function(block) {
|
|
|
|
var i, token, tokens;
|
|
|
|
tokens = this.tokens;
|
|
|
|
i = 0;
|
|
|
|
while (token = tokens[i]) {
|
|
|
|
i += block.call(this, token, i, tokens);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Rewriter.prototype.detectEnd = function(i, condition, action) {
|
2012-07-05 06:37:09 +00:00
|
|
|
var levels, token, tokens, _ref, _ref1;
|
2012-02-06 20:59:17 +00:00
|
|
|
tokens = this.tokens;
|
|
|
|
levels = 0;
|
|
|
|
while (token = tokens[i]) {
|
|
|
|
if (levels === 0 && condition.call(this, token, i)) {
|
|
|
|
return action.call(this, token, i);
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
if (!token || levels < 0) {
|
|
|
|
return action.call(this, token, i - 1);
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
if (_ref = token[0], __indexOf.call(EXPRESSION_START, _ref) >= 0) {
|
|
|
|
levels += 1;
|
2012-07-05 06:37:09 +00:00
|
|
|
} else if (_ref1 = token[0], __indexOf.call(EXPRESSION_END, _ref1) >= 0) {
|
2012-02-06 20:59:17 +00:00
|
|
|
levels -= 1;
|
|
|
|
}
|
|
|
|
i += 1;
|
|
|
|
}
|
|
|
|
return i - 1;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Rewriter.prototype.removeLeadingNewlines = function() {
|
2012-07-05 06:37:09 +00:00
|
|
|
var i, tag, _i, _len, _ref;
|
2012-02-06 20:59:17 +00:00
|
|
|
_ref = this.tokens;
|
2012-07-05 06:37:09 +00:00
|
|
|
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
|
2012-02-06 20:59:17 +00:00
|
|
|
tag = _ref[i][0];
|
2013-12-30 15:00:16 +00:00
|
|
|
if (tag !== 'TERMINATOR') {
|
|
|
|
break;
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
}
|
|
|
|
if (i) {
|
|
|
|
return this.tokens.splice(0, i);
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Rewriter.prototype.closeOpenCalls = function() {
|
|
|
|
var action, condition;
|
|
|
|
condition = function(token, i) {
|
|
|
|
var _ref;
|
|
|
|
return ((_ref = token[0]) === ')' || _ref === 'CALL_END') || token[0] === 'OUTDENT' && this.tag(i - 1) === ')';
|
|
|
|
};
|
|
|
|
action = function(token, i) {
|
|
|
|
return this.tokens[token[0] === 'OUTDENT' ? i - 1 : i][0] = 'CALL_END';
|
|
|
|
};
|
|
|
|
return this.scanTokens(function(token, i) {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (token[0] === 'CALL_START') {
|
|
|
|
this.detectEnd(i + 1, condition, action);
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
return 1;
|
|
|
|
});
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Rewriter.prototype.closeOpenIndexes = function() {
|
|
|
|
var action, condition;
|
|
|
|
condition = function(token, i) {
|
|
|
|
var _ref;
|
|
|
|
return (_ref = token[0]) === ']' || _ref === 'INDEX_END';
|
|
|
|
};
|
|
|
|
action = function(token, i) {
|
|
|
|
return token[0] = 'INDEX_END';
|
|
|
|
};
|
|
|
|
return this.scanTokens(function(token, i) {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (token[0] === 'INDEX_START') {
|
|
|
|
this.detectEnd(i + 1, condition, action);
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
return 1;
|
|
|
|
});
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
Rewriter.prototype.matchTags = function() {
|
|
|
|
var fuzz, i, j, pattern, _i, _ref, _ref1;
|
|
|
|
i = arguments[0], pattern = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
|
|
|
|
fuzz = 0;
|
|
|
|
for (j = _i = 0, _ref = pattern.length; 0 <= _ref ? _i < _ref : _i > _ref; j = 0 <= _ref ? ++_i : --_i) {
|
|
|
|
while (this.tag(i + j + fuzz) === 'HERECOMMENT') {
|
|
|
|
fuzz += 2;
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
if (pattern[j] == null) {
|
|
|
|
continue;
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
if (typeof pattern[j] === 'string') {
|
|
|
|
pattern[j] = [pattern[j]];
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
if (_ref1 = this.tag(i + j + fuzz), __indexOf.call(pattern[j], _ref1) < 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
Rewriter.prototype.looksObjectish = function(j) {
|
|
|
|
return this.matchTags(j, '@', null, ':') || this.matchTags(j, null, ':');
|
|
|
|
};
|
|
|
|
|
|
|
|
Rewriter.prototype.findTagsBackwards = function(i, tags) {
|
|
|
|
var backStack, _ref, _ref1, _ref2, _ref3, _ref4, _ref5;
|
|
|
|
backStack = [];
|
|
|
|
while (i >= 0 && (backStack.length || (_ref2 = this.tag(i), __indexOf.call(tags, _ref2) < 0) && ((_ref3 = this.tag(i), __indexOf.call(EXPRESSION_START, _ref3) < 0) || this.tokens[i].generated) && (_ref4 = this.tag(i), __indexOf.call(LINEBREAKS, _ref4) < 0))) {
|
|
|
|
if (_ref = this.tag(i), __indexOf.call(EXPRESSION_END, _ref) >= 0) {
|
|
|
|
backStack.push(this.tag(i));
|
|
|
|
}
|
|
|
|
if ((_ref1 = this.tag(i), __indexOf.call(EXPRESSION_START, _ref1) >= 0) && backStack.length) {
|
|
|
|
backStack.pop();
|
|
|
|
}
|
|
|
|
i -= 1;
|
|
|
|
}
|
|
|
|
return _ref5 = this.tag(i), __indexOf.call(tags, _ref5) >= 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
Rewriter.prototype.addImplicitBracesAndParens = function() {
|
|
|
|
var stack;
|
|
|
|
stack = [];
|
|
|
|
return this.scanTokens(function(token, i, tokens) {
|
|
|
|
var endAllImplicitCalls, endImplicitCall, endImplicitObject, forward, inImplicit, inImplicitCall, inImplicitControl, inImplicitObject, nextTag, offset, prevTag, prevToken, s, sameLine, stackIdx, stackTag, stackTop, startIdx, startImplicitCall, startImplicitObject, startsLine, tag, _ref, _ref1, _ref2, _ref3, _ref4, _ref5;
|
2012-07-05 06:37:09 +00:00
|
|
|
tag = token[0];
|
2013-12-30 15:00:16 +00:00
|
|
|
prevTag = (prevToken = i > 0 ? tokens[i - 1] : [])[0];
|
|
|
|
nextTag = (i < tokens.length - 1 ? tokens[i + 1] : [])[0];
|
|
|
|
stackTop = function() {
|
|
|
|
return stack[stack.length - 1];
|
|
|
|
};
|
|
|
|
startIdx = i;
|
|
|
|
forward = function(n) {
|
|
|
|
return i - startIdx + n;
|
|
|
|
};
|
|
|
|
inImplicit = function() {
|
|
|
|
var _ref, _ref1;
|
|
|
|
return (_ref = stackTop()) != null ? (_ref1 = _ref[2]) != null ? _ref1.ours : void 0 : void 0;
|
|
|
|
};
|
|
|
|
inImplicitCall = function() {
|
|
|
|
var _ref;
|
|
|
|
return inImplicit() && ((_ref = stackTop()) != null ? _ref[0] : void 0) === '(';
|
|
|
|
};
|
|
|
|
inImplicitObject = function() {
|
|
|
|
var _ref;
|
|
|
|
return inImplicit() && ((_ref = stackTop()) != null ? _ref[0] : void 0) === '{';
|
|
|
|
};
|
|
|
|
inImplicitControl = function() {
|
|
|
|
var _ref;
|
|
|
|
return inImplicit && ((_ref = stackTop()) != null ? _ref[0] : void 0) === 'CONTROL';
|
|
|
|
};
|
|
|
|
startImplicitCall = function(j) {
|
|
|
|
var idx;
|
|
|
|
idx = j != null ? j : i;
|
|
|
|
stack.push([
|
|
|
|
'(', idx, {
|
|
|
|
ours: true
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
tokens.splice(idx, 0, generate('CALL_START', '('));
|
|
|
|
if (j == null) {
|
|
|
|
return i += 1;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
endImplicitCall = function() {
|
|
|
|
stack.pop();
|
|
|
|
tokens.splice(i, 0, generate('CALL_END', ')'));
|
|
|
|
return i += 1;
|
|
|
|
};
|
|
|
|
endAllImplicitCalls = function() {
|
|
|
|
while (inImplicitCall()) {
|
|
|
|
endImplicitCall();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
startImplicitObject = function(j, startsLine) {
|
|
|
|
var idx;
|
|
|
|
if (startsLine == null) {
|
|
|
|
startsLine = true;
|
|
|
|
}
|
|
|
|
idx = j != null ? j : i;
|
|
|
|
stack.push([
|
|
|
|
'{', idx, {
|
|
|
|
sameLine: true,
|
|
|
|
startsLine: startsLine,
|
|
|
|
ours: true
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
tokens.splice(idx, 0, generate('{', generate(new String('{'))));
|
|
|
|
if (j == null) {
|
|
|
|
return i += 1;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
endImplicitObject = function(j) {
|
|
|
|
j = j != null ? j : i;
|
|
|
|
stack.pop();
|
|
|
|
tokens.splice(j, 0, generate('}', '}'));
|
|
|
|
return i += 1;
|
|
|
|
};
|
|
|
|
if (inImplicitCall() && (tag === 'IF' || tag === 'TRY' || tag === 'FINALLY' || tag === 'CATCH' || tag === 'CLASS' || tag === 'SWITCH')) {
|
|
|
|
stack.push([
|
|
|
|
'CONTROL', i, {
|
|
|
|
ours: true
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
return forward(1);
|
|
|
|
}
|
|
|
|
if (tag === 'INDENT' && inImplicit()) {
|
|
|
|
if (prevTag !== '=>' && prevTag !== '->' && prevTag !== '[' && prevTag !== '(' && prevTag !== ',' && prevTag !== '{' && prevTag !== 'TRY' && prevTag !== 'ELSE' && prevTag !== '=') {
|
|
|
|
while (inImplicitCall()) {
|
|
|
|
endImplicitCall();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (inImplicitControl()) {
|
|
|
|
stack.pop();
|
|
|
|
}
|
|
|
|
stack.push([tag, i]);
|
|
|
|
return forward(1);
|
2012-07-05 06:37:09 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
if (__indexOf.call(EXPRESSION_START, tag) >= 0) {
|
|
|
|
stack.push([tag, i]);
|
|
|
|
return forward(1);
|
2012-07-05 06:37:09 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
if (__indexOf.call(EXPRESSION_END, tag) >= 0) {
|
|
|
|
while (inImplicit()) {
|
|
|
|
if (inImplicitCall()) {
|
|
|
|
endImplicitCall();
|
|
|
|
} else if (inImplicitObject()) {
|
|
|
|
endImplicitObject();
|
|
|
|
} else {
|
|
|
|
stack.pop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stack.pop();
|
2012-07-05 06:37:09 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
if ((__indexOf.call(IMPLICIT_FUNC, tag) >= 0 && token.spaced && !token.stringEnd || tag === '?' && i > 0 && !tokens[i - 1].spaced) && (__indexOf.call(IMPLICIT_CALL, nextTag) >= 0 || __indexOf.call(IMPLICIT_UNSPACED_CALL, nextTag) >= 0 && !((_ref = tokens[i + 1]) != null ? _ref.spaced : void 0) && !((_ref1 = tokens[i + 1]) != null ? _ref1.newLine : void 0))) {
|
|
|
|
if (tag === '?') {
|
|
|
|
tag = token[0] = 'FUNC_EXIST';
|
|
|
|
}
|
|
|
|
startImplicitCall(i + 1);
|
|
|
|
return forward(2);
|
|
|
|
}
|
|
|
|
if (__indexOf.call(IMPLICIT_FUNC, tag) >= 0 && this.matchTags(i + 1, 'INDENT', null, ':') && !this.findTagsBackwards(i, ['CLASS', 'EXTENDS', 'IF', 'CATCH', 'SWITCH', 'LEADING_WHEN', 'FOR', 'WHILE', 'UNTIL'])) {
|
|
|
|
startImplicitCall(i + 1);
|
|
|
|
stack.push(['INDENT', i + 2]);
|
|
|
|
return forward(3);
|
|
|
|
}
|
|
|
|
if (tag === ':') {
|
|
|
|
if (this.tag(i - 2) === '@') {
|
|
|
|
s = i - 2;
|
|
|
|
} else {
|
|
|
|
s = i - 1;
|
|
|
|
}
|
|
|
|
while (this.tag(s - 2) === 'HERECOMMENT') {
|
|
|
|
s -= 2;
|
|
|
|
}
|
|
|
|
startsLine = s === 0 || (_ref2 = this.tag(s - 1), __indexOf.call(LINEBREAKS, _ref2) >= 0) || tokens[s - 1].newLine;
|
|
|
|
if (stackTop()) {
|
|
|
|
_ref3 = stackTop(), stackTag = _ref3[0], stackIdx = _ref3[1];
|
|
|
|
if ((stackTag === '{' || stackTag === 'INDENT' && this.tag(stackIdx - 1) === '{') && (startsLine || this.tag(s - 1) === ',' || this.tag(s - 1) === '{')) {
|
|
|
|
return forward(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
startImplicitObject(s, !!startsLine);
|
|
|
|
return forward(2);
|
|
|
|
}
|
|
|
|
if (inImplicitCall() && __indexOf.call(CALL_CLOSERS, tag) >= 0) {
|
|
|
|
if (prevTag === 'OUTDENT') {
|
|
|
|
endImplicitCall();
|
|
|
|
return forward(1);
|
|
|
|
}
|
|
|
|
if (prevToken.newLine) {
|
|
|
|
endAllImplicitCalls();
|
|
|
|
return forward(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (inImplicitObject() && __indexOf.call(LINEBREAKS, tag) >= 0) {
|
|
|
|
stackTop()[2].sameLine = false;
|
|
|
|
}
|
|
|
|
if (__indexOf.call(IMPLICIT_END, tag) >= 0) {
|
|
|
|
while (inImplicit()) {
|
|
|
|
_ref4 = stackTop(), stackTag = _ref4[0], stackIdx = _ref4[1], (_ref5 = _ref4[2], sameLine = _ref5.sameLine, startsLine = _ref5.startsLine);
|
|
|
|
if (inImplicitCall() && prevTag !== ',') {
|
|
|
|
endImplicitCall();
|
|
|
|
} else if (inImplicitObject() && sameLine && !startsLine) {
|
|
|
|
endImplicitObject();
|
|
|
|
} else if (inImplicitObject() && tag === 'TERMINATOR' && prevTag !== ',' && !(startsLine && this.looksObjectish(i + 1))) {
|
|
|
|
endImplicitObject();
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (tag === ',' && !this.looksObjectish(i + 1) && inImplicitObject() && (nextTag !== 'TERMINATOR' || !this.looksObjectish(i + 2))) {
|
|
|
|
offset = nextTag === 'OUTDENT' ? 1 : 0;
|
|
|
|
while (inImplicitObject()) {
|
|
|
|
endImplicitObject(i + offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return forward(1);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
Rewriter.prototype.addLocationDataToGeneratedTokens = function() {
|
2012-02-06 20:59:17 +00:00
|
|
|
return this.scanTokens(function(token, i, tokens) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var column, line, nextLocation, prevLocation, _ref, _ref1;
|
|
|
|
if (token[2]) {
|
2012-02-06 20:59:17 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
if (!(token.generated || token.explicit)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (token[0] === '{' && (nextLocation = (_ref = tokens[i + 1]) != null ? _ref[2] : void 0)) {
|
|
|
|
line = nextLocation.first_line, column = nextLocation.first_column;
|
|
|
|
} else if (prevLocation = (_ref1 = tokens[i - 1]) != null ? _ref1[2] : void 0) {
|
|
|
|
line = prevLocation.last_line, column = prevLocation.last_column;
|
|
|
|
} else {
|
|
|
|
line = column = 0;
|
|
|
|
}
|
|
|
|
token[2] = {
|
|
|
|
first_line: line,
|
|
|
|
first_column: column,
|
|
|
|
last_line: line,
|
|
|
|
last_column: column
|
|
|
|
};
|
|
|
|
return 1;
|
2012-02-06 20:59:17 +00:00
|
|
|
});
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
Rewriter.prototype.normalizeLines = function() {
|
2012-07-05 06:37:09 +00:00
|
|
|
var action, condition, indent, outdent, starter;
|
|
|
|
starter = indent = outdent = null;
|
|
|
|
condition = function(token, i) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var _ref, _ref1, _ref2, _ref3;
|
|
|
|
return token[1] !== ';' && (_ref = token[0], __indexOf.call(SINGLE_CLOSERS, _ref) >= 0) && !(token[0] === 'TERMINATOR' && (_ref1 = this.tag(i + 1), __indexOf.call(EXPRESSION_CLOSE, _ref1) >= 0)) && !(token[0] === 'ELSE' && starter !== 'THEN') && !(((_ref2 = token[0]) === 'CATCH' || _ref2 === 'FINALLY') && (starter === '->' || starter === '=>')) || (_ref3 = token[0], __indexOf.call(CALL_CLOSERS, _ref3) >= 0) && this.tokens[i - 1].newLine;
|
2012-07-05 06:37:09 +00:00
|
|
|
};
|
|
|
|
action = function(token, i) {
|
|
|
|
return this.tokens.splice((this.tag(i - 1) === ',' ? i - 1 : i), 0, outdent);
|
|
|
|
};
|
2012-02-06 20:59:17 +00:00
|
|
|
return this.scanTokens(function(token, i, tokens) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var j, tag, _i, _ref, _ref1, _ref2;
|
2012-02-06 20:59:17 +00:00
|
|
|
tag = token[0];
|
2013-12-30 15:00:16 +00:00
|
|
|
if (tag === 'TERMINATOR') {
|
|
|
|
if (this.tag(i + 1) === 'ELSE' && this.tag(i - 1) !== 'OUTDENT') {
|
|
|
|
tokens.splice.apply(tokens, [i, 1].concat(__slice.call(this.indentation())));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (_ref = this.tag(i + 1), __indexOf.call(EXPRESSION_CLOSE, _ref) >= 0) {
|
|
|
|
tokens.splice(i, 1);
|
|
|
|
return 0;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
if (tag === 'CATCH') {
|
|
|
|
for (j = _i = 1; _i <= 2; j = ++_i) {
|
|
|
|
if (!((_ref1 = this.tag(i + j)) === 'OUTDENT' || _ref1 === 'TERMINATOR' || _ref1 === 'FINALLY')) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
tokens.splice.apply(tokens, [i + j, 0].concat(__slice.call(this.indentation())));
|
|
|
|
return 2 + j;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
if (__indexOf.call(SINGLE_LINERS, tag) >= 0 && this.tag(i + 1) !== 'INDENT' && !(tag === 'ELSE' && this.tag(i + 1) === 'IF')) {
|
|
|
|
starter = tag;
|
2013-12-30 15:00:16 +00:00
|
|
|
_ref2 = this.indentation(true), indent = _ref2[0], outdent = _ref2[1];
|
|
|
|
if (starter === 'THEN') {
|
|
|
|
indent.fromThen = true;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
tokens.splice(i + 1, 0, indent);
|
|
|
|
this.detectEnd(i + 2, condition, action);
|
2013-12-30 15:00:16 +00:00
|
|
|
if (tag === 'THEN') {
|
|
|
|
tokens.splice(i, 1);
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
});
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Rewriter.prototype.tagPostfixConditionals = function() {
|
2012-07-05 06:37:09 +00:00
|
|
|
var action, condition, original;
|
|
|
|
original = null;
|
2012-02-06 20:59:17 +00:00
|
|
|
condition = function(token, i) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var prevTag, tag;
|
|
|
|
tag = token[0];
|
|
|
|
prevTag = this.tokens[i - 1][0];
|
|
|
|
return tag === 'TERMINATOR' || (tag === 'INDENT' && __indexOf.call(SINGLE_LINERS, prevTag) < 0);
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
action = function(token, i) {
|
|
|
|
if (token[0] !== 'INDENT' || (token.generated && !token.fromThen)) {
|
|
|
|
return original[0] = 'POST_' + original[0];
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
};
|
|
|
|
return this.scanTokens(function(token, i) {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (token[0] !== 'IF') {
|
|
|
|
return 1;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
original = token;
|
2012-07-05 06:37:09 +00:00
|
|
|
this.detectEnd(i + 1, condition, action);
|
2012-02-06 20:59:17 +00:00
|
|
|
return 1;
|
|
|
|
});
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
Rewriter.prototype.indentation = function(implicit) {
|
2012-07-05 06:37:09 +00:00
|
|
|
var indent, outdent;
|
2013-12-30 15:00:16 +00:00
|
|
|
if (implicit == null) {
|
|
|
|
implicit = false;
|
|
|
|
}
|
|
|
|
indent = ['INDENT', 2];
|
|
|
|
outdent = ['OUTDENT', 2];
|
|
|
|
if (implicit) {
|
|
|
|
indent.generated = outdent.generated = true;
|
|
|
|
}
|
|
|
|
if (!implicit) {
|
|
|
|
indent.explicit = outdent.explicit = true;
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
return [indent, outdent];
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
Rewriter.prototype.generate = generate;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Rewriter.prototype.tag = function(i) {
|
|
|
|
var _ref;
|
|
|
|
return (_ref = this.tokens[i]) != null ? _ref[0] : void 0;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
return Rewriter;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
})();
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
BALANCED_PAIRS = [['(', ')'], ['[', ']'], ['{', '}'], ['INDENT', 'OUTDENT'], ['CALL_START', 'CALL_END'], ['PARAM_START', 'PARAM_END'], ['INDEX_START', 'INDEX_END']];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
exports.INVERSES = INVERSES = {};
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
EXPRESSION_START = [];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
EXPRESSION_END = [];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
for (_i = 0, _len = BALANCED_PAIRS.length; _i < _len; _i++) {
|
|
|
|
_ref = BALANCED_PAIRS[_i], left = _ref[0], rite = _ref[1];
|
|
|
|
EXPRESSION_START.push(INVERSES[rite] = left);
|
|
|
|
EXPRESSION_END.push(INVERSES[left] = rite);
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
EXPRESSION_CLOSE = ['CATCH', 'THEN', 'ELSE', 'FINALLY'].concat(EXPRESSION_END);
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
IMPLICIT_FUNC = ['IDENTIFIER', 'SUPER', ')', 'CALL_END', ']', 'INDEX_END', '@', 'THIS'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
IMPLICIT_CALL = ['IDENTIFIER', 'NUMBER', 'STRING', 'JS', 'REGEX', 'NEW', 'PARAM_START', 'CLASS', 'IF', 'TRY', 'SWITCH', 'THIS', 'BOOL', 'NULL', 'UNDEFINED', 'UNARY', 'SUPER', 'THROW', '@', '->', '=>', '[', '(', '{', '--', '++'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
IMPLICIT_UNSPACED_CALL = ['+', '-'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
IMPLICIT_END = ['POST_IF', 'FOR', 'WHILE', 'UNTIL', 'WHEN', 'BY', 'LOOP', 'TERMINATOR'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
SINGLE_LINERS = ['ELSE', '->', '=>', 'TRY', 'FINALLY', 'THEN'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
SINGLE_CLOSERS = ['TERMINATOR', 'CATCH', 'FINALLY', 'ELSE', 'OUTDENT', 'LEADING_WHEN'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
LINEBREAKS = ['TERMINATOR', 'INDENT', 'OUTDENT'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
CALL_CLOSERS = ['.', '?.', '::', '?::'];
|
|
|
|
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
define('ace/mode/coffee/helpers', ['require', 'exports', 'module' ], function(require, exports, module) {
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
var buildLocationData, extend, flatten, last, repeat, syntaxErrorToString, _ref;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
exports.starts = function(string, literal, start) {
|
|
|
|
return literal === string.substr(start, literal.length);
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
exports.ends = function(string, literal, back) {
|
|
|
|
var len;
|
|
|
|
len = literal.length;
|
|
|
|
return literal === string.substr(string.length - len - (back || 0), len);
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
exports.repeat = repeat = function(str, n) {
|
|
|
|
var res;
|
|
|
|
res = '';
|
|
|
|
while (n > 0) {
|
|
|
|
if (n & 1) {
|
|
|
|
res += str;
|
|
|
|
}
|
|
|
|
n >>>= 1;
|
|
|
|
str += str;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
};
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
exports.compact = function(array) {
|
|
|
|
var item, _i, _len, _results;
|
|
|
|
_results = [];
|
|
|
|
for (_i = 0, _len = array.length; _i < _len; _i++) {
|
|
|
|
item = array[_i];
|
2013-12-30 15:00:16 +00:00
|
|
|
if (item) {
|
|
|
|
_results.push(item);
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
return _results;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
exports.count = function(string, substr) {
|
|
|
|
var num, pos;
|
|
|
|
num = pos = 0;
|
2013-12-30 15:00:16 +00:00
|
|
|
if (!substr.length) {
|
|
|
|
return 1 / 0;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
while (pos = 1 + string.indexOf(substr, pos)) {
|
|
|
|
num++;
|
|
|
|
}
|
|
|
|
return num;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
exports.merge = function(options, overrides) {
|
|
|
|
return extend(extend({}, options), overrides);
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
extend = exports.extend = function(object, properties) {
|
|
|
|
var key, val;
|
|
|
|
for (key in properties) {
|
|
|
|
val = properties[key];
|
|
|
|
object[key] = val;
|
|
|
|
}
|
|
|
|
return object;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
exports.flatten = flatten = function(array) {
|
|
|
|
var element, flattened, _i, _len;
|
|
|
|
flattened = [];
|
|
|
|
for (_i = 0, _len = array.length; _i < _len; _i++) {
|
|
|
|
element = array[_i];
|
|
|
|
if (element instanceof Array) {
|
|
|
|
flattened = flattened.concat(flatten(element));
|
|
|
|
} else {
|
|
|
|
flattened.push(element);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return flattened;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
exports.del = function(obj, key) {
|
|
|
|
var val;
|
|
|
|
val = obj[key];
|
|
|
|
delete obj[key];
|
|
|
|
return val;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
exports.last = last = function(array, back) {
|
2012-02-06 20:59:17 +00:00
|
|
|
return array[array.length - (back || 0) - 1];
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
exports.some = (_ref = Array.prototype.some) != null ? _ref : function(fn) {
|
|
|
|
var e, _i, _len;
|
|
|
|
for (_i = 0, _len = this.length; _i < _len; _i++) {
|
|
|
|
e = this[_i];
|
|
|
|
if (fn(e)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.invertLiterate = function(code) {
|
|
|
|
var line, lines, maybe_code;
|
|
|
|
maybe_code = true;
|
|
|
|
lines = (function() {
|
|
|
|
var _i, _len, _ref1, _results;
|
|
|
|
_ref1 = code.split('\n');
|
|
|
|
_results = [];
|
|
|
|
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
|
|
|
line = _ref1[_i];
|
|
|
|
if (maybe_code && /^([ ]{4}|[ ]{0,3}\t)/.test(line)) {
|
|
|
|
_results.push(line);
|
|
|
|
} else if (maybe_code = /^\s*$/.test(line)) {
|
|
|
|
_results.push(line);
|
|
|
|
} else {
|
|
|
|
_results.push('# ' + line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return _results;
|
|
|
|
})();
|
|
|
|
return lines.join('\n');
|
|
|
|
};
|
|
|
|
|
|
|
|
buildLocationData = function(first, last) {
|
|
|
|
if (!last) {
|
|
|
|
return first;
|
|
|
|
} else {
|
|
|
|
return {
|
|
|
|
first_line: first.first_line,
|
|
|
|
first_column: first.first_column,
|
|
|
|
last_line: last.last_line,
|
|
|
|
last_column: last.last_column
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.addLocationDataFn = function(first, last) {
|
|
|
|
return function(obj) {
|
|
|
|
if (((typeof obj) === 'object') && (!!obj['updateLocationDataIfMissing'])) {
|
|
|
|
obj.updateLocationDataIfMissing(buildLocationData(first, last));
|
|
|
|
}
|
|
|
|
return obj;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.locationDataToString = function(obj) {
|
|
|
|
var locationData;
|
|
|
|
if (("2" in obj) && ("first_line" in obj[2])) {
|
|
|
|
locationData = obj[2];
|
|
|
|
} else if ("first_line" in obj) {
|
|
|
|
locationData = obj;
|
|
|
|
}
|
|
|
|
if (locationData) {
|
|
|
|
return ("" + (locationData.first_line + 1) + ":" + (locationData.first_column + 1) + "-") + ("" + (locationData.last_line + 1) + ":" + (locationData.last_column + 1));
|
|
|
|
} else {
|
|
|
|
return "No location data";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.baseFileName = function(file, stripExt, useWinPathSep) {
|
|
|
|
var parts, pathSep;
|
|
|
|
if (stripExt == null) {
|
|
|
|
stripExt = false;
|
|
|
|
}
|
|
|
|
if (useWinPathSep == null) {
|
|
|
|
useWinPathSep = false;
|
|
|
|
}
|
|
|
|
pathSep = useWinPathSep ? /\\|\// : /\//;
|
|
|
|
parts = file.split(pathSep);
|
|
|
|
file = parts[parts.length - 1];
|
|
|
|
if (!(stripExt && file.indexOf('.') >= 0)) {
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
parts = file.split('.');
|
|
|
|
parts.pop();
|
|
|
|
if (parts[parts.length - 1] === 'coffee' && parts.length > 1) {
|
|
|
|
parts.pop();
|
|
|
|
}
|
|
|
|
return parts.join('.');
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.isCoffee = function(file) {
|
|
|
|
return /\.((lit)?coffee|coffee\.md)$/.test(file);
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.isLiterate = function(file) {
|
|
|
|
return /\.(litcoffee|coffee\.md)$/.test(file);
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.throwSyntaxError = function(message, location) {
|
|
|
|
var error;
|
|
|
|
if (location.last_line == null) {
|
|
|
|
location.last_line = location.first_line;
|
|
|
|
}
|
|
|
|
if (location.last_column == null) {
|
|
|
|
location.last_column = location.first_column;
|
|
|
|
}
|
|
|
|
error = new SyntaxError(message);
|
|
|
|
error.location = location;
|
|
|
|
error.toString = syntaxErrorToString;
|
|
|
|
error.stack = error.toString();
|
|
|
|
throw error;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.updateSyntaxError = function(error, code, filename) {
|
|
|
|
if (error.toString === syntaxErrorToString) {
|
|
|
|
error.code || (error.code = code);
|
|
|
|
error.filename || (error.filename = filename);
|
|
|
|
error.stack = error.toString();
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
};
|
|
|
|
|
|
|
|
syntaxErrorToString = function() {
|
|
|
|
var codeLine, colorize, colorsEnabled, end, filename, first_column, first_line, last_column, last_line, marker, start, _ref1, _ref2;
|
|
|
|
if (!(this.code && this.location)) {
|
|
|
|
return Error.prototype.toString.call(this);
|
|
|
|
}
|
|
|
|
_ref1 = this.location, first_line = _ref1.first_line, first_column = _ref1.first_column, last_line = _ref1.last_line, last_column = _ref1.last_column;
|
|
|
|
if (last_line == null) {
|
|
|
|
last_line = first_line;
|
|
|
|
}
|
|
|
|
if (last_column == null) {
|
|
|
|
last_column = first_column;
|
|
|
|
}
|
|
|
|
filename = this.filename || '[stdin]';
|
|
|
|
codeLine = this.code.split('\n')[first_line];
|
|
|
|
start = first_column;
|
|
|
|
end = first_line === last_line ? last_column + 1 : codeLine.length;
|
|
|
|
marker = repeat(' ', start) + repeat('^', end - start);
|
|
|
|
if (typeof process !== "undefined" && process !== null) {
|
|
|
|
colorsEnabled = process.stdout.isTTY && !process.env.NODE_DISABLE_COLORS;
|
|
|
|
}
|
|
|
|
if ((_ref2 = this.colorful) != null ? _ref2 : colorsEnabled) {
|
|
|
|
colorize = function(str) {
|
|
|
|
return "\x1B[1;31m" + str + "\x1B[0m";
|
|
|
|
};
|
|
|
|
codeLine = codeLine.slice(0, start) + colorize(codeLine.slice(start, end)) + codeLine.slice(end);
|
|
|
|
marker = colorize(marker);
|
|
|
|
}
|
|
|
|
return "" + filename + ":" + (first_line + 1) + ":" + (first_column + 1) + ": error: " + this.message + "\n" + codeLine + "\n" + marker;
|
|
|
|
};
|
|
|
|
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
define('ace/mode/coffee/parser', ['require', 'exports', 'module' ], function(require, exports, module) {
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
var parser = {trace: function trace() { },
|
|
|
|
yy: {},
|
2013-12-30 15:00:16 +00:00
|
|
|
symbols_: {"error":2,"Root":3,"Body":4,"Line":5,"TERMINATOR":6,"Expression":7,"Statement":8,"Return":9,"Comment":10,"STATEMENT":11,"Value":12,"Invocation":13,"Code":14,"Operation":15,"Assign":16,"If":17,"Try":18,"While":19,"For":20,"Switch":21,"Class":22,"Throw":23,"Block":24,"INDENT":25,"OUTDENT":26,"Identifier":27,"IDENTIFIER":28,"AlphaNumeric":29,"NUMBER":30,"STRING":31,"Literal":32,"JS":33,"REGEX":34,"DEBUGGER":35,"UNDEFINED":36,"NULL":37,"BOOL":38,"Assignable":39,"=":40,"AssignObj":41,"ObjAssignable":42,":":43,"ThisProperty":44,"RETURN":45,"HERECOMMENT":46,"PARAM_START":47,"ParamList":48,"PARAM_END":49,"FuncGlyph":50,"->":51,"=>":52,"OptComma":53,",":54,"Param":55,"ParamVar":56,"...":57,"Array":58,"Object":59,"Splat":60,"SimpleAssignable":61,"Accessor":62,"Parenthetical":63,"Range":64,"This":65,".":66,"?.":67,"::":68,"?::":69,"Index":70,"INDEX_START":71,"IndexValue":72,"INDEX_END":73,"INDEX_SOAK":74,"Slice":75,"{":76,"AssignList":77,"}":78,"CLASS":79,"EXTENDS":80,"OptFuncExist":81,"Arguments":82,"SUPER":83,"FUNC_EXIST":84,"CALL_START":85,"CALL_END":86,"ArgList":87,"THIS":88,"@":89,"[":90,"]":91,"RangeDots":92,"..":93,"Arg":94,"SimpleArgs":95,"TRY":96,"Catch":97,"FINALLY":98,"CATCH":99,"THROW":100,"(":101,")":102,"WhileSource":103,"WHILE":104,"WHEN":105,"UNTIL":106,"Loop":107,"LOOP":108,"ForBody":109,"FOR":110,"ForStart":111,"ForSource":112,"ForVariables":113,"OWN":114,"ForValue":115,"FORIN":116,"FOROF":117,"BY":118,"SWITCH":119,"Whens":120,"ELSE":121,"When":122,"LEADING_WHEN":123,"IfBlock":124,"IF":125,"POST_IF":126,"UNARY":127,"-":128,"+":129,"--":130,"++":131,"?":132,"MATH":133,"SHIFT":134,"COMPARE":135,"LOGIC":136,"RELATION":137,"COMPOUND_ASSIGN":138,"$accept":0,"$end":1},
|
|
|
|
terminals_: {2:"error",6:"TERMINATOR",11:"STATEMENT",25:"INDENT",26:"OUTDENT",28:"IDENTIFIER",30:"NUMBER",31:"STRING",33:"JS",34:"REGEX",35:"DEBUGGER",36:"UNDEFINED",37:"NULL",38:"BOOL",40:"=",43:":",45:"RETURN",46:"HERECOMMENT",47:"PARAM_START",49:"PARAM_END",51:"->",52:"=>",54:",",57:"...",66:".",67:"?.",68:"::",69:"?::",71:"INDEX_START",73:"INDEX_END",74:"INDEX_SOAK",76:"{",78:"}",79:"CLASS",80:"EXTENDS",83:"SUPER",84:"FUNC_EXIST",85:"CALL_START",86:"CALL_END",88:"THIS",89:"@",90:"[",91:"]",93:"..",96:"TRY",98:"FINALLY",99:"CATCH",100:"THROW",101:"(",102:")",104:"WHILE",105:"WHEN",106:"UNTIL",108:"LOOP",110:"FOR",114:"OWN",116:"FORIN",117:"FOROF",118:"BY",119:"SWITCH",121:"ELSE",123:"LEADING_WHEN",125:"IF",126:"POST_IF",127:"UNARY",128:"-",129:"+",130:"--",131:"++",132:"?",133:"MATH",134:"SHIFT",135:"COMPARE",136:"LOGIC",137:"RELATION",138:"COMPOUND_ASSIGN"},
|
|
|
|
productions_: [0,[3,0],[3,1],[4,1],[4,3],[4,2],[5,1],[5,1],[8,1],[8,1],[8,1],[7,1],[7,1],[7,1],[7,1],[7,1],[7,1],[7,1],[7,1],[7,1],[7,1],[7,1],[7,1],[24,2],[24,3],[27,1],[29,1],[29,1],[32,1],[32,1],[32,1],[32,1],[32,1],[32,1],[32,1],[16,3],[16,4],[16,5],[41,1],[41,3],[41,5],[41,1],[42,1],[42,1],[42,1],[9,2],[9,1],[10,1],[14,5],[14,2],[50,1],[50,1],[53,0],[53,1],[48,0],[48,1],[48,3],[48,4],[48,6],[55,1],[55,2],[55,3],[56,1],[56,1],[56,1],[56,1],[60,2],[61,1],[61,2],[61,2],[61,1],[39,1],[39,1],[39,1],[12,1],[12,1],[12,1],[12,1],[12,1],[62,2],[62,2],[62,2],[62,2],[62,1],[62,1],[70,3],[70,2],[72,1],[72,1],[59,4],[77,0],[77,1],[77,3],[77,4],[77,6],[22,1],[22,2],[22,3],[22,4],[22,2],[22,3],[22,4],[22,5],[13,3],[13,3],[13,1],[13,2],[81,0],[81,1],[82,2],[82,4],[65,1],[65,1],[44,2],[58,2],[58,4],[92,1],[92,1],[64,5],[75,3],[75,2],[75,2],[75,1],[87,1],[87,3],[87,4],[87,4],[87,6],[94,1],[94,1],[95,1],[95,3],[18,2],[18,3],[18,4],[18,5],[97,3],[97,3],[97,2],[23,2],[63,3],[63,5],[103,2],[103,4],[103,2],[103,4],[19,2],[19,2],[19,2],[19,1],[107,2],[107,2],[20,2],[20,2],[20,2],[109,2],[109,2],[111,2],[111,3],[115,1],[115,1],[115,1],[115,1],[113,1],[113,3],[112,2],[112,2],[112,4],[112,4],[112,4],[112,6],[112,6],[21,5],[21,7],[21,4],[21,6],[120,1],[120,2],[122,3],[122,4],[124,3],[124,5],[17,1],[17,3],[17,3],[17,3],[15,2],[15,2],[15,2],[15,2],[15,2],[15,2],[15,2],[15,2],[15,3],[15,3],[15,3],[15,3],[15,3],[15,3],[15,3],[15,3],[15,5],[15,4],[15,3]],
|
|
|
|
performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate /* action[1] */, $$ /* vstack */, _$ /* lstack */) {
|
2012-02-06 20:59:17 +00:00
|
|
|
|
|
|
|
var $0 = $$.length - 1;
|
|
|
|
switch (yystate) {
|
2013-12-30 15:00:16 +00:00
|
|
|
case 1:return this.$ = yy.addLocationDataFn(_$[$0], _$[$0])(new yy.Block);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
|
|
|
case 2:return this.$ = $$[$0];
|
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 3:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])(yy.Block.wrap([$$[$0]]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 4:this.$ = yy.addLocationDataFn(_$[$0-2], _$[$0])($$[$0-2].push($$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 5:this.$ = $$[$0-1];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 6:this.$ = $$[$0];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
|
|
|
case 7:this.$ = $$[$0];
|
|
|
|
break;
|
|
|
|
case 8:this.$ = $$[$0];
|
|
|
|
break;
|
|
|
|
case 9:this.$ = $$[$0];
|
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 10:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])(new yy.Literal($$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 11:this.$ = $$[$0];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 12:this.$ = $$[$0];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
|
|
|
case 13:this.$ = $$[$0];
|
|
|
|
break;
|
|
|
|
case 14:this.$ = $$[$0];
|
|
|
|
break;
|
|
|
|
case 15:this.$ = $$[$0];
|
|
|
|
break;
|
|
|
|
case 16:this.$ = $$[$0];
|
|
|
|
break;
|
|
|
|
case 17:this.$ = $$[$0];
|
|
|
|
break;
|
|
|
|
case 18:this.$ = $$[$0];
|
|
|
|
break;
|
|
|
|
case 19:this.$ = $$[$0];
|
|
|
|
break;
|
|
|
|
case 20:this.$ = $$[$0];
|
|
|
|
break;
|
|
|
|
case 21:this.$ = $$[$0];
|
|
|
|
break;
|
|
|
|
case 22:this.$ = $$[$0];
|
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 23:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])(new yy.Block);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 24:this.$ = yy.addLocationDataFn(_$[$0-2], _$[$0])($$[$0-1]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 25:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])(new yy.Literal($$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 26:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])(new yy.Literal($$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 27:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])(new yy.Literal($$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 28:this.$ = $$[$0];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 29:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])(new yy.Literal($$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 30:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])(new yy.Literal($$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 31:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])(new yy.Literal($$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 32:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])(new yy.Undefined);
|
2012-07-05 06:37:09 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 33:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])(new yy.Null);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 34:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])(new yy.Bool($$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 35:this.$ = yy.addLocationDataFn(_$[$0-2], _$[$0])(new yy.Assign($$[$0-2], $$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 36:this.$ = yy.addLocationDataFn(_$[$0-3], _$[$0])(new yy.Assign($$[$0-3], $$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 37:this.$ = yy.addLocationDataFn(_$[$0-4], _$[$0])(new yy.Assign($$[$0-4], $$[$0-1]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 38:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])(new yy.Value($$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 39:this.$ = yy.addLocationDataFn(_$[$0-2], _$[$0])(new yy.Assign(yy.addLocationDataFn(_$[$0-2])(new yy.Value($$[$0-2])), $$[$0], 'object'));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 40:this.$ = yy.addLocationDataFn(_$[$0-4], _$[$0])(new yy.Assign(yy.addLocationDataFn(_$[$0-4])(new yy.Value($$[$0-4])), $$[$0-1], 'object'));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
|
|
|
case 41:this.$ = $$[$0];
|
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 42:this.$ = $$[$0];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 43:this.$ = $$[$0];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 44:this.$ = $$[$0];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 45:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])(new yy.Return($$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 46:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])(new yy.Return);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 47:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])(new yy.Comment($$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 48:this.$ = yy.addLocationDataFn(_$[$0-4], _$[$0])(new yy.Code($$[$0-3], $$[$0], $$[$0-1]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 49:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])(new yy.Code([], $$[$0], $$[$0-1]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 50:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])('func');
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 51:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])('boundfunc');
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 52:this.$ = $$[$0];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 53:this.$ = $$[$0];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 54:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])([]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 55:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])([$$[$0]]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 56:this.$ = yy.addLocationDataFn(_$[$0-2], _$[$0])($$[$0-2].concat($$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 57:this.$ = yy.addLocationDataFn(_$[$0-3], _$[$0])($$[$0-3].concat($$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 58:this.$ = yy.addLocationDataFn(_$[$0-5], _$[$0])($$[$0-5].concat($$[$0-2]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 59:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])(new yy.Param($$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 60:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])(new yy.Param($$[$0-1], null, true));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 61:this.$ = yy.addLocationDataFn(_$[$0-2], _$[$0])(new yy.Param($$[$0-2], $$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 62:this.$ = $$[$0];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 63:this.$ = $$[$0];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 64:this.$ = $$[$0];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 65:this.$ = $$[$0];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 66:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])(new yy.Splat($$[$0-1]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 67:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])(new yy.Value($$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 68:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])($$[$0-1].add($$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 69:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])(new yy.Value($$[$0-1], [].concat($$[$0])));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 70:this.$ = $$[$0];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 71:this.$ = $$[$0];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 72:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])(new yy.Value($$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 73:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])(new yy.Value($$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 74:this.$ = $$[$0];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 75:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])(new yy.Value($$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 76:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])(new yy.Value($$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 77:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])(new yy.Value($$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 78:this.$ = $$[$0];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 79:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])(new yy.Access($$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 80:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])(new yy.Access($$[$0], 'soak'));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 81:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])([yy.addLocationDataFn(_$[$0-1])(new yy.Access(new yy.Literal('prototype'))), yy.addLocationDataFn(_$[$0])(new yy.Access($$[$0]))]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 82:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])([yy.addLocationDataFn(_$[$0-1])(new yy.Access(new yy.Literal('prototype'), 'soak')), yy.addLocationDataFn(_$[$0])(new yy.Access($$[$0]))]);
|
|
|
|
break;
|
|
|
|
case 83:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])(new yy.Access(new yy.Literal('prototype')));
|
|
|
|
break;
|
|
|
|
case 84:this.$ = $$[$0];
|
|
|
|
break;
|
|
|
|
case 85:this.$ = yy.addLocationDataFn(_$[$0-2], _$[$0])($$[$0-1]);
|
|
|
|
break;
|
|
|
|
case 86:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])(yy.extend($$[$0], {
|
2012-07-05 06:37:09 +00:00
|
|
|
soak: true
|
2013-12-30 15:00:16 +00:00
|
|
|
}));
|
|
|
|
break;
|
|
|
|
case 87:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])(new yy.Index($$[$0]));
|
|
|
|
break;
|
|
|
|
case 88:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])(new yy.Slice($$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 89:this.$ = yy.addLocationDataFn(_$[$0-3], _$[$0])(new yy.Obj($$[$0-2], $$[$0-3].generated));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 90:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])([]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 91:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])([$$[$0]]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 92:this.$ = yy.addLocationDataFn(_$[$0-2], _$[$0])($$[$0-2].concat($$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 93:this.$ = yy.addLocationDataFn(_$[$0-3], _$[$0])($$[$0-3].concat($$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 94:this.$ = yy.addLocationDataFn(_$[$0-5], _$[$0])($$[$0-5].concat($$[$0-2]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 95:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])(new yy.Class);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 96:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])(new yy.Class(null, null, $$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 97:this.$ = yy.addLocationDataFn(_$[$0-2], _$[$0])(new yy.Class(null, $$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 98:this.$ = yy.addLocationDataFn(_$[$0-3], _$[$0])(new yy.Class(null, $$[$0-1], $$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 99:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])(new yy.Class($$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 100:this.$ = yy.addLocationDataFn(_$[$0-2], _$[$0])(new yy.Class($$[$0-1], null, $$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 101:this.$ = yy.addLocationDataFn(_$[$0-3], _$[$0])(new yy.Class($$[$0-2], $$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 102:this.$ = yy.addLocationDataFn(_$[$0-4], _$[$0])(new yy.Class($$[$0-3], $$[$0-1], $$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 103:this.$ = yy.addLocationDataFn(_$[$0-2], _$[$0])(new yy.Call($$[$0-2], $$[$0], $$[$0-1]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 104:this.$ = yy.addLocationDataFn(_$[$0-2], _$[$0])(new yy.Call($$[$0-2], $$[$0], $$[$0-1]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 105:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])(new yy.Call('super', [new yy.Splat(new yy.Literal('arguments'))]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 106:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])(new yy.Call('super', $$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 107:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])(false);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 108:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])(true);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 109:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])([]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 110:this.$ = yy.addLocationDataFn(_$[$0-3], _$[$0])($$[$0-2]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 111:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])(new yy.Value(new yy.Literal('this')));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 112:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])(new yy.Value(new yy.Literal('this')));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 113:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])(new yy.Value(yy.addLocationDataFn(_$[$0-1])(new yy.Literal('this')), [yy.addLocationDataFn(_$[$0])(new yy.Access($$[$0]))], 'this'));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 114:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])(new yy.Arr([]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 115:this.$ = yy.addLocationDataFn(_$[$0-3], _$[$0])(new yy.Arr($$[$0-2]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 116:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])('inclusive');
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 117:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])('exclusive');
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 118:this.$ = yy.addLocationDataFn(_$[$0-4], _$[$0])(new yy.Range($$[$0-3], $$[$0-1], $$[$0-2]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 119:this.$ = yy.addLocationDataFn(_$[$0-2], _$[$0])(new yy.Range($$[$0-2], $$[$0], $$[$0-1]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 120:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])(new yy.Range($$[$0-1], null, $$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 121:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])(new yy.Range(null, $$[$0], $$[$0-1]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 122:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])(new yy.Range(null, null, $$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 123:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])([$$[$0]]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 124:this.$ = yy.addLocationDataFn(_$[$0-2], _$[$0])($$[$0-2].concat($$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 125:this.$ = yy.addLocationDataFn(_$[$0-3], _$[$0])($$[$0-3].concat($$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 126:this.$ = yy.addLocationDataFn(_$[$0-3], _$[$0])($$[$0-2]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 127:this.$ = yy.addLocationDataFn(_$[$0-5], _$[$0])($$[$0-5].concat($$[$0-2]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 128:this.$ = $$[$0];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 129:this.$ = $$[$0];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 130:this.$ = $$[$0];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 131:this.$ = yy.addLocationDataFn(_$[$0-2], _$[$0])([].concat($$[$0-2], $$[$0]));
|
2012-07-05 06:37:09 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 132:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])(new yy.Try($$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 133:this.$ = yy.addLocationDataFn(_$[$0-2], _$[$0])(new yy.Try($$[$0-1], $$[$0][0], $$[$0][1]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 134:this.$ = yy.addLocationDataFn(_$[$0-3], _$[$0])(new yy.Try($$[$0-2], null, null, $$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 135:this.$ = yy.addLocationDataFn(_$[$0-4], _$[$0])(new yy.Try($$[$0-3], $$[$0-2][0], $$[$0-2][1], $$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 136:this.$ = yy.addLocationDataFn(_$[$0-2], _$[$0])([$$[$0-1], $$[$0]]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 137:this.$ = yy.addLocationDataFn(_$[$0-2], _$[$0])([yy.addLocationDataFn(_$[$0-1])(new yy.Value($$[$0-1])), $$[$0]]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 138:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])([null, $$[$0]]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 139:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])(new yy.Throw($$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 140:this.$ = yy.addLocationDataFn(_$[$0-2], _$[$0])(new yy.Parens($$[$0-1]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 141:this.$ = yy.addLocationDataFn(_$[$0-4], _$[$0])(new yy.Parens($$[$0-2]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 142:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])(new yy.While($$[$0]));
|
2012-07-05 06:37:09 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 143:this.$ = yy.addLocationDataFn(_$[$0-3], _$[$0])(new yy.While($$[$0-2], {
|
2012-02-06 20:59:17 +00:00
|
|
|
guard: $$[$0]
|
2013-12-30 15:00:16 +00:00
|
|
|
}));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 144:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])(new yy.While($$[$0], {
|
2012-02-06 20:59:17 +00:00
|
|
|
invert: true
|
2013-12-30 15:00:16 +00:00
|
|
|
}));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 145:this.$ = yy.addLocationDataFn(_$[$0-3], _$[$0])(new yy.While($$[$0-2], {
|
2012-02-06 20:59:17 +00:00
|
|
|
invert: true,
|
|
|
|
guard: $$[$0]
|
2013-12-30 15:00:16 +00:00
|
|
|
}));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 146:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])($$[$0-1].addBody($$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 147:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])($$[$0].addBody(yy.addLocationDataFn(_$[$0-1])(yy.Block.wrap([$$[$0-1]]))));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 148:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])($$[$0].addBody(yy.addLocationDataFn(_$[$0-1])(yy.Block.wrap([$$[$0-1]]))));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 149:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])($$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 150:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])(new yy.While(yy.addLocationDataFn(_$[$0-1])(new yy.Literal('true'))).addBody($$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 151:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])(new yy.While(yy.addLocationDataFn(_$[$0-1])(new yy.Literal('true'))).addBody(yy.addLocationDataFn(_$[$0])(yy.Block.wrap([$$[$0]]))));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 152:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])(new yy.For($$[$0-1], $$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 153:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])(new yy.For($$[$0-1], $$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 154:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])(new yy.For($$[$0], $$[$0-1]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 155:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])({
|
|
|
|
source: yy.addLocationDataFn(_$[$0])(new yy.Value($$[$0]))
|
|
|
|
});
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 156:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])((function () {
|
2012-02-06 20:59:17 +00:00
|
|
|
$$[$0].own = $$[$0-1].own;
|
|
|
|
$$[$0].name = $$[$0-1][0];
|
|
|
|
$$[$0].index = $$[$0-1][1];
|
|
|
|
return $$[$0];
|
2013-12-30 15:00:16 +00:00
|
|
|
}()));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 157:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])($$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 158:this.$ = yy.addLocationDataFn(_$[$0-2], _$[$0])((function () {
|
2012-02-06 20:59:17 +00:00
|
|
|
$$[$0].own = true;
|
|
|
|
return $$[$0];
|
2013-12-30 15:00:16 +00:00
|
|
|
}()));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 159:this.$ = $$[$0];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 160:this.$ = $$[$0];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 161:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])(new yy.Value($$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 162:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])(new yy.Value($$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 163:this.$ = yy.addLocationDataFn(_$[$0], _$[$0])([$$[$0]]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 164:this.$ = yy.addLocationDataFn(_$[$0-2], _$[$0])([$$[$0-2], $$[$0]]);
|
|
|
|
break;
|
|
|
|
case 165:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])({
|
2012-02-06 20:59:17 +00:00
|
|
|
source: $$[$0]
|
2013-12-30 15:00:16 +00:00
|
|
|
});
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 166:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])({
|
2012-02-06 20:59:17 +00:00
|
|
|
source: $$[$0],
|
|
|
|
object: true
|
2013-12-30 15:00:16 +00:00
|
|
|
});
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 167:this.$ = yy.addLocationDataFn(_$[$0-3], _$[$0])({
|
2012-02-06 20:59:17 +00:00
|
|
|
source: $$[$0-2],
|
|
|
|
guard: $$[$0]
|
2013-12-30 15:00:16 +00:00
|
|
|
});
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 168:this.$ = yy.addLocationDataFn(_$[$0-3], _$[$0])({
|
2012-02-06 20:59:17 +00:00
|
|
|
source: $$[$0-2],
|
|
|
|
guard: $$[$0],
|
|
|
|
object: true
|
2013-12-30 15:00:16 +00:00
|
|
|
});
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 169:this.$ = yy.addLocationDataFn(_$[$0-3], _$[$0])({
|
2012-02-06 20:59:17 +00:00
|
|
|
source: $$[$0-2],
|
|
|
|
step: $$[$0]
|
2013-12-30 15:00:16 +00:00
|
|
|
});
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 170:this.$ = yy.addLocationDataFn(_$[$0-5], _$[$0])({
|
2012-02-06 20:59:17 +00:00
|
|
|
source: $$[$0-4],
|
|
|
|
guard: $$[$0-2],
|
|
|
|
step: $$[$0]
|
2013-12-30 15:00:16 +00:00
|
|
|
});
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 171:this.$ = yy.addLocationDataFn(_$[$0-5], _$[$0])({
|
2012-02-06 20:59:17 +00:00
|
|
|
source: $$[$0-4],
|
|
|
|
step: $$[$0-2],
|
|
|
|
guard: $$[$0]
|
2013-12-30 15:00:16 +00:00
|
|
|
});
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 172:this.$ = yy.addLocationDataFn(_$[$0-4], _$[$0])(new yy.Switch($$[$0-3], $$[$0-1]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 173:this.$ = yy.addLocationDataFn(_$[$0-6], _$[$0])(new yy.Switch($$[$0-5], $$[$0-3], $$[$0-1]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 174:this.$ = yy.addLocationDataFn(_$[$0-3], _$[$0])(new yy.Switch(null, $$[$0-1]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 175:this.$ = yy.addLocationDataFn(_$[$0-5], _$[$0])(new yy.Switch(null, $$[$0-3], $$[$0-1]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 176:this.$ = $$[$0];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 177:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])($$[$0-1].concat($$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 178:this.$ = yy.addLocationDataFn(_$[$0-2], _$[$0])([[$$[$0-1], $$[$0]]]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 179:this.$ = yy.addLocationDataFn(_$[$0-3], _$[$0])([[$$[$0-2], $$[$0-1]]]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 180:this.$ = yy.addLocationDataFn(_$[$0-2], _$[$0])(new yy.If($$[$0-1], $$[$0], {
|
2012-02-06 20:59:17 +00:00
|
|
|
type: $$[$0-2]
|
2013-12-30 15:00:16 +00:00
|
|
|
}));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 181:this.$ = yy.addLocationDataFn(_$[$0-4], _$[$0])($$[$0-4].addElse(yy.addLocationDataFn(_$[$0-2], _$[$0])(new yy.If($$[$0-1], $$[$0], {
|
2012-02-06 20:59:17 +00:00
|
|
|
type: $$[$0-2]
|
2013-12-30 15:00:16 +00:00
|
|
|
}))));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 182:this.$ = $$[$0];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 183:this.$ = yy.addLocationDataFn(_$[$0-2], _$[$0])($$[$0-2].addElse($$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 184:this.$ = yy.addLocationDataFn(_$[$0-2], _$[$0])(new yy.If($$[$0], yy.addLocationDataFn(_$[$0-2])(yy.Block.wrap([$$[$0-2]])), {
|
2012-02-06 20:59:17 +00:00
|
|
|
type: $$[$0-1],
|
|
|
|
statement: true
|
2013-12-30 15:00:16 +00:00
|
|
|
}));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 185:this.$ = yy.addLocationDataFn(_$[$0-2], _$[$0])(new yy.If($$[$0], yy.addLocationDataFn(_$[$0-2])(yy.Block.wrap([$$[$0-2]])), {
|
2012-02-06 20:59:17 +00:00
|
|
|
type: $$[$0-1],
|
|
|
|
statement: true
|
2013-12-30 15:00:16 +00:00
|
|
|
}));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 186:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])(new yy.Op($$[$0-1], $$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 187:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])(new yy.Op('-', $$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 188:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])(new yy.Op('+', $$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 189:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])(new yy.Op('--', $$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 190:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])(new yy.Op('++', $$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 191:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])(new yy.Op('--', $$[$0-1], null, true));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 192:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])(new yy.Op('++', $$[$0-1], null, true));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 193:this.$ = yy.addLocationDataFn(_$[$0-1], _$[$0])(new yy.Existence($$[$0-1]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 194:this.$ = yy.addLocationDataFn(_$[$0-2], _$[$0])(new yy.Op('+', $$[$0-2], $$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 195:this.$ = yy.addLocationDataFn(_$[$0-2], _$[$0])(new yy.Op('-', $$[$0-2], $$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 196:this.$ = yy.addLocationDataFn(_$[$0-2], _$[$0])(new yy.Op($$[$0-1], $$[$0-2], $$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 197:this.$ = yy.addLocationDataFn(_$[$0-2], _$[$0])(new yy.Op($$[$0-1], $$[$0-2], $$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 198:this.$ = yy.addLocationDataFn(_$[$0-2], _$[$0])(new yy.Op($$[$0-1], $$[$0-2], $$[$0]));
|
2012-07-05 06:37:09 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 199:this.$ = yy.addLocationDataFn(_$[$0-2], _$[$0])(new yy.Op($$[$0-1], $$[$0-2], $$[$0]));
|
2012-07-05 06:37:09 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 200:this.$ = yy.addLocationDataFn(_$[$0-2], _$[$0])((function () {
|
2012-02-06 20:59:17 +00:00
|
|
|
if ($$[$0-1].charAt(0) === '!') {
|
|
|
|
return new yy.Op($$[$0-1].slice(1), $$[$0-2], $$[$0]).invert();
|
|
|
|
} else {
|
|
|
|
return new yy.Op($$[$0-1], $$[$0-2], $$[$0]);
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
}()));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 201:this.$ = yy.addLocationDataFn(_$[$0-2], _$[$0])(new yy.Assign($$[$0-2], $$[$0], $$[$0-1]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 202:this.$ = yy.addLocationDataFn(_$[$0-4], _$[$0])(new yy.Assign($$[$0-4], $$[$0-1], $$[$0-3]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case 203:this.$ = yy.addLocationDataFn(_$[$0-3], _$[$0])(new yy.Assign($$[$0-3], $$[$0], $$[$0-2]));
|
|
|
|
break;
|
|
|
|
case 204:this.$ = yy.addLocationDataFn(_$[$0-2], _$[$0])(new yy.Extends($$[$0-2], $$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
2013-12-30 15:00:16 +00:00
|
|
|
table: [{1:[2,1],3:1,4:2,5:3,7:4,8:5,9:18,10:19,11:[1,20],12:6,13:7,14:8,15:9,16:10,17:11,18:12,19:13,20:14,21:15,22:16,23:17,27:60,28:[1,71],29:47,30:[1,69],31:[1,70],32:22,33:[1,48],34:[1,49],35:[1,50],36:[1,51],37:[1,52],38:[1,53],39:21,44:61,45:[1,43],46:[1,44],47:[1,27],50:28,51:[1,58],52:[1,59],58:45,59:46,61:34,63:23,64:24,65:25,76:[1,68],79:[1,41],83:[1,26],88:[1,56],89:[1,57],90:[1,55],96:[1,36],100:[1,42],101:[1,54],103:37,104:[1,63],106:[1,64],107:38,108:[1,65],109:39,110:[1,66],111:67,119:[1,40],124:35,125:[1,62],127:[1,29],128:[1,30],129:[1,31],130:[1,32],131:[1,33]},{1:[3]},{1:[2,2],6:[1,72]},{1:[2,3],6:[2,3],26:[2,3],102:[2,3]},{1:[2,6],6:[2,6],26:[2,6],102:[2,6],103:82,104:[1,63],106:[1,64],109:83,110:[1,66],111:67,126:[1,81],128:[1,75],129:[1,74],132:[1,73],133:[1,76],134:[1,77],135:[1,78],136:[1,79],137:[1,80]},{1:[2,7],6:[2,7],26:[2,7],102:[2,7],103:85,104:[1,63],106:[1,64],109:86,110:[1,66],111:67,126:[1,84]},{1:[2,11],6:[2,11],25:[2,11],26:[2,11],49:[2,11],54:[2,11],57:[2,11],62:88,66:[1,90],67:[1,91],68:[1,92],69:[1,93],70:94,71:[1,95],73:[2,11],74:[1,96],78:[2,11],81:87,84:[1,89],85:[2,107],86:[2,11],91:[2,11],93:[2,11],102:[2,11],104:[2,11],105:[2,11],106:[2,11],110:[2,11],118:[2,11],126:[2,11],128:[2,11],129:[2,11],132:[2,11],133:[2,11],134:[2,11],135:[2,11],136:[2,11],137:[2,11]},{1:[2,12],6:[2,12],25:[2,12],26:[2,12],49:[2,12],54:[2,12],57:[2,12],62:98,66:[1,90],67:[1,91],68:[1,92],69:[1,93],70:94,71:[1,95],73:[2,12],74:[1,96],78:[2,12],81:97,84:[1,89],85:[2,107],86:[2,12],91:[2,12],93:[2,12],102:[2,12],104:[2,12],105:[2,12],106:[2,12],110:[2,12],118:[2,12],126:[2,12],128:[2,12],129:[2,12],132:[2,12],133:[2,12],134:[2,12],135:[2,12],136:[2,12],137:[2,12]},{1:[2,13],6:[2,13],25:[2,13],26:[2,13],49:[2,13],54:[2,13],57:[2,13],73:[2,13],78:[2,13],86:[2,13],91:[2,13],93:[2,13],102:[2,13],104:[2,13],105:[2,13],106:[2,13],110:[2,13],118:[2,13],126:[2,13],128:[2,13],129:[2,13],132:[2,13],133:[2,13],134:[2,13],135:[2,13],136:[2,13],137:[2,13]},{1:[2,14],6:[2,14],25:[2,14],26:[2,14],49:[2,14],54:[2,14],57:[2,14],73:[2,14],78:[2,14],86:[2,14],91:[2,14],93:[2,14],102:[2,14],104:[2,14],105:[2,14],106:[2,14],110:[2,14],118:[2,14],126:[2,14],128:[2,14],129:[2,14],132:[2,14],133:[2,14],134:[2,14],135:[2,14],136:[2,14],137:[2,14]},{1:[2,15],6:[2,15],25:[2,15],26:[2,15],49:[2,15],54:[2,15],57:[2,15],73:[2,15],78:[2,15],86:[2,15],91:[2,15],93:[2,15],102:[2,15],104:[2,15],105:[2,15],106:[2,15],110:[2,15],118:[2,15],126:[2,15],128:[2,15],129:[2,15],132:[2,15],133:[2,15],134:[2,15],135:[2,15],136:[2,15],137:[2,15]},{1:[2,16],6:[2,16],25:[2,16],26:[2,16],49:[2,16],54:[2,16],57:[2,16],73:[2,16],78:[2,16],86:[2,16],91:[2,16],93:[2,16],102:[2,16],104:[2,16],105:[2,16],106:[2,16],110:[2,16],118:[2,16],126:[2,16],128:[2,16],129:[2,16],132:[2,16],133:[2,16],134:[2,16],135:[2,16],136:[2,16],137:[2,16]},{1:[2,17],6:[2,17],25:[2,17],26:[2,17],49:[2,17],54:[2,17],57:[2,17],73:[2,17],78:[2,17],86:[2,17],91:[2,17],93:[2,17],102:[2,17],104:[2,17],105:[2,17],106:[2,17],110:[2,17],118:[2,17],126:[2,17],128:[2,17],129:[2,17],132:[2,17],133:[2,17],134:[2,17],135:[2,17],136:[2,17],137:[2,17]},{1:[2,18],6:[2,18],25:[2,18],26:[2,18],49:[2,18],54:[2,18],57:[2,18],73:[2,18],78:[2,18],86:[2,18],91:[2,18],93:[2,18],102:[2,18],104:[2,18],105:[2,18],106:[2,18],110:[2,18],118:[2,18],126:[2,18],128:[2,18],129:[2,18],132:[2,18],133:[2,18],134:[2,18],135:[2,18],136:[2,18],137:[2,18]},{1:[2,19],6:[2,19],25:[2,19],26:[2,19],49:[2,19],54:[2,19],57:[2,19],73:[2,19],78:[2,19],86:[2,19],91:[2,19],93:[2,19],102:[2,19],104:[2,19],105:[2,19],106:[2,19],110:[2,19],118:[2,19],126:[2,19],128:[2,19],129:[2,19],132:[2,19],133:[2,19],134:[2,19],135:[2,19],136:[2,19],137:[2,19]},{1:[2,20],6:[2,20],25:[2,20],26:[2,20],49:[2,20],54:[2,20],57:[2,20],73:[2,20],78:[2,20],86:[2,20],91:[2,20],93:[2,20],102:[2,20],104:[2,20],105:[2,20],106:[2,20],110:[2,20],118:[2,20],126:[2,20],128:[2,20],129:[2,20],132:[2,20],133:[2,20],134:[2,20],135:[2,20],136:[2,20],137:[2,20]},{1:[2,21],6:[2,21],25:[2,21],26:[2,21],49:[2,21],54:[2,21],57:[2,21],73:[2,21],78:[2,21],86:[2,21],91:[2
|
|
|
|
defaultActions: {58:[2,50],59:[2,51],89:[2,108],186:[2,88]},
|
2012-02-06 20:59:17 +00:00
|
|
|
parseError: function parseError(str, hash) {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (hash.recoverable) {
|
|
|
|
this.trace(str);
|
|
|
|
} else {
|
|
|
|
var e = new Error(str)
|
|
|
|
e.location = hash.loc
|
|
|
|
throw e;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
},
|
|
|
|
parse: function parse(input) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var self = this, stack = [0], vstack = [null], lstack = [], table = this.table, yytext = '', yylineno = 0, yyleng = 0, recovering = 0, TERROR = 2, EOF = 1;
|
2012-02-06 20:59:17 +00:00
|
|
|
this.lexer.setInput(input);
|
|
|
|
this.lexer.yy = this.yy;
|
|
|
|
this.yy.lexer = this.lexer;
|
2013-12-30 15:00:16 +00:00
|
|
|
this.yy.parser = this;
|
|
|
|
if (typeof this.lexer.yylloc == 'undefined') {
|
2012-02-06 20:59:17 +00:00
|
|
|
this.lexer.yylloc = {};
|
2013-12-30 15:00:16 +00:00
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
var yyloc = this.lexer.yylloc;
|
|
|
|
lstack.push(yyloc);
|
2013-12-30 15:00:16 +00:00
|
|
|
var ranges = this.lexer.options && this.lexer.options.ranges;
|
|
|
|
if (typeof this.yy.parseError === 'function') {
|
2012-02-06 20:59:17 +00:00
|
|
|
this.parseError = this.yy.parseError;
|
2013-12-30 15:00:16 +00:00
|
|
|
} else {
|
|
|
|
this.parseError = Object.getPrototypeOf(this).parseError;
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
function popStack(n) {
|
|
|
|
stack.length = stack.length - 2 * n;
|
2012-02-06 20:59:17 +00:00
|
|
|
vstack.length = vstack.length - n;
|
|
|
|
lstack.length = lstack.length - n;
|
|
|
|
}
|
|
|
|
function lex() {
|
|
|
|
var token;
|
2013-12-30 15:00:16 +00:00
|
|
|
token = self.lexer.lex() || EOF;
|
|
|
|
if (typeof token !== 'number') {
|
2012-02-06 20:59:17 +00:00
|
|
|
token = self.symbols_[token] || token;
|
|
|
|
}
|
|
|
|
return token;
|
2012-07-05 06:37:09 +00:00
|
|
|
}
|
|
|
|
var symbol, preErrorSymbol, state, action, a, r, yyval = {}, p, len, newState, expected;
|
2012-02-06 20:59:17 +00:00
|
|
|
while (true) {
|
2012-07-05 06:37:09 +00:00
|
|
|
state = stack[stack.length - 1];
|
2012-02-06 20:59:17 +00:00
|
|
|
if (this.defaultActions[state]) {
|
|
|
|
action = this.defaultActions[state];
|
|
|
|
} else {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (symbol === null || typeof symbol == 'undefined') {
|
2012-02-06 20:59:17 +00:00
|
|
|
symbol = lex();
|
2013-12-30 15:00:16 +00:00
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
action = table[state] && table[state][symbol];
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
if (typeof action === 'undefined' || !action.length || !action[0]) {
|
|
|
|
var errStr = '';
|
2012-02-06 20:59:17 +00:00
|
|
|
expected = [];
|
2013-12-30 15:00:16 +00:00
|
|
|
for (p in table[state]) {
|
|
|
|
if (this.terminals_[p] && p > TERROR) {
|
|
|
|
expected.push('\'' + this.terminals_[p] + '\'');
|
2012-07-05 06:37:09 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
if (this.lexer.showPosition) {
|
2013-12-30 15:00:16 +00:00
|
|
|
errStr = 'Expecting ' + expected.join(', ') + ', got \'' + (this.terminals_[symbol] || symbol) + '\'';
|
2012-02-06 20:59:17 +00:00
|
|
|
} else {
|
2013-12-30 15:00:16 +00:00
|
|
|
errStr = 'Unexpected ' + (symbol == EOF ? 'end of input' : '\'' + (this.terminals_[symbol] || symbol) + '\'');
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
if (this.lexer.yylloc.first_line !== yyloc.first_line) yyloc = this.lexer.yylloc;
|
|
|
|
this.parseError(errStr, {
|
|
|
|
text: this.lexer.match,
|
|
|
|
token: this.terminals_[symbol] || symbol,
|
|
|
|
line: this.lexer.yylineno,
|
|
|
|
loc: yyloc,
|
|
|
|
expected: expected
|
|
|
|
});
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
if (action[0] instanceof Array && action.length > 1) {
|
2013-12-30 15:00:16 +00:00
|
|
|
throw new Error('Parse Error: multiple actions possible at state: ' + state + ', token: ' + symbol);
|
2012-07-05 06:37:09 +00:00
|
|
|
}
|
|
|
|
switch (action[0]) {
|
|
|
|
case 1:
|
|
|
|
stack.push(symbol);
|
|
|
|
vstack.push(this.lexer.yytext);
|
|
|
|
lstack.push(this.lexer.yylloc);
|
|
|
|
stack.push(action[1]);
|
|
|
|
symbol = null;
|
|
|
|
if (!preErrorSymbol) {
|
2012-02-06 20:59:17 +00:00
|
|
|
yyleng = this.lexer.yyleng;
|
|
|
|
yytext = this.lexer.yytext;
|
|
|
|
yylineno = this.lexer.yylineno;
|
|
|
|
yyloc = this.lexer.yylloc;
|
2013-12-30 15:00:16 +00:00
|
|
|
if (recovering > 0) {
|
2012-07-05 06:37:09 +00:00
|
|
|
recovering--;
|
2013-12-30 15:00:16 +00:00
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
} else {
|
|
|
|
symbol = preErrorSymbol;
|
|
|
|
preErrorSymbol = null;
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
len = this.productions_[action[1]][1];
|
|
|
|
yyval.$ = vstack[vstack.length - len];
|
2013-12-30 15:00:16 +00:00
|
|
|
yyval._$ = {
|
|
|
|
first_line: lstack[lstack.length - (len || 1)].first_line,
|
|
|
|
last_line: lstack[lstack.length - 1].last_line,
|
|
|
|
first_column: lstack[lstack.length - (len || 1)].first_column,
|
|
|
|
last_column: lstack[lstack.length - 1].last_column
|
|
|
|
};
|
|
|
|
if (ranges) {
|
|
|
|
yyval._$.range = [
|
|
|
|
lstack[lstack.length - (len || 1)].range[0],
|
|
|
|
lstack[lstack.length - 1].range[1]
|
|
|
|
];
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
r = this.performAction.call(yyval, yytext, yyleng, yylineno, this.yy, action[1], vstack, lstack);
|
2013-12-30 15:00:16 +00:00
|
|
|
if (typeof r !== 'undefined') {
|
2012-07-05 06:37:09 +00:00
|
|
|
return r;
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
if (len) {
|
|
|
|
stack = stack.slice(0, -1 * len * 2);
|
|
|
|
vstack = vstack.slice(0, -1 * len);
|
|
|
|
lstack = lstack.slice(0, -1 * len);
|
|
|
|
}
|
|
|
|
stack.push(this.productions_[action[1]][0]);
|
|
|
|
vstack.push(yyval.$);
|
|
|
|
lstack.push(yyval._$);
|
|
|
|
newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
|
|
|
|
stack.push(newState);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
return true;
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
}
|
|
|
|
return true;
|
2013-12-30 15:00:16 +00:00
|
|
|
}};
|
|
|
|
undefined
|
|
|
|
function Parser () {
|
|
|
|
this.yy = {};
|
2012-07-05 06:37:09 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
Parser.prototype = parser;parser.Parser = Parser;
|
2012-02-06 20:59:17 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
module.exports = new Parser;
|
2012-02-06 20:59:17 +00:00
|
|
|
|
|
|
|
|
2012-07-05 06:37:09 +00:00
|
|
|
});
|
2012-02-06 20:59:17 +00:00
|
|
|
|
2012-07-05 06:37:09 +00:00
|
|
|
define('ace/mode/coffee/nodes', ['require', 'exports', 'module' , 'ace/mode/coffee/scope', 'ace/mode/coffee/lexer', 'ace/mode/coffee/helpers'], function(require, exports, module) {
|
2012-02-06 20:59:17 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
var Access, Arr, Assign, Base, Block, Call, Class, Code, CodeFragment, Comment, Existence, Extends, For, HEXNUM, IDENTIFIER, IDENTIFIER_STR, IS_REGEX, IS_STRING, If, In, Index, LEVEL_ACCESS, LEVEL_COND, LEVEL_LIST, LEVEL_OP, LEVEL_PAREN, LEVEL_TOP, Literal, METHOD_DEF, NEGATE, NO, NUMBER, Obj, Op, Param, Parens, RESERVED, Range, Return, SIMPLENUM, STRICT_PROSCRIBED, Scope, Slice, Splat, Switch, TAB, THIS, Throw, Try, UTILITIES, Value, While, YES, addLocationDataFn, compact, del, ends, extend, flatten, fragmentsToText, isLiteralArguments, isLiteralThis, last, locationDataToString, merge, multident, parseNum, some, starts, throwSyntaxError, unfoldSoak, utility, _ref, _ref1,
|
2012-07-05 06:37:09 +00:00
|
|
|
__hasProp = {}.hasOwnProperty,
|
2013-12-30 15:00:16 +00:00
|
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
|
|
|
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
|
|
|
|
__slice = [].slice;
|
|
|
|
|
|
|
|
Error.stackTraceLimit = Infinity;
|
2012-02-06 20:59:17 +00:00
|
|
|
|
2012-07-05 06:37:09 +00:00
|
|
|
Scope = require('./scope').Scope;
|
2012-02-06 20:59:17 +00:00
|
|
|
|
2012-07-05 06:37:09 +00:00
|
|
|
_ref = require('./lexer'), RESERVED = _ref.RESERVED, STRICT_PROSCRIBED = _ref.STRICT_PROSCRIBED;
|
2012-02-06 20:59:17 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
_ref1 = require('./helpers'), compact = _ref1.compact, flatten = _ref1.flatten, extend = _ref1.extend, merge = _ref1.merge, del = _ref1.del, starts = _ref1.starts, ends = _ref1.ends, last = _ref1.last, some = _ref1.some, addLocationDataFn = _ref1.addLocationDataFn, locationDataToString = _ref1.locationDataToString, throwSyntaxError = _ref1.throwSyntaxError;
|
2012-02-06 20:59:17 +00:00
|
|
|
|
|
|
|
exports.extend = extend;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
exports.addLocationDataFn = addLocationDataFn;
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
YES = function() {
|
|
|
|
return true;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
NO = function() {
|
|
|
|
return false;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
THIS = function() {
|
|
|
|
return this;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
NEGATE = function() {
|
|
|
|
this.negated = !this.negated;
|
|
|
|
return this;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
exports.CodeFragment = CodeFragment = (function() {
|
|
|
|
function CodeFragment(parent, code) {
|
|
|
|
var _ref2;
|
|
|
|
this.code = "" + code;
|
|
|
|
this.locationData = parent != null ? parent.locationData : void 0;
|
|
|
|
this.type = (parent != null ? (_ref2 = parent.constructor) != null ? _ref2.name : void 0 : void 0) || 'unknown';
|
|
|
|
}
|
|
|
|
|
|
|
|
CodeFragment.prototype.toString = function() {
|
|
|
|
return "" + this.code + (this.locationData ? ": " + locationDataToString(this.locationData) : '');
|
|
|
|
};
|
|
|
|
|
|
|
|
return CodeFragment;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
})();
|
|
|
|
|
|
|
|
fragmentsToText = function(fragments) {
|
|
|
|
var fragment;
|
|
|
|
return ((function() {
|
|
|
|
var _i, _len, _results;
|
|
|
|
_results = [];
|
|
|
|
for (_i = 0, _len = fragments.length; _i < _len; _i++) {
|
|
|
|
fragment = fragments[_i];
|
|
|
|
_results.push(fragment.code);
|
|
|
|
}
|
|
|
|
return _results;
|
|
|
|
})()).join('');
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
exports.Base = Base = (function() {
|
2012-02-06 20:59:17 +00:00
|
|
|
function Base() {}
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Base.prototype.compile = function(o, lvl) {
|
2013-12-30 15:00:16 +00:00
|
|
|
return fragmentsToText(this.compileToFragments(o, lvl));
|
|
|
|
};
|
|
|
|
|
|
|
|
Base.prototype.compileToFragments = function(o, lvl) {
|
2012-02-06 20:59:17 +00:00
|
|
|
var node;
|
|
|
|
o = extend({}, o);
|
2013-12-30 15:00:16 +00:00
|
|
|
if (lvl) {
|
|
|
|
o.level = lvl;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
node = this.unfoldSoak(o) || this;
|
|
|
|
node.tab = o.indent;
|
|
|
|
if (o.level === LEVEL_TOP || !node.isStatement(o)) {
|
|
|
|
return node.compileNode(o);
|
|
|
|
} else {
|
|
|
|
return node.compileClosure(o);
|
|
|
|
}
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Base.prototype.compileClosure = function(o) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var args, argumentsNode, func, jumpNode, meth;
|
|
|
|
if (jumpNode = this.jumps()) {
|
|
|
|
jumpNode.error('cannot use a pure statement in an expression');
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
o.sharedScope = true;
|
2013-12-30 15:00:16 +00:00
|
|
|
func = new Code([], Block.wrap([this]));
|
|
|
|
args = [];
|
|
|
|
if ((argumentsNode = this.contains(isLiteralArguments)) || this.contains(isLiteralThis)) {
|
|
|
|
args = [new Literal('this')];
|
|
|
|
if (argumentsNode) {
|
|
|
|
meth = 'apply';
|
|
|
|
args.push(new Literal('arguments'));
|
|
|
|
} else {
|
|
|
|
meth = 'call';
|
|
|
|
}
|
|
|
|
func = new Value(func, [new Access(new Literal(meth))]);
|
|
|
|
}
|
|
|
|
return (new Call(func, args)).compileNode(o);
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Base.prototype.cache = function(o, level, reused) {
|
|
|
|
var ref, sub;
|
|
|
|
if (!this.isComplex()) {
|
2013-12-30 15:00:16 +00:00
|
|
|
ref = level ? this.compileToFragments(o, level) : this;
|
2012-02-06 20:59:17 +00:00
|
|
|
return [ref, ref];
|
|
|
|
} else {
|
|
|
|
ref = new Literal(reused || o.scope.freeVariable('ref'));
|
|
|
|
sub = new Assign(ref, this);
|
|
|
|
if (level) {
|
2013-12-30 15:00:16 +00:00
|
|
|
return [sub.compileToFragments(o, level), [this.makeCode(ref.value)]];
|
2012-02-06 20:59:17 +00:00
|
|
|
} else {
|
|
|
|
return [sub, ref];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
Base.prototype.cacheToCodeFragments = function(cacheValues) {
|
|
|
|
return [fragmentsToText(cacheValues[0]), fragmentsToText(cacheValues[1])];
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
Base.prototype.makeReturn = function(res) {
|
|
|
|
var me;
|
|
|
|
me = this.unwrapAll();
|
|
|
|
if (res) {
|
|
|
|
return new Call(new Literal("" + res + ".push"), [me]);
|
|
|
|
} else {
|
|
|
|
return new Return(me);
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Base.prototype.contains = function(pred) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var node;
|
|
|
|
node = void 0;
|
|
|
|
this.traverseChildren(false, function(n) {
|
|
|
|
if (pred(n)) {
|
|
|
|
node = n;
|
2012-02-06 20:59:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2013-12-30 15:00:16 +00:00
|
|
|
return node;
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Base.prototype.lastNonComment = function(list) {
|
|
|
|
var i;
|
|
|
|
i = list.length;
|
|
|
|
while (i--) {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (!(list[i] instanceof Comment)) {
|
|
|
|
return list[i];
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Base.prototype.toString = function(idt, name) {
|
|
|
|
var tree;
|
2013-12-30 15:00:16 +00:00
|
|
|
if (idt == null) {
|
|
|
|
idt = '';
|
|
|
|
}
|
|
|
|
if (name == null) {
|
|
|
|
name = this.constructor.name;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
tree = '\n' + idt + name;
|
2013-12-30 15:00:16 +00:00
|
|
|
if (this.soak) {
|
|
|
|
tree += '?';
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
this.eachChild(function(node) {
|
|
|
|
return tree += node.toString(idt + TAB);
|
|
|
|
});
|
|
|
|
return tree;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Base.prototype.eachChild = function(func) {
|
2012-07-05 06:37:09 +00:00
|
|
|
var attr, child, _i, _j, _len, _len1, _ref2, _ref3;
|
2013-12-30 15:00:16 +00:00
|
|
|
if (!this.children) {
|
|
|
|
return this;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
_ref2 = this.children;
|
|
|
|
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
|
|
|
attr = _ref2[_i];
|
|
|
|
if (this[attr]) {
|
|
|
|
_ref3 = flatten([this[attr]]);
|
2012-07-05 06:37:09 +00:00
|
|
|
for (_j = 0, _len1 = _ref3.length; _j < _len1; _j++) {
|
2012-02-06 20:59:17 +00:00
|
|
|
child = _ref3[_j];
|
2013-12-30 15:00:16 +00:00
|
|
|
if (func(child) === false) {
|
|
|
|
return this;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Base.prototype.traverseChildren = function(crossScope, func) {
|
|
|
|
return this.eachChild(function(child) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var recur;
|
|
|
|
recur = func(child);
|
|
|
|
if (recur !== false) {
|
|
|
|
return child.traverseChildren(crossScope, func);
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
});
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Base.prototype.invert = function() {
|
|
|
|
return new Op('!', this);
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Base.prototype.unwrapAll = function() {
|
|
|
|
var node;
|
|
|
|
node = this;
|
|
|
|
while (node !== (node = node.unwrap())) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
return node;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Base.prototype.children = [];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Base.prototype.isStatement = NO;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Base.prototype.jumps = NO;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Base.prototype.isComplex = YES;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Base.prototype.isChainable = NO;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Base.prototype.isAssignable = NO;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Base.prototype.unwrap = THIS;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Base.prototype.unfoldSoak = NO;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Base.prototype.assigns = NO;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
Base.prototype.updateLocationDataIfMissing = function(locationData) {
|
|
|
|
if (this.locationData) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
this.locationData = locationData;
|
|
|
|
return this.eachChild(function(child) {
|
|
|
|
return child.updateLocationDataIfMissing(locationData);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
Base.prototype.error = function(message) {
|
|
|
|
return throwSyntaxError(message, this.locationData);
|
|
|
|
};
|
|
|
|
|
|
|
|
Base.prototype.makeCode = function(code) {
|
|
|
|
return new CodeFragment(this, code);
|
|
|
|
};
|
|
|
|
|
|
|
|
Base.prototype.wrapInBraces = function(fragments) {
|
|
|
|
return [].concat(this.makeCode('('), fragments, this.makeCode(')'));
|
|
|
|
};
|
|
|
|
|
|
|
|
Base.prototype.joinFragmentArrays = function(fragmentsList, joinStr) {
|
|
|
|
var answer, fragments, i, _i, _len;
|
|
|
|
answer = [];
|
|
|
|
for (i = _i = 0, _len = fragmentsList.length; _i < _len; i = ++_i) {
|
|
|
|
fragments = fragmentsList[i];
|
|
|
|
if (i) {
|
|
|
|
answer.push(this.makeCode(joinStr));
|
|
|
|
}
|
|
|
|
answer = answer.concat(fragments);
|
|
|
|
}
|
|
|
|
return answer;
|
|
|
|
};
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
return Base;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
})();
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
exports.Block = Block = (function(_super) {
|
|
|
|
__extends(Block, _super);
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
function Block(nodes) {
|
|
|
|
this.expressions = compact(flatten(nodes || []));
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Block.prototype.children = ['expressions'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Block.prototype.push = function(node) {
|
|
|
|
this.expressions.push(node);
|
|
|
|
return this;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Block.prototype.pop = function() {
|
|
|
|
return this.expressions.pop();
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Block.prototype.unshift = function(node) {
|
|
|
|
this.expressions.unshift(node);
|
|
|
|
return this;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Block.prototype.unwrap = function() {
|
|
|
|
if (this.expressions.length === 1) {
|
|
|
|
return this.expressions[0];
|
|
|
|
} else {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Block.prototype.isEmpty = function() {
|
|
|
|
return !this.expressions.length;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Block.prototype.isStatement = function(o) {
|
|
|
|
var exp, _i, _len, _ref2;
|
|
|
|
_ref2 = this.expressions;
|
|
|
|
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
|
|
|
exp = _ref2[_i];
|
2013-12-30 15:00:16 +00:00
|
|
|
if (exp.isStatement(o)) {
|
|
|
|
return true;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Block.prototype.jumps = function(o) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var exp, jumpNode, _i, _len, _ref2;
|
2012-02-06 20:59:17 +00:00
|
|
|
_ref2 = this.expressions;
|
|
|
|
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
|
|
|
exp = _ref2[_i];
|
2013-12-30 15:00:16 +00:00
|
|
|
if (jumpNode = exp.jumps(o)) {
|
|
|
|
return jumpNode;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
Block.prototype.makeReturn = function(res) {
|
2012-02-06 20:59:17 +00:00
|
|
|
var expr, len;
|
|
|
|
len = this.expressions.length;
|
|
|
|
while (len--) {
|
|
|
|
expr = this.expressions[len];
|
|
|
|
if (!(expr instanceof Comment)) {
|
2012-07-05 06:37:09 +00:00
|
|
|
this.expressions[len] = expr.makeReturn(res);
|
2012-02-06 20:59:17 +00:00
|
|
|
if (expr instanceof Return && !expr.expression) {
|
|
|
|
this.expressions.splice(len, 1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
Block.prototype.compileToFragments = function(o, level) {
|
|
|
|
if (o == null) {
|
|
|
|
o = {};
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
if (o.scope) {
|
2013-12-30 15:00:16 +00:00
|
|
|
return Block.__super__.compileToFragments.call(this, o, level);
|
2012-02-06 20:59:17 +00:00
|
|
|
} else {
|
|
|
|
return this.compileRoot(o);
|
|
|
|
}
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Block.prototype.compileNode = function(o) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var answer, compiledNodes, fragments, index, node, top, _i, _len, _ref2;
|
2012-02-06 20:59:17 +00:00
|
|
|
this.tab = o.indent;
|
|
|
|
top = o.level === LEVEL_TOP;
|
2013-12-30 15:00:16 +00:00
|
|
|
compiledNodes = [];
|
2012-02-06 20:59:17 +00:00
|
|
|
_ref2 = this.expressions;
|
2013-12-30 15:00:16 +00:00
|
|
|
for (index = _i = 0, _len = _ref2.length; _i < _len; index = ++_i) {
|
|
|
|
node = _ref2[index];
|
2012-02-06 20:59:17 +00:00
|
|
|
node = node.unwrapAll();
|
|
|
|
node = node.unfoldSoak(o) || node;
|
2012-07-05 06:37:09 +00:00
|
|
|
if (node instanceof Block) {
|
2013-12-30 15:00:16 +00:00
|
|
|
compiledNodes.push(node.compileNode(o));
|
2012-07-05 06:37:09 +00:00
|
|
|
} else if (top) {
|
2012-02-06 20:59:17 +00:00
|
|
|
node.front = true;
|
2013-12-30 15:00:16 +00:00
|
|
|
fragments = node.compileToFragments(o);
|
2012-07-05 06:37:09 +00:00
|
|
|
if (!node.isStatement(o)) {
|
2013-12-30 15:00:16 +00:00
|
|
|
fragments.unshift(this.makeCode("" + this.tab));
|
|
|
|
fragments.push(this.makeCode(";"));
|
2012-07-05 06:37:09 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
compiledNodes.push(fragments);
|
2012-02-06 20:59:17 +00:00
|
|
|
} else {
|
2013-12-30 15:00:16 +00:00
|
|
|
compiledNodes.push(node.compileToFragments(o, LEVEL_LIST));
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (top) {
|
2012-07-05 06:37:09 +00:00
|
|
|
if (this.spaced) {
|
2013-12-30 15:00:16 +00:00
|
|
|
return [].concat(this.joinFragmentArrays(compiledNodes, '\n\n'), this.makeCode("\n"));
|
2012-07-05 06:37:09 +00:00
|
|
|
} else {
|
2013-12-30 15:00:16 +00:00
|
|
|
return this.joinFragmentArrays(compiledNodes, '\n');
|
2012-07-05 06:37:09 +00:00
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
if (compiledNodes.length) {
|
|
|
|
answer = this.joinFragmentArrays(compiledNodes, ', ');
|
|
|
|
} else {
|
|
|
|
answer = [this.makeCode("void 0")];
|
|
|
|
}
|
|
|
|
if (compiledNodes.length > 1 && o.level >= LEVEL_LIST) {
|
|
|
|
return this.wrapInBraces(answer);
|
2012-02-06 20:59:17 +00:00
|
|
|
} else {
|
2013-12-30 15:00:16 +00:00
|
|
|
return answer;
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Block.prototype.compileRoot = function(o) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var exp, fragments, i, name, prelude, preludeExps, rest, _i, _len, _ref2;
|
2012-07-05 06:37:09 +00:00
|
|
|
o.indent = o.bare ? '' : TAB;
|
2012-02-06 20:59:17 +00:00
|
|
|
o.level = LEVEL_TOP;
|
2012-07-05 06:37:09 +00:00
|
|
|
this.spaced = true;
|
2013-12-30 15:00:16 +00:00
|
|
|
o.scope = new Scope(null, this, null);
|
|
|
|
_ref2 = o.locals || [];
|
|
|
|
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
|
|
|
name = _ref2[_i];
|
|
|
|
o.scope.parameter(name);
|
|
|
|
}
|
|
|
|
prelude = [];
|
2012-07-05 06:37:09 +00:00
|
|
|
if (!o.bare) {
|
|
|
|
preludeExps = (function() {
|
2013-12-30 15:00:16 +00:00
|
|
|
var _j, _len1, _ref3, _results;
|
|
|
|
_ref3 = this.expressions;
|
2012-07-05 06:37:09 +00:00
|
|
|
_results = [];
|
2013-12-30 15:00:16 +00:00
|
|
|
for (i = _j = 0, _len1 = _ref3.length; _j < _len1; i = ++_j) {
|
|
|
|
exp = _ref3[i];
|
|
|
|
if (!(exp.unwrap() instanceof Comment)) {
|
|
|
|
break;
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
_results.push(exp);
|
|
|
|
}
|
|
|
|
return _results;
|
|
|
|
}).call(this);
|
|
|
|
rest = this.expressions.slice(preludeExps.length);
|
|
|
|
this.expressions = preludeExps;
|
|
|
|
if (preludeExps.length) {
|
2013-12-30 15:00:16 +00:00
|
|
|
prelude = this.compileNode(merge(o, {
|
2012-07-05 06:37:09 +00:00
|
|
|
indent: ''
|
2013-12-30 15:00:16 +00:00
|
|
|
}));
|
|
|
|
prelude.push(this.makeCode("\n"));
|
2012-07-05 06:37:09 +00:00
|
|
|
}
|
|
|
|
this.expressions = rest;
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
fragments = this.compileWithDeclarations(o);
|
|
|
|
if (o.bare) {
|
|
|
|
return fragments;
|
|
|
|
}
|
|
|
|
return [].concat(prelude, this.makeCode("(function() {\n"), fragments, this.makeCode("\n}).call(this);\n"));
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Block.prototype.compileWithDeclarations = function(o) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var assigns, declars, exp, fragments, i, post, rest, scope, spaced, _i, _len, _ref2, _ref3, _ref4;
|
|
|
|
fragments = [];
|
|
|
|
post = [];
|
2012-02-06 20:59:17 +00:00
|
|
|
_ref2 = this.expressions;
|
2012-07-05 06:37:09 +00:00
|
|
|
for (i = _i = 0, _len = _ref2.length; _i < _len; i = ++_i) {
|
2012-02-06 20:59:17 +00:00
|
|
|
exp = _ref2[i];
|
|
|
|
exp = exp.unwrap();
|
2013-12-30 15:00:16 +00:00
|
|
|
if (!(exp instanceof Comment || exp instanceof Literal)) {
|
|
|
|
break;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
o = merge(o, {
|
|
|
|
level: LEVEL_TOP
|
|
|
|
});
|
|
|
|
if (i) {
|
2012-07-05 06:37:09 +00:00
|
|
|
rest = this.expressions.splice(i, 9e9);
|
|
|
|
_ref3 = [this.spaced, false], spaced = _ref3[0], this.spaced = _ref3[1];
|
2013-12-30 15:00:16 +00:00
|
|
|
_ref4 = [this.compileNode(o), spaced], fragments = _ref4[0], this.spaced = _ref4[1];
|
2012-02-06 20:59:17 +00:00
|
|
|
this.expressions = rest;
|
|
|
|
}
|
|
|
|
post = this.compileNode(o);
|
|
|
|
scope = o.scope;
|
|
|
|
if (scope.expressions === this) {
|
|
|
|
declars = o.scope.hasDeclarations();
|
|
|
|
assigns = scope.hasAssignments;
|
2012-07-05 06:37:09 +00:00
|
|
|
if (declars || assigns) {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (i) {
|
|
|
|
fragments.push(this.makeCode('\n'));
|
|
|
|
}
|
|
|
|
fragments.push(this.makeCode("" + this.tab + "var "));
|
|
|
|
if (declars) {
|
|
|
|
fragments.push(this.makeCode(scope.declaredVariables().join(', ')));
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
if (assigns) {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (declars) {
|
|
|
|
fragments.push(this.makeCode(",\n" + (this.tab + TAB)));
|
|
|
|
}
|
|
|
|
fragments.push(this.makeCode(scope.assignedVariables().join(",\n" + (this.tab + TAB))));
|
2012-07-05 06:37:09 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
fragments.push(this.makeCode(";\n" + (this.spaced ? '\n' : '')));
|
|
|
|
} else if (fragments.length && post.length) {
|
|
|
|
fragments.push(this.makeCode("\n"));
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
return fragments.concat(post);
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Block.wrap = function(nodes) {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (nodes.length === 1 && nodes[0] instanceof Block) {
|
|
|
|
return nodes[0];
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
return new Block(nodes);
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
return Block;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
})(Base);
|
|
|
|
|
|
|
|
exports.Literal = Literal = (function(_super) {
|
|
|
|
__extends(Literal, _super);
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
function Literal(value) {
|
|
|
|
this.value = value;
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Literal.prototype.makeReturn = function() {
|
|
|
|
if (this.isStatement()) {
|
|
|
|
return this;
|
|
|
|
} else {
|
2012-07-05 06:37:09 +00:00
|
|
|
return Literal.__super__.makeReturn.apply(this, arguments);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Literal.prototype.isAssignable = function() {
|
|
|
|
return IDENTIFIER.test(this.value);
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Literal.prototype.isStatement = function() {
|
|
|
|
var _ref2;
|
|
|
|
return (_ref2 = this.value) === 'break' || _ref2 === 'continue' || _ref2 === 'debugger';
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Literal.prototype.isComplex = NO;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Literal.prototype.assigns = function(name) {
|
|
|
|
return name === this.value;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Literal.prototype.jumps = function(o) {
|
2012-07-05 06:37:09 +00:00
|
|
|
if (this.value === 'break' && !((o != null ? o.loop : void 0) || (o != null ? o.block : void 0))) {
|
2012-02-06 20:59:17 +00:00
|
|
|
return this;
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
if (this.value === 'continue' && !(o != null ? o.loop : void 0)) {
|
|
|
|
return this;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Literal.prototype.compileNode = function(o) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var answer, code, _ref2;
|
|
|
|
code = this.value === 'this' ? ((_ref2 = o.scope.method) != null ? _ref2.bound : void 0) ? o.scope.method.context : this.value : this.value.reserved ? "\"" + this.value + "\"" : this.value;
|
|
|
|
answer = this.isStatement() ? "" + this.tab + code + ";" : code;
|
|
|
|
return [this.makeCode(answer)];
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Literal.prototype.toString = function() {
|
|
|
|
return ' "' + this.value + '"';
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
return Literal;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
})(Base);
|
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
exports.Undefined = (function(_super) {
|
|
|
|
__extends(Undefined, _super);
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
function Undefined() {
|
|
|
|
return Undefined.__super__.constructor.apply(this, arguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
Undefined.prototype.isAssignable = NO;
|
|
|
|
|
|
|
|
Undefined.prototype.isComplex = NO;
|
|
|
|
|
|
|
|
Undefined.prototype.compileNode = function(o) {
|
|
|
|
return [this.makeCode(o.level >= LEVEL_ACCESS ? '(void 0)' : 'void 0')];
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
return Undefined;
|
|
|
|
|
|
|
|
})(Base);
|
|
|
|
|
|
|
|
exports.Null = (function(_super) {
|
|
|
|
__extends(Null, _super);
|
|
|
|
|
|
|
|
function Null() {
|
|
|
|
return Null.__super__.constructor.apply(this, arguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
Null.prototype.isAssignable = NO;
|
|
|
|
|
|
|
|
Null.prototype.isComplex = NO;
|
|
|
|
|
|
|
|
Null.prototype.compileNode = function() {
|
|
|
|
return [this.makeCode("null")];
|
|
|
|
};
|
|
|
|
|
|
|
|
return Null;
|
|
|
|
|
|
|
|
})(Base);
|
|
|
|
|
|
|
|
exports.Bool = (function(_super) {
|
|
|
|
__extends(Bool, _super);
|
|
|
|
|
|
|
|
Bool.prototype.isAssignable = NO;
|
|
|
|
|
|
|
|
Bool.prototype.isComplex = NO;
|
|
|
|
|
|
|
|
Bool.prototype.compileNode = function() {
|
|
|
|
return [this.makeCode(this.val)];
|
|
|
|
};
|
|
|
|
|
|
|
|
function Bool(val) {
|
|
|
|
this.val = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Bool;
|
|
|
|
|
|
|
|
})(Base);
|
|
|
|
|
|
|
|
exports.Return = Return = (function(_super) {
|
|
|
|
__extends(Return, _super);
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
function Return(expr) {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (expr && !expr.unwrap().isUndefined) {
|
|
|
|
this.expression = expr;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Return.prototype.children = ['expression'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Return.prototype.isStatement = YES;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Return.prototype.makeReturn = THIS;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Return.prototype.jumps = THIS;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
Return.prototype.compileToFragments = function(o, level) {
|
2012-02-06 20:59:17 +00:00
|
|
|
var expr, _ref2;
|
|
|
|
expr = (_ref2 = this.expression) != null ? _ref2.makeReturn() : void 0;
|
|
|
|
if (expr && !(expr instanceof Return)) {
|
2013-12-30 15:00:16 +00:00
|
|
|
return expr.compileToFragments(o, level);
|
2012-02-06 20:59:17 +00:00
|
|
|
} else {
|
2013-12-30 15:00:16 +00:00
|
|
|
return Return.__super__.compileToFragments.call(this, o, level);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Return.prototype.compileNode = function(o) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var answer;
|
|
|
|
answer = [];
|
|
|
|
answer.push(this.makeCode(this.tab + ("return" + (this.expression ? " " : ""))));
|
|
|
|
if (this.expression) {
|
|
|
|
answer = answer.concat(this.expression.compileToFragments(o, LEVEL_PAREN));
|
|
|
|
}
|
|
|
|
answer.push(this.makeCode(";"));
|
|
|
|
return answer;
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
return Return;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
})(Base);
|
|
|
|
|
|
|
|
exports.Value = Value = (function(_super) {
|
|
|
|
__extends(Value, _super);
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
function Value(base, props, tag) {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (!props && base instanceof Value) {
|
|
|
|
return base;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
this.base = base;
|
|
|
|
this.properties = props || [];
|
2013-12-30 15:00:16 +00:00
|
|
|
if (tag) {
|
|
|
|
this[tag] = true;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
return this;
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Value.prototype.children = ['base', 'properties'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
Value.prototype.add = function(props) {
|
|
|
|
this.properties = this.properties.concat(props);
|
2012-02-06 20:59:17 +00:00
|
|
|
return this;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Value.prototype.hasProperties = function() {
|
|
|
|
return !!this.properties.length;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
Value.prototype.bareLiteral = function(type) {
|
|
|
|
return !this.properties.length && this.base instanceof type;
|
|
|
|
};
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Value.prototype.isArray = function() {
|
2013-12-30 15:00:16 +00:00
|
|
|
return this.bareLiteral(Arr);
|
|
|
|
};
|
|
|
|
|
|
|
|
Value.prototype.isRange = function() {
|
|
|
|
return this.bareLiteral(Range);
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Value.prototype.isComplex = function() {
|
|
|
|
return this.hasProperties() || this.base.isComplex();
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Value.prototype.isAssignable = function() {
|
|
|
|
return this.hasProperties() || this.base.isAssignable();
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Value.prototype.isSimpleNumber = function() {
|
2013-12-30 15:00:16 +00:00
|
|
|
return this.bareLiteral(Literal) && SIMPLENUM.test(this.base.value);
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
Value.prototype.isString = function() {
|
2013-12-30 15:00:16 +00:00
|
|
|
return this.bareLiteral(Literal) && IS_STRING.test(this.base.value);
|
|
|
|
};
|
|
|
|
|
|
|
|
Value.prototype.isRegex = function() {
|
|
|
|
return this.bareLiteral(Literal) && IS_REGEX.test(this.base.value);
|
2012-07-05 06:37:09 +00:00
|
|
|
};
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Value.prototype.isAtomic = function() {
|
|
|
|
var node, _i, _len, _ref2;
|
|
|
|
_ref2 = this.properties.concat(this.base);
|
|
|
|
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
|
|
|
node = _ref2[_i];
|
2013-12-30 15:00:16 +00:00
|
|
|
if (node.soak || node instanceof Call) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
Value.prototype.isNotCallable = function() {
|
|
|
|
return this.isSimpleNumber() || this.isString() || this.isRegex() || this.isArray() || this.isRange() || this.isSplice() || this.isObject();
|
|
|
|
};
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Value.prototype.isStatement = function(o) {
|
|
|
|
return !this.properties.length && this.base.isStatement(o);
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Value.prototype.assigns = function(name) {
|
|
|
|
return !this.properties.length && this.base.assigns(name);
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Value.prototype.jumps = function(o) {
|
|
|
|
return !this.properties.length && this.base.jumps(o);
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Value.prototype.isObject = function(onlyGenerated) {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (this.properties.length) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
return (this.base instanceof Obj) && (!onlyGenerated || this.base.generated);
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Value.prototype.isSplice = function() {
|
|
|
|
return last(this.properties) instanceof Slice;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
Value.prototype.looksStatic = function(className) {
|
|
|
|
var _ref2;
|
|
|
|
return this.base.value === className && this.properties.length && ((_ref2 = this.properties[0].name) != null ? _ref2.value : void 0) !== 'prototype';
|
|
|
|
};
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Value.prototype.unwrap = function() {
|
|
|
|
if (this.properties.length) {
|
|
|
|
return this;
|
|
|
|
} else {
|
|
|
|
return this.base;
|
|
|
|
}
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Value.prototype.cacheReference = function(o) {
|
|
|
|
var base, bref, name, nref;
|
|
|
|
name = last(this.properties);
|
|
|
|
if (this.properties.length < 2 && !this.base.isComplex() && !(name != null ? name.isComplex() : void 0)) {
|
|
|
|
return [this, this];
|
|
|
|
}
|
|
|
|
base = new Value(this.base, this.properties.slice(0, -1));
|
|
|
|
if (base.isComplex()) {
|
|
|
|
bref = new Literal(o.scope.freeVariable('base'));
|
|
|
|
base = new Value(new Parens(new Assign(bref, base)));
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
if (!name) {
|
|
|
|
return [base, bref];
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
if (name.isComplex()) {
|
|
|
|
nref = new Literal(o.scope.freeVariable('name'));
|
|
|
|
name = new Index(new Assign(nref, name.index));
|
|
|
|
nref = new Index(nref);
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
return [base.add(name), new Value(bref || base.base, [nref || name])];
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Value.prototype.compileNode = function(o) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var fragments, prop, props, _i, _len;
|
2012-02-06 20:59:17 +00:00
|
|
|
this.base.front = this.front;
|
|
|
|
props = this.properties;
|
2013-12-30 15:00:16 +00:00
|
|
|
fragments = this.base.compileToFragments(o, (props.length ? LEVEL_ACCESS : null));
|
|
|
|
if ((this.base instanceof Parens || props.length) && SIMPLENUM.test(fragmentsToText(fragments))) {
|
|
|
|
fragments.push(this.makeCode('.'));
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
for (_i = 0, _len = props.length; _i < _len; _i++) {
|
|
|
|
prop = props[_i];
|
2013-12-30 15:00:16 +00:00
|
|
|
fragments.push.apply(fragments, prop.compileToFragments(o));
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
return fragments;
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Value.prototype.unfoldSoak = function(o) {
|
2013-12-30 15:00:16 +00:00
|
|
|
return this.unfoldedSoak != null ? this.unfoldedSoak : this.unfoldedSoak = (function(_this) {
|
|
|
|
return function() {
|
|
|
|
var fst, i, ifn, prop, ref, snd, _i, _len, _ref2, _ref3;
|
|
|
|
if (ifn = _this.base.unfoldSoak(o)) {
|
|
|
|
(_ref2 = ifn.body.properties).push.apply(_ref2, _this.properties);
|
|
|
|
return ifn;
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
_ref3 = _this.properties;
|
|
|
|
for (i = _i = 0, _len = _ref3.length; _i < _len; i = ++_i) {
|
|
|
|
prop = _ref3[i];
|
|
|
|
if (!prop.soak) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
prop.soak = false;
|
|
|
|
fst = new Value(_this.base, _this.properties.slice(0, i));
|
|
|
|
snd = new Value(_this.base, _this.properties.slice(i));
|
|
|
|
if (fst.isComplex()) {
|
|
|
|
ref = new Literal(o.scope.freeVariable('ref'));
|
|
|
|
fst = new Parens(new Assign(ref, fst));
|
|
|
|
snd.base = ref;
|
|
|
|
}
|
|
|
|
return new If(new Existence(fst), snd, {
|
|
|
|
soak: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
})(this)();
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
return Value;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
})(Base);
|
|
|
|
|
|
|
|
exports.Comment = Comment = (function(_super) {
|
|
|
|
__extends(Comment, _super);
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
function Comment(comment) {
|
|
|
|
this.comment = comment;
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Comment.prototype.isStatement = YES;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Comment.prototype.makeReturn = THIS;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Comment.prototype.compileNode = function(o, level) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var code, comment;
|
|
|
|
comment = this.comment.replace(/^(\s*)#/gm, "$1 *");
|
|
|
|
code = "/*" + (multident(comment, this.tab)) + (__indexOf.call(comment, '\n') >= 0 ? "\n" + this.tab : '') + " */";
|
|
|
|
if ((level || o.level) === LEVEL_TOP) {
|
|
|
|
code = o.indent + code;
|
|
|
|
}
|
|
|
|
return [this.makeCode("\n"), this.makeCode(code)];
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
return Comment;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
})(Base);
|
|
|
|
|
|
|
|
exports.Call = Call = (function(_super) {
|
|
|
|
__extends(Call, _super);
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
function Call(variable, args, soak) {
|
|
|
|
this.args = args != null ? args : [];
|
|
|
|
this.soak = soak;
|
|
|
|
this.isNew = false;
|
|
|
|
this.isSuper = variable === 'super';
|
|
|
|
this.variable = this.isSuper ? null : variable;
|
2013-12-30 15:00:16 +00:00
|
|
|
if (variable instanceof Value && variable.isNotCallable()) {
|
|
|
|
variable.error("literal is not a function");
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Call.prototype.children = ['variable', 'args'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Call.prototype.newInstance = function() {
|
2012-07-05 06:37:09 +00:00
|
|
|
var base, _ref2;
|
|
|
|
base = ((_ref2 = this.variable) != null ? _ref2.base : void 0) || this.variable;
|
|
|
|
if (base instanceof Call && !base.isNew) {
|
2012-02-06 20:59:17 +00:00
|
|
|
base.newInstance();
|
|
|
|
} else {
|
|
|
|
this.isNew = true;
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Call.prototype.superReference = function(o) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var accesses, method;
|
|
|
|
method = o.scope.namedMethod();
|
|
|
|
if (method != null ? method.klass : void 0) {
|
2012-07-05 06:37:09 +00:00
|
|
|
accesses = [new Access(new Literal('__super__'))];
|
|
|
|
if (method["static"]) {
|
|
|
|
accesses.push(new Access(new Literal('constructor')));
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
accesses.push(new Access(new Literal(method.name)));
|
2012-07-05 06:37:09 +00:00
|
|
|
return (new Value(new Literal(method.klass), accesses)).compile(o);
|
2013-12-30 15:00:16 +00:00
|
|
|
} else if (method != null ? method.ctor : void 0) {
|
|
|
|
return "" + method.name + ".__super__.constructor";
|
2012-02-06 20:59:17 +00:00
|
|
|
} else {
|
2013-12-30 15:00:16 +00:00
|
|
|
return this.error('cannot call super outside of an instance method.');
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
Call.prototype.superThis = function(o) {
|
|
|
|
var method;
|
|
|
|
method = o.scope.method;
|
|
|
|
return (method && !method.klass && method.context) || "this";
|
|
|
|
};
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Call.prototype.unfoldSoak = function(o) {
|
|
|
|
var call, ifn, left, list, rite, _i, _len, _ref2, _ref3;
|
|
|
|
if (this.soak) {
|
|
|
|
if (this.variable) {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (ifn = unfoldSoak(o, this, 'variable')) {
|
|
|
|
return ifn;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
_ref2 = new Value(this.variable).cacheReference(o), left = _ref2[0], rite = _ref2[1];
|
|
|
|
} else {
|
|
|
|
left = new Literal(this.superReference(o));
|
|
|
|
rite = new Value(left);
|
|
|
|
}
|
|
|
|
rite = new Call(rite, this.args);
|
|
|
|
rite.isNew = this.isNew;
|
|
|
|
left = new Literal("typeof " + (left.compile(o)) + " === \"function\"");
|
|
|
|
return new If(left, new Value(rite), {
|
|
|
|
soak: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
call = this;
|
|
|
|
list = [];
|
|
|
|
while (true) {
|
|
|
|
if (call.variable instanceof Call) {
|
|
|
|
list.push(call);
|
|
|
|
call = call.variable;
|
|
|
|
continue;
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
if (!(call.variable instanceof Value)) {
|
|
|
|
break;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
list.push(call);
|
2013-12-30 15:00:16 +00:00
|
|
|
if (!((call = call.variable.base) instanceof Call)) {
|
|
|
|
break;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
_ref3 = list.reverse();
|
|
|
|
for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
|
|
|
|
call = _ref3[_i];
|
|
|
|
if (ifn) {
|
|
|
|
if (call.variable instanceof Call) {
|
|
|
|
call.variable = ifn;
|
|
|
|
} else {
|
|
|
|
call.variable.base = ifn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ifn = unfoldSoak(o, call, 'variable');
|
|
|
|
}
|
|
|
|
return ifn;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Call.prototype.compileNode = function(o) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var arg, argIndex, compiledArgs, compiledArray, fragments, preface, _i, _len, _ref2, _ref3;
|
|
|
|
if ((_ref2 = this.variable) != null) {
|
|
|
|
_ref2.front = this.front;
|
|
|
|
}
|
|
|
|
compiledArray = Splat.compileSplattedArray(o, this.args, true);
|
|
|
|
if (compiledArray.length) {
|
|
|
|
return this.compileSplat(o, compiledArray);
|
|
|
|
}
|
|
|
|
compiledArgs = [];
|
|
|
|
_ref3 = this.args;
|
|
|
|
for (argIndex = _i = 0, _len = _ref3.length; _i < _len; argIndex = ++_i) {
|
|
|
|
arg = _ref3[argIndex];
|
|
|
|
if (argIndex) {
|
|
|
|
compiledArgs.push(this.makeCode(", "));
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
compiledArgs.push.apply(compiledArgs, arg.compileToFragments(o, LEVEL_LIST));
|
|
|
|
}
|
|
|
|
fragments = [];
|
2012-02-06 20:59:17 +00:00
|
|
|
if (this.isSuper) {
|
2013-12-30 15:00:16 +00:00
|
|
|
preface = this.superReference(o) + (".call(" + (this.superThis(o)));
|
|
|
|
if (compiledArgs.length) {
|
|
|
|
preface += ", ";
|
|
|
|
}
|
|
|
|
fragments.push(this.makeCode(preface));
|
2012-02-06 20:59:17 +00:00
|
|
|
} else {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (this.isNew) {
|
|
|
|
fragments.push(this.makeCode('new '));
|
|
|
|
}
|
|
|
|
fragments.push.apply(fragments, this.variable.compileToFragments(o, LEVEL_ACCESS));
|
|
|
|
fragments.push(this.makeCode("("));
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
fragments.push.apply(fragments, compiledArgs);
|
|
|
|
fragments.push(this.makeCode(")"));
|
|
|
|
return fragments;
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Call.prototype.compileSplat = function(o, splatArgs) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var answer, base, fun, idt, name, ref;
|
2012-02-06 20:59:17 +00:00
|
|
|
if (this.isSuper) {
|
2013-12-30 15:00:16 +00:00
|
|
|
return [].concat(this.makeCode("" + (this.superReference(o)) + ".apply(" + (this.superThis(o)) + ", "), splatArgs, this.makeCode(")"));
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
if (this.isNew) {
|
|
|
|
idt = this.tab + TAB;
|
2013-12-30 15:00:16 +00:00
|
|
|
return [].concat(this.makeCode("(function(func, args, ctor) {\n" + idt + "ctor.prototype = func.prototype;\n" + idt + "var child = new ctor, result = func.apply(child, args);\n" + idt + "return Object(result) === result ? result : child;\n" + this.tab + "})("), this.variable.compileToFragments(o, LEVEL_LIST), this.makeCode(", "), splatArgs, this.makeCode(", function(){})"));
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
answer = [];
|
2012-02-06 20:59:17 +00:00
|
|
|
base = new Value(this.variable);
|
|
|
|
if ((name = base.properties.pop()) && base.isComplex()) {
|
|
|
|
ref = o.scope.freeVariable('ref');
|
2013-12-30 15:00:16 +00:00
|
|
|
answer = answer.concat(this.makeCode("(" + ref + " = "), base.compileToFragments(o, LEVEL_LIST), this.makeCode(")"), name.compileToFragments(o));
|
2012-02-06 20:59:17 +00:00
|
|
|
} else {
|
2013-12-30 15:00:16 +00:00
|
|
|
fun = base.compileToFragments(o, LEVEL_ACCESS);
|
|
|
|
if (SIMPLENUM.test(fragmentsToText(fun))) {
|
|
|
|
fun = this.wrapInBraces(fun);
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
if (name) {
|
2013-12-30 15:00:16 +00:00
|
|
|
ref = fragmentsToText(fun);
|
|
|
|
fun.push.apply(fun, name.compileToFragments(o));
|
2012-02-06 20:59:17 +00:00
|
|
|
} else {
|
|
|
|
ref = 'null';
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
answer = answer.concat(fun);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
return answer = answer.concat(this.makeCode(".apply(" + ref + ", "), splatArgs, this.makeCode(")"));
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
return Call;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
})(Base);
|
|
|
|
|
|
|
|
exports.Extends = Extends = (function(_super) {
|
|
|
|
__extends(Extends, _super);
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
function Extends(child, parent) {
|
|
|
|
this.child = child;
|
|
|
|
this.parent = parent;
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Extends.prototype.children = ['child', 'parent'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
Extends.prototype.compileToFragments = function(o) {
|
|
|
|
return new Call(new Value(new Literal(utility('extends'))), [this.child, this.parent]).compileToFragments(o);
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
return Extends;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
})(Base);
|
|
|
|
|
|
|
|
exports.Access = Access = (function(_super) {
|
|
|
|
__extends(Access, _super);
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
function Access(name, tag) {
|
|
|
|
this.name = name;
|
|
|
|
this.name.asKey = true;
|
|
|
|
this.soak = tag === 'soak';
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Access.prototype.children = ['name'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
Access.prototype.compileToFragments = function(o) {
|
2012-02-06 20:59:17 +00:00
|
|
|
var name;
|
2013-12-30 15:00:16 +00:00
|
|
|
name = this.name.compileToFragments(o);
|
|
|
|
if (IDENTIFIER.test(fragmentsToText(name))) {
|
|
|
|
name.unshift(this.makeCode("."));
|
2012-07-05 06:37:09 +00:00
|
|
|
} else {
|
2013-12-30 15:00:16 +00:00
|
|
|
name.unshift(this.makeCode("["));
|
|
|
|
name.push(this.makeCode("]"));
|
2012-07-05 06:37:09 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
return name;
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Access.prototype.isComplex = NO;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
return Access;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
})(Base);
|
|
|
|
|
|
|
|
exports.Index = Index = (function(_super) {
|
|
|
|
__extends(Index, _super);
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
function Index(index) {
|
|
|
|
this.index = index;
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Index.prototype.children = ['index'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
Index.prototype.compileToFragments = function(o) {
|
|
|
|
return [].concat(this.makeCode("["), this.index.compileToFragments(o, LEVEL_PAREN), this.makeCode("]"));
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Index.prototype.isComplex = function() {
|
|
|
|
return this.index.isComplex();
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
return Index;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
})(Base);
|
|
|
|
|
|
|
|
exports.Range = Range = (function(_super) {
|
|
|
|
__extends(Range, _super);
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Range.prototype.children = ['from', 'to'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
function Range(from, to, tag) {
|
|
|
|
this.from = from;
|
|
|
|
this.to = to;
|
|
|
|
this.exclusive = tag === 'exclusive';
|
|
|
|
this.equals = this.exclusive ? '' : '=';
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Range.prototype.compileVariables = function(o) {
|
|
|
|
var step, _ref2, _ref3, _ref4, _ref5;
|
|
|
|
o = merge(o, {
|
|
|
|
top: true
|
|
|
|
});
|
2013-12-30 15:00:16 +00:00
|
|
|
_ref2 = this.cacheToCodeFragments(this.from.cache(o, LEVEL_LIST)), this.fromC = _ref2[0], this.fromVar = _ref2[1];
|
|
|
|
_ref3 = this.cacheToCodeFragments(this.to.cache(o, LEVEL_LIST)), this.toC = _ref3[0], this.toVar = _ref3[1];
|
2012-02-06 20:59:17 +00:00
|
|
|
if (step = del(o, 'step')) {
|
2013-12-30 15:00:16 +00:00
|
|
|
_ref4 = this.cacheToCodeFragments(step.cache(o, LEVEL_LIST)), this.step = _ref4[0], this.stepVar = _ref4[1];
|
|
|
|
}
|
|
|
|
_ref5 = [this.fromVar.match(NUMBER), this.toVar.match(NUMBER)], this.fromNum = _ref5[0], this.toNum = _ref5[1];
|
|
|
|
if (this.stepVar) {
|
|
|
|
return this.stepNum = this.stepVar.match(NUMBER);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Range.prototype.compileNode = function(o) {
|
2012-07-05 06:37:09 +00:00
|
|
|
var cond, condPart, from, gt, idx, idxName, known, lt, namedIndex, stepPart, to, varPart, _ref2, _ref3;
|
2013-12-30 15:00:16 +00:00
|
|
|
if (!this.fromVar) {
|
|
|
|
this.compileVariables(o);
|
|
|
|
}
|
|
|
|
if (!o.index) {
|
|
|
|
return this.compileArray(o);
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
known = this.fromNum && this.toNum;
|
|
|
|
idx = del(o, 'index');
|
2012-07-05 06:37:09 +00:00
|
|
|
idxName = del(o, 'name');
|
|
|
|
namedIndex = idxName && idxName !== idx;
|
|
|
|
varPart = "" + idx + " = " + this.fromC;
|
2013-12-30 15:00:16 +00:00
|
|
|
if (this.toC !== this.toVar) {
|
|
|
|
varPart += ", " + this.toC;
|
|
|
|
}
|
|
|
|
if (this.step !== this.stepVar) {
|
|
|
|
varPart += ", " + this.step;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
_ref2 = ["" + idx + " <" + this.equals, "" + idx + " >" + this.equals], lt = _ref2[0], gt = _ref2[1];
|
2013-12-30 15:00:16 +00:00
|
|
|
condPart = this.stepNum ? parseNum(this.stepNum[0]) > 0 ? "" + lt + " " + this.toVar : "" + gt + " " + this.toVar : known ? ((_ref3 = [parseNum(this.fromNum[0]), parseNum(this.toNum[0])], from = _ref3[0], to = _ref3[1], _ref3), from <= to ? "" + lt + " " + to : "" + gt + " " + to) : (cond = this.stepVar ? "" + this.stepVar + " > 0" : "" + this.fromVar + " <= " + this.toVar, "" + cond + " ? " + lt + " " + this.toVar + " : " + gt + " " + this.toVar);
|
2012-07-05 06:37:09 +00:00
|
|
|
stepPart = this.stepVar ? "" + idx + " += " + this.stepVar : known ? namedIndex ? from <= to ? "++" + idx : "--" + idx : from <= to ? "" + idx + "++" : "" + idx + "--" : namedIndex ? "" + cond + " ? ++" + idx + " : --" + idx : "" + cond + " ? " + idx + "++ : " + idx + "--";
|
2013-12-30 15:00:16 +00:00
|
|
|
if (namedIndex) {
|
|
|
|
varPart = "" + idxName + " = " + varPart;
|
|
|
|
}
|
|
|
|
if (namedIndex) {
|
|
|
|
stepPart = "" + idxName + " = " + stepPart;
|
|
|
|
}
|
|
|
|
return [this.makeCode("" + varPart + "; " + condPart + "; " + stepPart)];
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Range.prototype.compileArray = function(o) {
|
2012-07-05 06:37:09 +00:00
|
|
|
var args, body, cond, hasArgs, i, idt, post, pre, range, result, vars, _i, _ref2, _ref3, _results;
|
2012-02-06 20:59:17 +00:00
|
|
|
if (this.fromNum && this.toNum && Math.abs(this.fromNum - this.toNum) <= 20) {
|
|
|
|
range = (function() {
|
|
|
|
_results = [];
|
|
|
|
for (var _i = _ref2 = +this.fromNum, _ref3 = +this.toNum; _ref2 <= _ref3 ? _i <= _ref3 : _i >= _ref3; _ref2 <= _ref3 ? _i++ : _i--){ _results.push(_i); }
|
|
|
|
return _results;
|
2012-07-05 06:37:09 +00:00
|
|
|
}).apply(this);
|
2013-12-30 15:00:16 +00:00
|
|
|
if (this.exclusive) {
|
|
|
|
range.pop();
|
|
|
|
}
|
|
|
|
return [this.makeCode("[" + (range.join(', ')) + "]")];
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
idt = this.tab + TAB;
|
|
|
|
i = o.scope.freeVariable('i');
|
|
|
|
result = o.scope.freeVariable('results');
|
|
|
|
pre = "\n" + idt + result + " = [];";
|
|
|
|
if (this.fromNum && this.toNum) {
|
|
|
|
o.index = i;
|
2013-12-30 15:00:16 +00:00
|
|
|
body = fragmentsToText(this.compileNode(o));
|
2012-02-06 20:59:17 +00:00
|
|
|
} else {
|
2012-07-05 06:37:09 +00:00
|
|
|
vars = ("" + i + " = " + this.fromC) + (this.toC !== this.toVar ? ", " + this.toC : '');
|
2012-02-06 20:59:17 +00:00
|
|
|
cond = "" + this.fromVar + " <= " + this.toVar;
|
|
|
|
body = "var " + vars + "; " + cond + " ? " + i + " <" + this.equals + " " + this.toVar + " : " + i + " >" + this.equals + " " + this.toVar + "; " + cond + " ? " + i + "++ : " + i + "--";
|
|
|
|
}
|
|
|
|
post = "{ " + result + ".push(" + i + "); }\n" + idt + "return " + result + ";\n" + o.indent;
|
2012-07-05 06:37:09 +00:00
|
|
|
hasArgs = function(node) {
|
2013-12-30 15:00:16 +00:00
|
|
|
return node != null ? node.contains(isLiteralArguments) : void 0;
|
2012-07-05 06:37:09 +00:00
|
|
|
};
|
2013-12-30 15:00:16 +00:00
|
|
|
if (hasArgs(this.from) || hasArgs(this.to)) {
|
|
|
|
args = ', arguments';
|
|
|
|
}
|
|
|
|
return [this.makeCode("(function() {" + pre + "\n" + idt + "for (" + body + ")" + post + "}).apply(this" + (args != null ? args : '') + ")")];
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
return Range;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
})(Base);
|
|
|
|
|
|
|
|
exports.Slice = Slice = (function(_super) {
|
|
|
|
__extends(Slice, _super);
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Slice.prototype.children = ['range'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
function Slice(range) {
|
|
|
|
this.range = range;
|
|
|
|
Slice.__super__.constructor.call(this);
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Slice.prototype.compileNode = function(o) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var compiled, compiledText, from, fromCompiled, to, toStr, _ref2;
|
2012-02-06 20:59:17 +00:00
|
|
|
_ref2 = this.range, to = _ref2.to, from = _ref2.from;
|
2013-12-30 15:00:16 +00:00
|
|
|
fromCompiled = from && from.compileToFragments(o, LEVEL_PAREN) || [this.makeCode('0')];
|
|
|
|
if (to) {
|
|
|
|
compiled = to.compileToFragments(o, LEVEL_PAREN);
|
|
|
|
compiledText = fragmentsToText(compiled);
|
|
|
|
if (!(!this.range.exclusive && +compiledText === -1)) {
|
|
|
|
toStr = ', ' + (this.range.exclusive ? compiledText : SIMPLENUM.test(compiledText) ? "" + (+compiledText + 1) : (compiled = to.compileToFragments(o, LEVEL_ACCESS), "+" + (fragmentsToText(compiled)) + " + 1 || 9e9"));
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
return [this.makeCode(".slice(" + (fragmentsToText(fromCompiled)) + (toStr || '') + ")")];
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
return Slice;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
})(Base);
|
|
|
|
|
|
|
|
exports.Obj = Obj = (function(_super) {
|
|
|
|
__extends(Obj, _super);
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
function Obj(props, generated) {
|
|
|
|
this.generated = generated != null ? generated : false;
|
|
|
|
this.objects = this.properties = props || [];
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
Obj.prototype.children = ['properties'];
|
|
|
|
|
|
|
|
Obj.prototype.compileNode = function(o) {
|
|
|
|
var answer, i, idt, indent, join, lastNoncom, node, prop, props, _i, _j, _len, _len1;
|
|
|
|
props = this.properties;
|
|
|
|
if (!props.length) {
|
|
|
|
return [this.makeCode(this.front ? '({})' : '{}')];
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
if (this.generated) {
|
2013-12-30 15:00:16 +00:00
|
|
|
for (_i = 0, _len = props.length; _i < _len; _i++) {
|
|
|
|
node = props[_i];
|
2012-02-06 20:59:17 +00:00
|
|
|
if (node instanceof Value) {
|
2013-12-30 15:00:16 +00:00
|
|
|
node.error('cannot have an implicit value in an implicit object');
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
idt = o.indent += TAB;
|
|
|
|
lastNoncom = this.lastNonComment(this.properties);
|
2013-12-30 15:00:16 +00:00
|
|
|
answer = [];
|
|
|
|
for (i = _j = 0, _len1 = props.length; _j < _len1; i = ++_j) {
|
|
|
|
prop = props[i];
|
|
|
|
join = i === props.length - 1 ? '' : prop === lastNoncom || prop instanceof Comment ? '\n' : ',\n';
|
|
|
|
indent = prop instanceof Comment ? '' : idt;
|
|
|
|
if (prop instanceof Assign && prop.variable instanceof Value && prop.variable.hasProperties()) {
|
|
|
|
prop.variable.error('Invalid object key');
|
|
|
|
}
|
|
|
|
if (prop instanceof Value && prop["this"]) {
|
|
|
|
prop = new Assign(prop.properties[0].name, prop, 'object');
|
|
|
|
}
|
|
|
|
if (!(prop instanceof Comment)) {
|
|
|
|
if (!(prop instanceof Assign)) {
|
|
|
|
prop = new Assign(prop, prop, 'object');
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
(prop.variable.base || prop.variable).asKey = true;
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
if (indent) {
|
|
|
|
answer.push(this.makeCode(indent));
|
|
|
|
}
|
|
|
|
answer.push.apply(answer, prop.compileToFragments(o, LEVEL_TOP));
|
|
|
|
if (join) {
|
|
|
|
answer.push(this.makeCode(join));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
answer.unshift(this.makeCode("{" + (props.length && '\n')));
|
|
|
|
answer.push(this.makeCode("" + (props.length && '\n' + this.tab) + "}"));
|
2012-02-06 20:59:17 +00:00
|
|
|
if (this.front) {
|
2013-12-30 15:00:16 +00:00
|
|
|
return this.wrapInBraces(answer);
|
2012-02-06 20:59:17 +00:00
|
|
|
} else {
|
2013-12-30 15:00:16 +00:00
|
|
|
return answer;
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Obj.prototype.assigns = function(name) {
|
|
|
|
var prop, _i, _len, _ref2;
|
|
|
|
_ref2 = this.properties;
|
|
|
|
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
|
|
|
prop = _ref2[_i];
|
2013-12-30 15:00:16 +00:00
|
|
|
if (prop.assigns(name)) {
|
|
|
|
return true;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
return Obj;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
})(Base);
|
|
|
|
|
|
|
|
exports.Arr = Arr = (function(_super) {
|
|
|
|
__extends(Arr, _super);
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
function Arr(objs) {
|
|
|
|
this.objects = objs || [];
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Arr.prototype.children = ['objects'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Arr.prototype.compileNode = function(o) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var answer, compiledObjs, fragments, index, obj, _i, _len;
|
|
|
|
if (!this.objects.length) {
|
|
|
|
return [this.makeCode('[]')];
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
o.indent += TAB;
|
2013-12-30 15:00:16 +00:00
|
|
|
answer = Splat.compileSplattedArray(o, this.objects);
|
|
|
|
if (answer.length) {
|
|
|
|
return answer;
|
|
|
|
}
|
|
|
|
answer = [];
|
|
|
|
compiledObjs = (function() {
|
|
|
|
var _i, _len, _ref2, _results;
|
|
|
|
_ref2 = this.objects;
|
2012-02-06 20:59:17 +00:00
|
|
|
_results = [];
|
2013-12-30 15:00:16 +00:00
|
|
|
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
|
|
|
obj = _ref2[_i];
|
|
|
|
_results.push(obj.compileToFragments(o, LEVEL_LIST));
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
return _results;
|
2013-12-30 15:00:16 +00:00
|
|
|
}).call(this);
|
|
|
|
for (index = _i = 0, _len = compiledObjs.length; _i < _len; index = ++_i) {
|
|
|
|
fragments = compiledObjs[index];
|
|
|
|
if (index) {
|
|
|
|
answer.push(this.makeCode(", "));
|
|
|
|
}
|
|
|
|
answer.push.apply(answer, fragments);
|
|
|
|
}
|
|
|
|
if (fragmentsToText(answer).indexOf('\n') >= 0) {
|
|
|
|
answer.unshift(this.makeCode("[\n" + o.indent));
|
|
|
|
answer.push(this.makeCode("\n" + this.tab + "]"));
|
2012-02-06 20:59:17 +00:00
|
|
|
} else {
|
2013-12-30 15:00:16 +00:00
|
|
|
answer.unshift(this.makeCode("["));
|
|
|
|
answer.push(this.makeCode("]"));
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
return answer;
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Arr.prototype.assigns = function(name) {
|
|
|
|
var obj, _i, _len, _ref2;
|
|
|
|
_ref2 = this.objects;
|
|
|
|
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
|
|
|
obj = _ref2[_i];
|
2013-12-30 15:00:16 +00:00
|
|
|
if (obj.assigns(name)) {
|
|
|
|
return true;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
return Arr;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
})(Base);
|
|
|
|
|
|
|
|
exports.Class = Class = (function(_super) {
|
|
|
|
__extends(Class, _super);
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
function Class(variable, parent, body) {
|
|
|
|
this.variable = variable;
|
|
|
|
this.parent = parent;
|
|
|
|
this.body = body != null ? body : new Block;
|
|
|
|
this.boundFuncs = [];
|
|
|
|
this.body.classBody = true;
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Class.prototype.children = ['variable', 'parent', 'body'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Class.prototype.determineName = function() {
|
|
|
|
var decl, tail;
|
2013-12-30 15:00:16 +00:00
|
|
|
if (!this.variable) {
|
|
|
|
return null;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
decl = (tail = last(this.variable.properties)) ? tail instanceof Access && tail.name.value : this.variable.base.value;
|
2012-07-05 06:37:09 +00:00
|
|
|
if (__indexOf.call(STRICT_PROSCRIBED, decl) >= 0) {
|
2013-12-30 15:00:16 +00:00
|
|
|
this.variable.error("class variable name may not be " + decl);
|
2012-07-05 06:37:09 +00:00
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
return decl && (decl = IDENTIFIER.test(decl) && decl);
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Class.prototype.setContext = function(name) {
|
|
|
|
return this.body.traverseChildren(false, function(node) {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (node.classBody) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
if (node instanceof Literal && node.value === 'this') {
|
|
|
|
return node.value = name;
|
|
|
|
} else if (node instanceof Code) {
|
|
|
|
node.klass = name;
|
2013-12-30 15:00:16 +00:00
|
|
|
if (node.bound) {
|
|
|
|
return node.context = name;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Class.prototype.addBoundFunctions = function(o) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var bvar, lhs, _i, _len, _ref2;
|
|
|
|
_ref2 = this.boundFuncs;
|
|
|
|
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
|
|
|
bvar = _ref2[_i];
|
|
|
|
lhs = (new Value(new Literal("this"), [new Access(bvar)])).compile(o);
|
|
|
|
this.ctor.body.unshift(new Literal("" + lhs + " = " + (utility('bind')) + "(" + lhs + ", this)"));
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Class.prototype.addProperties = function(node, name, o) {
|
|
|
|
var assign, base, exprs, func, props;
|
|
|
|
props = node.base.properties.slice(0);
|
|
|
|
exprs = (function() {
|
|
|
|
var _results;
|
|
|
|
_results = [];
|
|
|
|
while (assign = props.shift()) {
|
|
|
|
if (assign instanceof Assign) {
|
|
|
|
base = assign.variable.base;
|
|
|
|
delete assign.context;
|
|
|
|
func = assign.value;
|
|
|
|
if (base.value === 'constructor') {
|
|
|
|
if (this.ctor) {
|
2013-12-30 15:00:16 +00:00
|
|
|
assign.error('cannot define more than one constructor in a class');
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
if (func.bound) {
|
2013-12-30 15:00:16 +00:00
|
|
|
assign.error('cannot define a constructor as a bound function');
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
if (func instanceof Code) {
|
|
|
|
assign = this.ctor = func;
|
|
|
|
} else {
|
2013-12-30 15:00:16 +00:00
|
|
|
this.externalCtor = o.classScope.freeVariable('class');
|
2012-02-06 20:59:17 +00:00
|
|
|
assign = new Assign(new Literal(this.externalCtor), func);
|
|
|
|
}
|
|
|
|
} else {
|
2012-07-05 06:37:09 +00:00
|
|
|
if (assign.variable["this"]) {
|
|
|
|
func["static"] = true;
|
|
|
|
} else {
|
|
|
|
assign.variable = new Value(new Literal(name), [new Access(new Literal('prototype')), new Access(base)]);
|
|
|
|
if (func instanceof Code && func.bound) {
|
|
|
|
this.boundFuncs.push(base);
|
|
|
|
func.bound = false;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_results.push(assign);
|
|
|
|
}
|
|
|
|
return _results;
|
|
|
|
}).call(this);
|
|
|
|
return compact(exprs);
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Class.prototype.walkBody = function(name, o) {
|
2013-12-30 15:00:16 +00:00
|
|
|
return this.traverseChildren(false, (function(_this) {
|
|
|
|
return function(child) {
|
|
|
|
var cont, exps, i, node, _i, _len, _ref2;
|
|
|
|
cont = true;
|
|
|
|
if (child instanceof Class) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (child instanceof Block) {
|
|
|
|
_ref2 = exps = child.expressions;
|
|
|
|
for (i = _i = 0, _len = _ref2.length; _i < _len; i = ++_i) {
|
|
|
|
node = _ref2[i];
|
|
|
|
if (node instanceof Assign && node.variable.looksStatic(name)) {
|
|
|
|
node.value["static"] = true;
|
|
|
|
} else if (node instanceof Value && node.isObject(true)) {
|
|
|
|
cont = false;
|
|
|
|
exps[i] = _this.addProperties(node, name, o);
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
child.expressions = exps = flatten(exps);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
return cont && !(child instanceof Class);
|
|
|
|
};
|
|
|
|
})(this));
|
2012-07-05 06:37:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Class.prototype.hoistDirectivePrologue = function() {
|
|
|
|
var expressions, index, node;
|
|
|
|
index = 0;
|
|
|
|
expressions = this.body.expressions;
|
|
|
|
while ((node = expressions[index]) && node instanceof Comment || node instanceof Value && node.isString()) {
|
|
|
|
++index;
|
|
|
|
}
|
|
|
|
return this.directives = expressions.splice(0, index);
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Class.prototype.ensureConstructor = function(name) {
|
|
|
|
if (!this.ctor) {
|
|
|
|
this.ctor = new Code;
|
|
|
|
if (this.externalCtor) {
|
|
|
|
this.ctor.body.push(new Literal("" + this.externalCtor + ".apply(this, arguments)"));
|
2013-12-30 15:00:16 +00:00
|
|
|
} else if (this.parent) {
|
|
|
|
this.ctor.body.push(new Literal("" + name + ".__super__.constructor.apply(this, arguments)"));
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
this.ctor.body.makeReturn();
|
2012-02-06 20:59:17 +00:00
|
|
|
this.body.expressions.unshift(this.ctor);
|
|
|
|
}
|
|
|
|
this.ctor.ctor = this.ctor.name = name;
|
|
|
|
this.ctor.klass = null;
|
|
|
|
return this.ctor.noReturn = true;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Class.prototype.compileNode = function(o) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var args, argumentsNode, func, jumpNode, klass, lname, name, superClass, _ref2;
|
|
|
|
if (jumpNode = this.body.jumps()) {
|
|
|
|
jumpNode.error('Class bodies cannot contain pure statements');
|
|
|
|
}
|
|
|
|
if (argumentsNode = this.body.contains(isLiteralArguments)) {
|
|
|
|
argumentsNode.error("Class bodies shouldn't reference arguments");
|
|
|
|
}
|
|
|
|
name = this.determineName() || '_Class';
|
|
|
|
if (name.reserved) {
|
|
|
|
name = "_" + name;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
lname = new Literal(name);
|
2013-12-30 15:00:16 +00:00
|
|
|
func = new Code([], Block.wrap([this.body]));
|
|
|
|
args = [];
|
|
|
|
o.classScope = func.makeScope(o.scope);
|
2012-07-05 06:37:09 +00:00
|
|
|
this.hoistDirectivePrologue();
|
2012-02-06 20:59:17 +00:00
|
|
|
this.setContext(name);
|
|
|
|
this.walkBody(name, o);
|
|
|
|
this.ensureConstructor(name);
|
2013-12-30 15:00:16 +00:00
|
|
|
this.addBoundFunctions(o);
|
2012-07-05 06:37:09 +00:00
|
|
|
this.body.spaced = true;
|
2012-02-06 20:59:17 +00:00
|
|
|
this.body.expressions.push(lname);
|
2012-07-05 06:37:09 +00:00
|
|
|
if (this.parent) {
|
2013-12-30 15:00:16 +00:00
|
|
|
superClass = new Literal(o.classScope.freeVariable('super', false));
|
|
|
|
this.body.expressions.unshift(new Extends(lname, superClass));
|
|
|
|
func.params.push(new Param(superClass));
|
|
|
|
args.push(this.parent);
|
|
|
|
}
|
|
|
|
(_ref2 = this.body.expressions).unshift.apply(_ref2, this.directives);
|
|
|
|
klass = new Parens(new Call(func, args));
|
|
|
|
if (this.variable) {
|
|
|
|
klass = new Assign(this.variable, klass);
|
2012-07-05 06:37:09 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
return klass.compileToFragments(o);
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
return Class;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
})(Base);
|
|
|
|
|
|
|
|
exports.Assign = Assign = (function(_super) {
|
|
|
|
__extends(Assign, _super);
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
function Assign(variable, value, context, options) {
|
2012-07-05 06:37:09 +00:00
|
|
|
var forbidden, name, _ref2;
|
2012-02-06 20:59:17 +00:00
|
|
|
this.variable = variable;
|
|
|
|
this.value = value;
|
|
|
|
this.context = context;
|
|
|
|
this.param = options && options.param;
|
2012-07-05 06:37:09 +00:00
|
|
|
this.subpattern = options && options.subpattern;
|
|
|
|
forbidden = (_ref2 = (name = this.variable.unwrapAll().value), __indexOf.call(STRICT_PROSCRIBED, _ref2) >= 0);
|
|
|
|
if (forbidden && this.context !== 'object') {
|
2013-12-30 15:00:16 +00:00
|
|
|
this.variable.error("variable name may not be \"" + name + "\"");
|
2012-07-05 06:37:09 +00:00
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Assign.prototype.children = ['variable', 'value'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
Assign.prototype.isStatement = function(o) {
|
|
|
|
return (o != null ? o.level : void 0) === LEVEL_TOP && (this.context != null) && __indexOf.call(this.context, "?") >= 0;
|
|
|
|
};
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Assign.prototype.assigns = function(name) {
|
|
|
|
return this[this.context === 'object' ? 'value' : 'variable'].assigns(name);
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Assign.prototype.unfoldSoak = function(o) {
|
|
|
|
return unfoldSoak(o, this, 'variable');
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Assign.prototype.compileNode = function(o) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var answer, compiledName, isValue, match, name, val, varBase, _ref2, _ref3, _ref4;
|
2012-02-06 20:59:17 +00:00
|
|
|
if (isValue = this.variable instanceof Value) {
|
|
|
|
if (this.variable.isArray() || this.variable.isObject()) {
|
|
|
|
return this.compilePatternMatch(o);
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
if (this.variable.isSplice()) {
|
|
|
|
return this.compileSplice(o);
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
if ((_ref2 = this.context) === '||=' || _ref2 === '&&=' || _ref2 === '?=') {
|
|
|
|
return this.compileConditional(o);
|
|
|
|
}
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
compiledName = this.variable.compileToFragments(o, LEVEL_LIST);
|
|
|
|
name = fragmentsToText(compiledName);
|
2012-07-05 06:37:09 +00:00
|
|
|
if (!this.context) {
|
2013-12-30 15:00:16 +00:00
|
|
|
varBase = this.variable.unwrapAll();
|
|
|
|
if (!varBase.isAssignable()) {
|
|
|
|
this.variable.error("\"" + (this.variable.compile(o)) + "\" cannot be assigned");
|
2012-07-05 06:37:09 +00:00
|
|
|
}
|
|
|
|
if (!(typeof varBase.hasProperties === "function" ? varBase.hasProperties() : void 0)) {
|
|
|
|
if (this.param) {
|
|
|
|
o.scope.add(name, 'var');
|
|
|
|
} else {
|
|
|
|
o.scope.find(name);
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.value instanceof Code && (match = METHOD_DEF.exec(name))) {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (match[2]) {
|
|
|
|
this.value.klass = match[1];
|
|
|
|
}
|
|
|
|
this.value.name = (_ref3 = (_ref4 = match[3]) != null ? _ref4 : match[4]) != null ? _ref3 : match[5];
|
|
|
|
}
|
|
|
|
val = this.value.compileToFragments(o, LEVEL_LIST);
|
|
|
|
if (this.context === 'object') {
|
|
|
|
return compiledName.concat(this.makeCode(": "), val);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
answer = compiledName.concat(this.makeCode(" " + (this.context || '=') + " "), val);
|
2012-02-06 20:59:17 +00:00
|
|
|
if (o.level <= LEVEL_LIST) {
|
2013-12-30 15:00:16 +00:00
|
|
|
return answer;
|
2012-02-06 20:59:17 +00:00
|
|
|
} else {
|
2013-12-30 15:00:16 +00:00
|
|
|
return this.wrapInBraces(answer);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Assign.prototype.compilePatternMatch = function(o) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var acc, assigns, code, fragments, i, idx, isObject, ivar, name, obj, objects, olen, ref, rest, splat, top, val, value, vvar, vvarText, _i, _len, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7;
|
2012-02-06 20:59:17 +00:00
|
|
|
top = o.level === LEVEL_TOP;
|
|
|
|
value = this.value;
|
|
|
|
objects = this.variable.base.objects;
|
|
|
|
if (!(olen = objects.length)) {
|
2013-12-30 15:00:16 +00:00
|
|
|
code = value.compileToFragments(o);
|
2012-02-06 20:59:17 +00:00
|
|
|
if (o.level >= LEVEL_OP) {
|
2013-12-30 15:00:16 +00:00
|
|
|
return this.wrapInBraces(code);
|
2012-02-06 20:59:17 +00:00
|
|
|
} else {
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
isObject = this.variable.isObject();
|
|
|
|
if (top && olen === 1 && !((obj = objects[0]) instanceof Splat)) {
|
|
|
|
if (obj instanceof Assign) {
|
2012-07-05 06:37:09 +00:00
|
|
|
_ref2 = obj, (_ref3 = _ref2.variable, idx = _ref3.base), obj = _ref2.value;
|
2012-02-06 20:59:17 +00:00
|
|
|
} else {
|
2013-12-30 15:00:16 +00:00
|
|
|
idx = isObject ? obj["this"] ? obj.properties[0].name : obj : new Literal(0);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
acc = IDENTIFIER.test(idx.unwrap().value || 0);
|
|
|
|
value = new Value(value);
|
|
|
|
value.properties.push(new (acc ? Access : Index)(idx));
|
2013-12-30 15:00:16 +00:00
|
|
|
if (_ref4 = obj.unwrap().value, __indexOf.call(RESERVED, _ref4) >= 0) {
|
|
|
|
obj.error("assignment to a reserved word: " + (obj.compile(o)));
|
2012-07-05 06:37:09 +00:00
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
return new Assign(obj, value, null, {
|
|
|
|
param: this.param
|
2013-12-30 15:00:16 +00:00
|
|
|
}).compileToFragments(o, LEVEL_TOP);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
vvar = value.compileToFragments(o, LEVEL_LIST);
|
|
|
|
vvarText = fragmentsToText(vvar);
|
2012-02-06 20:59:17 +00:00
|
|
|
assigns = [];
|
|
|
|
splat = false;
|
2013-12-30 15:00:16 +00:00
|
|
|
if (!IDENTIFIER.test(vvarText) || this.variable.assigns(vvarText)) {
|
|
|
|
assigns.push([this.makeCode("" + (ref = o.scope.freeVariable('ref')) + " = ")].concat(__slice.call(vvar)));
|
|
|
|
vvar = [this.makeCode(ref)];
|
|
|
|
vvarText = ref;
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
for (i = _i = 0, _len = objects.length; _i < _len; i = ++_i) {
|
2012-02-06 20:59:17 +00:00
|
|
|
obj = objects[i];
|
|
|
|
idx = i;
|
|
|
|
if (isObject) {
|
|
|
|
if (obj instanceof Assign) {
|
2013-12-30 15:00:16 +00:00
|
|
|
_ref5 = obj, (_ref6 = _ref5.variable, idx = _ref6.base), obj = _ref5.value;
|
2012-02-06 20:59:17 +00:00
|
|
|
} else {
|
|
|
|
if (obj.base instanceof Parens) {
|
2013-12-30 15:00:16 +00:00
|
|
|
_ref7 = new Value(obj.unwrapAll()).cacheReference(o), obj = _ref7[0], idx = _ref7[1];
|
2012-02-06 20:59:17 +00:00
|
|
|
} else {
|
|
|
|
idx = obj["this"] ? obj.properties[0].name : obj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!splat && obj instanceof Splat) {
|
2012-07-05 06:37:09 +00:00
|
|
|
name = obj.name.unwrap().value;
|
|
|
|
obj = obj.unwrap();
|
2013-12-30 15:00:16 +00:00
|
|
|
val = "" + olen + " <= " + vvarText + ".length ? " + (utility('slice')) + ".call(" + vvarText + ", " + i;
|
2012-02-06 20:59:17 +00:00
|
|
|
if (rest = olen - i - 1) {
|
|
|
|
ivar = o.scope.freeVariable('i');
|
2013-12-30 15:00:16 +00:00
|
|
|
val += ", " + ivar + " = " + vvarText + ".length - " + rest + ") : (" + ivar + " = " + i + ", [])";
|
2012-02-06 20:59:17 +00:00
|
|
|
} else {
|
|
|
|
val += ") : []";
|
|
|
|
}
|
|
|
|
val = new Literal(val);
|
|
|
|
splat = "" + ivar + "++";
|
|
|
|
} else {
|
2012-07-05 06:37:09 +00:00
|
|
|
name = obj.unwrap().value;
|
2012-02-06 20:59:17 +00:00
|
|
|
if (obj instanceof Splat) {
|
2013-12-30 15:00:16 +00:00
|
|
|
obj.error("multiple splats are disallowed in an assignment");
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
if (typeof idx === 'number') {
|
|
|
|
idx = new Literal(splat || idx);
|
|
|
|
acc = false;
|
|
|
|
} else {
|
|
|
|
acc = isObject && IDENTIFIER.test(idx.unwrap().value || 0);
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
val = new Value(new Literal(vvarText), [new (acc ? Access : Index)(idx)]);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
if ((name != null) && __indexOf.call(RESERVED, name) >= 0) {
|
2013-12-30 15:00:16 +00:00
|
|
|
obj.error("assignment to a reserved word: " + (obj.compile(o)));
|
2012-07-05 06:37:09 +00:00
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
assigns.push(new Assign(obj, val, null, {
|
2012-07-05 06:37:09 +00:00
|
|
|
param: this.param,
|
|
|
|
subpattern: true
|
2013-12-30 15:00:16 +00:00
|
|
|
}).compileToFragments(o, LEVEL_LIST));
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
if (!(top || this.subpattern)) {
|
|
|
|
assigns.push(vvar);
|
|
|
|
}
|
|
|
|
fragments = this.joinFragmentArrays(assigns, ', ');
|
2012-02-06 20:59:17 +00:00
|
|
|
if (o.level < LEVEL_LIST) {
|
2013-12-30 15:00:16 +00:00
|
|
|
return fragments;
|
2012-02-06 20:59:17 +00:00
|
|
|
} else {
|
2013-12-30 15:00:16 +00:00
|
|
|
return this.wrapInBraces(fragments);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Assign.prototype.compileConditional = function(o) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var fragments, left, right, _ref2;
|
2012-07-05 06:37:09 +00:00
|
|
|
_ref2 = this.variable.cacheReference(o), left = _ref2[0], right = _ref2[1];
|
2013-12-30 15:00:16 +00:00
|
|
|
if (!left.properties.length && left.base instanceof Literal && left.base.value !== "this" && !o.scope.check(left.base.value)) {
|
|
|
|
this.variable.error("the variable \"" + left.base.value + "\" can't be assigned with " + this.context + " because it has not been declared before");
|
|
|
|
}
|
|
|
|
if (__indexOf.call(this.context, "?") >= 0) {
|
|
|
|
o.isExistentialEquals = true;
|
|
|
|
return new If(new Existence(left), right, {
|
|
|
|
type: 'if'
|
|
|
|
}).addElse(new Assign(right, this.value, '=')).compileToFragments(o);
|
|
|
|
} else {
|
|
|
|
fragments = new Op(this.context.slice(0, -1), left, new Assign(right, this.value, '=')).compileToFragments(o);
|
|
|
|
if (o.level <= LEVEL_LIST) {
|
|
|
|
return fragments;
|
|
|
|
} else {
|
|
|
|
return this.wrapInBraces(fragments);
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Assign.prototype.compileSplice = function(o) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var answer, exclusive, from, fromDecl, fromRef, name, to, valDef, valRef, _ref2, _ref3, _ref4;
|
2012-02-06 20:59:17 +00:00
|
|
|
_ref2 = this.variable.properties.pop().range, from = _ref2.from, to = _ref2.to, exclusive = _ref2.exclusive;
|
|
|
|
name = this.variable.compile(o);
|
2013-12-30 15:00:16 +00:00
|
|
|
if (from) {
|
|
|
|
_ref3 = this.cacheToCodeFragments(from.cache(o, LEVEL_OP)), fromDecl = _ref3[0], fromRef = _ref3[1];
|
|
|
|
} else {
|
|
|
|
fromDecl = fromRef = '0';
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
if (to) {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (from instanceof Value && from.isSimpleNumber() && to instanceof Value && to.isSimpleNumber()) {
|
|
|
|
to = to.compile(o) - fromRef;
|
|
|
|
if (!exclusive) {
|
|
|
|
to += 1;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
} else {
|
2012-07-05 06:37:09 +00:00
|
|
|
to = to.compile(o, LEVEL_ACCESS) + ' - ' + fromRef;
|
2013-12-30 15:00:16 +00:00
|
|
|
if (!exclusive) {
|
|
|
|
to += ' + 1';
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
to = "9e9";
|
|
|
|
}
|
|
|
|
_ref4 = this.value.cache(o, LEVEL_LIST), valDef = _ref4[0], valRef = _ref4[1];
|
2013-12-30 15:00:16 +00:00
|
|
|
answer = [].concat(this.makeCode("[].splice.apply(" + name + ", [" + fromDecl + ", " + to + "].concat("), valDef, this.makeCode(")), "), valRef);
|
2012-02-06 20:59:17 +00:00
|
|
|
if (o.level > LEVEL_TOP) {
|
2013-12-30 15:00:16 +00:00
|
|
|
return this.wrapInBraces(answer);
|
2012-02-06 20:59:17 +00:00
|
|
|
} else {
|
2013-12-30 15:00:16 +00:00
|
|
|
return answer;
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
return Assign;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
})(Base);
|
|
|
|
|
|
|
|
exports.Code = Code = (function(_super) {
|
|
|
|
__extends(Code, _super);
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
function Code(params, body, tag) {
|
|
|
|
this.params = params || [];
|
|
|
|
this.body = body || new Block;
|
|
|
|
this.bound = tag === 'boundfunc';
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Code.prototype.children = ['params', 'body'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Code.prototype.isStatement = function() {
|
|
|
|
return !!this.ctor;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Code.prototype.jumps = NO;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
Code.prototype.makeScope = function(parentScope) {
|
|
|
|
return new Scope(parentScope, this.body, this);
|
|
|
|
};
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Code.prototype.compileNode = function(o) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var answer, boundfunc, code, exprs, i, lit, p, param, params, ref, splats, uniqs, val, wasEmpty, wrapper, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _len5, _m, _n, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7;
|
|
|
|
if (this.bound && ((_ref2 = o.scope.method) != null ? _ref2.bound : void 0)) {
|
|
|
|
this.context = o.scope.method.context;
|
|
|
|
}
|
|
|
|
if (this.bound && !this.context) {
|
|
|
|
this.context = '_this';
|
|
|
|
wrapper = new Code([new Param(new Literal(this.context))], new Block([this]));
|
|
|
|
boundfunc = new Call(wrapper, [new Literal('this')]);
|
|
|
|
boundfunc.updateLocationDataIfMissing(this.locationData);
|
|
|
|
return boundfunc.compileNode(o);
|
|
|
|
}
|
|
|
|
o.scope = del(o, 'classScope') || this.makeScope(o.scope);
|
2012-02-06 20:59:17 +00:00
|
|
|
o.scope.shared = del(o, 'sharedScope');
|
|
|
|
o.indent += TAB;
|
|
|
|
delete o.bare;
|
2012-07-05 06:37:09 +00:00
|
|
|
delete o.isExistentialEquals;
|
|
|
|
params = [];
|
2012-02-06 20:59:17 +00:00
|
|
|
exprs = [];
|
2012-07-05 06:37:09 +00:00
|
|
|
_ref3 = this.params;
|
2013-12-30 15:00:16 +00:00
|
|
|
for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
|
|
|
|
param = _ref3[_i];
|
|
|
|
o.scope.parameter(param.asReference(o));
|
|
|
|
}
|
|
|
|
_ref4 = this.params;
|
|
|
|
for (_j = 0, _len1 = _ref4.length; _j < _len1; _j++) {
|
|
|
|
param = _ref4[_j];
|
|
|
|
if (!param.splat) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
_ref5 = this.params;
|
|
|
|
for (_k = 0, _len2 = _ref5.length; _k < _len2; _k++) {
|
|
|
|
p = _ref5[_k].name;
|
|
|
|
if (p["this"]) {
|
|
|
|
p = p.properties[0].name;
|
|
|
|
}
|
|
|
|
if (p.value) {
|
|
|
|
o.scope.add(p.value, 'var', true);
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
}
|
|
|
|
splats = new Assign(new Value(new Arr((function() {
|
2013-12-30 15:00:16 +00:00
|
|
|
var _l, _len3, _ref6, _results;
|
|
|
|
_ref6 = this.params;
|
2012-07-05 06:37:09 +00:00
|
|
|
_results = [];
|
2013-12-30 15:00:16 +00:00
|
|
|
for (_l = 0, _len3 = _ref6.length; _l < _len3; _l++) {
|
|
|
|
p = _ref6[_l];
|
2012-07-05 06:37:09 +00:00
|
|
|
_results.push(p.asReference(o));
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
return _results;
|
|
|
|
}).call(this))), new Value(new Literal('arguments')));
|
|
|
|
break;
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
_ref6 = this.params;
|
|
|
|
for (_l = 0, _len3 = _ref6.length; _l < _len3; _l++) {
|
|
|
|
param = _ref6[_l];
|
2012-02-06 20:59:17 +00:00
|
|
|
if (param.isComplex()) {
|
|
|
|
val = ref = param.asReference(o);
|
2013-12-30 15:00:16 +00:00
|
|
|
if (param.value) {
|
|
|
|
val = new Op('?', ref, param.value);
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
exprs.push(new Assign(new Value(param.name), val, '=', {
|
|
|
|
param: true
|
|
|
|
}));
|
|
|
|
} else {
|
|
|
|
ref = param;
|
|
|
|
if (param.value) {
|
|
|
|
lit = new Literal(ref.name.value + ' == null');
|
|
|
|
val = new Assign(new Value(param.name), param.value, '=');
|
|
|
|
exprs.push(new If(lit, val));
|
|
|
|
}
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
if (!splats) {
|
|
|
|
params.push(ref);
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
wasEmpty = this.body.isEmpty();
|
2013-12-30 15:00:16 +00:00
|
|
|
if (splats) {
|
|
|
|
exprs.unshift(splats);
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
if (exprs.length) {
|
2013-12-30 15:00:16 +00:00
|
|
|
(_ref7 = this.body.expressions).unshift.apply(_ref7, exprs);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
for (i = _m = 0, _len4 = params.length; _m < _len4; i = ++_m) {
|
|
|
|
p = params[i];
|
2013-12-30 15:00:16 +00:00
|
|
|
params[i] = p.compileToFragments(o);
|
|
|
|
o.scope.parameter(fragmentsToText(params[i]));
|
2012-07-05 06:37:09 +00:00
|
|
|
}
|
|
|
|
uniqs = [];
|
2013-12-30 15:00:16 +00:00
|
|
|
this.eachParamName(function(name, node) {
|
2012-07-05 06:37:09 +00:00
|
|
|
if (__indexOf.call(uniqs, name) >= 0) {
|
2013-12-30 15:00:16 +00:00
|
|
|
node.error("multiple parameters named '" + name + "'");
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
return uniqs.push(name);
|
|
|
|
});
|
|
|
|
if (!(wasEmpty || this.noReturn)) {
|
|
|
|
this.body.makeReturn();
|
|
|
|
}
|
|
|
|
code = 'function';
|
|
|
|
if (this.ctor) {
|
|
|
|
code += ' ' + this.name;
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
code += '(';
|
|
|
|
answer = [this.makeCode(code)];
|
|
|
|
for (i = _n = 0, _len5 = params.length; _n < _len5; i = ++_n) {
|
|
|
|
p = params[i];
|
|
|
|
if (i) {
|
|
|
|
answer.push(this.makeCode(", "));
|
2012-07-05 06:37:09 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
answer.push.apply(answer, p);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
answer.push(this.makeCode(') {'));
|
2012-02-06 20:59:17 +00:00
|
|
|
if (!this.body.isEmpty()) {
|
2013-12-30 15:00:16 +00:00
|
|
|
answer = answer.concat(this.makeCode("\n"), this.body.compileWithDeclarations(o), this.makeCode("\n" + this.tab));
|
|
|
|
}
|
|
|
|
answer.push(this.makeCode('}'));
|
|
|
|
if (this.ctor) {
|
|
|
|
return [this.makeCode(this.tab)].concat(__slice.call(answer));
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
if (this.front || (o.level >= LEVEL_ACCESS)) {
|
2013-12-30 15:00:16 +00:00
|
|
|
return this.wrapInBraces(answer);
|
2012-02-06 20:59:17 +00:00
|
|
|
} else {
|
2013-12-30 15:00:16 +00:00
|
|
|
return answer;
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
Code.prototype.eachParamName = function(iterator) {
|
|
|
|
var param, _i, _len, _ref2, _results;
|
2012-07-05 06:37:09 +00:00
|
|
|
_ref2 = this.params;
|
2013-12-30 15:00:16 +00:00
|
|
|
_results = [];
|
2012-07-05 06:37:09 +00:00
|
|
|
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
|
|
|
param = _ref2[_i];
|
2013-12-30 15:00:16 +00:00
|
|
|
_results.push(param.eachName(iterator));
|
2012-07-05 06:37:09 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
return _results;
|
2012-07-05 06:37:09 +00:00
|
|
|
};
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Code.prototype.traverseChildren = function(crossScope, func) {
|
|
|
|
if (crossScope) {
|
|
|
|
return Code.__super__.traverseChildren.call(this, crossScope, func);
|
|
|
|
}
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
return Code;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
})(Base);
|
|
|
|
|
|
|
|
exports.Param = Param = (function(_super) {
|
|
|
|
__extends(Param, _super);
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
function Param(name, value, splat) {
|
2012-07-05 06:37:09 +00:00
|
|
|
var _ref2;
|
2012-02-06 20:59:17 +00:00
|
|
|
this.name = name;
|
|
|
|
this.value = value;
|
|
|
|
this.splat = splat;
|
2012-07-05 06:37:09 +00:00
|
|
|
if (_ref2 = (name = this.name.unwrapAll().value), __indexOf.call(STRICT_PROSCRIBED, _ref2) >= 0) {
|
2013-12-30 15:00:16 +00:00
|
|
|
this.name.error("parameter name \"" + name + "\" is not allowed");
|
2012-07-05 06:37:09 +00:00
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Param.prototype.children = ['name', 'value'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
Param.prototype.compileToFragments = function(o) {
|
|
|
|
return this.name.compileToFragments(o, LEVEL_LIST);
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Param.prototype.asReference = function(o) {
|
|
|
|
var node;
|
2013-12-30 15:00:16 +00:00
|
|
|
if (this.reference) {
|
|
|
|
return this.reference;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
node = this.name;
|
|
|
|
if (node["this"]) {
|
|
|
|
node = node.properties[0].name;
|
|
|
|
if (node.value.reserved) {
|
2012-07-05 06:37:09 +00:00
|
|
|
node = new Literal(o.scope.freeVariable(node.value));
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
} else if (node.isComplex()) {
|
|
|
|
node = new Literal(o.scope.freeVariable('arg'));
|
|
|
|
}
|
|
|
|
node = new Value(node);
|
2013-12-30 15:00:16 +00:00
|
|
|
if (this.splat) {
|
|
|
|
node = new Splat(node);
|
|
|
|
}
|
|
|
|
node.updateLocationDataIfMissing(this.locationData);
|
2012-02-06 20:59:17 +00:00
|
|
|
return this.reference = node;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Param.prototype.isComplex = function() {
|
|
|
|
return this.name.isComplex();
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
Param.prototype.eachName = function(iterator, name) {
|
|
|
|
var atParam, node, obj, _i, _len, _ref2;
|
|
|
|
if (name == null) {
|
|
|
|
name = this.name;
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
atParam = function(obj) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var node;
|
|
|
|
node = obj.properties[0].name;
|
|
|
|
if (!node.value.reserved) {
|
|
|
|
return iterator(node.value, node);
|
2012-07-05 06:37:09 +00:00
|
|
|
}
|
|
|
|
};
|
2013-12-30 15:00:16 +00:00
|
|
|
if (name instanceof Literal) {
|
|
|
|
return iterator(name.value, name);
|
|
|
|
}
|
|
|
|
if (name instanceof Value) {
|
|
|
|
return atParam(name);
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
_ref2 = name.objects;
|
|
|
|
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
|
|
|
obj = _ref2[_i];
|
|
|
|
if (obj instanceof Assign) {
|
2013-12-30 15:00:16 +00:00
|
|
|
this.eachName(iterator, obj.value.unwrap());
|
|
|
|
} else if (obj instanceof Splat) {
|
|
|
|
node = obj.name.unwrap();
|
|
|
|
iterator(node.value, node);
|
|
|
|
} else if (obj instanceof Value) {
|
|
|
|
if (obj.isArray() || obj.isObject()) {
|
|
|
|
this.eachName(iterator, obj.base);
|
|
|
|
} else if (obj["this"]) {
|
|
|
|
atParam(obj);
|
|
|
|
} else {
|
|
|
|
iterator(obj.base.value, obj.base);
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
} else {
|
2013-12-30 15:00:16 +00:00
|
|
|
obj.error("illegal parameter " + (obj.compile()));
|
2012-07-05 06:37:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
return Param;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
})(Base);
|
|
|
|
|
|
|
|
exports.Splat = Splat = (function(_super) {
|
|
|
|
__extends(Splat, _super);
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Splat.prototype.children = ['name'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Splat.prototype.isAssignable = YES;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
function Splat(name) {
|
|
|
|
this.name = name.compile ? name : new Literal(name);
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Splat.prototype.assigns = function(name) {
|
|
|
|
return this.name.assigns(name);
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
Splat.prototype.compileToFragments = function(o) {
|
|
|
|
return this.name.compileToFragments(o);
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
Splat.prototype.unwrap = function() {
|
|
|
|
return this.name;
|
|
|
|
};
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Splat.compileSplattedArray = function(o, list, apply) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var args, base, compiledNode, concatPart, fragments, i, index, node, _i, _len;
|
2012-02-06 20:59:17 +00:00
|
|
|
index = -1;
|
|
|
|
while ((node = list[++index]) && !(node instanceof Splat)) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
if (index >= list.length) {
|
|
|
|
return [];
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
if (list.length === 1) {
|
2013-12-30 15:00:16 +00:00
|
|
|
node = list[0];
|
|
|
|
fragments = node.compileToFragments(o, LEVEL_LIST);
|
|
|
|
if (apply) {
|
|
|
|
return fragments;
|
|
|
|
}
|
|
|
|
return [].concat(node.makeCode("" + (utility('slice')) + ".call("), fragments, node.makeCode(")"));
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
args = list.slice(index);
|
2012-07-05 06:37:09 +00:00
|
|
|
for (i = _i = 0, _len = args.length; _i < _len; i = ++_i) {
|
2012-02-06 20:59:17 +00:00
|
|
|
node = args[i];
|
2013-12-30 15:00:16 +00:00
|
|
|
compiledNode = node.compileToFragments(o, LEVEL_LIST);
|
|
|
|
args[i] = node instanceof Splat ? [].concat(node.makeCode("" + (utility('slice')) + ".call("), compiledNode, node.makeCode(")")) : [].concat(node.makeCode("["), compiledNode, node.makeCode("]"));
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
if (index === 0) {
|
2013-12-30 15:00:16 +00:00
|
|
|
node = list[0];
|
|
|
|
concatPart = node.joinFragmentArrays(args.slice(1), ', ');
|
|
|
|
return args[0].concat(node.makeCode(".concat("), concatPart, node.makeCode(")"));
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
base = (function() {
|
2012-07-05 06:37:09 +00:00
|
|
|
var _j, _len1, _ref2, _results;
|
2012-02-06 20:59:17 +00:00
|
|
|
_ref2 = list.slice(0, index);
|
|
|
|
_results = [];
|
2012-07-05 06:37:09 +00:00
|
|
|
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
|
|
|
|
node = _ref2[_j];
|
2013-12-30 15:00:16 +00:00
|
|
|
_results.push(node.compileToFragments(o, LEVEL_LIST));
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
return _results;
|
|
|
|
})();
|
2013-12-30 15:00:16 +00:00
|
|
|
base = list[0].joinFragmentArrays(base, ', ');
|
|
|
|
concatPart = list[index].joinFragmentArrays(args, ', ');
|
|
|
|
return [].concat(list[0].makeCode("["), base, list[index].makeCode("].concat("), concatPart, (last(list)).makeCode(")"));
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
return Splat;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
})(Base);
|
|
|
|
|
|
|
|
exports.While = While = (function(_super) {
|
|
|
|
__extends(While, _super);
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
function While(condition, options) {
|
|
|
|
this.condition = (options != null ? options.invert : void 0) ? condition.invert() : condition;
|
|
|
|
this.guard = options != null ? options.guard : void 0;
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
While.prototype.children = ['condition', 'guard', 'body'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
While.prototype.isStatement = YES;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
While.prototype.makeReturn = function(res) {
|
|
|
|
if (res) {
|
|
|
|
return While.__super__.makeReturn.apply(this, arguments);
|
|
|
|
} else {
|
|
|
|
this.returns = !this.jumps({
|
|
|
|
loop: true
|
|
|
|
});
|
|
|
|
return this;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
While.prototype.addBody = function(body) {
|
|
|
|
this.body = body;
|
|
|
|
return this;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
While.prototype.jumps = function() {
|
2013-12-30 15:00:16 +00:00
|
|
|
var expressions, jumpNode, node, _i, _len;
|
2012-02-06 20:59:17 +00:00
|
|
|
expressions = this.body.expressions;
|
2013-12-30 15:00:16 +00:00
|
|
|
if (!expressions.length) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
for (_i = 0, _len = expressions.length; _i < _len; _i++) {
|
|
|
|
node = expressions[_i];
|
2013-12-30 15:00:16 +00:00
|
|
|
if (jumpNode = node.jumps({
|
2012-02-06 20:59:17 +00:00
|
|
|
loop: true
|
2013-12-30 15:00:16 +00:00
|
|
|
})) {
|
|
|
|
return jumpNode;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
While.prototype.compileNode = function(o) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var answer, body, rvar, set;
|
2012-02-06 20:59:17 +00:00
|
|
|
o.indent += TAB;
|
|
|
|
set = '';
|
|
|
|
body = this.body;
|
|
|
|
if (body.isEmpty()) {
|
2013-12-30 15:00:16 +00:00
|
|
|
body = this.makeCode('');
|
2012-02-06 20:59:17 +00:00
|
|
|
} else {
|
2012-07-05 06:37:09 +00:00
|
|
|
if (this.returns) {
|
|
|
|
body.makeReturn(rvar = o.scope.freeVariable('results'));
|
2012-02-06 20:59:17 +00:00
|
|
|
set = "" + this.tab + rvar + " = [];\n";
|
|
|
|
}
|
|
|
|
if (this.guard) {
|
2012-07-05 06:37:09 +00:00
|
|
|
if (body.expressions.length > 1) {
|
|
|
|
body.expressions.unshift(new If((new Parens(this.guard)).invert(), new Literal("continue")));
|
|
|
|
} else {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (this.guard) {
|
|
|
|
body = Block.wrap([new If(this.guard, body)]);
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
body = [].concat(this.makeCode("\n"), body.compileToFragments(o, LEVEL_TOP), this.makeCode("\n" + this.tab));
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
answer = [].concat(this.makeCode(set + this.tab + "while ("), this.condition.compileToFragments(o, LEVEL_PAREN), this.makeCode(") {"), body, this.makeCode("}"));
|
|
|
|
if (this.returns) {
|
|
|
|
answer.push(this.makeCode("\n" + this.tab + "return " + rvar + ";"));
|
|
|
|
}
|
|
|
|
return answer;
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
return While;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
})(Base);
|
|
|
|
|
|
|
|
exports.Op = Op = (function(_super) {
|
2012-02-06 20:59:17 +00:00
|
|
|
var CONVERSIONS, INVERSIONS;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
__extends(Op, _super);
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
function Op(op, first, second, flip) {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (op === 'in') {
|
|
|
|
return new In(first, second);
|
|
|
|
}
|
|
|
|
if (op === 'do') {
|
|
|
|
return this.generateDo(first);
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
if (op === 'new') {
|
2012-07-05 06:37:09 +00:00
|
|
|
if (first instanceof Call && !first["do"] && !first.isNew) {
|
2012-02-06 20:59:17 +00:00
|
|
|
return first.newInstance();
|
|
|
|
}
|
|
|
|
if (first instanceof Code && first.bound || first["do"]) {
|
|
|
|
first = new Parens(first);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.operator = CONVERSIONS[op] || op;
|
|
|
|
this.first = first;
|
|
|
|
this.second = second;
|
|
|
|
this.flip = !!flip;
|
|
|
|
return this;
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
CONVERSIONS = {
|
|
|
|
'==': '===',
|
|
|
|
'!=': '!==',
|
|
|
|
'of': 'in'
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
INVERSIONS = {
|
|
|
|
'!==': '===',
|
|
|
|
'===': '!=='
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Op.prototype.children = ['first', 'second'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Op.prototype.isSimpleNumber = NO;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Op.prototype.isUnary = function() {
|
|
|
|
return !this.second;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Op.prototype.isComplex = function() {
|
|
|
|
var _ref2;
|
|
|
|
return !(this.isUnary() && ((_ref2 = this.operator) === '+' || _ref2 === '-')) || this.first.isComplex();
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Op.prototype.isChainable = function() {
|
|
|
|
var _ref2;
|
|
|
|
return (_ref2 = this.operator) === '<' || _ref2 === '>' || _ref2 === '>=' || _ref2 === '<=' || _ref2 === '===' || _ref2 === '!==';
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Op.prototype.invert = function() {
|
|
|
|
var allInvertable, curr, fst, op, _ref2;
|
|
|
|
if (this.isChainable() && this.first.isChainable()) {
|
|
|
|
allInvertable = true;
|
|
|
|
curr = this;
|
|
|
|
while (curr && curr.operator) {
|
|
|
|
allInvertable && (allInvertable = curr.operator in INVERSIONS);
|
|
|
|
curr = curr.first;
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
if (!allInvertable) {
|
|
|
|
return new Parens(this).invert();
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
curr = this;
|
|
|
|
while (curr && curr.operator) {
|
|
|
|
curr.invert = !curr.invert;
|
|
|
|
curr.operator = INVERSIONS[curr.operator];
|
|
|
|
curr = curr.first;
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
} else if (op = INVERSIONS[this.operator]) {
|
|
|
|
this.operator = op;
|
2013-12-30 15:00:16 +00:00
|
|
|
if (this.first.unwrap() instanceof Op) {
|
|
|
|
this.first.invert();
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
return this;
|
|
|
|
} else if (this.second) {
|
|
|
|
return new Parens(this).invert();
|
|
|
|
} else if (this.operator === '!' && (fst = this.first.unwrap()) instanceof Op && ((_ref2 = fst.operator) === '!' || _ref2 === 'in' || _ref2 === 'instanceof')) {
|
|
|
|
return fst;
|
|
|
|
} else {
|
|
|
|
return new Op('!', this);
|
|
|
|
}
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Op.prototype.unfoldSoak = function(o) {
|
|
|
|
var _ref2;
|
|
|
|
return ((_ref2 = this.operator) === '++' || _ref2 === '--' || _ref2 === 'delete') && unfoldSoak(o, this, 'first');
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
Op.prototype.generateDo = function(exp) {
|
|
|
|
var call, func, param, passedParams, ref, _i, _len, _ref2;
|
|
|
|
passedParams = [];
|
|
|
|
func = exp instanceof Assign && (ref = exp.value.unwrap()) instanceof Code ? ref : exp;
|
|
|
|
_ref2 = func.params || [];
|
|
|
|
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
|
|
|
param = _ref2[_i];
|
|
|
|
if (param.value) {
|
|
|
|
passedParams.push(param.value);
|
|
|
|
delete param.value;
|
|
|
|
} else {
|
|
|
|
passedParams.push(param);
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
call = new Call(exp, passedParams);
|
|
|
|
call["do"] = true;
|
|
|
|
return call;
|
|
|
|
};
|
|
|
|
|
|
|
|
Op.prototype.compileNode = function(o) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var answer, isChain, _ref2, _ref3;
|
2012-07-05 06:37:09 +00:00
|
|
|
isChain = this.isChainable() && this.first.isChainable();
|
2013-12-30 15:00:16 +00:00
|
|
|
if (!isChain) {
|
|
|
|
this.first.front = this.front;
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
if (this.operator === 'delete' && o.scope.check(this.first.unwrapAll().value)) {
|
2013-12-30 15:00:16 +00:00
|
|
|
this.error('delete operand may not be argument or var');
|
2012-07-05 06:37:09 +00:00
|
|
|
}
|
|
|
|
if (((_ref2 = this.operator) === '--' || _ref2 === '++') && (_ref3 = this.first.unwrapAll().value, __indexOf.call(STRICT_PROSCRIBED, _ref3) >= 0)) {
|
2013-12-30 15:00:16 +00:00
|
|
|
this.error("cannot increment/decrement \"" + (this.first.unwrapAll().value) + "\"");
|
|
|
|
}
|
|
|
|
if (this.isUnary()) {
|
|
|
|
return this.compileUnary(o);
|
|
|
|
}
|
|
|
|
if (isChain) {
|
|
|
|
return this.compileChain(o);
|
|
|
|
}
|
|
|
|
if (this.operator === '?') {
|
|
|
|
return this.compileExistence(o);
|
2012-07-05 06:37:09 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
answer = [].concat(this.first.compileToFragments(o, LEVEL_OP), this.makeCode(' ' + this.operator + ' '), this.second.compileToFragments(o, LEVEL_OP));
|
2012-02-06 20:59:17 +00:00
|
|
|
if (o.level <= LEVEL_OP) {
|
2013-12-30 15:00:16 +00:00
|
|
|
return answer;
|
2012-02-06 20:59:17 +00:00
|
|
|
} else {
|
2013-12-30 15:00:16 +00:00
|
|
|
return this.wrapInBraces(answer);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Op.prototype.compileChain = function(o) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var fragments, fst, shared, _ref2;
|
2012-02-06 20:59:17 +00:00
|
|
|
_ref2 = this.first.second.cache(o), this.first.second = _ref2[0], shared = _ref2[1];
|
2013-12-30 15:00:16 +00:00
|
|
|
fst = this.first.compileToFragments(o, LEVEL_OP);
|
|
|
|
fragments = fst.concat(this.makeCode(" " + (this.invert ? '&&' : '||') + " "), shared.compileToFragments(o), this.makeCode(" " + this.operator + " "), this.second.compileToFragments(o, LEVEL_OP));
|
|
|
|
return this.wrapInBraces(fragments);
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Op.prototype.compileExistence = function(o) {
|
|
|
|
var fst, ref;
|
2013-12-30 15:00:16 +00:00
|
|
|
if (this.first.isComplex()) {
|
2012-02-06 20:59:17 +00:00
|
|
|
ref = new Literal(o.scope.freeVariable('ref'));
|
|
|
|
fst = new Parens(new Assign(ref, this.first));
|
|
|
|
} else {
|
|
|
|
fst = this.first;
|
|
|
|
ref = fst;
|
|
|
|
}
|
|
|
|
return new If(new Existence(fst), ref, {
|
|
|
|
type: 'if'
|
2013-12-30 15:00:16 +00:00
|
|
|
}).addElse(this.second).compileToFragments(o);
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Op.prototype.compileUnary = function(o) {
|
2012-07-05 06:37:09 +00:00
|
|
|
var op, parts, plusMinus;
|
2013-12-30 15:00:16 +00:00
|
|
|
parts = [];
|
|
|
|
op = this.operator;
|
|
|
|
parts.push([this.makeCode(op)]);
|
|
|
|
if (op === '!' && this.first instanceof Existence) {
|
|
|
|
this.first.negated = !this.first.negated;
|
|
|
|
return this.first.compileToFragments(o);
|
|
|
|
}
|
|
|
|
if (o.level >= LEVEL_ACCESS) {
|
|
|
|
return (new Parens(this)).compileToFragments(o);
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
plusMinus = op === '+' || op === '-';
|
|
|
|
if ((op === 'new' || op === 'typeof' || op === 'delete') || plusMinus && this.first instanceof Op && this.first.operator === op) {
|
2013-12-30 15:00:16 +00:00
|
|
|
parts.push([this.makeCode(' ')]);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
if ((plusMinus && this.first instanceof Op) || (op === 'new' && this.first.isStatement(o))) {
|
2012-02-06 20:59:17 +00:00
|
|
|
this.first = new Parens(this.first);
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
parts.push(this.first.compileToFragments(o, LEVEL_OP));
|
|
|
|
if (this.flip) {
|
|
|
|
parts.reverse();
|
|
|
|
}
|
|
|
|
return this.joinFragmentArrays(parts, '');
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Op.prototype.toString = function(idt) {
|
|
|
|
return Op.__super__.toString.call(this, idt, this.constructor.name + ' ' + this.operator);
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
return Op;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
})(Base);
|
|
|
|
|
|
|
|
exports.In = In = (function(_super) {
|
|
|
|
__extends(In, _super);
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
function In(object, array) {
|
|
|
|
this.object = object;
|
|
|
|
this.array = array;
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
In.prototype.children = ['object', 'array'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
In.prototype.invert = NEGATE;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
In.prototype.compileNode = function(o) {
|
|
|
|
var hasSplat, obj, _i, _len, _ref2;
|
|
|
|
if (this.array instanceof Value && this.array.isArray()) {
|
|
|
|
_ref2 = this.array.base.objects;
|
|
|
|
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
|
|
|
obj = _ref2[_i];
|
2013-12-30 15:00:16 +00:00
|
|
|
if (!(obj instanceof Splat)) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
hasSplat = true;
|
|
|
|
break;
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
if (!hasSplat) {
|
|
|
|
return this.compileOrTest(o);
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
return this.compileLoopTest(o);
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
In.prototype.compileOrTest = function(o) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var cmp, cnj, i, item, ref, sub, tests, _i, _len, _ref2, _ref3, _ref4;
|
|
|
|
if (this.array.base.objects.length === 0) {
|
|
|
|
return [this.makeCode("" + (!!this.negated))];
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
_ref2 = this.object.cache(o, LEVEL_OP), sub = _ref2[0], ref = _ref2[1];
|
|
|
|
_ref3 = this.negated ? [' !== ', ' && '] : [' === ', ' || '], cmp = _ref3[0], cnj = _ref3[1];
|
2013-12-30 15:00:16 +00:00
|
|
|
tests = [];
|
|
|
|
_ref4 = this.array.base.objects;
|
|
|
|
for (i = _i = 0, _len = _ref4.length; _i < _len; i = ++_i) {
|
|
|
|
item = _ref4[i];
|
|
|
|
if (i) {
|
|
|
|
tests.push(this.makeCode(cnj));
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
tests = tests.concat((i ? ref : sub), this.makeCode(cmp), item.compileToFragments(o, LEVEL_ACCESS));
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
if (o.level < LEVEL_OP) {
|
|
|
|
return tests;
|
|
|
|
} else {
|
2013-12-30 15:00:16 +00:00
|
|
|
return this.wrapInBraces(tests);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
In.prototype.compileLoopTest = function(o) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var fragments, ref, sub, _ref2;
|
2012-02-06 20:59:17 +00:00
|
|
|
_ref2 = this.object.cache(o, LEVEL_LIST), sub = _ref2[0], ref = _ref2[1];
|
2013-12-30 15:00:16 +00:00
|
|
|
fragments = [].concat(this.makeCode(utility('indexOf') + ".call("), this.array.compileToFragments(o, LEVEL_LIST), this.makeCode(", "), ref, this.makeCode(") " + (this.negated ? '< 0' : '>= 0')));
|
|
|
|
if (fragmentsToText(sub) === fragmentsToText(ref)) {
|
|
|
|
return fragments;
|
|
|
|
}
|
|
|
|
fragments = sub.concat(this.makeCode(', '), fragments);
|
2012-02-06 20:59:17 +00:00
|
|
|
if (o.level < LEVEL_LIST) {
|
2013-12-30 15:00:16 +00:00
|
|
|
return fragments;
|
2012-02-06 20:59:17 +00:00
|
|
|
} else {
|
2013-12-30 15:00:16 +00:00
|
|
|
return this.wrapInBraces(fragments);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
In.prototype.toString = function(idt) {
|
|
|
|
return In.__super__.toString.call(this, idt, this.constructor.name + (this.negated ? '!' : ''));
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
return In;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
})(Base);
|
|
|
|
|
|
|
|
exports.Try = Try = (function(_super) {
|
|
|
|
__extends(Try, _super);
|
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
function Try(attempt, errorVariable, recovery, ensure) {
|
2012-02-06 20:59:17 +00:00
|
|
|
this.attempt = attempt;
|
2013-12-30 15:00:16 +00:00
|
|
|
this.errorVariable = errorVariable;
|
2012-02-06 20:59:17 +00:00
|
|
|
this.recovery = recovery;
|
|
|
|
this.ensure = ensure;
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Try.prototype.children = ['attempt', 'recovery', 'ensure'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Try.prototype.isStatement = YES;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Try.prototype.jumps = function(o) {
|
|
|
|
var _ref2;
|
|
|
|
return this.attempt.jumps(o) || ((_ref2 = this.recovery) != null ? _ref2.jumps(o) : void 0);
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
Try.prototype.makeReturn = function(res) {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (this.attempt) {
|
|
|
|
this.attempt = this.attempt.makeReturn(res);
|
|
|
|
}
|
|
|
|
if (this.recovery) {
|
|
|
|
this.recovery = this.recovery.makeReturn(res);
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
return this;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Try.prototype.compileNode = function(o) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var catchPart, ensurePart, placeholder, tryPart;
|
2012-02-06 20:59:17 +00:00
|
|
|
o.indent += TAB;
|
2013-12-30 15:00:16 +00:00
|
|
|
tryPart = this.attempt.compileToFragments(o, LEVEL_TOP);
|
|
|
|
catchPart = this.recovery ? (placeholder = new Literal('_error'), this.errorVariable ? this.recovery.unshift(new Assign(this.errorVariable, placeholder)) : void 0, [].concat(this.makeCode(" catch ("), placeholder.compileToFragments(o), this.makeCode(") {\n"), this.recovery.compileToFragments(o, LEVEL_TOP), this.makeCode("\n" + this.tab + "}"))) : !(this.ensure || this.recovery) ? [this.makeCode(' catch (_error) {}')] : [];
|
|
|
|
ensurePart = this.ensure ? [].concat(this.makeCode(" finally {\n"), this.ensure.compileToFragments(o, LEVEL_TOP), this.makeCode("\n" + this.tab + "}")) : [];
|
|
|
|
return [].concat(this.makeCode("" + this.tab + "try {\n"), tryPart, this.makeCode("\n" + this.tab + "}"), catchPart, ensurePart);
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
return Try;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
})(Base);
|
|
|
|
|
|
|
|
exports.Throw = Throw = (function(_super) {
|
|
|
|
__extends(Throw, _super);
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
function Throw(expression) {
|
|
|
|
this.expression = expression;
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Throw.prototype.children = ['expression'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Throw.prototype.isStatement = YES;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Throw.prototype.jumps = NO;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Throw.prototype.makeReturn = THIS;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Throw.prototype.compileNode = function(o) {
|
2013-12-30 15:00:16 +00:00
|
|
|
return [].concat(this.makeCode(this.tab + "throw "), this.expression.compileToFragments(o), this.makeCode(";"));
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
return Throw;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
})(Base);
|
|
|
|
|
|
|
|
exports.Existence = Existence = (function(_super) {
|
|
|
|
__extends(Existence, _super);
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
function Existence(expression) {
|
|
|
|
this.expression = expression;
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Existence.prototype.children = ['expression'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Existence.prototype.invert = NEGATE;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Existence.prototype.compileNode = function(o) {
|
|
|
|
var cmp, cnj, code, _ref2;
|
2012-07-05 06:37:09 +00:00
|
|
|
this.expression.front = this.front;
|
2012-02-06 20:59:17 +00:00
|
|
|
code = this.expression.compile(o, LEVEL_OP);
|
2012-07-05 06:37:09 +00:00
|
|
|
if (IDENTIFIER.test(code) && !o.scope.check(code)) {
|
|
|
|
_ref2 = this.negated ? ['===', '||'] : ['!==', '&&'], cmp = _ref2[0], cnj = _ref2[1];
|
|
|
|
code = "typeof " + code + " " + cmp + " \"undefined\" " + cnj + " " + code + " " + cmp + " null";
|
|
|
|
} else {
|
|
|
|
code = "" + code + " " + (this.negated ? '==' : '!=') + " null";
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
return [this.makeCode(o.level <= LEVEL_COND ? code : "(" + code + ")")];
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
return Existence;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
})(Base);
|
|
|
|
|
|
|
|
exports.Parens = Parens = (function(_super) {
|
|
|
|
__extends(Parens, _super);
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
function Parens(body) {
|
|
|
|
this.body = body;
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Parens.prototype.children = ['body'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Parens.prototype.unwrap = function() {
|
|
|
|
return this.body;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Parens.prototype.isComplex = function() {
|
|
|
|
return this.body.isComplex();
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Parens.prototype.compileNode = function(o) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var bare, expr, fragments;
|
2012-02-06 20:59:17 +00:00
|
|
|
expr = this.body.unwrap();
|
|
|
|
if (expr instanceof Value && expr.isAtomic()) {
|
|
|
|
expr.front = this.front;
|
2013-12-30 15:00:16 +00:00
|
|
|
return expr.compileToFragments(o);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
fragments = expr.compileToFragments(o, LEVEL_PAREN);
|
2012-02-06 20:59:17 +00:00
|
|
|
bare = o.level < LEVEL_OP && (expr instanceof Op || expr instanceof Call || (expr instanceof For && expr.returns));
|
|
|
|
if (bare) {
|
2013-12-30 15:00:16 +00:00
|
|
|
return fragments;
|
2012-02-06 20:59:17 +00:00
|
|
|
} else {
|
2013-12-30 15:00:16 +00:00
|
|
|
return this.wrapInBraces(fragments);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
return Parens;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
})(Base);
|
|
|
|
|
|
|
|
exports.For = For = (function(_super) {
|
|
|
|
__extends(For, _super);
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
function For(body, source) {
|
|
|
|
var _ref2;
|
|
|
|
this.source = source.source, this.guard = source.guard, this.step = source.step, this.name = source.name, this.index = source.index;
|
|
|
|
this.body = Block.wrap([body]);
|
|
|
|
this.own = !!source.own;
|
|
|
|
this.object = !!source.object;
|
|
|
|
if (this.object) {
|
|
|
|
_ref2 = [this.index, this.name], this.name = _ref2[0], this.index = _ref2[1];
|
|
|
|
}
|
|
|
|
if (this.index instanceof Value) {
|
2013-12-30 15:00:16 +00:00
|
|
|
this.index.error('index cannot be a pattern matching expression');
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
this.range = this.source instanceof Value && this.source.base instanceof Range && !this.source.properties.length;
|
|
|
|
this.pattern = this.name instanceof Value;
|
|
|
|
if (this.range && this.index) {
|
2013-12-30 15:00:16 +00:00
|
|
|
this.index.error('indexes do not apply to range loops');
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
if (this.range && this.pattern) {
|
2013-12-30 15:00:16 +00:00
|
|
|
this.name.error('cannot pattern match over range loops');
|
|
|
|
}
|
|
|
|
if (this.own && !this.object) {
|
|
|
|
this.name.error('cannot use own with for-in');
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
this.returns = false;
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
For.prototype.children = ['body', 'source', 'guard', 'step'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
For.prototype.compileNode = function(o) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var body, bodyFragments, compare, compareDown, declare, declareDown, defPart, defPartFragments, down, forPartFragments, guardPart, idt1, increment, index, ivar, kvar, kvarAssign, lastJumps, lvar, name, namePart, ref, resultPart, returnResult, rvar, scope, source, step, stepNum, stepVar, svar, varPart, _ref2, _ref3;
|
2012-02-06 20:59:17 +00:00
|
|
|
body = Block.wrap([this.body]);
|
|
|
|
lastJumps = (_ref2 = last(body.expressions)) != null ? _ref2.jumps() : void 0;
|
2013-12-30 15:00:16 +00:00
|
|
|
if (lastJumps && lastJumps instanceof Return) {
|
|
|
|
this.returns = false;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
source = this.range ? this.source.base : this.source;
|
|
|
|
scope = o.scope;
|
2013-12-30 15:00:16 +00:00
|
|
|
name = this.name && (this.name.compile(o, LEVEL_LIST));
|
|
|
|
index = this.index && (this.index.compile(o, LEVEL_LIST));
|
2012-02-06 20:59:17 +00:00
|
|
|
if (name && !this.pattern) {
|
2013-12-30 15:00:16 +00:00
|
|
|
scope.find(name);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
if (index) {
|
2013-12-30 15:00:16 +00:00
|
|
|
scope.find(index);
|
|
|
|
}
|
|
|
|
if (this.returns) {
|
|
|
|
rvar = scope.freeVariable('results');
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
ivar = (this.object && index) || scope.freeVariable('i');
|
|
|
|
kvar = (this.range && name) || index || ivar;
|
|
|
|
kvarAssign = kvar !== ivar ? "" + kvar + " = " : "";
|
2013-12-30 15:00:16 +00:00
|
|
|
if (this.step && !this.range) {
|
|
|
|
_ref3 = this.cacheToCodeFragments(this.step.cache(o, LEVEL_LIST)), step = _ref3[0], stepVar = _ref3[1];
|
|
|
|
stepNum = stepVar.match(NUMBER);
|
|
|
|
}
|
|
|
|
if (this.pattern) {
|
|
|
|
name = ivar;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
varPart = '';
|
|
|
|
guardPart = '';
|
|
|
|
defPart = '';
|
|
|
|
idt1 = this.tab + TAB;
|
|
|
|
if (this.range) {
|
2013-12-30 15:00:16 +00:00
|
|
|
forPartFragments = source.compileToFragments(merge(o, {
|
2012-02-06 20:59:17 +00:00
|
|
|
index: ivar,
|
2012-07-05 06:37:09 +00:00
|
|
|
name: name,
|
2012-02-06 20:59:17 +00:00
|
|
|
step: this.step
|
|
|
|
}));
|
|
|
|
} else {
|
|
|
|
svar = this.source.compile(o, LEVEL_LIST);
|
|
|
|
if ((name || this.own) && !IDENTIFIER.test(svar)) {
|
2013-12-30 15:00:16 +00:00
|
|
|
defPart += "" + this.tab + (ref = scope.freeVariable('ref')) + " = " + svar + ";\n";
|
2012-02-06 20:59:17 +00:00
|
|
|
svar = ref;
|
|
|
|
}
|
|
|
|
if (name && !this.pattern) {
|
2012-07-05 06:37:09 +00:00
|
|
|
namePart = "" + name + " = " + svar + "[" + kvar + "]";
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
if (!this.object) {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (step !== stepVar) {
|
|
|
|
defPart += "" + this.tab + step + ";\n";
|
|
|
|
}
|
|
|
|
if (!(this.step && stepNum && (down = parseNum(stepNum[0]) < 0))) {
|
|
|
|
lvar = scope.freeVariable('len');
|
|
|
|
}
|
|
|
|
declare = "" + kvarAssign + ivar + " = 0, " + lvar + " = " + svar + ".length";
|
|
|
|
declareDown = "" + kvarAssign + ivar + " = " + svar + ".length - 1";
|
|
|
|
compare = "" + ivar + " < " + lvar;
|
|
|
|
compareDown = "" + ivar + " >= 0";
|
2012-07-05 06:37:09 +00:00
|
|
|
if (this.step) {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (stepNum) {
|
|
|
|
if (down) {
|
|
|
|
compare = compareDown;
|
|
|
|
declare = declareDown;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
compare = "" + stepVar + " > 0 ? " + compare + " : " + compareDown;
|
|
|
|
declare = "(" + stepVar + " > 0 ? (" + declare + ") : " + declareDown + ")";
|
|
|
|
}
|
|
|
|
increment = "" + ivar + " += " + stepVar;
|
|
|
|
} else {
|
|
|
|
increment = "" + (kvar !== ivar ? "++" + ivar : "" + ivar + "++");
|
2012-07-05 06:37:09 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
forPartFragments = [this.makeCode("" + declare + "; " + compare + "; " + kvarAssign + increment)];
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.returns) {
|
|
|
|
resultPart = "" + this.tab + rvar + " = [];\n";
|
|
|
|
returnResult = "\n" + this.tab + "return " + rvar + ";";
|
2012-07-05 06:37:09 +00:00
|
|
|
body.makeReturn(rvar);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
if (this.guard) {
|
2012-07-05 06:37:09 +00:00
|
|
|
if (body.expressions.length > 1) {
|
|
|
|
body.expressions.unshift(new If((new Parens(this.guard)).invert(), new Literal("continue")));
|
|
|
|
} else {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (this.guard) {
|
|
|
|
body = Block.wrap([new If(this.guard, body)]);
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
if (this.pattern) {
|
2012-07-05 06:37:09 +00:00
|
|
|
body.expressions.unshift(new Assign(this.name, new Literal("" + svar + "[" + kvar + "]")));
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
defPartFragments = [].concat(this.makeCode(defPart), this.pluckDirectCall(o, body));
|
|
|
|
if (namePart) {
|
|
|
|
varPart = "\n" + idt1 + namePart + ";";
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
if (this.object) {
|
2013-12-30 15:00:16 +00:00
|
|
|
forPartFragments = [this.makeCode("" + kvar + " in " + svar)];
|
2012-02-06 20:59:17 +00:00
|
|
|
if (this.own) {
|
2012-07-05 06:37:09 +00:00
|
|
|
guardPart = "\n" + idt1 + "if (!" + (utility('hasProp')) + ".call(" + svar + ", " + kvar + ")) continue;";
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
bodyFragments = body.compileToFragments(merge(o, {
|
2012-02-06 20:59:17 +00:00
|
|
|
indent: idt1
|
|
|
|
}), LEVEL_TOP);
|
2013-12-30 15:00:16 +00:00
|
|
|
if (bodyFragments && (bodyFragments.length > 0)) {
|
|
|
|
bodyFragments = [].concat(this.makeCode("\n"), bodyFragments, this.makeCode("\n"));
|
|
|
|
}
|
|
|
|
return [].concat(defPartFragments, this.makeCode("" + (resultPart || '') + this.tab + "for ("), forPartFragments, this.makeCode(") {" + guardPart + varPart), bodyFragments, this.makeCode("" + this.tab + "}" + (returnResult || '')));
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
For.prototype.pluckDirectCall = function(o, body) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var base, defs, expr, fn, idx, ref, val, _i, _len, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8;
|
|
|
|
defs = [];
|
2012-02-06 20:59:17 +00:00
|
|
|
_ref2 = body.expressions;
|
2012-07-05 06:37:09 +00:00
|
|
|
for (idx = _i = 0, _len = _ref2.length; _i < _len; idx = ++_i) {
|
2012-02-06 20:59:17 +00:00
|
|
|
expr = _ref2[idx];
|
|
|
|
expr = expr.unwrapAll();
|
2013-12-30 15:00:16 +00:00
|
|
|
if (!(expr instanceof Call)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
val = (_ref3 = expr.variable) != null ? _ref3.unwrapAll() : void 0;
|
|
|
|
if (!((val instanceof Code) || (val instanceof Value && ((_ref4 = val.base) != null ? _ref4.unwrapAll() : void 0) instanceof Code && val.properties.length === 1 && ((_ref5 = (_ref6 = val.properties[0].name) != null ? _ref6.value : void 0) === 'call' || _ref5 === 'apply')))) {
|
2012-02-06 20:59:17 +00:00
|
|
|
continue;
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
fn = ((_ref7 = val.base) != null ? _ref7.unwrapAll() : void 0) || val;
|
2012-02-06 20:59:17 +00:00
|
|
|
ref = new Literal(o.scope.freeVariable('fn'));
|
|
|
|
base = new Value(ref);
|
2013-12-30 15:00:16 +00:00
|
|
|
if (val.base) {
|
|
|
|
_ref8 = [base, val], val.base = _ref8[0], base = _ref8[1];
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
body.expressions[idx] = new Call(base, expr.args);
|
2013-12-30 15:00:16 +00:00
|
|
|
defs = defs.concat(this.makeCode(this.tab), new Assign(ref, fn).compileToFragments(o, LEVEL_TOP), this.makeCode(';\n'));
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
return defs;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
return For;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
})(While);
|
|
|
|
|
|
|
|
exports.Switch = Switch = (function(_super) {
|
|
|
|
__extends(Switch, _super);
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
function Switch(subject, cases, otherwise) {
|
|
|
|
this.subject = subject;
|
|
|
|
this.cases = cases;
|
|
|
|
this.otherwise = otherwise;
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Switch.prototype.children = ['subject', 'cases', 'otherwise'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Switch.prototype.isStatement = YES;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Switch.prototype.jumps = function(o) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var block, conds, jumpNode, _i, _len, _ref2, _ref3, _ref4;
|
2012-02-06 20:59:17 +00:00
|
|
|
if (o == null) {
|
|
|
|
o = {
|
|
|
|
block: true
|
|
|
|
};
|
|
|
|
}
|
|
|
|
_ref2 = this.cases;
|
|
|
|
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
|
|
|
_ref3 = _ref2[_i], conds = _ref3[0], block = _ref3[1];
|
2013-12-30 15:00:16 +00:00
|
|
|
if (jumpNode = block.jumps(o)) {
|
|
|
|
return jumpNode;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
return (_ref4 = this.otherwise) != null ? _ref4.jumps(o) : void 0;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
Switch.prototype.makeReturn = function(res) {
|
2012-02-06 20:59:17 +00:00
|
|
|
var pair, _i, _len, _ref2, _ref3;
|
|
|
|
_ref2 = this.cases;
|
|
|
|
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
|
|
|
pair = _ref2[_i];
|
2012-07-05 06:37:09 +00:00
|
|
|
pair[1].makeReturn(res);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
if (res) {
|
|
|
|
this.otherwise || (this.otherwise = new Block([new Literal('void 0')]));
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
if ((_ref3 = this.otherwise) != null) {
|
|
|
|
_ref3.makeReturn(res);
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
return this;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Switch.prototype.compileNode = function(o) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var block, body, cond, conditions, expr, fragments, i, idt1, idt2, _i, _j, _len, _len1, _ref2, _ref3, _ref4;
|
2012-02-06 20:59:17 +00:00
|
|
|
idt1 = o.indent + TAB;
|
|
|
|
idt2 = o.indent = idt1 + TAB;
|
2013-12-30 15:00:16 +00:00
|
|
|
fragments = [].concat(this.makeCode(this.tab + "switch ("), (this.subject ? this.subject.compileToFragments(o, LEVEL_PAREN) : this.makeCode("false")), this.makeCode(") {\n"));
|
|
|
|
_ref2 = this.cases;
|
|
|
|
for (i = _i = 0, _len = _ref2.length; _i < _len; i = ++_i) {
|
|
|
|
_ref3 = _ref2[i], conditions = _ref3[0], block = _ref3[1];
|
|
|
|
_ref4 = flatten([conditions]);
|
|
|
|
for (_j = 0, _len1 = _ref4.length; _j < _len1; _j++) {
|
|
|
|
cond = _ref4[_j];
|
|
|
|
if (!this.subject) {
|
|
|
|
cond = cond.invert();
|
|
|
|
}
|
|
|
|
fragments = fragments.concat(this.makeCode(idt1 + "case "), cond.compileToFragments(o, LEVEL_PAREN), this.makeCode(":\n"));
|
|
|
|
}
|
|
|
|
if ((body = block.compileToFragments(o, LEVEL_TOP)).length > 0) {
|
|
|
|
fragments = fragments.concat(body, this.makeCode('\n'));
|
|
|
|
}
|
|
|
|
if (i === this.cases.length - 1 && !this.otherwise) {
|
|
|
|
break;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
expr = this.lastNonComment(block.expressions);
|
|
|
|
if (expr instanceof Return || (expr instanceof Literal && expr.jumps() && expr.value !== 'debugger')) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
fragments.push(cond.makeCode(idt2 + 'break;\n'));
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
if (this.otherwise && this.otherwise.expressions.length) {
|
2013-12-30 15:00:16 +00:00
|
|
|
fragments.push.apply(fragments, [this.makeCode(idt1 + "default:\n")].concat(__slice.call(this.otherwise.compileToFragments(o, LEVEL_TOP)), [this.makeCode("\n")]));
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
fragments.push(this.makeCode(this.tab + '}'));
|
|
|
|
return fragments;
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
return Switch;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
})(Base);
|
|
|
|
|
|
|
|
exports.If = If = (function(_super) {
|
|
|
|
__extends(If, _super);
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
function If(condition, body, options) {
|
|
|
|
this.body = body;
|
2013-12-30 15:00:16 +00:00
|
|
|
if (options == null) {
|
|
|
|
options = {};
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
this.condition = options.type === 'unless' ? condition.invert() : condition;
|
|
|
|
this.elseBody = null;
|
|
|
|
this.isChain = false;
|
|
|
|
this.soak = options.soak;
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
If.prototype.children = ['condition', 'body', 'elseBody'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
If.prototype.bodyNode = function() {
|
|
|
|
var _ref2;
|
|
|
|
return (_ref2 = this.body) != null ? _ref2.unwrap() : void 0;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
If.prototype.elseBodyNode = function() {
|
|
|
|
var _ref2;
|
|
|
|
return (_ref2 = this.elseBody) != null ? _ref2.unwrap() : void 0;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
If.prototype.addElse = function(elseBody) {
|
|
|
|
if (this.isChain) {
|
|
|
|
this.elseBodyNode().addElse(elseBody);
|
|
|
|
} else {
|
|
|
|
this.isChain = elseBody instanceof If;
|
|
|
|
this.elseBody = this.ensureBlock(elseBody);
|
2013-12-30 15:00:16 +00:00
|
|
|
this.elseBody.updateLocationDataIfMissing(elseBody.locationData);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
return this;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
If.prototype.isStatement = function(o) {
|
|
|
|
var _ref2;
|
|
|
|
return (o != null ? o.level : void 0) === LEVEL_TOP || this.bodyNode().isStatement(o) || ((_ref2 = this.elseBodyNode()) != null ? _ref2.isStatement(o) : void 0);
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
If.prototype.jumps = function(o) {
|
|
|
|
var _ref2;
|
|
|
|
return this.body.jumps(o) || ((_ref2 = this.elseBody) != null ? _ref2.jumps(o) : void 0);
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
If.prototype.compileNode = function(o) {
|
|
|
|
if (this.isStatement(o)) {
|
|
|
|
return this.compileStatement(o);
|
|
|
|
} else {
|
|
|
|
return this.compileExpression(o);
|
|
|
|
}
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
If.prototype.makeReturn = function(res) {
|
|
|
|
if (res) {
|
|
|
|
this.elseBody || (this.elseBody = new Block([new Literal('void 0')]));
|
|
|
|
}
|
|
|
|
this.body && (this.body = new Block([this.body.makeReturn(res)]));
|
|
|
|
this.elseBody && (this.elseBody = new Block([this.elseBody.makeReturn(res)]));
|
2012-02-06 20:59:17 +00:00
|
|
|
return this;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
If.prototype.ensureBlock = function(node) {
|
|
|
|
if (node instanceof Block) {
|
|
|
|
return node;
|
|
|
|
} else {
|
|
|
|
return new Block([node]);
|
|
|
|
}
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
If.prototype.compileStatement = function(o) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var answer, body, child, cond, exeq, ifPart, indent;
|
2012-02-06 20:59:17 +00:00
|
|
|
child = del(o, 'chainChild');
|
|
|
|
exeq = del(o, 'isExistentialEquals');
|
|
|
|
if (exeq) {
|
|
|
|
return new If(this.condition.invert(), this.elseBodyNode(), {
|
|
|
|
type: 'if'
|
2013-12-30 15:00:16 +00:00
|
|
|
}).compileToFragments(o);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
indent = o.indent + TAB;
|
|
|
|
cond = this.condition.compileToFragments(o, LEVEL_PAREN);
|
|
|
|
body = this.ensureBlock(this.body).compileToFragments(merge(o, {
|
|
|
|
indent: indent
|
|
|
|
}));
|
|
|
|
ifPart = [].concat(this.makeCode("if ("), cond, this.makeCode(") {\n"), body, this.makeCode("\n" + this.tab + "}"));
|
|
|
|
if (!child) {
|
|
|
|
ifPart.unshift(this.makeCode(this.tab));
|
2012-07-05 06:37:09 +00:00
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
if (!this.elseBody) {
|
|
|
|
return ifPart;
|
|
|
|
}
|
|
|
|
answer = ifPart.concat(this.makeCode(' else '));
|
|
|
|
if (this.isChain) {
|
|
|
|
o.chainChild = true;
|
|
|
|
answer = answer.concat(this.elseBody.unwrap().compileToFragments(o, LEVEL_TOP));
|
|
|
|
} else {
|
|
|
|
answer = answer.concat(this.makeCode("{\n"), this.elseBody.compileToFragments(merge(o, {
|
|
|
|
indent: indent
|
|
|
|
}), LEVEL_TOP), this.makeCode("\n" + this.tab + "}"));
|
|
|
|
}
|
|
|
|
return answer;
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
If.prototype.compileExpression = function(o) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var alt, body, cond, fragments;
|
|
|
|
cond = this.condition.compileToFragments(o, LEVEL_COND);
|
|
|
|
body = this.bodyNode().compileToFragments(o, LEVEL_LIST);
|
|
|
|
alt = this.elseBodyNode() ? this.elseBodyNode().compileToFragments(o, LEVEL_LIST) : [this.makeCode('void 0')];
|
|
|
|
fragments = cond.concat(this.makeCode(" ? "), body, this.makeCode(" : "), alt);
|
2012-02-06 20:59:17 +00:00
|
|
|
if (o.level >= LEVEL_COND) {
|
2013-12-30 15:00:16 +00:00
|
|
|
return this.wrapInBraces(fragments);
|
2012-02-06 20:59:17 +00:00
|
|
|
} else {
|
2013-12-30 15:00:16 +00:00
|
|
|
return fragments;
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
If.prototype.unfoldSoak = function() {
|
|
|
|
return this.soak && this;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
return If;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
})(Base);
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
UTILITIES = {
|
2012-07-05 06:37:09 +00:00
|
|
|
"extends": function() {
|
2013-12-30 15:00:16 +00:00
|
|
|
return "function(child, parent) { for (var key in parent) { if (" + (utility('hasProp')) + ".call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }";
|
2012-07-05 06:37:09 +00:00
|
|
|
},
|
|
|
|
bind: function() {
|
|
|
|
return 'function(fn, me){ return function(){ return fn.apply(me, arguments); }; }';
|
|
|
|
},
|
|
|
|
indexOf: function() {
|
|
|
|
return "[].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }";
|
|
|
|
},
|
|
|
|
hasProp: function() {
|
|
|
|
return '{}.hasOwnProperty';
|
|
|
|
},
|
|
|
|
slice: function() {
|
|
|
|
return '[].slice';
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
LEVEL_TOP = 1;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
LEVEL_PAREN = 2;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
LEVEL_LIST = 3;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
LEVEL_COND = 4;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
LEVEL_OP = 5;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
LEVEL_ACCESS = 6;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
TAB = ' ';
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
IDENTIFIER_STR = "[$A-Za-z_\\x7f-\\uffff][$\\w\\x7f-\\uffff]*";
|
|
|
|
|
|
|
|
IDENTIFIER = RegExp("^" + IDENTIFIER_STR + "$");
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
SIMPLENUM = /^[+-]?\d+$/;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
HEXNUM = /^[+-]?0x[\da-f]+/i;
|
|
|
|
|
|
|
|
NUMBER = /^[+-]?(?:0x[\da-f]+|\d*\.?\d+(?:e[+-]?\d+)?)$/i;
|
|
|
|
|
|
|
|
METHOD_DEF = RegExp("^(" + IDENTIFIER_STR + ")(\\.prototype)?(?:\\.(" + IDENTIFIER_STR + ")|\\[(\"(?:[^\\\\\"\\r\\n]|\\\\.)*\"|'(?:[^\\\\'\\r\\n]|\\\\.)*')\\]|\\[(0x[\\da-fA-F]+|\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\])$");
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
IS_STRING = /^['"]/;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
IS_REGEX = /^\//;
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
utility = function(name) {
|
|
|
|
var ref;
|
|
|
|
ref = "__" + name;
|
2012-07-05 06:37:09 +00:00
|
|
|
Scope.root.assign(ref, UTILITIES[name]());
|
2012-02-06 20:59:17 +00:00
|
|
|
return ref;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
multident = function(code, tab) {
|
2012-07-05 06:37:09 +00:00
|
|
|
code = code.replace(/\n/g, '$&' + tab);
|
|
|
|
return code.replace(/\s+$/, '');
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
parseNum = function(x) {
|
|
|
|
if (x == null) {
|
|
|
|
return 0;
|
|
|
|
} else if (x.match(HEXNUM)) {
|
|
|
|
return parseInt(x, 16);
|
|
|
|
} else {
|
|
|
|
return parseFloat(x);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
isLiteralArguments = function(node) {
|
|
|
|
return node instanceof Literal && node.value === 'arguments' && !node.asKey;
|
|
|
|
};
|
|
|
|
|
|
|
|
isLiteralThis = function(node) {
|
|
|
|
return (node instanceof Literal && node.value === 'this' && !node.asKey) || (node instanceof Code && node.bound) || (node instanceof Call && node.isSuper);
|
|
|
|
};
|
|
|
|
|
|
|
|
unfoldSoak = function(o, parent, name) {
|
|
|
|
var ifn;
|
|
|
|
if (!(ifn = parent[name].unfoldSoak(o))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
parent[name] = ifn.body;
|
|
|
|
ifn.body = new Value(parent);
|
|
|
|
return ifn;
|
|
|
|
};
|
|
|
|
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
define('ace/mode/coffee/scope', ['require', 'exports', 'module' , 'ace/mode/coffee/helpers'], function(require, exports, module) {
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
var Scope, extend, last, _ref;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
_ref = require('./helpers'), extend = _ref.extend, last = _ref.last;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
exports.Scope = Scope = (function() {
|
|
|
|
Scope.root = null;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
function Scope(parent, expressions, method) {
|
|
|
|
this.parent = parent;
|
|
|
|
this.expressions = expressions;
|
|
|
|
this.method = method;
|
|
|
|
this.variables = [
|
|
|
|
{
|
|
|
|
name: 'arguments',
|
|
|
|
type: 'arguments'
|
|
|
|
}
|
|
|
|
];
|
|
|
|
this.positions = {};
|
2013-12-30 15:00:16 +00:00
|
|
|
if (!this.parent) {
|
|
|
|
Scope.root = this;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Scope.prototype.add = function(name, type, immediate) {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (this.shared && !immediate) {
|
|
|
|
return this.parent.add(name, type, immediate);
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
if (Object.prototype.hasOwnProperty.call(this.positions, name)) {
|
|
|
|
return this.variables[this.positions[name]].type = type;
|
2012-02-06 20:59:17 +00:00
|
|
|
} else {
|
|
|
|
return this.positions[name] = this.variables.push({
|
|
|
|
name: name,
|
|
|
|
type: type
|
|
|
|
}) - 1;
|
|
|
|
}
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
Scope.prototype.namedMethod = function() {
|
|
|
|
var _ref1;
|
|
|
|
if (((_ref1 = this.method) != null ? _ref1.name : void 0) || !this.parent) {
|
|
|
|
return this.method;
|
|
|
|
}
|
|
|
|
return this.parent.namedMethod();
|
|
|
|
};
|
|
|
|
|
|
|
|
Scope.prototype.find = function(name) {
|
|
|
|
if (this.check(name)) {
|
|
|
|
return true;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
this.add(name, 'var');
|
|
|
|
return false;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Scope.prototype.parameter = function(name) {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (this.shared && this.parent.check(name, true)) {
|
|
|
|
return;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
return this.add(name, 'param');
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
Scope.prototype.check = function(name) {
|
|
|
|
var _ref1;
|
|
|
|
return !!(this.type(name) || ((_ref1 = this.parent) != null ? _ref1.check(name) : void 0));
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Scope.prototype.temporary = function(name, index) {
|
|
|
|
if (name.length > 1) {
|
2012-07-05 06:37:09 +00:00
|
|
|
return '_' + name + (index > 1 ? index - 1 : '');
|
2012-02-06 20:59:17 +00:00
|
|
|
} else {
|
|
|
|
return '_' + (index + parseInt(name, 36)).toString(36).replace(/\d/g, 'a');
|
|
|
|
}
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Scope.prototype.type = function(name) {
|
2012-07-05 06:37:09 +00:00
|
|
|
var v, _i, _len, _ref1;
|
|
|
|
_ref1 = this.variables;
|
|
|
|
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
|
|
|
v = _ref1[_i];
|
2013-12-30 15:00:16 +00:00
|
|
|
if (v.name === name) {
|
|
|
|
return v.type;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
Scope.prototype.freeVariable = function(name, reserve) {
|
2012-02-06 20:59:17 +00:00
|
|
|
var index, temp;
|
2013-12-30 15:00:16 +00:00
|
|
|
if (reserve == null) {
|
|
|
|
reserve = true;
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
index = 0;
|
2012-07-05 06:37:09 +00:00
|
|
|
while (this.check((temp = this.temporary(name, index)))) {
|
2012-02-06 20:59:17 +00:00
|
|
|
index++;
|
|
|
|
}
|
2013-12-30 15:00:16 +00:00
|
|
|
if (reserve) {
|
|
|
|
this.add(temp, 'var', true);
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
return temp;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Scope.prototype.assign = function(name, value) {
|
|
|
|
this.add(name, {
|
|
|
|
value: value,
|
|
|
|
assigned: true
|
2012-07-05 06:37:09 +00:00
|
|
|
}, true);
|
2012-02-06 20:59:17 +00:00
|
|
|
return this.hasAssignments = true;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Scope.prototype.hasDeclarations = function() {
|
|
|
|
return !!this.declaredVariables().length;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Scope.prototype.declaredVariables = function() {
|
2012-07-05 06:37:09 +00:00
|
|
|
var realVars, tempVars, v, _i, _len, _ref1;
|
2012-02-06 20:59:17 +00:00
|
|
|
realVars = [];
|
|
|
|
tempVars = [];
|
2012-07-05 06:37:09 +00:00
|
|
|
_ref1 = this.variables;
|
|
|
|
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
|
|
|
v = _ref1[_i];
|
2012-02-06 20:59:17 +00:00
|
|
|
if (v.type === 'var') {
|
|
|
|
(v.name.charAt(0) === '_' ? tempVars : realVars).push(v.name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return realVars.sort().concat(tempVars.sort());
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Scope.prototype.assignedVariables = function() {
|
2012-07-05 06:37:09 +00:00
|
|
|
var v, _i, _len, _ref1, _results;
|
|
|
|
_ref1 = this.variables;
|
2012-02-06 20:59:17 +00:00
|
|
|
_results = [];
|
2012-07-05 06:37:09 +00:00
|
|
|
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
|
|
|
v = _ref1[_i];
|
2013-12-30 15:00:16 +00:00
|
|
|
if (v.type.assigned) {
|
|
|
|
_results.push("" + v.name + " = " + v.type.value);
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
return _results;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
return Scope;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
})();
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
});
|