2012-02-06 20:59:17 +00:00
|
|
|
"no use strict";
|
|
|
|
|
|
|
|
var console = {
|
|
|
|
log: function(msg) {
|
|
|
|
postMessage({type: "log", data: msg});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
var window = {
|
|
|
|
console: console
|
|
|
|
};
|
|
|
|
|
|
|
|
var normalizeModule = function(parentId, moduleName) {
|
|
|
|
// normalize plugin requires
|
|
|
|
if (moduleName.indexOf("!") !== -1) {
|
|
|
|
var chunks = moduleName.split("!");
|
|
|
|
return normalizeModule(parentId, chunks[0]) + "!" + normalizeModule(parentId, chunks[1]);
|
|
|
|
}
|
|
|
|
// normalize relative requires
|
|
|
|
if (moduleName.charAt(0) == ".") {
|
|
|
|
var base = parentId.split("/").slice(0, -1).join("/");
|
|
|
|
var moduleName = base + "/" + moduleName;
|
|
|
|
|
|
|
|
while(moduleName.indexOf(".") !== -1 && previous != moduleName) {
|
|
|
|
var previous = moduleName;
|
|
|
|
var moduleName = moduleName.replace(/\/\.\//, "/").replace(/[^\/]+\/\.\.\//, "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return moduleName;
|
|
|
|
};
|
|
|
|
|
|
|
|
var require = function(parentId, id) {
|
|
|
|
var id = normalizeModule(parentId, id);
|
|
|
|
|
|
|
|
var module = require.modules[id];
|
|
|
|
if (module) {
|
|
|
|
if (!module.initialized) {
|
|
|
|
module.exports = module.factory().exports;
|
|
|
|
module.initialized = true;
|
|
|
|
}
|
|
|
|
return module.exports;
|
|
|
|
}
|
|
|
|
|
|
|
|
var chunks = id.split("/");
|
|
|
|
chunks[0] = require.tlns[chunks[0]] || chunks[0];
|
|
|
|
var path = chunks.join("/") + ".js";
|
|
|
|
|
|
|
|
require.id = id;
|
|
|
|
importScripts(path);
|
|
|
|
return require(parentId, id);
|
|
|
|
};
|
|
|
|
|
|
|
|
require.modules = {};
|
|
|
|
require.tlns = {};
|
|
|
|
|
|
|
|
var define = function(id, deps, factory) {
|
|
|
|
if (arguments.length == 2) {
|
|
|
|
factory = deps;
|
|
|
|
} else if (arguments.length == 1) {
|
|
|
|
factory = id;
|
|
|
|
id = require.id;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (id.indexOf("text!") === 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var req = function(deps, factory) {
|
|
|
|
return require(id, deps, factory);
|
|
|
|
};
|
|
|
|
|
|
|
|
require.modules[id] = {
|
|
|
|
factory: function() {
|
|
|
|
var module = {
|
|
|
|
exports: {}
|
|
|
|
};
|
|
|
|
var returnExports = factory(req, module.exports, module);
|
|
|
|
if (returnExports)
|
|
|
|
module.exports = returnExports;
|
|
|
|
return module;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
function initBaseUrls(topLevelNamespaces) {
|
|
|
|
require.tlns = topLevelNamespaces;
|
|
|
|
}
|
|
|
|
|
|
|
|
function initSender() {
|
|
|
|
|
|
|
|
var EventEmitter = require(null, "ace/lib/event_emitter").EventEmitter;
|
|
|
|
var oop = require(null, "ace/lib/oop");
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
var main;
|
|
|
|
var sender;
|
|
|
|
|
|
|
|
onmessage = function(e) {
|
|
|
|
var msg = e.data;
|
|
|
|
if (msg.command) {
|
|
|
|
main[msg.command].apply(main, msg.args);
|
|
|
|
}
|
|
|
|
else if (msg.init) {
|
|
|
|
initBaseUrls(msg.tlns);
|
|
|
|
require(null, "ace/lib/fixoldbrowsers");
|
|
|
|
sender = initSender();
|
|
|
|
var clazz = require(null, msg.module)[msg.classname];
|
|
|
|
main = new clazz(sender);
|
|
|
|
}
|
|
|
|
else if (msg.event && sender) {
|
|
|
|
sender._emit(msg.event, msg.data);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
// vim:set ts=4 sts=4 sw=4 st:
|
|
|
|
// -- kriskowal Kris Kowal Copyright (C) 2009-2010 MIT License
|
|
|
|
// -- tlrobinson Tom Robinson Copyright (C) 2009-2010 MIT License (Narwhal Project)
|
|
|
|
// -- dantman Daniel Friesen Copyright(C) 2010 XXX No License Specified
|
|
|
|
// -- fschaefer Florian Schäfer Copyright (C) 2010 MIT License
|
|
|
|
// -- Irakli Gozalishvili Copyright (C) 2010 MIT License
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Copyright (c) 2009, 280 North Inc. http://280north.com/
|
|
|
|
MIT License. http://github.com/280north/narwhal/blob/master/README.md
|
|
|
|
*/
|
|
|
|
|
|
|
|
define('ace/lib/fixoldbrowsers', ['require', 'exports', 'module' , 'ace/lib/regexp', 'ace/lib/es5-shim'], function(require, exports, module) {
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
|
|
|
|
require("./regexp");
|
|
|
|
require("./es5-shim");
|
|
|
|
|
2012-07-05 06:37:09 +00:00
|
|
|
});
|
2012-02-06 20:59:17 +00:00
|
|
|
|
|
|
|
define('ace/lib/regexp', ['require', 'exports', 'module' ], function(require, exports, module) {
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
|
|
|
|
//---------------------------------
|
|
|
|
// Private variables
|
|
|
|
//---------------------------------
|
|
|
|
|
|
|
|
var real = {
|
|
|
|
exec: RegExp.prototype.exec,
|
|
|
|
test: RegExp.prototype.test,
|
|
|
|
match: String.prototype.match,
|
|
|
|
replace: String.prototype.replace,
|
|
|
|
split: String.prototype.split
|
|
|
|
},
|
|
|
|
compliantExecNpcg = real.exec.call(/()??/, "")[1] === undefined, // check `exec` handling of nonparticipating capturing groups
|
|
|
|
compliantLastIndexIncrement = function () {
|
|
|
|
var x = /^/g;
|
|
|
|
real.test.call(x, "");
|
|
|
|
return !x.lastIndex;
|
|
|
|
}();
|
|
|
|
|
2012-07-05 06:37:09 +00:00
|
|
|
if (compliantLastIndexIncrement && compliantExecNpcg)
|
|
|
|
return;
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
//---------------------------------
|
|
|
|
// Overriden native methods
|
|
|
|
//---------------------------------
|
|
|
|
|
|
|
|
// Adds named capture support (with backreferences returned as `result.name`), and fixes two
|
|
|
|
// cross-browser issues per ES3:
|
|
|
|
// - Captured values for nonparticipating capturing groups should be returned as `undefined`,
|
|
|
|
// rather than the empty string.
|
|
|
|
// - `lastIndex` should not be incremented after zero-length matches.
|
|
|
|
RegExp.prototype.exec = function (str) {
|
|
|
|
var match = real.exec.apply(this, arguments),
|
|
|
|
name, r2;
|
2012-07-05 06:37:09 +00:00
|
|
|
if ( typeof(str) == 'string' && match) {
|
2012-02-06 20:59:17 +00:00
|
|
|
// Fix browsers whose `exec` methods don't consistently return `undefined` for
|
|
|
|
// nonparticipating capturing groups
|
|
|
|
if (!compliantExecNpcg && match.length > 1 && indexOf(match, "") > -1) {
|
|
|
|
r2 = RegExp(this.source, real.replace.call(getNativeFlags(this), "g", ""));
|
|
|
|
// Using `str.slice(match.index)` rather than `match[0]` in case lookahead allowed
|
|
|
|
// matching due to characters outside the match
|
|
|
|
real.replace.call(str.slice(match.index), r2, function () {
|
|
|
|
for (var i = 1; i < arguments.length - 2; i++) {
|
|
|
|
if (arguments[i] === undefined)
|
|
|
|
match[i] = undefined;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// Attach named capture properties
|
|
|
|
if (this._xregexp && this._xregexp.captureNames) {
|
|
|
|
for (var i = 1; i < match.length; i++) {
|
|
|
|
name = this._xregexp.captureNames[i - 1];
|
|
|
|
if (name)
|
|
|
|
match[name] = match[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Fix browsers that increment `lastIndex` after zero-length matches
|
|
|
|
if (!compliantLastIndexIncrement && this.global && !match[0].length && (this.lastIndex > match.index))
|
|
|
|
this.lastIndex--;
|
|
|
|
}
|
|
|
|
return match;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Don't override `test` if it won't change anything
|
|
|
|
if (!compliantLastIndexIncrement) {
|
|
|
|
// Fix browser bug in native method
|
|
|
|
RegExp.prototype.test = function (str) {
|
|
|
|
// Use the native `exec` to skip some processing overhead, even though the overriden
|
|
|
|
// `exec` would take care of the `lastIndex` fix
|
|
|
|
var match = real.exec.call(this, str);
|
|
|
|
// Fix browsers that increment `lastIndex` after zero-length matches
|
|
|
|
if (match && this.global && !match[0].length && (this.lastIndex > match.index))
|
|
|
|
this.lastIndex--;
|
|
|
|
return !!match;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------
|
|
|
|
// Private helper functions
|
|
|
|
//---------------------------------
|
|
|
|
|
|
|
|
function getNativeFlags (regex) {
|
|
|
|
return (regex.global ? "g" : "") +
|
|
|
|
(regex.ignoreCase ? "i" : "") +
|
|
|
|
(regex.multiline ? "m" : "") +
|
|
|
|
(regex.extended ? "x" : "") + // Proposed for ES4; included in AS3
|
|
|
|
(regex.sticky ? "y" : "");
|
|
|
|
};
|
|
|
|
|
|
|
|
function indexOf (array, item, from) {
|
|
|
|
if (Array.prototype.indexOf) // Use the native array method if available
|
|
|
|
return array.indexOf(item, from);
|
|
|
|
for (var i = from || 0; i < array.length; i++) {
|
|
|
|
if (array[i] === item)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
};
|
|
|
|
|
2012-07-05 06:37:09 +00:00
|
|
|
});
|
|
|
|
// vim: ts=4 sts=4 sw=4 expandtab
|
2012-02-06 20:59:17 +00:00
|
|
|
// -- kriskowal Kris Kowal Copyright (C) 2009-2011 MIT License
|
|
|
|
// -- tlrobinson Tom Robinson Copyright (C) 2009-2010 MIT License (Narwhal Project)
|
|
|
|
// -- dantman Daniel Friesen Copyright (C) 2010 XXX TODO License or CLA
|
|
|
|
// -- fschaefer Florian Schäfer Copyright (C) 2010 MIT License
|
|
|
|
// -- Gozala Irakli Gozalishvili Copyright (C) 2010 MIT License
|
|
|
|
// -- kitcambridge Kit Cambridge Copyright (C) 2011 MIT License
|
|
|
|
// -- kossnocorp Sasha Koss XXX TODO License or CLA
|
|
|
|
// -- bryanforbes Bryan Forbes XXX TODO License or CLA
|
|
|
|
// -- killdream Quildreen Motta Copyright (C) 2011 MIT Licence
|
|
|
|
// -- michaelficarra Michael Ficarra Copyright (C) 2011 3-clause BSD License
|
|
|
|
// -- sharkbrainguy Gerard Paapu Copyright (C) 2011 MIT License
|
|
|
|
// -- bbqsrc Brendan Molloy (C) 2011 Creative Commons Zero (public domain)
|
|
|
|
// -- iwyg XXX TODO License or CLA
|
|
|
|
// -- DomenicDenicola Domenic Denicola Copyright (C) 2011 MIT License
|
|
|
|
// -- xavierm02 Montillet Xavier XXX TODO License or CLA
|
|
|
|
// -- Raynos Raynos XXX TODO License or CLA
|
|
|
|
// -- samsonjs Sami Samhuri Copyright (C) 2010 MIT License
|
|
|
|
// -- rwldrn Rick Waldron Copyright (C) 2011 MIT License
|
|
|
|
// -- lexer Alexey Zakharov XXX TODO License or CLA
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Copyright (c) 2009, 280 North Inc. http://280north.com/
|
|
|
|
MIT License. http://github.com/280north/narwhal/blob/master/README.md
|
|
|
|
*/
|
|
|
|
|
|
|
|
define('ace/lib/es5-shim', ['require', 'exports', 'module' ], function(require, exports, module) {
|
|
|
|
|
2012-07-05 06:37:09 +00:00
|
|
|
/*
|
2012-02-06 20:59:17 +00:00
|
|
|
* Brings an environment as close to ECMAScript 5 compliance
|
|
|
|
* as is possible with the facilities of erstwhile engines.
|
|
|
|
*
|
|
|
|
* Annotated ES5: http://es5.github.com/ (specific links below)
|
|
|
|
* ES5 Spec: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf
|
|
|
|
*
|
|
|
|
* @module
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*whatsupdoc*/
|
|
|
|
|
|
|
|
//
|
|
|
|
// Function
|
|
|
|
// ========
|
|
|
|
//
|
|
|
|
|
|
|
|
// ES-5 15.3.4.5
|
|
|
|
// http://es5.github.com/#x15.3.4.5
|
|
|
|
|
|
|
|
if (!Function.prototype.bind) {
|
|
|
|
Function.prototype.bind = function bind(that) { // .length is 1
|
|
|
|
// 1. Let Target be the this value.
|
|
|
|
var target = this;
|
|
|
|
// 2. If IsCallable(Target) is false, throw a TypeError exception.
|
|
|
|
if (typeof target != "function")
|
|
|
|
throw new TypeError(); // TODO message
|
|
|
|
// 3. Let A be a new (possibly empty) internal list of all of the
|
|
|
|
// argument values provided after thisArg (arg1, arg2 etc), in order.
|
|
|
|
// XXX slicedArgs will stand in for "A" if used
|
|
|
|
var args = slice.call(arguments, 1); // for normal call
|
|
|
|
// 4. Let F be a new native ECMAScript object.
|
|
|
|
// 11. Set the [[Prototype]] internal property of F to the standard
|
|
|
|
// built-in Function prototype object as specified in 15.3.3.1.
|
|
|
|
// 12. Set the [[Call]] internal property of F as described in
|
|
|
|
// 15.3.4.5.1.
|
|
|
|
// 13. Set the [[Construct]] internal property of F as described in
|
|
|
|
// 15.3.4.5.2.
|
|
|
|
// 14. Set the [[HasInstance]] internal property of F as described in
|
|
|
|
// 15.3.4.5.3.
|
|
|
|
var bound = function () {
|
|
|
|
|
|
|
|
if (this instanceof bound) {
|
|
|
|
// 15.3.4.5.2 [[Construct]]
|
|
|
|
// When the [[Construct]] internal method of a function object,
|
|
|
|
// F that was created using the bind function is called with a
|
|
|
|
// list of arguments ExtraArgs, the following steps are taken:
|
|
|
|
// 1. Let target be the value of F's [[TargetFunction]]
|
|
|
|
// internal property.
|
|
|
|
// 2. If target has no [[Construct]] internal method, a
|
|
|
|
// TypeError exception is thrown.
|
|
|
|
// 3. Let boundArgs be the value of F's [[BoundArgs]] internal
|
|
|
|
// property.
|
|
|
|
// 4. Let args be a new list containing the same values as the
|
|
|
|
// list boundArgs in the same order followed by the same
|
|
|
|
// values as the list ExtraArgs in the same order.
|
|
|
|
// 5. Return the result of calling the [[Construct]] internal
|
|
|
|
// method of target providing args as the arguments.
|
|
|
|
|
|
|
|
var F = function(){};
|
|
|
|
F.prototype = target.prototype;
|
|
|
|
var self = new F;
|
|
|
|
|
|
|
|
var result = target.apply(
|
|
|
|
self,
|
|
|
|
args.concat(slice.call(arguments))
|
|
|
|
);
|
|
|
|
if (result !== null && Object(result) === result)
|
|
|
|
return result;
|
|
|
|
return self;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// 15.3.4.5.1 [[Call]]
|
|
|
|
// When the [[Call]] internal method of a function object, F,
|
|
|
|
// which was created using the bind function is called with a
|
|
|
|
// this value and a list of arguments ExtraArgs, the following
|
|
|
|
// steps are taken:
|
|
|
|
// 1. Let boundArgs be the value of F's [[BoundArgs]] internal
|
|
|
|
// property.
|
|
|
|
// 2. Let boundThis be the value of F's [[BoundThis]] internal
|
|
|
|
// property.
|
|
|
|
// 3. Let target be the value of F's [[TargetFunction]] internal
|
|
|
|
// property.
|
|
|
|
// 4. Let args be a new list containing the same values as the
|
|
|
|
// list boundArgs in the same order followed by the same
|
|
|
|
// values as the list ExtraArgs in the same order.
|
|
|
|
// 5. Return the result of calling the [[Call]] internal method
|
|
|
|
// of target providing boundThis as the this value and
|
|
|
|
// providing args as the arguments.
|
|
|
|
|
|
|
|
// equiv: target.call(this, ...boundArgs, ...args)
|
|
|
|
return target.apply(
|
|
|
|
that,
|
|
|
|
args.concat(slice.call(arguments))
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
// XXX bound.length is never writable, so don't even try
|
|
|
|
//
|
|
|
|
// 15. If the [[Class]] internal property of Target is "Function", then
|
|
|
|
// a. Let L be the length property of Target minus the length of A.
|
|
|
|
// b. Set the length own property of F to either 0 or L, whichever is
|
|
|
|
// larger.
|
|
|
|
// 16. Else set the length own property of F to 0.
|
|
|
|
// 17. Set the attributes of the length own property of F to the values
|
|
|
|
// specified in 15.3.5.1.
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
// 18. Set the [[Extensible]] internal property of F to true.
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
// 19. Let thrower be the [[ThrowTypeError]] function Object (13.2.3).
|
|
|
|
// 20. Call the [[DefineOwnProperty]] internal method of F with
|
|
|
|
// arguments "caller", PropertyDescriptor {[[Get]]: thrower, [[Set]]:
|
|
|
|
// thrower, [[Enumerable]]: false, [[Configurable]]: false}, and
|
|
|
|
// false.
|
|
|
|
// 21. Call the [[DefineOwnProperty]] internal method of F with
|
|
|
|
// arguments "arguments", PropertyDescriptor {[[Get]]: thrower,
|
|
|
|
// [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: false},
|
|
|
|
// and false.
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
// NOTE Function objects created using Function.prototype.bind do not
|
|
|
|
// have a prototype property or the [[Code]], [[FormalParameters]], and
|
|
|
|
// [[Scope]] internal properties.
|
|
|
|
// XXX can't delete prototype in pure-js.
|
|
|
|
|
|
|
|
// 22. Return F.
|
|
|
|
return bound;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Shortcut to an often accessed properties, in order to avoid multiple
|
|
|
|
// dereference that costs universally.
|
|
|
|
// _Please note: Shortcuts are defined after `Function.prototype.bind` as we
|
|
|
|
// us it in defining shortcuts.
|
|
|
|
var call = Function.prototype.call;
|
|
|
|
var prototypeOfArray = Array.prototype;
|
|
|
|
var prototypeOfObject = Object.prototype;
|
|
|
|
var slice = prototypeOfArray.slice;
|
|
|
|
var toString = call.bind(prototypeOfObject.toString);
|
|
|
|
var owns = call.bind(prototypeOfObject.hasOwnProperty);
|
|
|
|
|
|
|
|
// If JS engine supports accessors creating shortcuts.
|
|
|
|
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__);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Array
|
|
|
|
// =====
|
|
|
|
//
|
|
|
|
|
|
|
|
// ES5 15.4.3.2
|
|
|
|
// http://es5.github.com/#x15.4.3.2
|
|
|
|
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/isArray
|
|
|
|
if (!Array.isArray) {
|
|
|
|
Array.isArray = function isArray(obj) {
|
|
|
|
return toString(obj) == "[object Array]";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// The IsCallable() check in the Array functions
|
|
|
|
// has been replaced with a strict check on the
|
|
|
|
// internal class of the object to trap cases where
|
|
|
|
// the provided function was actually a regular
|
|
|
|
// expression literal, which in V8 and
|
|
|
|
// JavaScriptCore is a typeof "function". Only in
|
|
|
|
// V8 are regular expression literals permitted as
|
|
|
|
// reduce parameters, so it is desirable in the
|
|
|
|
// general case for the shim to match the more
|
|
|
|
// strict and common behavior of rejecting regular
|
|
|
|
// expressions.
|
|
|
|
|
|
|
|
// ES5 15.4.4.18
|
|
|
|
// http://es5.github.com/#x15.4.4.18
|
|
|
|
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/array/forEach
|
|
|
|
if (!Array.prototype.forEach) {
|
|
|
|
Array.prototype.forEach = function forEach(fun /*, thisp*/) {
|
|
|
|
var self = toObject(this),
|
|
|
|
thisp = arguments[1],
|
|
|
|
i = 0,
|
|
|
|
length = self.length >>> 0;
|
|
|
|
|
|
|
|
// If no callback function or if callback is not a callable function
|
|
|
|
if (toString(fun) != "[object Function]") {
|
|
|
|
throw new TypeError(); // TODO message
|
|
|
|
}
|
|
|
|
|
|
|
|
while (i < length) {
|
|
|
|
if (i in self) {
|
|
|
|
// Invoke the callback function with call, passing arguments:
|
|
|
|
// context, property value, property key, thisArg object context
|
|
|
|
fun.call(thisp, self[i], i, self);
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// ES5 15.4.4.19
|
|
|
|
// http://es5.github.com/#x15.4.4.19
|
|
|
|
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/map
|
|
|
|
if (!Array.prototype.map) {
|
|
|
|
Array.prototype.map = function map(fun /*, thisp*/) {
|
|
|
|
var self = toObject(this),
|
|
|
|
length = self.length >>> 0,
|
|
|
|
result = Array(length),
|
|
|
|
thisp = arguments[1];
|
|
|
|
|
|
|
|
// If no callback function or if callback is not a callable function
|
|
|
|
if (toString(fun) != "[object Function]") {
|
|
|
|
throw new TypeError(); // TODO message
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0; i < length; i++) {
|
|
|
|
if (i in self)
|
|
|
|
result[i] = fun.call(thisp, self[i], i, self);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// ES5 15.4.4.20
|
|
|
|
// http://es5.github.com/#x15.4.4.20
|
|
|
|
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/filter
|
|
|
|
if (!Array.prototype.filter) {
|
|
|
|
Array.prototype.filter = function filter(fun /*, thisp */) {
|
|
|
|
var self = toObject(this),
|
|
|
|
length = self.length >>> 0,
|
|
|
|
result = [],
|
|
|
|
thisp = arguments[1];
|
|
|
|
|
|
|
|
// If no callback function or if callback is not a callable function
|
|
|
|
if (toString(fun) != "[object Function]") {
|
|
|
|
throw new TypeError(); // TODO message
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0; i < length; i++) {
|
|
|
|
if (i in self && fun.call(thisp, self[i], i, self))
|
|
|
|
result.push(self[i]);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// ES5 15.4.4.16
|
|
|
|
// http://es5.github.com/#x15.4.4.16
|
|
|
|
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/every
|
|
|
|
if (!Array.prototype.every) {
|
|
|
|
Array.prototype.every = function every(fun /*, thisp */) {
|
|
|
|
var self = toObject(this),
|
|
|
|
length = self.length >>> 0,
|
|
|
|
thisp = arguments[1];
|
|
|
|
|
|
|
|
// If no callback function or if callback is not a callable function
|
|
|
|
if (toString(fun) != "[object Function]") {
|
|
|
|
throw new TypeError(); // TODO message
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0; i < length; i++) {
|
|
|
|
if (i in self && !fun.call(thisp, self[i], i, self))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// ES5 15.4.4.17
|
|
|
|
// http://es5.github.com/#x15.4.4.17
|
|
|
|
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/some
|
|
|
|
if (!Array.prototype.some) {
|
|
|
|
Array.prototype.some = function some(fun /*, thisp */) {
|
|
|
|
var self = toObject(this),
|
|
|
|
length = self.length >>> 0,
|
|
|
|
thisp = arguments[1];
|
|
|
|
|
|
|
|
// If no callback function or if callback is not a callable function
|
|
|
|
if (toString(fun) != "[object Function]") {
|
|
|
|
throw new TypeError(); // TODO message
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0; i < length; i++) {
|
|
|
|
if (i in self && fun.call(thisp, self[i], i, self))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// ES5 15.4.4.21
|
|
|
|
// http://es5.github.com/#x15.4.4.21
|
|
|
|
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduce
|
|
|
|
if (!Array.prototype.reduce) {
|
|
|
|
Array.prototype.reduce = function reduce(fun /*, initial*/) {
|
|
|
|
var self = toObject(this),
|
|
|
|
length = self.length >>> 0;
|
|
|
|
|
|
|
|
// If no callback function or if callback is not a callable function
|
|
|
|
if (toString(fun) != "[object Function]") {
|
|
|
|
throw new TypeError(); // TODO message
|
|
|
|
}
|
|
|
|
|
|
|
|
// no value to return if no initial value and an empty array
|
|
|
|
if (!length && arguments.length == 1)
|
|
|
|
throw new TypeError(); // TODO message
|
|
|
|
|
|
|
|
var i = 0;
|
|
|
|
var result;
|
|
|
|
if (arguments.length >= 2) {
|
|
|
|
result = arguments[1];
|
|
|
|
} else {
|
|
|
|
do {
|
|
|
|
if (i in self) {
|
|
|
|
result = self[i++];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if array contains no values, no initial value to return
|
|
|
|
if (++i >= length)
|
|
|
|
throw new TypeError(); // TODO message
|
|
|
|
} while (true);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; i < length; i++) {
|
|
|
|
if (i in self)
|
|
|
|
result = fun.call(void 0, result, self[i], i, self);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// ES5 15.4.4.22
|
|
|
|
// http://es5.github.com/#x15.4.4.22
|
|
|
|
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduceRight
|
|
|
|
if (!Array.prototype.reduceRight) {
|
|
|
|
Array.prototype.reduceRight = function reduceRight(fun /*, initial*/) {
|
|
|
|
var self = toObject(this),
|
|
|
|
length = self.length >>> 0;
|
|
|
|
|
|
|
|
// If no callback function or if callback is not a callable function
|
|
|
|
if (toString(fun) != "[object Function]") {
|
|
|
|
throw new TypeError(); // TODO message
|
|
|
|
}
|
|
|
|
|
|
|
|
// no value to return if no initial value, empty array
|
|
|
|
if (!length && arguments.length == 1)
|
|
|
|
throw new TypeError(); // TODO message
|
|
|
|
|
|
|
|
var result, i = length - 1;
|
|
|
|
if (arguments.length >= 2) {
|
|
|
|
result = arguments[1];
|
|
|
|
} else {
|
|
|
|
do {
|
|
|
|
if (i in self) {
|
|
|
|
result = self[i--];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if array contains no values, no initial value to return
|
|
|
|
if (--i < 0)
|
|
|
|
throw new TypeError(); // TODO message
|
|
|
|
} while (true);
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
if (i in this)
|
|
|
|
result = fun.call(void 0, result, self[i], i, self);
|
|
|
|
} while (i--);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// ES5 15.4.4.14
|
|
|
|
// http://es5.github.com/#x15.4.4.14
|
|
|
|
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf
|
|
|
|
if (!Array.prototype.indexOf) {
|
|
|
|
Array.prototype.indexOf = function indexOf(sought /*, fromIndex */ ) {
|
|
|
|
var self = toObject(this),
|
|
|
|
length = self.length >>> 0;
|
|
|
|
|
|
|
|
if (!length)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
var i = 0;
|
|
|
|
if (arguments.length > 1)
|
|
|
|
i = toInteger(arguments[1]);
|
|
|
|
|
|
|
|
// handle negative indices
|
|
|
|
i = i >= 0 ? i : Math.max(0, length + i);
|
|
|
|
for (; i < length; i++) {
|
|
|
|
if (i in self && self[i] === sought) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// ES5 15.4.4.15
|
|
|
|
// http://es5.github.com/#x15.4.4.15
|
|
|
|
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/lastIndexOf
|
|
|
|
if (!Array.prototype.lastIndexOf) {
|
|
|
|
Array.prototype.lastIndexOf = function lastIndexOf(sought /*, fromIndex */) {
|
|
|
|
var self = toObject(this),
|
|
|
|
length = self.length >>> 0;
|
|
|
|
|
|
|
|
if (!length)
|
|
|
|
return -1;
|
|
|
|
var i = length - 1;
|
|
|
|
if (arguments.length > 1)
|
|
|
|
i = Math.min(i, toInteger(arguments[1]));
|
|
|
|
// handle negative indices
|
|
|
|
i = i >= 0 ? i : length - Math.abs(i);
|
|
|
|
for (; i >= 0; i--) {
|
|
|
|
if (i in self && sought === self[i])
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Object
|
|
|
|
// ======
|
|
|
|
//
|
|
|
|
|
|
|
|
// ES5 15.2.3.2
|
|
|
|
// http://es5.github.com/#x15.2.3.2
|
|
|
|
if (!Object.getPrototypeOf) {
|
|
|
|
// https://github.com/kriskowal/es5-shim/issues#issue/2
|
|
|
|
// http://ejohn.org/blog/objectgetprototypeof/
|
|
|
|
// recommended by fschaefer on github
|
|
|
|
Object.getPrototypeOf = function getPrototypeOf(object) {
|
|
|
|
return object.__proto__ || (
|
|
|
|
object.constructor ?
|
|
|
|
object.constructor.prototype :
|
|
|
|
prototypeOfObject
|
|
|
|
);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// ES5 15.2.3.3
|
|
|
|
// http://es5.github.com/#x15.2.3.3
|
|
|
|
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 object does not owns property return undefined immediately.
|
|
|
|
if (!owns(object, property))
|
|
|
|
return;
|
|
|
|
|
|
|
|
var descriptor, getter, setter;
|
|
|
|
|
|
|
|
// If object has a property then it's for sure both `enumerable` and
|
|
|
|
// `configurable`.
|
|
|
|
descriptor = { enumerable: true, configurable: true };
|
|
|
|
|
|
|
|
// If JS engine supports accessor properties then property may be a
|
|
|
|
// getter or setter.
|
|
|
|
if (supportsAccessors) {
|
|
|
|
// Unfortunately `__lookupGetter__` will return a getter even
|
|
|
|
// if object has own non getter property along with a same named
|
|
|
|
// inherited getter. To avoid misbehavior we temporary remove
|
|
|
|
// `__proto__` so that `__lookupGetter__` will return getter only
|
|
|
|
// if it's owned by an object.
|
|
|
|
var prototype = object.__proto__;
|
|
|
|
object.__proto__ = prototypeOfObject;
|
|
|
|
|
|
|
|
var getter = lookupGetter(object, property);
|
|
|
|
var setter = lookupSetter(object, property);
|
|
|
|
|
|
|
|
// Once we have getter and setter we can put values back.
|
|
|
|
object.__proto__ = prototype;
|
|
|
|
|
|
|
|
if (getter || setter) {
|
|
|
|
if (getter) descriptor.get = getter;
|
|
|
|
if (setter) descriptor.set = setter;
|
|
|
|
|
|
|
|
// If it was accessor property we're done and return here
|
|
|
|
// in order to avoid adding `value` to the descriptor.
|
|
|
|
return descriptor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we got this far we know that object has an own property that is
|
|
|
|
// not an accessor so we set it as a value and return descriptor.
|
|
|
|
descriptor.value = object[property];
|
|
|
|
return descriptor;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// ES5 15.2.3.4
|
|
|
|
// http://es5.github.com/#x15.2.3.4
|
|
|
|
if (!Object.getOwnPropertyNames) {
|
|
|
|
Object.getOwnPropertyNames = function getOwnPropertyNames(object) {
|
|
|
|
return Object.keys(object);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// ES5 15.2.3.5
|
|
|
|
// http://es5.github.com/#x15.2.3.5
|
|
|
|
if (!Object.create) {
|
|
|
|
Object.create = function create(prototype, properties) {
|
|
|
|
var object;
|
|
|
|
if (prototype === null) {
|
|
|
|
object = { "__proto__": null };
|
|
|
|
} else {
|
|
|
|
if (typeof prototype != "object")
|
|
|
|
throw new TypeError("typeof prototype["+(typeof prototype)+"] != 'object'");
|
|
|
|
var Type = function () {};
|
|
|
|
Type.prototype = prototype;
|
|
|
|
object = new Type();
|
|
|
|
// IE has no built-in implementation of `Object.getPrototypeOf`
|
|
|
|
// neither `__proto__`, but this manually setting `__proto__` will
|
|
|
|
// guarantee that `Object.getPrototypeOf` will work as expected with
|
|
|
|
// objects created using `Object.create`
|
|
|
|
object.__proto__ = prototype;
|
|
|
|
}
|
|
|
|
if (properties !== void 0)
|
|
|
|
Object.defineProperties(object, properties);
|
|
|
|
return object;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// ES5 15.2.3.6
|
|
|
|
// http://es5.github.com/#x15.2.3.6
|
|
|
|
|
|
|
|
// Patch for WebKit and IE8 standard mode
|
|
|
|
// Designed by hax <hax.github.com>
|
|
|
|
// related issue: https://github.com/kriskowal/es5-shim/issues#issue/5
|
|
|
|
// IE8 Reference:
|
|
|
|
// http://msdn.microsoft.com/en-us/library/dd282900.aspx
|
|
|
|
// http://msdn.microsoft.com/en-us/library/dd229916.aspx
|
|
|
|
// WebKit Bugs:
|
|
|
|
// https://bugs.webkit.org/show_bug.cgi?id=36423
|
|
|
|
|
|
|
|
function doesDefinePropertyWork(object) {
|
|
|
|
try {
|
|
|
|
Object.defineProperty(object, "sentinel", {});
|
|
|
|
return "sentinel" in object;
|
|
|
|
} catch (exception) {
|
|
|
|
// returns falsy
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check whether defineProperty works if it's given. Otherwise,
|
|
|
|
// shim partially.
|
|
|
|
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);
|
|
|
|
|
|
|
|
// make a valiant attempt to use the real defineProperty
|
|
|
|
// for I8's DOM elements.
|
|
|
|
if (definePropertyFallback) {
|
|
|
|
try {
|
|
|
|
return definePropertyFallback.call(Object, object, property, descriptor);
|
|
|
|
} catch (exception) {
|
|
|
|
// try the shim if the real one doesn't work
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If it's a data property.
|
|
|
|
if (owns(descriptor, "value")) {
|
|
|
|
// fail silently if "writable", "enumerable", or "configurable"
|
|
|
|
// are requested but not supported
|
|
|
|
/*
|
|
|
|
// alternate approach:
|
|
|
|
if ( // can't implement these features; allow false but not true
|
|
|
|
!(owns(descriptor, "writable") ? descriptor.writable : true) ||
|
|
|
|
!(owns(descriptor, "enumerable") ? descriptor.enumerable : true) ||
|
|
|
|
!(owns(descriptor, "configurable") ? descriptor.configurable : true)
|
|
|
|
)
|
|
|
|
throw new RangeError(
|
|
|
|
"This implementation of Object.defineProperty does not " +
|
|
|
|
"support configurable, enumerable, or writable."
|
|
|
|
);
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (supportsAccessors && (lookupGetter(object, property) ||
|
|
|
|
lookupSetter(object, property)))
|
|
|
|
{
|
|
|
|
// As accessors are supported only on engines implementing
|
|
|
|
// `__proto__` we can safely override `__proto__` while defining
|
|
|
|
// a property to make sure that we don't hit an inherited
|
|
|
|
// accessor.
|
|
|
|
var prototype = object.__proto__;
|
|
|
|
object.__proto__ = prototypeOfObject;
|
|
|
|
// Deleting a property anyway since getter / setter may be
|
|
|
|
// defined on object itself.
|
|
|
|
delete object[property];
|
|
|
|
object[property] = descriptor.value;
|
|
|
|
// Setting original `__proto__` back now.
|
|
|
|
object.__proto__ = prototype;
|
|
|
|
} else {
|
|
|
|
object[property] = descriptor.value;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!supportsAccessors)
|
|
|
|
throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
|
|
|
|
// If we got that far then getters and setters can be defined !!
|
|
|
|
if (owns(descriptor, "get"))
|
|
|
|
defineGetter(object, property, descriptor.get);
|
|
|
|
if (owns(descriptor, "set"))
|
|
|
|
defineSetter(object, property, descriptor.set);
|
|
|
|
}
|
|
|
|
|
|
|
|
return object;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// ES5 15.2.3.7
|
|
|
|
// http://es5.github.com/#x15.2.3.7
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// ES5 15.2.3.8
|
|
|
|
// http://es5.github.com/#x15.2.3.8
|
|
|
|
if (!Object.seal) {
|
|
|
|
Object.seal = function seal(object) {
|
|
|
|
// this is misleading and breaks feature-detection, but
|
|
|
|
// allows "securable" code to "gracefully" degrade to working
|
|
|
|
// but insecure code.
|
|
|
|
return object;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// ES5 15.2.3.9
|
|
|
|
// http://es5.github.com/#x15.2.3.9
|
|
|
|
if (!Object.freeze) {
|
|
|
|
Object.freeze = function freeze(object) {
|
|
|
|
// this is misleading and breaks feature-detection, but
|
|
|
|
// allows "securable" code to "gracefully" degrade to working
|
|
|
|
// but insecure code.
|
|
|
|
return object;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// detect a Rhino bug and patch it
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ES5 15.2.3.10
|
|
|
|
// http://es5.github.com/#x15.2.3.10
|
|
|
|
if (!Object.preventExtensions) {
|
|
|
|
Object.preventExtensions = function preventExtensions(object) {
|
|
|
|
// this is misleading and breaks feature-detection, but
|
|
|
|
// allows "securable" code to "gracefully" degrade to working
|
|
|
|
// but insecure code.
|
|
|
|
return object;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// ES5 15.2.3.11
|
|
|
|
// http://es5.github.com/#x15.2.3.11
|
|
|
|
if (!Object.isSealed) {
|
|
|
|
Object.isSealed = function isSealed(object) {
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// ES5 15.2.3.12
|
|
|
|
// http://es5.github.com/#x15.2.3.12
|
|
|
|
if (!Object.isFrozen) {
|
|
|
|
Object.isFrozen = function isFrozen(object) {
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// ES5 15.2.3.13
|
|
|
|
// http://es5.github.com/#x15.2.3.13
|
|
|
|
if (!Object.isExtensible) {
|
|
|
|
Object.isExtensible = function isExtensible(object) {
|
|
|
|
// 1. If Type(O) is not Object throw a TypeError exception.
|
|
|
|
if (Object(object) === object) {
|
|
|
|
throw new TypeError(); // TODO message
|
|
|
|
}
|
|
|
|
// 2. Return the Boolean value of the [[Extensible]] internal property of O.
|
|
|
|
var name = '';
|
|
|
|
while (owns(object, name)) {
|
|
|
|
name += '?';
|
|
|
|
}
|
|
|
|
object[name] = true;
|
|
|
|
var returnValue = owns(object, name);
|
|
|
|
delete object[name];
|
|
|
|
return returnValue;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// ES5 15.2.3.14
|
|
|
|
// http://es5.github.com/#x15.2.3.14
|
|
|
|
if (!Object.keys) {
|
|
|
|
// http://whattheheadsaid.com/2010/10/a-safer-object-keys-compatibility-implementation
|
|
|
|
var hasDontEnumBug = true,
|
|
|
|
dontEnums = [
|
|
|
|
"toString",
|
|
|
|
"toLocaleString",
|
|
|
|
"valueOf",
|
|
|
|
"hasOwnProperty",
|
|
|
|
"isPrototypeOf",
|
|
|
|
"propertyIsEnumerable",
|
|
|
|
"constructor"
|
|
|
|
],
|
|
|
|
dontEnumsLength = dontEnums.length;
|
|
|
|
|
|
|
|
for (var key in {"toString": null})
|
|
|
|
hasDontEnumBug = false;
|
|
|
|
|
|
|
|
Object.keys = function keys(object) {
|
|
|
|
|
|
|
|
if ((typeof object != "object" && typeof object != "function") || object === null)
|
|
|
|
throw new TypeError("Object.keys called on a non-object");
|
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Date
|
|
|
|
// ====
|
|
|
|
//
|
|
|
|
|
|
|
|
// ES5 15.9.5.43
|
|
|
|
// http://es5.github.com/#x15.9.5.43
|
|
|
|
// This function returns a String value represent the instance in time
|
|
|
|
// represented by this Date object. The format of the String is the Date Time
|
|
|
|
// string format defined in 15.9.1.15. All fields are present in the String.
|
|
|
|
// The time zone is always UTC, denoted by the suffix Z. If the time value of
|
|
|
|
// this object is not a finite Number a RangeError exception is thrown.
|
|
|
|
if (!Date.prototype.toISOString || (new Date(-62198755200000).toISOString().indexOf('-000001') === -1)) {
|
|
|
|
Date.prototype.toISOString = function toISOString() {
|
|
|
|
var result, length, value, year;
|
|
|
|
if (!isFinite(this))
|
|
|
|
throw new RangeError;
|
|
|
|
|
|
|
|
// the date time string format is specified in 15.9.1.15.
|
|
|
|
result = [this.getUTCMonth() + 1, this.getUTCDate(),
|
|
|
|
this.getUTCHours(), this.getUTCMinutes(), this.getUTCSeconds()];
|
|
|
|
year = this.getUTCFullYear();
|
|
|
|
year = (year < 0 ? '-' : (year > 9999 ? '+' : '')) + ('00000' + Math.abs(year)).slice(0 <= year && year <= 9999 ? -4 : -6);
|
|
|
|
|
|
|
|
length = result.length;
|
|
|
|
while (length--) {
|
|
|
|
value = result[length];
|
|
|
|
// pad months, days, hours, minutes, and seconds to have two digits.
|
|
|
|
if (value < 10)
|
|
|
|
result[length] = "0" + value;
|
|
|
|
}
|
|
|
|
// pad milliseconds to have three digits.
|
|
|
|
return year + "-" + result.slice(0, 2).join("-") + "T" + result.slice(2).join(":") + "." +
|
|
|
|
("000" + this.getUTCMilliseconds()).slice(-3) + "Z";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ES5 15.9.4.4
|
|
|
|
// http://es5.github.com/#x15.9.4.4
|
|
|
|
if (!Date.now) {
|
|
|
|
Date.now = function now() {
|
|
|
|
return new Date().getTime();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// ES5 15.9.5.44
|
|
|
|
// http://es5.github.com/#x15.9.5.44
|
|
|
|
// This function provides a String representation of a Date object for use by
|
|
|
|
// JSON.stringify (15.12.3).
|
|
|
|
if (!Date.prototype.toJSON) {
|
|
|
|
Date.prototype.toJSON = function toJSON(key) {
|
|
|
|
// When the toJSON method is called with argument key, the following
|
|
|
|
// steps are taken:
|
|
|
|
|
|
|
|
// 1. Let O be the result of calling ToObject, giving it the this
|
|
|
|
// value as its argument.
|
|
|
|
// 2. Let tv be ToPrimitive(O, hint Number).
|
|
|
|
// 3. If tv is a Number and is not finite, return null.
|
|
|
|
// XXX
|
|
|
|
// 4. Let toISO be the result of calling the [[Get]] internal method of
|
|
|
|
// O with argument "toISOString".
|
|
|
|
// 5. If IsCallable(toISO) is false, throw a TypeError exception.
|
|
|
|
if (typeof this.toISOString != "function")
|
|
|
|
throw new TypeError(); // TODO message
|
|
|
|
// 6. Return the result of calling the [[Call]] internal method of
|
|
|
|
// toISO with O as the this value and an empty argument list.
|
|
|
|
return this.toISOString();
|
|
|
|
|
|
|
|
// NOTE 1 The argument is ignored.
|
|
|
|
|
|
|
|
// NOTE 2 The toJSON function is intentionally generic; it does not
|
|
|
|
// require that its this value be a Date object. Therefore, it can be
|
|
|
|
// transferred to other kinds of objects for use as a method. However,
|
|
|
|
// it does require that any such object have a toISOString method. An
|
|
|
|
// object is free to use the argument key to filter its
|
|
|
|
// stringification.
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// ES5 15.9.4.2
|
|
|
|
// http://es5.github.com/#x15.9.4.2
|
|
|
|
// based on work shared by Daniel Friesen (dantman)
|
|
|
|
// http://gist.github.com/303249
|
|
|
|
if (Date.parse("+275760-09-13T00:00:00.000Z") !== 8.64e15) {
|
|
|
|
// XXX global assignment won't work in embeddings that use
|
|
|
|
// an alternate object for the context.
|
|
|
|
Date = (function(NativeDate) {
|
|
|
|
|
|
|
|
// Date.length === 7
|
|
|
|
var Date = function Date(Y, M, D, h, m, s, ms) {
|
|
|
|
var length = arguments.length;
|
|
|
|
if (this instanceof NativeDate) {
|
|
|
|
var date = length == 1 && String(Y) === Y ? // isString(Y)
|
|
|
|
// We explicitly pass it through parse:
|
|
|
|
new NativeDate(Date.parse(Y)) :
|
|
|
|
// We have to manually make calls depending on argument
|
|
|
|
// length here
|
|
|
|
length >= 7 ? new NativeDate(Y, M, D, h, m, s, ms) :
|
|
|
|
length >= 6 ? new NativeDate(Y, M, D, h, m, s) :
|
|
|
|
length >= 5 ? new NativeDate(Y, M, D, h, m) :
|
|
|
|
length >= 4 ? new NativeDate(Y, M, D, h) :
|
|
|
|
length >= 3 ? new NativeDate(Y, M, D) :
|
|
|
|
length >= 2 ? new NativeDate(Y, M) :
|
|
|
|
length >= 1 ? new NativeDate(Y) :
|
|
|
|
new NativeDate();
|
|
|
|
// Prevent mixups with unfixed Date object
|
|
|
|
date.constructor = Date;
|
|
|
|
return date;
|
|
|
|
}
|
|
|
|
return NativeDate.apply(this, arguments);
|
|
|
|
};
|
|
|
|
|
|
|
|
// 15.9.1.15 Date Time String Format.
|
|
|
|
var isoDateExpression = new RegExp("^" +
|
|
|
|
"(\\d{4}|[\+\-]\\d{6})" + // four-digit year capture or sign + 6-digit extended year
|
|
|
|
"(?:-(\\d{2})" + // optional month capture
|
|
|
|
"(?:-(\\d{2})" + // optional day capture
|
|
|
|
"(?:" + // capture hours:minutes:seconds.milliseconds
|
|
|
|
"T(\\d{2})" + // hours capture
|
|
|
|
":(\\d{2})" + // minutes capture
|
|
|
|
"(?:" + // optional :seconds.milliseconds
|
|
|
|
":(\\d{2})" + // seconds capture
|
|
|
|
"(?:\\.(\\d{3}))?" + // milliseconds capture
|
|
|
|
")?" +
|
|
|
|
"(?:" + // capture UTC offset component
|
|
|
|
"Z|" + // UTC capture
|
|
|
|
"(?:" + // offset specifier +/-hours:minutes
|
|
|
|
"([-+])" + // sign capture
|
|
|
|
"(\\d{2})" + // hours offset capture
|
|
|
|
":(\\d{2})" + // minutes offset capture
|
|
|
|
")" +
|
|
|
|
")?)?)?)?" +
|
|
|
|
"$");
|
|
|
|
|
|
|
|
// Copy any custom methods a 3rd party library may have added
|
|
|
|
for (var key in NativeDate)
|
|
|
|
Date[key] = NativeDate[key];
|
|
|
|
|
|
|
|
// Copy "native" methods explicitly; they may be non-enumerable
|
|
|
|
Date.now = NativeDate.now;
|
|
|
|
Date.UTC = NativeDate.UTC;
|
|
|
|
Date.prototype = NativeDate.prototype;
|
|
|
|
Date.prototype.constructor = Date;
|
|
|
|
|
|
|
|
// Upgrade Date.parse to handle simplified ISO 8601 strings
|
|
|
|
Date.parse = function parse(string) {
|
|
|
|
var match = isoDateExpression.exec(string);
|
|
|
|
if (match) {
|
|
|
|
match.shift(); // kill match[0], the full match
|
|
|
|
// parse months, days, hours, minutes, seconds, and milliseconds
|
|
|
|
for (var i = 1; i < 7; i++) {
|
|
|
|
// provide default values if necessary
|
|
|
|
match[i] = +(match[i] || (i < 3 ? 1 : 0));
|
|
|
|
// match[1] is the month. Months are 0-11 in JavaScript
|
|
|
|
// `Date` objects, but 1-12 in ISO notation, so we
|
|
|
|
// decrement.
|
|
|
|
if (i == 1)
|
|
|
|
match[i]--;
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse the UTC offset component
|
|
|
|
var minuteOffset = +match.pop(), hourOffset = +match.pop(), sign = match.pop();
|
|
|
|
|
|
|
|
// compute the explicit time zone offset if specified
|
|
|
|
var offset = 0;
|
|
|
|
if (sign) {
|
|
|
|
// detect invalid offsets and return early
|
|
|
|
if (hourOffset > 23 || minuteOffset > 59)
|
|
|
|
return NaN;
|
|
|
|
|
|
|
|
// express the provided time zone offset in minutes. The offset is
|
|
|
|
// negative for time zones west of UTC; positive otherwise.
|
|
|
|
offset = (hourOffset * 60 + minuteOffset) * 6e4 * (sign == "+" ? -1 : 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Date.UTC for years between 0 and 99 converts year to 1900 + year
|
|
|
|
// The Gregorian calendar has a 400-year cycle, so
|
|
|
|
// to Date.UTC(year + 400, .... ) - 12622780800000 == Date.UTC(year, ...),
|
|
|
|
// where 12622780800000 - number of milliseconds in Gregorian calendar 400 years
|
|
|
|
var year = +match[0];
|
|
|
|
if (0 <= year && year <= 99) {
|
|
|
|
match[0] = year + 400;
|
|
|
|
return NativeDate.UTC.apply(this, match) + offset - 12622780800000;
|
|
|
|
}
|
|
|
|
|
|
|
|
// compute a new UTC date value, accounting for the optional offset
|
|
|
|
return NativeDate.UTC.apply(this, match) + offset;
|
|
|
|
}
|
|
|
|
return NativeDate.parse.apply(this, arguments);
|
|
|
|
};
|
|
|
|
|
|
|
|
return Date;
|
|
|
|
})(Date);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// String
|
|
|
|
// ======
|
|
|
|
//
|
|
|
|
|
|
|
|
// ES5 15.5.4.20
|
|
|
|
// http://es5.github.com/#x15.5.4.20
|
|
|
|
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()) {
|
|
|
|
// http://blog.stevenlevithan.com/archives/faster-trim-javascript
|
|
|
|
// http://perfectionkills.com/whitespace-deviations/
|
|
|
|
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, "");
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Util
|
|
|
|
// ======
|
|
|
|
//
|
|
|
|
|
|
|
|
// ES5 9.4
|
|
|
|
// http://es5.github.com/#x9.4
|
|
|
|
// http://jsperf.com/to-integer
|
|
|
|
var toInteger = function (n) {
|
|
|
|
n = +n;
|
|
|
|
if (n !== n) // isNaN
|
|
|
|
n = 0;
|
|
|
|
else if (n !== 0 && n !== (1/0) && n !== -(1/0))
|
|
|
|
n = (n > 0 || -1) * Math.floor(Math.abs(n));
|
|
|
|
return n;
|
|
|
|
};
|
|
|
|
|
|
|
|
var prepareString = "a"[0] != "a",
|
|
|
|
// ES5 9.9
|
|
|
|
// http://es5.github.com/#x9.9
|
|
|
|
toObject = function (o) {
|
|
|
|
if (o == null) { // this matches both null and undefined
|
|
|
|
throw new TypeError(); // TODO message
|
|
|
|
}
|
|
|
|
// If the implementation doesn't support by-index access of
|
|
|
|
// string characters (ex. IE < 7), split the string
|
|
|
|
if (prepareString && typeof o == "string" && o) {
|
|
|
|
return o.split("");
|
|
|
|
}
|
|
|
|
return Object(o);
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
});
|
2012-02-06 20:59:17 +00:00
|
|
|
|
|
|
|
define('ace/lib/event_emitter', ['require', 'exports', 'module' ], function(require, exports, module) {
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
|
|
|
|
var EventEmitter = {};
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
e = e || {};
|
|
|
|
e.type = eventName;
|
|
|
|
|
|
|
|
if (!e.stopPropagation) {
|
|
|
|
e.stopPropagation = function() {
|
|
|
|
this.propagationStopped = true;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!e.preventDefault) {
|
|
|
|
e.preventDefault = function() {
|
|
|
|
this.defaultPrevented = true;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var i=0; i<listeners.length; i++) {
|
|
|
|
listeners[i](e);
|
|
|
|
if (e.propagationStopped)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defaultHandler && !e.defaultPrevented)
|
2012-07-05 06:37:09 +00:00
|
|
|
return defaultHandler(e);
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
EventEmitter.setDefaultHandler = function(eventName, callback) {
|
|
|
|
this._defaultHandlers = this._defaultHandlers || {};
|
|
|
|
|
|
|
|
if (this._defaultHandlers[eventName])
|
|
|
|
throw new Error("The default handler for '" + eventName + "' is already set");
|
|
|
|
|
|
|
|
this._defaultHandlers[eventName] = callback;
|
|
|
|
};
|
|
|
|
|
|
|
|
EventEmitter.on =
|
|
|
|
EventEmitter.addEventListener = function(eventName, callback) {
|
|
|
|
this._eventRegistry = this._eventRegistry || {};
|
|
|
|
|
|
|
|
var listeners = this._eventRegistry[eventName];
|
|
|
|
if (!listeners)
|
|
|
|
var listeners = this._eventRegistry[eventName] = [];
|
|
|
|
|
|
|
|
if (listeners.indexOf(callback) == -1)
|
|
|
|
listeners.push(callback);
|
|
|
|
};
|
|
|
|
|
|
|
|
EventEmitter.removeListener =
|
|
|
|
EventEmitter.removeEventListener = function(eventName, callback) {
|
|
|
|
this._eventRegistry = this._eventRegistry || {};
|
|
|
|
|
|
|
|
var listeners = this._eventRegistry[eventName];
|
|
|
|
if (!listeners)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var index = listeners.indexOf(callback);
|
|
|
|
if (index !== -1)
|
|
|
|
listeners.splice(index, 1);
|
|
|
|
};
|
|
|
|
|
|
|
|
EventEmitter.removeAllListeners = function(eventName) {
|
|
|
|
if (this._eventRegistry) this._eventRegistry[eventName] = [];
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.EventEmitter = EventEmitter;
|
|
|
|
|
2012-07-05 06:37:09 +00:00
|
|
|
});
|
2012-02-06 20:59:17 +00:00
|
|
|
|
|
|
|
define('ace/lib/oop', ['require', 'exports', 'module' ], function(require, exports, module) {
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
|
|
|
|
exports.inherits = (function() {
|
|
|
|
var tempCtor = function() {};
|
|
|
|
return function(ctor, superCtor) {
|
|
|
|
tempCtor.prototype = superCtor.prototype;
|
|
|
|
ctor.super_ = superCtor.prototype;
|
|
|
|
ctor.prototype = new tempCtor();
|
|
|
|
ctor.prototype.constructor = ctor;
|
|
|
|
};
|
|
|
|
}());
|
|
|
|
|
|
|
|
exports.mixin = function(obj, mixin) {
|
|
|
|
for (var key in mixin) {
|
|
|
|
obj[key] = mixin[key];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.implement = function(proto, mixin) {
|
|
|
|
exports.mixin(proto, mixin);
|
|
|
|
};
|
|
|
|
|
|
|
|
});
|
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);
|
|
|
|
this.setTimeout(200);
|
|
|
|
};
|
|
|
|
|
|
|
|
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 {
|
|
|
|
coffee.parse(value);
|
|
|
|
} catch(e) {
|
|
|
|
var m = e.message.match(/Parse error on line (\d+): (.*)/);
|
|
|
|
if (m) {
|
|
|
|
this.sender.emit("error", {
|
2012-07-05 06:37:09 +00:00
|
|
|
row: parseInt(m[1], 10) - 1,
|
2012-02-06 20:59:17 +00:00
|
|
|
column: null,
|
|
|
|
text: m[2],
|
|
|
|
type: "error"
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
if (e instanceof SyntaxError) {
|
|
|
|
var m = e.message.match(/ on line (\d+)/);
|
2012-07-05 06:37:09 +00:00
|
|
|
if (m) {
|
2012-02-06 20:59:17 +00:00
|
|
|
this.sender.emit("error", {
|
2012-07-05 06:37:09 +00:00
|
|
|
row: parseInt(m[1], 10) - 1,
|
2012-02-06 20:59:17 +00:00
|
|
|
column: null,
|
|
|
|
text: e.message.replace(m[0], ""),
|
|
|
|
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);
|
|
|
|
|
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("");
|
|
|
|
|
|
|
|
var deferredUpdate = this.deferredUpdate = lang.deferredCall(this.onUpdate.bind(this));
|
|
|
|
|
|
|
|
var _self = this;
|
|
|
|
sender.on("change", function(e) {
|
|
|
|
doc.applyDeltas([e.data]);
|
|
|
|
deferredUpdate.schedule(_self.$timeout);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
(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() {
|
|
|
|
// abstract method
|
|
|
|
};
|
|
|
|
|
|
|
|
}).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;
|
|
|
|
|
2012-07-05 06:37:09 +00:00
|
|
|
/**
|
|
|
|
* new Document([text])
|
|
|
|
* - text (String | Array): The starting text
|
|
|
|
*
|
|
|
|
* Creates a new `Document`. If `text` is included, the `Document` contains those strings; otherwise, it's empty.
|
|
|
|
*
|
|
|
|
**/
|
2012-02-06 20:59:17 +00:00
|
|
|
var Document = function(text) {
|
|
|
|
this.$lines = [];
|
|
|
|
|
|
|
|
// There has to be one line at least in the document. If you pass an empty
|
|
|
|
// string to the insert function, nothing will happen. Workaround.
|
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)) {
|
|
|
|
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);
|
|
|
|
};
|
|
|
|
|
|
|
|
// check for IE split bug
|
|
|
|
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/);
|
|
|
|
};
|
|
|
|
this.$detectNewLine = function(text) {
|
|
|
|
var match = text.match(/^.*?(\r\n|\r|\n)/m);
|
|
|
|
if (match) {
|
|
|
|
this.$autoNewLine = match[1];
|
|
|
|
} else {
|
|
|
|
this.$autoNewLine = "\n";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
this.getNewLineCharacter = function() {
|
|
|
|
switch (this.$newLineMode) {
|
|
|
|
case "windows":
|
|
|
|
return "\r\n";
|
|
|
|
|
|
|
|
case "unix":
|
|
|
|
return "\n";
|
|
|
|
|
|
|
|
case "auto":
|
|
|
|
return this.$autoNewLine;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
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) {
|
|
|
|
return this.$lines[range.start.row].substring(range.start.column,
|
|
|
|
range.end.column);
|
|
|
|
}
|
|
|
|
else {
|
2012-07-05 06:37:09 +00:00
|
|
|
var lines = this.getLines(range.start.row+1, range.end.row-1);
|
|
|
|
lines.unshift((this.$lines[range.start.row] || "").substring(range.start.column));
|
|
|
|
lines.push((this.$lines[range.end.row] || "").substring(0, range.end.column));
|
2012-02-06 20:59:17 +00:00
|
|
|
return lines.join(this.getNewLineCharacter());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
|
2012-07-05 06:37:09 +00:00
|
|
|
// only detect new lines if the document has no line break yet
|
2012-02-06 20:59:17 +00:00
|
|
|
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
|
|
|
|
position = this.insertLines(position.row, lines);
|
|
|
|
position = this.insertInLine(position, lastLine || "");
|
|
|
|
}
|
|
|
|
return position;
|
|
|
|
};
|
|
|
|
this.insertLines = function(row, lines) {
|
|
|
|
if (lines.length == 0)
|
|
|
|
return {row: row, column: 0};
|
|
|
|
|
2012-07-05 06:37:09 +00:00
|
|
|
// apply doesn't work for big arrays (smallest threshold is on safari 0xFFFF)
|
|
|
|
// to circumvent that we have to break huge inserts into smaller chunks here
|
|
|
|
if (lines.length > 0xFFFF) {
|
|
|
|
var end = this.insertLines(row, lines.slice(0xFFFF));
|
|
|
|
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) {
|
|
|
|
// clip to document
|
|
|
|
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)
|
|
|
|
this.removeLines(firstFullRow, lastFullRow);
|
|
|
|
|
|
|
|
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) {
|
|
|
|
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) {
|
|
|
|
if (text.length == 0 && range.isEmpty())
|
|
|
|
return range.start;
|
|
|
|
|
|
|
|
// Shortcut: If the text we want to insert is the same as it is already
|
|
|
|
// in the document, we don't have to replace anything.
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}).call(Document.prototype);
|
|
|
|
|
|
|
|
exports.Document = Document;
|
|
|
|
});
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
define('ace/range', ['require', 'exports', 'module' ], function(require, exports, module) {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* class Range
|
2012-02-06 20:59:17 +00:00
|
|
|
*
|
2012-07-05 06:37:09 +00:00
|
|
|
* This object is used in various places to indicate a region within the editor. To better visualize how this works, imagine a rectangle. Each quadrant of the rectangle is analogus to a range, as ranges contain a starting row and starting column, and an ending row, and ending column.
|
2012-02-06 20:59:17 +00:00
|
|
|
*
|
2012-07-05 06:37:09 +00:00
|
|
|
**/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* new Range(startRow, startColumn, endRow, endColumn)
|
|
|
|
* - startRow (Number): The starting row
|
|
|
|
* - startColumn (Number): The starting column
|
|
|
|
* - endRow (Number): The ending row
|
|
|
|
* - endColumn (Number): The ending column
|
2012-02-06 20:59:17 +00:00
|
|
|
*
|
2012-07-05 06:37:09 +00:00
|
|
|
* Creates a new `Range` object with the given starting and ending row and column points.
|
2012-02-06 20:59:17 +00:00
|
|
|
*
|
2012-07-05 06:37:09 +00:00
|
|
|
**/
|
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
|
|
|
/**
|
|
|
|
* Range.isEqual(range) -> Boolean
|
|
|
|
* - range (Range): A range to check against
|
|
|
|
*
|
|
|
|
* Returns `true` if and only if the starting row and column, and ending tow and column, are equivalent to those given by `range`.
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
this.isEqual = function(range) {
|
2012-02-06 20:59:17 +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-07-05 06:37:09 +00:00
|
|
|
};
|
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 + "]");
|
2012-07-05 06:37:09 +00:00
|
|
|
};
|
2012-02-06 20:59:17 +00:00
|
|
|
|
|
|
|
this.contains = function(row, column) {
|
|
|
|
return this.compare(row, column) == 0;
|
2012-07-05 06:37:09 +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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-05 06:37:09 +00:00
|
|
|
/** related to: Range.compare
|
|
|
|
* Range.comparePoint(p) -> Number
|
|
|
|
* - p (Range): A point to compare with
|
|
|
|
* + (Number): This method returns one of the following numbers:<br/>
|
|
|
|
* * `0` if the two points are exactly equal<br/>
|
|
|
|
* * `-1` if `p.row` is less then the calling range<br/>
|
|
|
|
* * `1` if `p.row` is greater than the calling range<br/>
|
|
|
|
* <br/>
|
|
|
|
* If the starting row of the calling range is equal to `p.row`, and:<br/>
|
|
|
|
* * `p.column` is greater than or equal to the calling range's starting column, this returns `0`<br/>
|
|
|
|
* * Otherwise, it returns -1<br/>
|
|
|
|
*<br/>
|
|
|
|
* If the ending row of the calling range is equal to `p.row`, and:<br/>
|
|
|
|
* * `p.column` is less than or equal to the calling range's ending column, this returns `0`<br/>
|
|
|
|
* * Otherwise, it returns 1<br/>
|
|
|
|
*
|
|
|
|
* Checks the row and column points of `p` with the row and column points of the calling range.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
**/
|
2012-02-06 20:59:17 +00:00
|
|
|
this.comparePoint = function(p) {
|
|
|
|
return this.compare(p.row, p.column);
|
|
|
|
}
|
|
|
|
|
2012-07-05 06:37:09 +00:00
|
|
|
/** related to: Range.comparePoint
|
|
|
|
* Range.containsRange(range) -> Boolean
|
|
|
|
* - range (Range): A range to compare with
|
|
|
|
*
|
|
|
|
* Checks the start and end points of `range` and compares them to the calling range. Returns `true` if the `range` is contained within the caller's range.
|
|
|
|
*
|
|
|
|
**/
|
2012-02-06 20:59:17 +00:00
|
|
|
this.containsRange = function(range) {
|
|
|
|
return this.comparePoint(range.start) == 0 && this.comparePoint(range.end) == 0;
|
|
|
|
}
|
|
|
|
|
2012-07-05 06:37:09 +00:00
|
|
|
/**
|
|
|
|
* Range.intersects(range) -> Boolean
|
|
|
|
* - range (Range): A range to compare with
|
|
|
|
*
|
|
|
|
* Returns `true` if passed in `range` intersects with the one calling this method.
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
this.intersects = function(range) {
|
|
|
|
var cmp = this.compareRange(range);
|
|
|
|
return (cmp == -1 || cmp == 0 || cmp == 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Range.isEnd(row, column) -> Boolean
|
|
|
|
* - row (Number): A row point to compare with
|
|
|
|
* - column (Number): A column point to compare with
|
|
|
|
*
|
|
|
|
* Returns `true` if the caller's ending row point is the same as `row`, and if the caller's ending column is the same as `column`.
|
|
|
|
*
|
|
|
|
**/
|
2012-02-06 20:59:17 +00:00
|
|
|
this.isEnd = function(row, column) {
|
|
|
|
return this.end.row == row && this.end.column == column;
|
|
|
|
}
|
|
|
|
|
2012-07-05 06:37:09 +00:00
|
|
|
/**
|
|
|
|
* Range.isStart(row, column) -> Boolean
|
|
|
|
* - row (Number): A row point to compare with
|
|
|
|
* - column (Number): A column point to compare with
|
|
|
|
*
|
|
|
|
* Returns `true` if the caller's starting row point is the same as `row`, and if the caller's starting column is the same as `column`.
|
|
|
|
*
|
|
|
|
**/
|
2012-02-06 20:59:17 +00:00
|
|
|
this.isStart = function(row, column) {
|
|
|
|
return this.start.row == row && this.start.column == column;
|
|
|
|
}
|
|
|
|
|
2012-07-05 06:37:09 +00:00
|
|
|
/**
|
|
|
|
* Range.setStart(row, column)
|
|
|
|
* - row (Number): A row point to set
|
|
|
|
* - column (Number): A column point to set
|
|
|
|
*
|
|
|
|
* Sets the starting row and column for the range.
|
|
|
|
*
|
|
|
|
**/
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-05 06:37:09 +00:00
|
|
|
/**
|
|
|
|
* Range.setEnd(row, column)
|
|
|
|
* - row (Number): A row point to set
|
|
|
|
* - column (Number): A column point to set
|
|
|
|
*
|
|
|
|
* Sets the starting row and column for the range.
|
|
|
|
*
|
|
|
|
**/
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-05 06:37:09 +00:00
|
|
|
/** related to: Range.compare
|
|
|
|
* Range.inside(row, column) -> Boolean
|
|
|
|
* - row (Number): A row point to compare with
|
|
|
|
* - column (Number): A column point to compare with
|
|
|
|
*
|
|
|
|
* Returns `true` if the `row` and `column` are within the given range.
|
|
|
|
*
|
|
|
|
**/
|
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;
|
|
|
|
}
|
|
|
|
|
2012-07-05 06:37:09 +00:00
|
|
|
/** related to: Range.compare
|
|
|
|
* Range.insideStart(row, column) -> Boolean
|
|
|
|
* - row (Number): A row point to compare with
|
|
|
|
* - column (Number): A column point to compare with
|
|
|
|
*
|
|
|
|
* Returns `true` if the `row` and `column` are within the given range's starting points.
|
|
|
|
*
|
|
|
|
**/
|
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;
|
|
|
|
}
|
|
|
|
|
2012-07-05 06:37:09 +00:00
|
|
|
/** related to: Range.compare
|
|
|
|
* Range.insideEnd(row, column) -> Boolean
|
|
|
|
* - row (Number): A row point to compare with
|
|
|
|
* - column (Number): A column point to compare with
|
|
|
|
*
|
|
|
|
* Returns `true` if the `row` and `column` are within the given range's ending points.
|
|
|
|
*
|
|
|
|
**/
|
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;
|
|
|
|
}
|
|
|
|
|
2012-07-05 06:37:09 +00:00
|
|
|
/**
|
|
|
|
* Range.compare(row, column) -> Number
|
|
|
|
* - row (Number): A row point to compare with
|
|
|
|
* - column (Number): A column point to compare with
|
|
|
|
* + (Number): This method returns one of the following numbers:<br/>
|
|
|
|
* * `0` if the two points are exactly equal <br/>
|
|
|
|
* * `-1` if `p.row` is less then the calling range <br/>
|
|
|
|
* * `1` if `p.row` is greater than the calling range <br/>
|
|
|
|
* <br/>
|
|
|
|
* If the starting row of the calling range is equal to `p.row`, and: <br/>
|
|
|
|
* * `p.column` is greater than or equal to the calling range's starting column, this returns `0`<br/>
|
|
|
|
* * Otherwise, it returns -1<br/>
|
|
|
|
* <br/>
|
|
|
|
* If the ending row of the calling range is equal to `p.row`, and: <br/>
|
|
|
|
* * `p.column` is less than or equal to the calling range's ending column, this returns `0` <br/>
|
|
|
|
* * Otherwise, it returns 1
|
|
|
|
*
|
|
|
|
* Checks the row and column points with the row and column points of the calling range.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
**/
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-07-05 06:37:09 +00:00
|
|
|
* Range.compareEnd(row, column) -> Number
|
|
|
|
* - row (Number): A row point to compare with
|
|
|
|
* - column (Number): A column point to compare with
|
|
|
|
* + (Number): This method returns one of the following numbers:<br/>
|
|
|
|
* * `0` if the two points are exactly equal<br/>
|
|
|
|
* * `-1` if `p.row` is less then the calling range<br/>
|
|
|
|
* * `1` if `p.row` is greater than the calling range, or if `isEnd` is `true.<br/>
|
|
|
|
* <br/>
|
|
|
|
* If the starting row of the calling range is equal to `p.row`, and:<br/>
|
|
|
|
* * `p.column` is greater than or equal to the calling range's starting column, this returns `0`<br/>
|
|
|
|
* * Otherwise, it returns -1<br/>
|
|
|
|
*<br/>
|
|
|
|
* If the ending row of the calling range is equal to `p.row`, and:<br/>
|
|
|
|
* * `p.column` is less than or equal to the calling range's ending column, this returns `0`<br/>
|
|
|
|
* * Otherwise, it returns 1
|
|
|
|
*
|
|
|
|
* Checks the row and column points with the row and column points of the calling range.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
**/
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-05 06:37:09 +00:00
|
|
|
/**
|
|
|
|
* Range.compareInside(row, column) -> Number
|
|
|
|
* - row (Number): A row point to compare with
|
|
|
|
* - column (Number): A column point to compare with
|
|
|
|
* + (Number): This method returns one of the following numbers:<br/>
|
|
|
|
* * `1` if the ending row of the calling range is equal to `row`, and the ending column of the calling range is equal to `column`<br/>
|
|
|
|
* * `-1` if the starting row of the calling range is equal to `row`, and the starting column of the calling range is equal to `column`<br/>
|
|
|
|
* <br/>
|
|
|
|
* Otherwise, it returns the value after calling [[Range.compare `compare()`]].
|
|
|
|
*
|
|
|
|
* Checks the row and column points with the row and column points of the calling range.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
**/
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-05 06:37:09 +00:00
|
|
|
/**
|
|
|
|
* Range.clipRows(firstRow, lastRow) -> Range
|
|
|
|
* - firstRow (Number): The starting row
|
|
|
|
* - lastRow (Number): The ending row
|
|
|
|
*
|
|
|
|
* Returns the part of the current `Range` that occurs within the boundaries of `firstRow` and `lastRow` as a new `Range` object.
|
|
|
|
*
|
|
|
|
**/
|
2012-02-06 20:59:17 +00:00
|
|
|
this.clipRows = function(firstRow, lastRow) {
|
|
|
|
if (this.end.row > lastRow) {
|
|
|
|
var end = {
|
|
|
|
row: lastRow+1,
|
|
|
|
column: 0
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.start.row > lastRow) {
|
|
|
|
var start = {
|
|
|
|
row: lastRow+1,
|
|
|
|
column: 0
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.start.row < firstRow) {
|
|
|
|
var start = {
|
|
|
|
row: firstRow,
|
|
|
|
column: 0
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.end.row < firstRow) {
|
|
|
|
var end = {
|
|
|
|
row: firstRow,
|
|
|
|
column: 0
|
|
|
|
};
|
|
|
|
}
|
|
|
|
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() {
|
|
|
|
return (this.start.row == this.end.row && this.start.column == this.end.column);
|
|
|
|
};
|
|
|
|
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) {
|
|
|
|
var screenPosStart =
|
|
|
|
session.documentToScreenPosition(this.start);
|
|
|
|
var screenPosEnd =
|
|
|
|
session.documentToScreenPosition(this.end);
|
|
|
|
|
|
|
|
return new Range(
|
|
|
|
screenPosStart.row, screenPosStart.column,
|
|
|
|
screenPosEnd.row, screenPosEnd.column
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
}).call(Range.prototype);
|
|
|
|
Range.fromPoints = function(start, end) {
|
|
|
|
return new Range(start.row, start.column, end.row, end.column);
|
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
/**
|
2012-07-05 06:37:09 +00:00
|
|
|
* new Anchor(doc, row, column)
|
|
|
|
* - doc (Document): The document to associate with the anchor
|
|
|
|
* - row (Number): The starting row position
|
|
|
|
* - column (Number): The starting column position
|
|
|
|
*
|
|
|
|
* Creates a new `Anchor` and associates it with a document.
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
var Anchor = exports.Anchor = function(doc, row, column) {
|
|
|
|
this.document = doc;
|
|
|
|
|
|
|
|
if (typeof column == "undefined")
|
|
|
|
this.setPosition(row.row, row.column);
|
|
|
|
else
|
|
|
|
this.setPosition(row, column);
|
|
|
|
|
|
|
|
this.$onChange = this.onChange.bind(this);
|
|
|
|
doc.on("change", this.$onChange);
|
|
|
|
};
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
|
|
|
oop.implement(this, EventEmitter);
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
this.getPosition = function() {
|
|
|
|
return this.$clipPositionToDocument(this.row, this.column);
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
this.getDocument = function() {
|
|
|
|
return this.document;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
this.onChange = function(e) {
|
|
|
|
var delta = e.data;
|
|
|
|
var range = delta.range;
|
|
|
|
|
|
|
|
if (range.start.row == range.end.row && range.start.row != this.row)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (range.start.row > this.row)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (range.start.row == this.row && range.start.column > this.column)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var row = this.row;
|
|
|
|
var column = this.column;
|
|
|
|
|
|
|
|
if (delta.action === "insertText") {
|
|
|
|
if (range.start.row === row && range.start.column <= column) {
|
|
|
|
if (range.start.row === range.end.row) {
|
|
|
|
column += range.end.column - range.start.column;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
column -= range.start.column;
|
|
|
|
row += range.end.row - range.start.row;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (range.start.row !== range.end.row && range.start.row < row) {
|
|
|
|
row += range.end.row - range.start.row;
|
|
|
|
}
|
|
|
|
} else if (delta.action === "insertLines") {
|
|
|
|
if (range.start.row <= row) {
|
|
|
|
row += range.end.row - range.start.row;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (delta.action == "removeText") {
|
|
|
|
if (range.start.row == row && range.start.column < column) {
|
|
|
|
if (range.end.column >= column)
|
|
|
|
column = range.start.column;
|
|
|
|
else
|
|
|
|
column = Math.max(0, column - (range.end.column - range.start.column));
|
|
|
|
|
|
|
|
} else if (range.start.row !== range.end.row && range.start.row < row) {
|
|
|
|
if (range.end.row == row) {
|
|
|
|
column = Math.max(0, column - range.end.column) + range.start.column;
|
|
|
|
}
|
|
|
|
row -= (range.end.row - range.start.row);
|
|
|
|
}
|
|
|
|
else if (range.end.row == row) {
|
|
|
|
row -= range.end.row - range.start.row;
|
|
|
|
column = Math.max(0, column - range.end.column) + range.start.column;
|
|
|
|
}
|
|
|
|
} else if (delta.action == "removeLines") {
|
|
|
|
if (range.start.row <= row) {
|
|
|
|
if (range.end.row <= row)
|
|
|
|
row -= range.end.row - range.start.row;
|
|
|
|
else {
|
|
|
|
row = range.start.row;
|
|
|
|
column = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setPosition(row, column, true);
|
|
|
|
};
|
|
|
|
|
|
|
|
this.setPosition = function(row, column, noClip) {
|
|
|
|
var pos;
|
|
|
|
if (noClip) {
|
|
|
|
pos = {
|
|
|
|
row: row,
|
|
|
|
column: column
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pos = this.$clipPositionToDocument(row, column);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.row == pos.row && this.column == pos.column)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var old = {
|
|
|
|
row: this.row,
|
|
|
|
column: this.column
|
|
|
|
};
|
|
|
|
|
|
|
|
this.row = pos.row;
|
|
|
|
this.column = pos.column;
|
|
|
|
this._emit("change", {
|
|
|
|
old: old,
|
|
|
|
value: pos
|
|
|
|
});
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
this.detach = function() {
|
|
|
|
this.document.removeEventListener("change", this.$onChange);
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
this.$clipPositionToDocument = function(row, column) {
|
|
|
|
var pos = {};
|
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (column < 0)
|
|
|
|
pos.column = 0;
|
|
|
|
|
|
|
|
return pos;
|
|
|
|
};
|
|
|
|
|
|
|
|
}).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) {
|
|
|
|
return new Array(count + 1).join(string);
|
|
|
|
};
|
|
|
|
|
|
|
|
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) {
|
|
|
|
if (typeof obj != "object") {
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
var copy = obj.constructor();
|
|
|
|
for (var key in obj) {
|
|
|
|
if (typeof obj[key] == "object") {
|
|
|
|
copy[key] = this.deepCopy(obj[key]);
|
|
|
|
} 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;
|
|
|
|
|
|
|
|
};
|
|
|
|
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');
|
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
return deferred;
|
|
|
|
};
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
|
|
|
var Lexer = require("./lexer").Lexer;
|
|
|
|
var parser = require("./parser");
|
|
|
|
|
|
|
|
var lexer = new Lexer();
|
|
|
|
parser.lexer = {
|
|
|
|
lex: function() {
|
|
|
|
var tag, _ref2;
|
|
|
|
_ref2 = this.tokens[this.pos++] || [''], tag = _ref2[0], this.yytext = _ref2[1], this.yylineno = _ref2[2];
|
|
|
|
return tag;
|
|
|
|
},
|
|
|
|
setInput: function(tokens) {
|
|
|
|
this.tokens = tokens;
|
|
|
|
return this.pos = 0;
|
|
|
|
},
|
|
|
|
upcomingInput: function() {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
parser.yy = require('./nodes');
|
|
|
|
|
|
|
|
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
|
|
|
// Generated by CoffeeScript 1.2.1-pre
|
|
|
|
|
|
|
|
var 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, key, last, starts, _ref, _ref1,
|
|
|
|
__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;
|
|
|
|
|
|
|
|
_ref1 = require('./helpers'), count = _ref1.count, starts = _ref1.starts, compact = _ref1.compact, last = _ref1.last;
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
exports.Lexer = Lexer = (function() {
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
Lexer.name = 'Lexer';
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
function Lexer() {}
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Lexer.prototype.tokenize = function(code, opts) {
|
2012-07-05 06:37:09 +00:00
|
|
|
var i, tag;
|
|
|
|
if (opts == null) opts = {};
|
|
|
|
if (WHITESPACE.test(code)) code = "\n" + code;
|
2012-02-06 20:59:17 +00:00
|
|
|
code = code.replace(/\r/g, '').replace(TRAILING_SPACES, '');
|
|
|
|
this.code = code;
|
|
|
|
this.line = opts.line || 0;
|
|
|
|
this.indent = 0;
|
|
|
|
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 = [];
|
|
|
|
i = 0;
|
|
|
|
while (this.chunk = code.slice(i)) {
|
|
|
|
i += this.identifierToken() || this.commentToken() || this.whitespaceToken() || this.lineToken() || this.heredocToken() || this.stringToken() || this.numberToken() || this.regexToken() || this.jsToken() || this.literalToken();
|
|
|
|
}
|
|
|
|
this.closeIndentation();
|
2012-07-05 06:37:09 +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
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Lexer.prototype.identifierToken = function() {
|
|
|
|
var colon, forcedIdentifier, id, input, match, prev, tag, _ref2, _ref3;
|
2012-07-05 06:37:09 +00:00
|
|
|
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];
|
|
|
|
if (id === 'own' && this.tag() === 'FOR') {
|
|
|
|
this.token('OWN', id);
|
|
|
|
return id.length;
|
|
|
|
}
|
|
|
|
forcedIdentifier = colon || (prev = last(this.tokens)) && (((_ref2 = prev[0]) === '.' || _ref2 === '?.' || _ref2 === '::') || !prev.spaced && prev[0] === '@');
|
|
|
|
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() === '!') {
|
|
|
|
this.tokens.pop();
|
|
|
|
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) {
|
2012-07-05 06:37:09 +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':
|
|
|
|
case 'null':
|
|
|
|
case 'undefined':
|
|
|
|
return 'BOOL';
|
|
|
|
case 'break':
|
|
|
|
case 'continue':
|
|
|
|
return 'STATEMENT';
|
|
|
|
default:
|
|
|
|
return tag;
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
}
|
|
|
|
this.token(tag, id);
|
2012-07-05 06:37:09 +00:00
|
|
|
if (colon) this.token(':', ':');
|
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;
|
|
|
|
if (!(match = NUMBER.exec(this.chunk))) return 0;
|
2012-02-06 20:59:17 +00:00
|
|
|
number = match[0];
|
2012-07-05 06:37:09 +00:00
|
|
|
if (/E/.test(number)) {
|
|
|
|
this.error("exponential notation '" + number + "' must be indicated with a lowercase 'e'");
|
|
|
|
} else if (/[BOX]/.test(number)) {
|
|
|
|
this.error("radix prefix '" + number + "' must be lowercase");
|
|
|
|
} else if (/^0[89]/.test(number)) {
|
|
|
|
this.error("decimal literal '" + number + "' must not be prefixed with '0'");
|
|
|
|
} else if (/^0[0-7]/.test(number)) {
|
|
|
|
this.error("octal literal '" + number + "' must be prefixed with '0o'");
|
|
|
|
}
|
|
|
|
lexedLength = number.length;
|
|
|
|
if (octalLiteral = /0o([0-7]+)/.exec(number)) {
|
|
|
|
number = (parseInt(octalLiteral[1], 8)).toString();
|
|
|
|
}
|
|
|
|
if (binaryLiteral = /0b([01]+)/.exec(number)) {
|
|
|
|
number = (parseInt(binaryLiteral[1], 2)).toString();
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
this.token('NUMBER', number);
|
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() {
|
2012-07-05 06:37:09 +00:00
|
|
|
var match, octalEsc, string;
|
2012-02-06 20:59:17 +00:00
|
|
|
switch (this.chunk.charAt(0)) {
|
|
|
|
case "'":
|
2012-07-05 06:37:09 +00:00
|
|
|
if (!(match = SIMPLESTR.exec(this.chunk))) return 0;
|
2012-02-06 20:59:17 +00:00
|
|
|
this.token('STRING', (string = match[0]).replace(MULTILINER, '\\\n'));
|
|
|
|
break;
|
|
|
|
case '"':
|
2012-07-05 06:37:09 +00:00
|
|
|
if (!(string = this.balancedString(this.chunk, '"'))) return 0;
|
2012-02-06 20:59:17 +00:00
|
|
|
if (0 < string.indexOf('#{', 1)) {
|
|
|
|
this.interpolateString(string.slice(1, -1));
|
|
|
|
} else {
|
|
|
|
this.token('STRING', this.escapeLines(string));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
if (octalEsc = /^(?:\\.|[^\\])*\\[0-7]/.test(string)) {
|
|
|
|
this.error("octal escape sequences " + string + " are not allowed");
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
this.line += count(string, '\n');
|
|
|
|
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;
|
2012-07-05 06:37:09 +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, {
|
|
|
|
heredoc: true
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.token('STRING', this.makeString(doc, quote, true));
|
|
|
|
}
|
|
|
|
this.line += count(heredoc, '\n');
|
|
|
|
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;
|
2012-07-05 06:37:09 +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,
|
|
|
|
indent: Array(this.indent + 1).join(' ')
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
this.line += count(comment, '\n');
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
this.token('JS', (script = match[0]).slice(1, -1));
|
|
|
|
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;
|
|
|
|
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);
|
|
|
|
this.line += count(match[0], '\n');
|
|
|
|
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;
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
if (!(match = REGEX.exec(this.chunk))) return 0;
|
|
|
|
_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
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
if (regex === '//') regex = '/(?:)/';
|
|
|
|
this.token('REGEX', "" + regex + flags);
|
|
|
|
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) {
|
|
|
|
var body, flags, heregex, re, tag, tokens, value, _i, _len, _ref2, _ref3, _ref4, _ref5;
|
|
|
|
heregex = match[0], body = match[1], flags = match[2];
|
|
|
|
if (0 > body.indexOf('#{')) {
|
|
|
|
re = body.replace(HEREGEX_OMIT, '').replace(/\//g, '\\/');
|
2012-07-05 06:37:09 +00:00
|
|
|
if (re.match(/^\*/)) {
|
|
|
|
this.error('regular expressions cannot begin with `*`');
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
this.token('REGEX', "/" + (re || '(?:)') + "/" + flags);
|
|
|
|
return heregex.length;
|
|
|
|
}
|
|
|
|
this.token('IDENTIFIER', 'RegExp');
|
|
|
|
this.tokens.push(['CALL_START', '(']);
|
|
|
|
tokens = [];
|
|
|
|
_ref2 = this.interpolateString(body, {
|
|
|
|
regex: true
|
|
|
|
});
|
|
|
|
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
|
|
|
_ref3 = _ref2[_i], tag = _ref3[0], value = _ref3[1];
|
|
|
|
if (tag === 'TOKENS') {
|
|
|
|
tokens.push.apply(tokens, value);
|
|
|
|
} else {
|
2012-07-05 06:37:09 +00:00
|
|
|
if (!(value = value.replace(HEREGEX_OMIT, ''))) continue;
|
2012-02-06 20:59:17 +00:00
|
|
|
value = value.replace(/\\/g, '\\\\');
|
|
|
|
tokens.push(['STRING', this.makeString(value, '"', true)]);
|
|
|
|
}
|
|
|
|
tokens.push(['+', '+']);
|
|
|
|
}
|
|
|
|
tokens.pop();
|
|
|
|
if (((_ref4 = tokens[0]) != null ? _ref4[0] : void 0) !== 'STRING') {
|
|
|
|
this.tokens.push(['STRING', '""'], ['+', '+']);
|
|
|
|
}
|
|
|
|
(_ref5 = this.tokens).push.apply(_ref5, tokens);
|
2012-07-05 06:37:09 +00:00
|
|
|
if (flags) this.tokens.push([',', ','], ['STRING', '"' + flags + '"']);
|
2012-02-06 20:59:17 +00:00
|
|
|
this.token(')', ')');
|
|
|
|
return heregex.length;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Lexer.prototype.lineToken = function() {
|
|
|
|
var diff, indent, match, noNewlines, prev, size;
|
2012-07-05 06:37:09 +00:00
|
|
|
if (!(match = MULTI_DENT.exec(this.chunk))) return 0;
|
2012-02-06 20:59:17 +00:00
|
|
|
indent = match[0];
|
|
|
|
this.line += count(indent, '\n');
|
2012-07-05 06:37:09 +00:00
|
|
|
this.seenFor = false;
|
2012-02-06 20:59:17 +00:00
|
|
|
prev = last(this.tokens, 1);
|
|
|
|
size = indent.length - 1 - indent.lastIndexOf('\n');
|
|
|
|
noNewlines = this.unfinished();
|
|
|
|
if (size - this.indebt === this.indent) {
|
|
|
|
if (noNewlines) {
|
|
|
|
this.suppressNewlines();
|
|
|
|
} else {
|
|
|
|
this.newlineToken();
|
|
|
|
}
|
|
|
|
return indent.length;
|
|
|
|
}
|
|
|
|
if (size > this.indent) {
|
|
|
|
if (noNewlines) {
|
|
|
|
this.indebt = size - this.indent;
|
|
|
|
this.suppressNewlines();
|
|
|
|
return indent.length;
|
|
|
|
}
|
|
|
|
diff = size - this.indent + this.outdebt;
|
|
|
|
this.token('INDENT', diff);
|
|
|
|
this.indents.push(diff);
|
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;
|
|
|
|
} else {
|
|
|
|
this.indebt = 0;
|
|
|
|
this.outdentToken(this.indent - size, noNewlines);
|
|
|
|
}
|
|
|
|
this.indent = size;
|
|
|
|
return indent.length;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
Lexer.prototype.outdentToken = function(moveOut, noNewlines) {
|
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 {
|
|
|
|
dent = this.indents.pop() - this.outdebt;
|
|
|
|
moveOut -= dent;
|
|
|
|
this.outdebt = 0;
|
2012-07-05 06:37:09 +00:00
|
|
|
this.pair('OUTDENT');
|
2012-02-06 20:59:17 +00:00
|
|
|
this.token('OUTDENT', dent);
|
|
|
|
}
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
if (dent) this.outdebt -= moveOut;
|
|
|
|
while (this.value() === ';') {
|
|
|
|
this.tokens.pop();
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
if (!(this.tag() === 'TERMINATOR' || noNewlines)) {
|
|
|
|
this.token('TERMINATOR', '\n');
|
|
|
|
}
|
|
|
|
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);
|
2012-07-05 06:37:09 +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
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Lexer.prototype.newlineToken = function() {
|
2012-07-05 06:37:09 +00:00
|
|
|
while (this.value() === ';') {
|
|
|
|
this.tokens.pop();
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
if (this.tag() !== 'TERMINATOR') this.token('TERMINATOR', '\n');
|
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() {
|
2012-07-05 06:37:09 +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];
|
2012-07-05 06:37:09 +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)) {
|
2012-07-05 06:37:09 +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
|
|
|
}
|
2012-07-05 06:37:09 +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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-05 06:37:09 +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;
|
2012-07-05 06:37:09 +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();
|
2012-07-05 06:37:09 +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) {
|
2012-07-05 06:37:09 +00:00
|
|
|
var expr, heredoc, i, inner, interpolated, len, letter, nested, pi, regex, tag, tokens, value, _i, _len, _ref2, _ref3, _ref4;
|
|
|
|
if (options == null) options = {};
|
2012-02-06 20:59:17 +00:00
|
|
|
heredoc = options.heredoc, regex = options.regex;
|
|
|
|
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;
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
if (pi < i) tokens.push(['NEOSTRING', str.slice(pi, i)]);
|
2012-02-06 20:59:17 +00:00
|
|
|
inner = expr.slice(1, -1);
|
|
|
|
if (inner.length) {
|
|
|
|
nested = new Lexer().tokenize(inner, {
|
|
|
|
line: this.line,
|
|
|
|
rewrite: false
|
|
|
|
});
|
|
|
|
nested.pop();
|
|
|
|
if (((_ref2 = nested[0]) != null ? _ref2[0] : void 0) === 'TERMINATOR') {
|
|
|
|
nested.shift();
|
|
|
|
}
|
|
|
|
if (len = nested.length) {
|
|
|
|
if (len > 1) {
|
2012-07-05 06:37:09 +00:00
|
|
|
nested.unshift(['(', '(', this.line]);
|
|
|
|
nested.push([')', ')', this.line]);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
tokens.push(['TOKENS', nested]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
i += expr.length;
|
|
|
|
pi = i + 1;
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
if ((i > pi && pi < str.length)) tokens.push(['NEOSTRING', str.slice(pi)]);
|
|
|
|
if (regex) return tokens;
|
|
|
|
if (!tokens.length) return this.token('STRING', '""');
|
|
|
|
if (tokens[0][0] !== 'NEOSTRING') tokens.unshift(['', '']);
|
|
|
|
if (interpolated = tokens.length > 1) this.token('(', '(');
|
|
|
|
for (i = _i = 0, _len = tokens.length; _i < _len; i = ++_i) {
|
2012-02-06 20:59:17 +00:00
|
|
|
_ref3 = tokens[i], tag = _ref3[0], value = _ref3[1];
|
2012-07-05 06:37:09 +00:00
|
|
|
if (i) this.token('+', '+');
|
2012-02-06 20:59:17 +00:00
|
|
|
if (tag === 'TOKENS') {
|
|
|
|
(_ref4 = this.tokens).push.apply(_ref4, value);
|
|
|
|
} else {
|
|
|
|
this.token('STRING', this.makeString(value, '"', heredoc));
|
|
|
|
}
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
if (interpolated) this.token(')', ')');
|
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))) {
|
|
|
|
if ('OUTDENT' !== wanted) this.error("unmatched " + tag);
|
|
|
|
this.indent -= size = last(this.indents);
|
|
|
|
this.outdentToken(size, true);
|
|
|
|
return this.pair(tag);
|
|
|
|
}
|
|
|
|
return this.ends.pop();
|
|
|
|
};
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Lexer.prototype.token = function(tag, value) {
|
|
|
|
return this.tokens.push([tag, value, this.line]);
|
|
|
|
};
|
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;
|
|
|
|
return LINE_CONTINUER.test(this.chunk) || ((_ref2 = this.tag()) === '\\' || _ref2 === '.' || _ref2 === '?.' || _ref2 === 'UNARY' || _ref2 === 'MATH' || _ref2 === '+' || _ref2 === '-' || _ref2 === 'SHIFT' || _ref2 === 'RELATION' || _ref2 === 'COMPARE' || _ref2 === 'LOGIC' || _ref2 === 'THROW' || _ref2 === 'EXTENDS');
|
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) {
|
|
|
|
return str.replace(MULTILINER, heredoc ? '\\n' : '');
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Lexer.prototype.makeString = function(body, quote, heredoc) {
|
2012-07-05 06:37:09 +00:00
|
|
|
if (!body) return quote + quote;
|
2012-02-06 20:59:17 +00:00
|
|
|
body = body.replace(/\\([\s\S])/g, function(match, contents) {
|
|
|
|
if (contents === '\n' || contents === quote) {
|
|
|
|
return contents;
|
|
|
|
} else {
|
|
|
|
return match;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
body = body.replace(RegExp("" + quote, "g"), '\\$&');
|
|
|
|
return quote + this.escapeLines(body, heredoc) + quote;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
Lexer.prototype.error = function(message) {
|
|
|
|
throw SyntaxError("" + message + " on line " + (this.line + 1));
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
|
|
|
RESERVED = ['case', 'default', 'function', 'var', 'void', 'with', 'const', 'let', 'enum', 'export', 'import', 'native', '__hasProp', '__extends', '__slice', '__bind', '__indexOf', 'implements', 'interface', 'let', 'package', 'private', 'protected', 'public', 'static', 'yield'];
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
HEREDOC = /^("""|''')([\s\S]*?)(?:\n[^\n\S]*)?\1/;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +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
|
|
|
|
2012-02-06 20:59:17 +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
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
SIMPLESTR = /^'[^\\']*(?:\\.[^\\']*)*'/;
|
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)/;
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
HEREGEX = /^\/{3}([\s\S]+?)\/{3}([imgy]{0,4})(?!\w)/;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
HEREGEX_OMIT = /\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
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
BOOL = ['TRUE', 'FALSE', 'NULL', 'UNDEFINED'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
NOT_REGEX = ['NUMBER', 'REGEX', 'BOOL', '++', '--', ']'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +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
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
INDEXABLE = CALLABLE.concat('NUMBER', 'BOOL');
|
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
|
|
|
// Generated by CoffeeScript 1.2.1-pre
|
|
|
|
|
|
|
|
var BALANCED_PAIRS, EXPRESSION_CLOSE, EXPRESSION_END, EXPRESSION_START, IMPLICIT_BLOCK, IMPLICIT_CALL, IMPLICIT_END, IMPLICIT_FUNC, IMPLICIT_UNSPACED_CALL, INVERSES, LINEBREAKS, SINGLE_CLOSERS, SINGLE_LINERS, left, rite, _i, _len, _ref,
|
|
|
|
__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;
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
exports.Rewriter = (function() {
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
Rewriter.name = 'Rewriter';
|
|
|
|
|
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.removeMidExpressionNewlines();
|
|
|
|
this.closeOpenCalls();
|
|
|
|
this.closeOpenIndexes();
|
|
|
|
this.addImplicitIndentation();
|
|
|
|
this.tagPostfixConditionals();
|
|
|
|
this.addImplicitBraces();
|
|
|
|
this.addImplicitParentheses();
|
|
|
|
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);
|
|
|
|
}
|
2012-07-05 06:37:09 +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];
|
2012-07-05 06:37:09 +00:00
|
|
|
if (tag !== 'TERMINATOR') break;
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2012-07-05 06:37:09 +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.removeMidExpressionNewlines = function() {
|
|
|
|
return this.scanTokens(function(token, i, tokens) {
|
|
|
|
var _ref;
|
|
|
|
if (!(token[0] === 'TERMINATOR' && (_ref = this.tag(i + 1), __indexOf.call(EXPRESSION_CLOSE, _ref) >= 0))) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
tokens.splice(i, 1);
|
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
};
|
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) {
|
2012-07-05 06:37:09 +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) {
|
2012-07-05 06:37:09 +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
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Rewriter.prototype.addImplicitBraces = function() {
|
2012-07-05 06:37:09 +00:00
|
|
|
var action, condition, sameLine, stack, start, startIndent, startsLine;
|
2012-02-06 20:59:17 +00:00
|
|
|
stack = [];
|
|
|
|
start = null;
|
2012-07-05 06:37:09 +00:00
|
|
|
startsLine = null;
|
|
|
|
sameLine = true;
|
2012-02-06 20:59:17 +00:00
|
|
|
startIndent = 0;
|
|
|
|
condition = function(token, i) {
|
2012-07-05 06:37:09 +00:00
|
|
|
var one, tag, three, two, _ref, _ref1;
|
|
|
|
_ref = this.tokens.slice(i + 1, (i + 3) + 1 || 9e9), one = _ref[0], two = _ref[1], three = _ref[2];
|
|
|
|
if ('HERECOMMENT' === (one != null ? one[0] : void 0)) return false;
|
2012-02-06 20:59:17 +00:00
|
|
|
tag = token[0];
|
2012-07-05 06:37:09 +00:00
|
|
|
if (__indexOf.call(LINEBREAKS, tag) >= 0) sameLine = false;
|
|
|
|
return (((tag === 'TERMINATOR' || tag === 'OUTDENT') || (__indexOf.call(IMPLICIT_END, tag) >= 0 && sameLine)) && ((!startsLine && this.tag(i - 1) !== ',') || !((two != null ? two[0] : void 0) === ':' || (one != null ? one[0] : void 0) === '@' && (three != null ? three[0] : void 0) === ':'))) || (tag === ',' && one && ((_ref1 = one[0]) !== 'IDENTIFIER' && _ref1 !== 'NUMBER' && _ref1 !== 'STRING' && _ref1 !== '@' && _ref1 !== 'TERMINATOR' && _ref1 !== 'OUTDENT'));
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
|
|
|
action = function(token, i) {
|
|
|
|
var tok;
|
2012-07-05 06:37:09 +00:00
|
|
|
tok = this.generate('}', '}', token[2]);
|
2012-02-06 20:59:17 +00:00
|
|
|
return this.tokens.splice(i, 0, tok);
|
|
|
|
};
|
|
|
|
return this.scanTokens(function(token, i, tokens) {
|
2012-07-05 06:37:09 +00:00
|
|
|
var ago, idx, prevTag, tag, tok, value, _ref, _ref1;
|
2012-02-06 20:59:17 +00:00
|
|
|
if (_ref = (tag = token[0]), __indexOf.call(EXPRESSION_START, _ref) >= 0) {
|
|
|
|
stack.push([(tag === 'INDENT' && this.tag(i - 1) === '{' ? '{' : tag), i]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (__indexOf.call(EXPRESSION_END, tag) >= 0) {
|
|
|
|
start = stack.pop();
|
|
|
|
return 1;
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
if (!(tag === ':' && ((ago = this.tag(i - 2)) === ':' || ((_ref1 = stack[stack.length - 1]) != null ? _ref1[0] : void 0) !== '{'))) {
|
2012-02-06 20:59:17 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
sameLine = true;
|
2012-02-06 20:59:17 +00:00
|
|
|
stack.push(['{']);
|
|
|
|
idx = ago === '@' ? i - 2 : i - 1;
|
|
|
|
while (this.tag(idx - 2) === 'HERECOMMENT') {
|
|
|
|
idx -= 2;
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
prevTag = this.tag(idx - 1);
|
|
|
|
startsLine = !prevTag || (__indexOf.call(LINEBREAKS, prevTag) >= 0);
|
2012-02-06 20:59:17 +00:00
|
|
|
value = new String('{');
|
|
|
|
value.generated = true;
|
2012-07-05 06:37:09 +00:00
|
|
|
tok = this.generate('{', value, token[2]);
|
2012-02-06 20:59:17 +00:00
|
|
|
tokens.splice(idx, 0, tok);
|
|
|
|
this.detectEnd(i + 2, condition, action);
|
|
|
|
return 2;
|
|
|
|
});
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Rewriter.prototype.addImplicitParentheses = function() {
|
2012-07-05 06:37:09 +00:00
|
|
|
var action, condition, noCall, seenControl, seenSingle;
|
|
|
|
noCall = seenSingle = seenControl = false;
|
|
|
|
condition = function(token, i) {
|
|
|
|
var post, tag, _ref, _ref1;
|
|
|
|
tag = token[0];
|
|
|
|
if (!seenSingle && token.fromThen) return true;
|
|
|
|
if (tag === 'IF' || tag === 'ELSE' || tag === 'CATCH' || tag === '->' || tag === '=>' || tag === 'CLASS') {
|
|
|
|
seenSingle = true;
|
|
|
|
}
|
|
|
|
if (tag === 'IF' || tag === 'ELSE' || tag === 'SWITCH' || tag === 'TRY' || tag === '=') {
|
|
|
|
seenControl = true;
|
|
|
|
}
|
|
|
|
if ((tag === '.' || tag === '?.' || tag === '::') && this.tag(i - 1) === 'OUTDENT') {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return !token.generated && this.tag(i - 1) !== ',' && (__indexOf.call(IMPLICIT_END, tag) >= 0 || (tag === 'INDENT' && !seenControl)) && (tag !== 'INDENT' || (((_ref = this.tag(i - 2)) !== 'CLASS' && _ref !== 'EXTENDS') && (_ref1 = this.tag(i - 1), __indexOf.call(IMPLICIT_BLOCK, _ref1) < 0) && !((post = this.tokens[i + 1]) && post.generated && post[0] === '{')));
|
|
|
|
};
|
2012-02-06 20:59:17 +00:00
|
|
|
action = function(token, i) {
|
2012-07-05 06:37:09 +00:00
|
|
|
return this.tokens.splice(i, 0, this.generate('CALL_END', ')', token[2]));
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
|
|
|
return this.scanTokens(function(token, i, tokens) {
|
2012-07-05 06:37:09 +00:00
|
|
|
var callObject, current, next, prev, tag, _ref, _ref1, _ref2;
|
2012-02-06 20:59:17 +00:00
|
|
|
tag = token[0];
|
2012-07-05 06:37:09 +00:00
|
|
|
if (tag === 'CLASS' || tag === 'IF' || tag === 'FOR' || tag === 'WHILE') {
|
2012-02-06 20:59:17 +00:00
|
|
|
noCall = true;
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
_ref = tokens.slice(i - 1, (i + 1) + 1 || 9e9), prev = _ref[0], current = _ref[1], next = _ref[2];
|
|
|
|
callObject = !noCall && tag === 'INDENT' && next && next.generated && next[0] === '{' && prev && (_ref1 = prev[0], __indexOf.call(IMPLICIT_FUNC, _ref1) >= 0);
|
2012-02-06 20:59:17 +00:00
|
|
|
seenSingle = false;
|
|
|
|
seenControl = false;
|
2012-07-05 06:37:09 +00:00
|
|
|
if (__indexOf.call(LINEBREAKS, tag) >= 0) noCall = false;
|
|
|
|
if (prev && !prev.spaced && tag === '?') token.call = true;
|
|
|
|
if (token.fromThen) return 1;
|
|
|
|
if (!(callObject || (prev != null ? prev.spaced : void 0) && (prev.call || (_ref2 = prev[0], __indexOf.call(IMPLICIT_FUNC, _ref2) >= 0)) && (__indexOf.call(IMPLICIT_CALL, tag) >= 0 || !(token.spaced || token.newLine) && __indexOf.call(IMPLICIT_UNSPACED_CALL, tag) >= 0))) {
|
2012-02-06 20:59:17 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
tokens.splice(i, 0, this.generate('CALL_START', '(', token[2]));
|
|
|
|
this.detectEnd(i + 1, condition, action);
|
|
|
|
if (prev[0] === '?') prev[0] = 'FUNC_EXIST';
|
2012-02-06 20:59:17 +00:00
|
|
|
return 2;
|
|
|
|
});
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Rewriter.prototype.addImplicitIndentation = function() {
|
2012-07-05 06:37:09 +00:00
|
|
|
var action, condition, indent, outdent, starter;
|
|
|
|
starter = indent = outdent = null;
|
|
|
|
condition = function(token, i) {
|
|
|
|
var _ref;
|
|
|
|
return token[1] !== ';' && (_ref = token[0], __indexOf.call(SINGLE_CLOSERS, _ref) >= 0) && !(token[0] === 'ELSE' && (starter !== 'IF' && starter !== 'THEN'));
|
|
|
|
};
|
|
|
|
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) {
|
2012-07-05 06:37:09 +00:00
|
|
|
var tag, _ref, _ref1;
|
2012-02-06 20:59:17 +00:00
|
|
|
tag = token[0];
|
|
|
|
if (tag === 'TERMINATOR' && this.tag(i + 1) === 'THEN') {
|
|
|
|
tokens.splice(i, 1);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (tag === 'ELSE' && this.tag(i - 1) !== 'OUTDENT') {
|
|
|
|
tokens.splice.apply(tokens, [i, 0].concat(__slice.call(this.indentation(token))));
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
if (tag === 'CATCH' && ((_ref = this.tag(i + 2)) === 'OUTDENT' || _ref === 'TERMINATOR' || _ref === 'FINALLY')) {
|
|
|
|
tokens.splice.apply(tokens, [i + 2, 0].concat(__slice.call(this.indentation(token))));
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
if (__indexOf.call(SINGLE_LINERS, tag) >= 0 && this.tag(i + 1) !== 'INDENT' && !(tag === 'ELSE' && this.tag(i + 1) === 'IF')) {
|
|
|
|
starter = tag;
|
2012-07-05 06:37:09 +00:00
|
|
|
_ref1 = this.indentation(token, true), indent = _ref1[0], outdent = _ref1[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);
|
2012-07-05 06:37:09 +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) {
|
|
|
|
var _ref;
|
|
|
|
return (_ref = token[0]) === 'TERMINATOR' || _ref === 'INDENT';
|
|
|
|
};
|
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) {
|
|
|
|
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
|
|
|
|
|
|
|
Rewriter.prototype.indentation = function(token, implicit) {
|
|
|
|
var indent, outdent;
|
|
|
|
if (implicit == null) implicit = false;
|
|
|
|
indent = ['INDENT', 2, token[2]];
|
|
|
|
outdent = ['OUTDENT', 2, token[2]];
|
|
|
|
if (implicit) indent.generated = outdent.generated = true;
|
|
|
|
return [indent, outdent];
|
2012-02-06 20:59:17 +00:00
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
Rewriter.prototype.generate = function(tag, value, line) {
|
|
|
|
var tok;
|
|
|
|
tok = [tag, value, line];
|
|
|
|
tok.generated = true;
|
|
|
|
return tok;
|
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.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
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
EXPRESSION_CLOSE = ['CATCH', 'WHEN', '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
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
IMPLICIT_CALL = ['IDENTIFIER', 'NUMBER', 'STRING', 'JS', 'REGEX', 'NEW', 'PARAM_START', 'CLASS', 'IF', 'TRY', 'SWITCH', 'THIS', 'BOOL', 'UNARY', 'SUPER', '@', '->', '=>', '[', '(', '{', '--', '++'];
|
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_BLOCK = ['->', '=>', '{', '[', ','];
|
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
|
|
|
|
|
|
|
|
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
|
|
|
// Generated by CoffeeScript 1.2.1-pre
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
var extend, flatten;
|
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
|
|
|
|
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];
|
2012-07-05 06:37:09 +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;
|
2012-07-05 06:37:09 +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
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
exports.last = function(array, back) {
|
|
|
|
return array[array.length - (back || 0) - 1];
|
|
|
|
};
|
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) {
|
|
|
|
/* Jison generated parser */
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
undefined
|
2012-02-06 20:59:17 +00:00
|
|
|
var parser = {trace: function trace() { },
|
|
|
|
yy: {},
|
2012-07-05 06:37:09 +00:00
|
|
|
symbols_: {"error":2,"Root":3,"Body":4,"Block":5,"TERMINATOR":6,"Line":7,"Expression":8,"Statement":9,"Return":10,"Comment":11,"STATEMENT":12,"Value":13,"Invocation":14,"Code":15,"Operation":16,"Assign":17,"If":18,"Try":19,"While":20,"For":21,"Switch":22,"Class":23,"Throw":24,"INDENT":25,"OUTDENT":26,"Identifier":27,"IDENTIFIER":28,"AlphaNumeric":29,"NUMBER":30,"STRING":31,"Literal":32,"JS":33,"REGEX":34,"DEBUGGER":35,"BOOL":36,"Assignable":37,"=":38,"AssignObj":39,"ObjAssignable":40,":":41,"ThisProperty":42,"RETURN":43,"HERECOMMENT":44,"PARAM_START":45,"ParamList":46,"PARAM_END":47,"FuncGlyph":48,"->":49,"=>":50,"OptComma":51,",":52,"Param":53,"ParamVar":54,"...":55,"Array":56,"Object":57,"Splat":58,"SimpleAssignable":59,"Accessor":60,"Parenthetical":61,"Range":62,"This":63,".":64,"?.":65,"::":66,"Index":67,"INDEX_START":68,"IndexValue":69,"INDEX_END":70,"INDEX_SOAK":71,"Slice":72,"{":73,"AssignList":74,"}":75,"CLASS":76,"EXTENDS":77,"OptFuncExist":78,"Arguments":79,"SUPER":80,"FUNC_EXIST":81,"CALL_START":82,"CALL_END":83,"ArgList":84,"THIS":85,"@":86,"[":87,"]":88,"RangeDots":89,"..":90,"Arg":91,"SimpleArgs":92,"TRY":93,"Catch":94,"FINALLY":95,"CATCH":96,"THROW":97,"(":98,")":99,"WhileSource":100,"WHILE":101,"WHEN":102,"UNTIL":103,"Loop":104,"LOOP":105,"ForBody":106,"FOR":107,"ForStart":108,"ForSource":109,"ForVariables":110,"OWN":111,"ForValue":112,"FORIN":113,"FOROF":114,"BY":115,"SWITCH":116,"Whens":117,"ELSE":118,"When":119,"LEADING_WHEN":120,"IfBlock":121,"IF":122,"POST_IF":123,"UNARY":124,"-":125,"+":126,"--":127,"++":128,"?":129,"MATH":130,"SHIFT":131,"COMPARE":132,"LOGIC":133,"RELATION":134,"COMPOUND_ASSIGN":135,"$accept":0,"$end":1},
|
|
|
|
terminals_: {2:"error",6:"TERMINATOR",12:"STATEMENT",25:"INDENT",26:"OUTDENT",28:"IDENTIFIER",30:"NUMBER",31:"STRING",33:"JS",34:"REGEX",35:"DEBUGGER",36:"BOOL",38:"=",41:":",43:"RETURN",44:"HERECOMMENT",45:"PARAM_START",47:"PARAM_END",49:"->",50:"=>",52:",",55:"...",64:".",65:"?.",66:"::",68:"INDEX_START",70:"INDEX_END",71:"INDEX_SOAK",73:"{",75:"}",76:"CLASS",77:"EXTENDS",80:"SUPER",81:"FUNC_EXIST",82:"CALL_START",83:"CALL_END",85:"THIS",86:"@",87:"[",88:"]",90:"..",93:"TRY",95:"FINALLY",96:"CATCH",97:"THROW",98:"(",99:")",101:"WHILE",102:"WHEN",103:"UNTIL",105:"LOOP",107:"FOR",111:"OWN",113:"FORIN",114:"FOROF",115:"BY",116:"SWITCH",118:"ELSE",120:"LEADING_WHEN",122:"IF",123:"POST_IF",124:"UNARY",125:"-",126:"+",127:"--",128:"++",129:"?",130:"MATH",131:"SHIFT",132:"COMPARE",133:"LOGIC",134:"RELATION",135:"COMPOUND_ASSIGN"},
|
|
|
|
productions_: [0,[3,0],[3,1],[3,2],[4,1],[4,3],[4,2],[7,1],[7,1],[9,1],[9,1],[9,1],[8,1],[8,1],[8,1],[8,1],[8,1],[8,1],[8,1],[8,1],[8,1],[8,1],[8,1],[8,1],[5,2],[5,3],[27,1],[29,1],[29,1],[32,1],[32,1],[32,1],[32,1],[32,1],[17,3],[17,4],[17,5],[39,1],[39,3],[39,5],[39,1],[40,1],[40,1],[40,1],[10,2],[10,1],[11,1],[15,5],[15,2],[48,1],[48,1],[51,0],[51,1],[46,0],[46,1],[46,3],[53,1],[53,2],[53,3],[54,1],[54,1],[54,1],[54,1],[58,2],[59,1],[59,2],[59,2],[59,1],[37,1],[37,1],[37,1],[13,1],[13,1],[13,1],[13,1],[13,1],[60,2],[60,2],[60,2],[60,1],[60,1],[67,3],[67,2],[69,1],[69,1],[57,4],[74,0],[74,1],[74,3],[74,4],[74,6],[23,1],[23,2],[23,3],[23,4],[23,2],[23,3],[23,4],[23,5],[14,3],[14,3],[14,1],[14,2],[78,0],[78,1],[79,2],[79,4],[63,1],[63,1],[42,2],[56,2],[56,4],[89,1],[89,1],[62,5],[72,3],[72,2],[72,2],[72,1],[84,1],[84,3],[84,4],[84,4],[84,6],[91,1],[91,1],[92,1],[92,3],[19,2],[19,3],[19,4],[19,5],[94,3],[24,2],[61,3],[61,5],[100,2],[100,4],[100,2],[100,4],[20,2],[20,2],[20,2],[20,1],[104,2],[104,2],[21,2],[21,2],[21,2],[106,2],[106,2],[108,2],[108,3],[112,1],[112,1],[112,1],[110,1],[110,3],[109,2],[109,2],[109,4],[109,4],[109,4],[109,6],[109,6],[22,5],[22,7],[22,4],[22,6],[117,1],[117,2],[119,3],[119,4],[121,3],[121,5],[18,1],[18,3],[18,3],[18,3],[16,2],[16,2],[16,2],[16,2],[16,2],[16,2],[16,2],[16,2],[16,3],[16,3],[16,3],[16,3],[16,3],[16,3],[16,3],[16,3],[16,5],[16,3]],
|
2012-02-06 20:59:17 +00:00
|
|
|
performAction: function anonymous(yytext,yyleng,yylineno,yy,yystate,$$,_$) {
|
|
|
|
|
|
|
|
var $0 = $$.length - 1;
|
|
|
|
switch (yystate) {
|
|
|
|
case 1:return this.$ = new yy.Block;
|
|
|
|
break;
|
|
|
|
case 2:return this.$ = $$[$0];
|
|
|
|
break;
|
|
|
|
case 3:return this.$ = $$[$0-1];
|
|
|
|
break;
|
|
|
|
case 4:this.$ = yy.Block.wrap([$$[$0]]);
|
|
|
|
break;
|
|
|
|
case 5:this.$ = $$[$0-2].push($$[$0]);
|
|
|
|
break;
|
|
|
|
case 6:this.$ = $$[$0-1];
|
|
|
|
break;
|
|
|
|
case 7:this.$ = $$[$0];
|
|
|
|
break;
|
|
|
|
case 8:this.$ = $$[$0];
|
|
|
|
break;
|
|
|
|
case 9:this.$ = $$[$0];
|
|
|
|
break;
|
|
|
|
case 10:this.$ = $$[$0];
|
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 11:this.$ = new yy.Literal($$[$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;
|
|
|
|
case 23:this.$ = $$[$0];
|
|
|
|
break;
|
|
|
|
case 24:this.$ = new yy.Block;
|
|
|
|
break;
|
|
|
|
case 25:this.$ = $$[$0-1];
|
|
|
|
break;
|
|
|
|
case 26:this.$ = new yy.Literal($$[$0]);
|
|
|
|
break;
|
|
|
|
case 27:this.$ = new yy.Literal($$[$0]);
|
|
|
|
break;
|
|
|
|
case 28:this.$ = new yy.Literal($$[$0]);
|
|
|
|
break;
|
|
|
|
case 29:this.$ = $$[$0];
|
|
|
|
break;
|
|
|
|
case 30:this.$ = new yy.Literal($$[$0]);
|
|
|
|
break;
|
|
|
|
case 31:this.$ = new yy.Literal($$[$0]);
|
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 32:this.$ = new yy.Literal($$[$0]);
|
|
|
|
break;
|
|
|
|
case 33:this.$ = (function () {
|
2012-02-06 20:59:17 +00:00
|
|
|
var val;
|
|
|
|
val = new yy.Literal($$[$0]);
|
2012-07-05 06:37:09 +00:00
|
|
|
if ($$[$0] === 'undefined') val.isUndefined = true;
|
2012-02-06 20:59:17 +00:00
|
|
|
return val;
|
|
|
|
}());
|
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 34:this.$ = new yy.Assign($$[$0-2], $$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 35:this.$ = new yy.Assign($$[$0-3], $$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 36:this.$ = new yy.Assign($$[$0-4], $$[$0-1]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 37:this.$ = new yy.Value($$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 38:this.$ = new yy.Assign(new yy.Value($$[$0-2]), $$[$0], 'object');
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 39:this.$ = new yy.Assign(new yy.Value($$[$0-4]), $$[$0-1], 'object');
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
|
|
|
case 40:this.$ = $$[$0];
|
|
|
|
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;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 44:this.$ = new yy.Return($$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 45:this.$ = new yy.Return;
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 46:this.$ = new yy.Comment($$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 47:this.$ = new yy.Code($$[$0-3], $$[$0], $$[$0-1]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 48:this.$ = new yy.Code([], $$[$0], $$[$0-1]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 49:this.$ = 'func';
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 50:this.$ = 'boundfunc';
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 51:this.$ = $$[$0];
|
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;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 53:this.$ = [];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 54:this.$ = [$$[$0]];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 55:this.$ = $$[$0-2].concat($$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 56:this.$ = new yy.Param($$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 57:this.$ = new yy.Param($$[$0-1], null, true);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 58:this.$ = new yy.Param($$[$0-2], $$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
|
|
|
case 59:this.$ = $$[$0];
|
|
|
|
break;
|
|
|
|
case 60:this.$ = $$[$0];
|
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 61:this.$ = $$[$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;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 63:this.$ = new yy.Splat($$[$0-1]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 64:this.$ = new yy.Value($$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 65:this.$ = $$[$0-1].add($$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 66:this.$ = new yy.Value($$[$0-1], [].concat($$[$0]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 67:this.$ = $$[$0];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 68:this.$ = $$[$0];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 69:this.$ = new yy.Value($$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
|
|
|
case 70:this.$ = new yy.Value($$[$0]);
|
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 71:this.$ = $$[$0];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
|
|
|
case 72:this.$ = new yy.Value($$[$0]);
|
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 73:this.$ = new yy.Value($$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 74:this.$ = new yy.Value($$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 75:this.$ = $$[$0];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 76:this.$ = new yy.Access($$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 77:this.$ = new yy.Access($$[$0], 'soak');
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 78:this.$ = [new yy.Access(new yy.Literal('prototype')), new yy.Access($$[$0])];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 79:this.$ = new yy.Access(new yy.Literal('prototype'));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 80:this.$ = $$[$0];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 81:this.$ = $$[$0-1];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 82:this.$ = yy.extend($$[$0], {
|
|
|
|
soak: true
|
|
|
|
});
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 83:this.$ = new yy.Index($$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 84:this.$ = new yy.Slice($$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 85:this.$ = new yy.Obj($$[$0-2], $$[$0-3].generated);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 86:this.$ = [];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 87:this.$ = [$$[$0]];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 88:this.$ = $$[$0-2].concat($$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 89:this.$ = $$[$0-3].concat($$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 90:this.$ = $$[$0-5].concat($$[$0-2]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 91:this.$ = new yy.Class;
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 92:this.$ = new yy.Class(null, null, $$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 93:this.$ = new yy.Class(null, $$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 94:this.$ = new yy.Class(null, $$[$0-1], $$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 95:this.$ = new yy.Class($$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 96:this.$ = new yy.Class($$[$0-1], null, $$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 97:this.$ = new yy.Class($$[$0-2], $$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 98:this.$ = new yy.Class($$[$0-3], $$[$0-1], $$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
|
|
|
case 99:this.$ = new yy.Call($$[$0-2], $$[$0], $$[$0-1]);
|
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 100:this.$ = new yy.Call($$[$0-2], $$[$0], $$[$0-1]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 101:this.$ = new yy.Call('super', [new yy.Splat(new yy.Literal('arguments'))]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 102:this.$ = new yy.Call('super', $$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 103:this.$ = false;
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 104:this.$ = true;
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 105:this.$ = [];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 106:this.$ = $$[$0-2];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
|
|
|
case 107:this.$ = new yy.Value(new yy.Literal('this'));
|
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 108:this.$ = new yy.Value(new yy.Literal('this'));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 109:this.$ = new yy.Value(new yy.Literal('this'), [new yy.Access($$[$0])], 'this');
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 110:this.$ = new yy.Arr([]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 111:this.$ = new yy.Arr($$[$0-2]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 112:this.$ = 'inclusive';
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 113:this.$ = 'exclusive';
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 114:this.$ = new yy.Range($$[$0-3], $$[$0-1], $$[$0-2]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 115:this.$ = new yy.Range($$[$0-2], $$[$0], $$[$0-1]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 116:this.$ = new yy.Range($$[$0-1], null, $$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 117:this.$ = new yy.Range(null, $$[$0], $$[$0-1]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 118:this.$ = new yy.Range(null, null, $$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 119:this.$ = [$$[$0]];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 120:this.$ = $$[$0-2].concat($$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 121:this.$ = $$[$0-3].concat($$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 122:this.$ = $$[$0-2];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 123:this.$ = $$[$0-5].concat($$[$0-2]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
|
|
|
case 124:this.$ = $$[$0];
|
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 125:this.$ = $$[$0];
|
|
|
|
break;
|
|
|
|
case 126:this.$ = $$[$0];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 127:this.$ = [].concat($$[$0-2], $$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 128:this.$ = new yy.Try($$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 129:this.$ = new yy.Try($$[$0-1], $$[$0][0], $$[$0][1]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 130:this.$ = new yy.Try($$[$0-2], null, null, $$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 131:this.$ = new yy.Try($$[$0-3], $$[$0-2][0], $$[$0-2][1], $$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 132:this.$ = [$$[$0-1], $$[$0]];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 133:this.$ = new yy.Throw($$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 134:this.$ = new yy.Parens($$[$0-1]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 135:this.$ = new yy.Parens($$[$0-2]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 136:this.$ = new yy.While($$[$0]);
|
|
|
|
break;
|
|
|
|
case 137:this.$ = new yy.While($$[$0-2], {
|
2012-02-06 20:59:17 +00:00
|
|
|
guard: $$[$0]
|
|
|
|
});
|
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 138:this.$ = new yy.While($$[$0], {
|
2012-02-06 20:59:17 +00:00
|
|
|
invert: true
|
|
|
|
});
|
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 139:this.$ = new yy.While($$[$0-2], {
|
2012-02-06 20:59:17 +00:00
|
|
|
invert: true,
|
|
|
|
guard: $$[$0]
|
|
|
|
});
|
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 140:this.$ = $$[$0-1].addBody($$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 141:this.$ = $$[$0].addBody(yy.Block.wrap([$$[$0-1]]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 142:this.$ = $$[$0].addBody(yy.Block.wrap([$$[$0-1]]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 143:this.$ = $$[$0];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 144:this.$ = new yy.While(new yy.Literal('true')).addBody($$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 145:this.$ = new yy.While(new yy.Literal('true')).addBody(yy.Block.wrap([$$[$0]]));
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 146:this.$ = new yy.For($$[$0-1], $$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 147:this.$ = new yy.For($$[$0-1], $$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 148:this.$ = new yy.For($$[$0], $$[$0-1]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 149:this.$ = {
|
2012-02-06 20:59:17 +00:00
|
|
|
source: new yy.Value($$[$0])
|
|
|
|
};
|
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 150:this.$ = (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];
|
|
|
|
}());
|
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 151:this.$ = $$[$0];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 152:this.$ = (function () {
|
2012-02-06 20:59:17 +00:00
|
|
|
$$[$0].own = true;
|
|
|
|
return $$[$0];
|
|
|
|
}());
|
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 153:this.$ = $$[$0];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 154:this.$ = new yy.Value($$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 155:this.$ = new yy.Value($$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 156:this.$ = [$$[$0]];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 157:this.$ = [$$[$0-2], $$[$0]];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 158:this.$ = {
|
2012-02-06 20:59:17 +00:00
|
|
|
source: $$[$0]
|
|
|
|
};
|
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 159:this.$ = {
|
2012-02-06 20:59:17 +00:00
|
|
|
source: $$[$0],
|
|
|
|
object: true
|
|
|
|
};
|
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 160:this.$ = {
|
2012-02-06 20:59:17 +00:00
|
|
|
source: $$[$0-2],
|
|
|
|
guard: $$[$0]
|
|
|
|
};
|
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 161:this.$ = {
|
2012-02-06 20:59:17 +00:00
|
|
|
source: $$[$0-2],
|
|
|
|
guard: $$[$0],
|
|
|
|
object: true
|
|
|
|
};
|
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 162:this.$ = {
|
2012-02-06 20:59:17 +00:00
|
|
|
source: $$[$0-2],
|
|
|
|
step: $$[$0]
|
|
|
|
};
|
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 163:this.$ = {
|
2012-02-06 20:59:17 +00:00
|
|
|
source: $$[$0-4],
|
|
|
|
guard: $$[$0-2],
|
|
|
|
step: $$[$0]
|
|
|
|
};
|
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 164:this.$ = {
|
2012-02-06 20:59:17 +00:00
|
|
|
source: $$[$0-4],
|
|
|
|
step: $$[$0-2],
|
|
|
|
guard: $$[$0]
|
|
|
|
};
|
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 165:this.$ = new yy.Switch($$[$0-3], $$[$0-1]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 166:this.$ = new yy.Switch($$[$0-5], $$[$0-3], $$[$0-1]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 167:this.$ = new yy.Switch(null, $$[$0-1]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 168:this.$ = new yy.Switch(null, $$[$0-3], $$[$0-1]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 169:this.$ = $$[$0];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 170:this.$ = $$[$0-1].concat($$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 171:this.$ = [[$$[$0-1], $$[$0]]];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 172:this.$ = [[$$[$0-2], $$[$0-1]]];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 173:this.$ = new yy.If($$[$0-1], $$[$0], {
|
2012-02-06 20:59:17 +00:00
|
|
|
type: $$[$0-2]
|
|
|
|
});
|
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 174:this.$ = $$[$0-4].addElse(new yy.If($$[$0-1], $$[$0], {
|
2012-02-06 20:59:17 +00:00
|
|
|
type: $$[$0-2]
|
|
|
|
}));
|
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 175:this.$ = $$[$0];
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 176:this.$ = $$[$0-2].addElse($$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 177:this.$ = new yy.If($$[$0], yy.Block.wrap([$$[$0-2]]), {
|
2012-02-06 20:59:17 +00:00
|
|
|
type: $$[$0-1],
|
|
|
|
statement: true
|
|
|
|
});
|
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 178:this.$ = new yy.If($$[$0], yy.Block.wrap([$$[$0-2]]), {
|
2012-02-06 20:59:17 +00:00
|
|
|
type: $$[$0-1],
|
|
|
|
statement: true
|
|
|
|
});
|
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 179:this.$ = new yy.Op($$[$0-1], $$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 180:this.$ = new yy.Op('-', $$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 181:this.$ = new yy.Op('+', $$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 182:this.$ = new yy.Op('--', $$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 183:this.$ = new yy.Op('++', $$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 184:this.$ = new yy.Op('--', $$[$0-1], null, true);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 185:this.$ = new yy.Op('++', $$[$0-1], null, true);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 186:this.$ = new yy.Existence($$[$0-1]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 187:this.$ = new yy.Op('+', $$[$0-2], $$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 188:this.$ = new yy.Op('-', $$[$0-2], $$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
|
|
|
case 189:this.$ = new yy.Op($$[$0-1], $$[$0-2], $$[$0]);
|
|
|
|
break;
|
|
|
|
case 190:this.$ = new yy.Op($$[$0-1], $$[$0-2], $$[$0]);
|
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 191:this.$ = new yy.Op($$[$0-1], $$[$0-2], $$[$0]);
|
|
|
|
break;
|
|
|
|
case 192:this.$ = new yy.Op($$[$0-1], $$[$0-2], $$[$0]);
|
|
|
|
break;
|
|
|
|
case 193:this.$ = (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]);
|
|
|
|
}
|
|
|
|
}());
|
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 194:this.$ = new yy.Assign($$[$0-2], $$[$0], $$[$0-1]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 195:this.$ = new yy.Assign($$[$0-4], $$[$0-1], $$[$0-3]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
2012-07-05 06:37:09 +00:00
|
|
|
case 196:this.$ = new yy.Extends($$[$0-2], $$[$0]);
|
2012-02-06 20:59:17 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
2012-07-05 06:37:09 +00:00
|
|
|
table: [{1:[2,1],3:1,4:2,5:3,7:4,8:6,9:7,10:20,11:21,12:[1,22],13:8,14:9,15:10,16:11,17:12,18:13,19:14,20:15,21:16,22:17,23:18,24:19,25:[1,5],27:60,28:[1,71],29:49,30:[1,69],31:[1,70],32:24,33:[1,50],34:[1,51],35:[1,52],36:[1,53],37:23,42:61,43:[1,45],44:[1,46],45:[1,29],48:30,49:[1,58],50:[1,59],56:47,57:48,59:36,61:25,62:26,63:27,73:[1,68],76:[1,43],80:[1,28],85:[1,56],86:[1,57],87:[1,55],93:[1,38],97:[1,44],98:[1,54],100:39,101:[1,63],103:[1,64],104:40,105:[1,65],106:41,107:[1,66],108:67,116:[1,42],121:37,122:[1,62],124:[1,31],125:[1,32],126:[1,33],127:[1,34],128:[1,35]},{1:[3]},{1:[2,2],6:[1,72]},{6:[1,73]},{1:[2,4],6:[2,4],26:[2,4],99:[2,4]},{4:75,7:4,8:6,9:7,10:20,11:21,12:[1,22],13:8,14:9,15:10,16:11,17:12,18:13,19:14,20:15,21:16,22:17,23:18,24:19,26:[1,74],27:60,28:[1,71],29:49,30:[1,69],31:[1,70],32:24,33:[1,50],34:[1,51],35:[1,52],36:[1,53],37:23,42:61,43:[1,45],44:[1,46],45:[1,29],48:30,49:[1,58],50:[1,59],56:47,57:48,59:36,61:25,62:26,63:27,73:[1,68],76:[1,43],80:[1,28],85:[1,56],86:[1,57],87:[1,55],93:[1,38],97:[1,44],98:[1,54],100:39,101:[1,63],103:[1,64],104:40,105:[1,65],106:41,107:[1,66],108:67,116:[1,42],121:37,122:[1,62],124:[1,31],125:[1,32],126:[1,33],127:[1,34],128:[1,35]},{1:[2,7],6:[2,7],26:[2,7],99:[2,7],100:85,101:[1,63],103:[1,64],106:86,107:[1,66],108:67,123:[1,84],125:[1,78],126:[1,77],129:[1,76],130:[1,79],131:[1,80],132:[1,81],133:[1,82],134:[1,83]},{1:[2,8],6:[2,8],26:[2,8],99:[2,8],100:88,101:[1,63],103:[1,64],106:89,107:[1,66],108:67,123:[1,87]},{1:[2,12],6:[2,12],25:[2,12],26:[2,12],47:[2,12],52:[2,12],55:[2,12],60:91,64:[1,93],65:[1,94],66:[1,95],67:96,68:[1,97],70:[2,12],71:[1,98],75:[2,12],78:90,81:[1,92],82:[2,103],83:[2,12],88:[2,12],90:[2,12],99:[2,12],101:[2,12],102:[2,12],103:[2,12],107:[2,12],115:[2,12],123:[2,12],125:[2,12],126:[2,12],129:[2,12],130:[2,12],131:[2,12],132:[2,12],133:[2,12],134:[2,12]},{1:[2,13],6:[2,13],25:[2,13],26:[2,13],47:[2,13],52:[2,13],55:[2,13],60:100,64:[1,93],65:[1,94],66:[1,95],67:96,68:[1,97],70:[2,13],71:[1,98],75:[2,13],78:99,81:[1,92],82:[2,103],83:[2,13],88:[2,13],90:[2,13],99:[2,13],101:[2,13],102:[2,13],103:[2,13],107:[2,13],115:[2,13],123:[2,13],125:[2,13],126:[2,13],129:[2,13],130:[2,13],131:[2,13],132:[2,13],133:[2,13],134:[2,13]},{1:[2,14],6:[2,14],25:[2,14],26:[2,14],47:[2,14],52:[2,14],55:[2,14],70:[2,14],75:[2,14],83:[2,14],88:[2,14],90:[2,14],99:[2,14],101:[2,14],102:[2,14],103:[2,14],107:[2,14],115:[2,14],123:[2,14],125:[2,14],126:[2,14],129:[2,14],130:[2,14],131:[2,14],132:[2,14],133:[2,14],134:[2,14]},{1:[2,15],6:[2,15],25:[2,15],26:[2,15],47:[2,15],52:[2,15],55:[2,15],70:[2,15],75:[2,15],83:[2,15],88:[2,15],90:[2,15],99:[2,15],101:[2,15],102:[2,15],103:[2,15],107:[2,15],115:[2,15],123:[2,15],125:[2,15],126:[2,15],129:[2,15],130:[2,15],131:[2,15],132:[2,15],133:[2,15],134:[2,15]},{1:[2,16],6:[2,16],25:[2,16],26:[2,16],47:[2,16],52:[2,16],55:[2,16],70:[2,16],75:[2,16],83:[2,16],88:[2,16],90:[2,16],99:[2,16],101:[2,16],102:[2,16],103:[2,16],107:[2,16],115:[2,16],123:[2,16],125:[2,16],126:[2,16],129:[2,16],130:[2,16],131:[2,16],132:[2,16],133:[2,16],134:[2,16]},{1:[2,17],6:[2,17],25:[2,17],26:[2,17],47:[2,17],52:[2,17],55:[2,17],70:[2,17],75:[2,17],83:[2,17],88:[2,17],90:[2,17],99:[2,17],101:[2,17],102:[2,17],103:[2,17],107:[2,17],115:[2,17],123:[2,17],125:[2,17],126:[2,17],129:[2,17],130:[2,17],131:[2,17],132:[2,17],133:[2,17],134:[2,17]},{1:[2,18],6:[2,18],25:[2,18],26:[2,18],47:[2,18],52:[2,18],55:[2,18],70:[2,18],75:[2,18],83:[2,18],88:[2,18],90:[2,18],99:[2,18],101:[2,18],102:[2,18],103:[2,18],107:[2,18],115:[2,18],123:[2,18],125:[2,18],126:[2,18],129:[2,18],130:[2,18],131:[2,18],132:[2,18],133:[2,18],134:[2,18]},{1:[2,19],6:[2,19],25:[2,19],26:[2,19],47:[2,19],52:[2,19],55:[2,19],70:[2,19],75:[2,19],83:[2,19],88:[2,19],90:[2,19],99:[2,19],101:[2,19],102:[2,19],103:[2,19],107:[2,19],115:[2,19],123:[2,19],125:[2,19],126:[2,19],129:[2,19],130:[2,19],131:[2,19],132:[2,19],133:[2,19],134:[2,19]},{1:[2,20],6:[2,20],25:[2,20],26:[2,20],47:[2,20],52:[2,20],55:[2,20],70:[2,20],75:[2,20],83:[2,20],88:[2,20],90:[2,20],99:[2,20],101:[2,20],
|
|
|
|
defaultActions: {58:[2,49],59:[2,50],73:[2,3],92:[2,104],186:[2,84]},
|
2012-02-06 20:59:17 +00:00
|
|
|
parseError: function parseError(str, hash) {
|
|
|
|
throw new Error(str);
|
|
|
|
},
|
|
|
|
parse: function parse(input) {
|
2012-07-05 06:37:09 +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;
|
2012-07-05 06:37:09 +00:00
|
|
|
if (typeof this.lexer.yylloc == "undefined")
|
2012-02-06 20:59:17 +00:00
|
|
|
this.lexer.yylloc = {};
|
|
|
|
var yyloc = this.lexer.yylloc;
|
|
|
|
lstack.push(yyloc);
|
2012-07-05 06:37:09 +00:00
|
|
|
if (typeof this.yy.parseError === "function")
|
2012-02-06 20:59:17 +00:00
|
|
|
this.parseError = this.yy.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;
|
2012-07-05 06:37:09 +00:00
|
|
|
token = self.lexer.lex() || 1;
|
|
|
|
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 {
|
|
|
|
if (symbol == null)
|
|
|
|
symbol = lex();
|
|
|
|
action = table[state] && table[state][symbol];
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
if (typeof action === "undefined" || !action.length || !action[0]) {
|
2012-02-06 20:59:17 +00:00
|
|
|
if (!recovering) {
|
|
|
|
expected = [];
|
2012-07-05 06:37:09 +00:00
|
|
|
for (p in table[state])
|
|
|
|
if (this.terminals_[p] && p > 2) {
|
|
|
|
expected.push("'" + this.terminals_[p] + "'");
|
|
|
|
}
|
|
|
|
var errStr = "";
|
2012-02-06 20:59:17 +00:00
|
|
|
if (this.lexer.showPosition) {
|
2012-07-05 06:37:09 +00:00
|
|
|
errStr = "Parse error on line " + (yylineno + 1) + ":\n" + this.lexer.showPosition() + "\nExpecting " + expected.join(", ") + ", got '" + this.terminals_[symbol] + "'";
|
2012-02-06 20:59:17 +00:00
|
|
|
} else {
|
2012-07-05 06:37:09 +00:00
|
|
|
errStr = "Parse error on line " + (yylineno + 1) + ": Unexpected " + (symbol == 1?"end of input":"'" + (this.terminals_[symbol] || symbol) + "'");
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
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) {
|
|
|
|
throw new Error("Parse Error: multiple actions possible at state: " + state + ", token: " + symbol);
|
|
|
|
}
|
|
|
|
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;
|
2012-07-05 06:37:09 +00:00
|
|
|
if (recovering > 0)
|
|
|
|
recovering--;
|
|
|
|
} 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];
|
|
|
|
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};
|
|
|
|
r = this.performAction.call(yyval, yytext, yyleng, yylineno, this.yy, action[1], vstack, lstack);
|
|
|
|
if (typeof r !== "undefined") {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
};
|
2012-02-06 20:59:17 +00:00
|
|
|
|
2012-07-05 06:37:09 +00:00
|
|
|
module.exports = 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) {
|
|
|
|
// Generated by CoffeeScript 1.2.1-pre
|
2012-02-06 20:59:17 +00:00
|
|
|
|
2012-07-05 06:37:09 +00:00
|
|
|
var Access, Arr, Assign, Base, Block, Call, Class, Closure, Code, Comment, Existence, Extends, For, IDENTIFIER, IDENTIFIER_STR, IS_STRING, If, In, Index, LEVEL_ACCESS, LEVEL_COND, LEVEL_LIST, LEVEL_OP, LEVEL_PAREN, LEVEL_TOP, Literal, METHOD_DEF, NEGATE, NO, Obj, Op, Param, Parens, RESERVED, Range, Return, SIMPLENUM, STRICT_PROSCRIBED, Scope, Slice, Splat, Switch, TAB, THIS, Throw, Try, UTILITIES, Value, While, YES, compact, del, ends, extend, flatten, last, merge, multident, starts, unfoldSoak, utility, _ref, _ref1,
|
|
|
|
__hasProp = {}.hasOwnProperty,
|
|
|
|
__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; };
|
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
|
|
|
|
2012-07-05 06:37:09 +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;
|
2012-02-06 20:59:17 +00:00
|
|
|
|
|
|
|
exports.extend = extend;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
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
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
exports.Base = Base = (function() {
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
Base.name = 'Base';
|
|
|
|
|
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) {
|
|
|
|
var node;
|
|
|
|
o = extend({}, o);
|
2012-07-05 06:37:09 +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) {
|
2012-07-05 06:37:09 +00:00
|
|
|
if (this.jumps()) {
|
2012-02-06 20:59:17 +00:00
|
|
|
throw SyntaxError('cannot use a pure statement in an expression.');
|
|
|
|
}
|
|
|
|
o.sharedScope = true;
|
|
|
|
return Closure.wrap(this).compileNode(o);
|
|
|
|
};
|
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()) {
|
|
|
|
ref = level ? this.compile(o, level) : this;
|
|
|
|
return [ref, ref];
|
|
|
|
} else {
|
|
|
|
ref = new Literal(reused || o.scope.freeVariable('ref'));
|
|
|
|
sub = new Assign(ref, this);
|
|
|
|
if (level) {
|
|
|
|
return [sub.compile(o, level), ref.value];
|
|
|
|
} else {
|
|
|
|
return [sub, ref];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Base.prototype.compileLoopReference = function(o, name) {
|
|
|
|
var src, tmp;
|
|
|
|
src = tmp = this.compile(o, LEVEL_LIST);
|
|
|
|
if (!((-Infinity < +src && +src < Infinity) || IDENTIFIER.test(src) && o.scope.check(src, true))) {
|
|
|
|
src = "" + (tmp = o.scope.freeVariable(name)) + " = " + src;
|
|
|
|
}
|
|
|
|
return [src, tmp];
|
|
|
|
};
|
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) {
|
|
|
|
var contains;
|
|
|
|
contains = false;
|
|
|
|
this.traverseChildren(false, function(node) {
|
|
|
|
if (pred(node)) {
|
|
|
|
contains = true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return contains;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Base.prototype.containsType = function(type) {
|
|
|
|
return this instanceof type || this.contains(function(node) {
|
|
|
|
return node instanceof type;
|
|
|
|
});
|
|
|
|
};
|
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--) {
|
2012-07-05 06:37:09 +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;
|
2012-07-05 06:37:09 +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;
|
2012-07-05 06:37:09 +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;
|
|
|
|
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];
|
2012-07-05 06:37:09 +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) {
|
2012-07-05 06:37:09 +00:00
|
|
|
if (func(child) === false) return false;
|
2012-02-06 20:59:17 +00:00
|
|
|
return child.traverseChildren(crossScope, func);
|
|
|
|
});
|
|
|
|
};
|
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
|
|
|
|
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);
|
|
|
|
|
|
|
|
Block.name = 'Block';
|
|
|
|
|
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];
|
2012-07-05 06:37:09 +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) {
|
|
|
|
var exp, _i, _len, _ref2;
|
|
|
|
_ref2 = this.expressions;
|
|
|
|
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
|
|
|
exp = _ref2[_i];
|
2012-07-05 06:37:09 +00:00
|
|
|
if (exp.jumps(o)) return exp;
|
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
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Block.prototype.compile = function(o, level) {
|
2012-07-05 06:37:09 +00:00
|
|
|
if (o == null) o = {};
|
2012-02-06 20:59:17 +00:00
|
|
|
if (o.scope) {
|
|
|
|
return Block.__super__.compile.call(this, o, level);
|
|
|
|
} 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) {
|
|
|
|
var code, codes, node, top, _i, _len, _ref2;
|
|
|
|
this.tab = o.indent;
|
|
|
|
top = o.level === LEVEL_TOP;
|
|
|
|
codes = [];
|
|
|
|
_ref2 = this.expressions;
|
|
|
|
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
|
|
|
node = _ref2[_i];
|
|
|
|
node = node.unwrapAll();
|
|
|
|
node = node.unfoldSoak(o) || node;
|
2012-07-05 06:37:09 +00:00
|
|
|
if (node instanceof Block) {
|
|
|
|
codes.push(node.compileNode(o));
|
|
|
|
} else if (top) {
|
2012-02-06 20:59:17 +00:00
|
|
|
node.front = true;
|
|
|
|
code = node.compile(o);
|
2012-07-05 06:37:09 +00:00
|
|
|
if (!node.isStatement(o)) {
|
|
|
|
code = "" + this.tab + code + ";";
|
|
|
|
if (node instanceof Literal) code = "" + code + "\n";
|
|
|
|
}
|
|
|
|
codes.push(code);
|
2012-02-06 20:59:17 +00:00
|
|
|
} else {
|
|
|
|
codes.push(node.compile(o, LEVEL_LIST));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (top) {
|
2012-07-05 06:37:09 +00:00
|
|
|
if (this.spaced) {
|
|
|
|
return "\n" + (codes.join('\n\n')) + "\n";
|
|
|
|
} else {
|
|
|
|
return codes.join('\n');
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
code = codes.join(', ') || 'void 0';
|
|
|
|
if (codes.length > 1 && o.level >= LEVEL_LIST) {
|
|
|
|
return "(" + code + ")";
|
|
|
|
} else {
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Block.prototype.compileRoot = function(o) {
|
2012-07-05 06:37:09 +00:00
|
|
|
var code, exp, i, prelude, preludeExps, rest;
|
|
|
|
o.indent = o.bare ? '' : TAB;
|
2012-02-06 20:59:17 +00:00
|
|
|
o.scope = new Scope(null, this, null);
|
|
|
|
o.level = LEVEL_TOP;
|
2012-07-05 06:37:09 +00:00
|
|
|
this.spaced = true;
|
|
|
|
prelude = "";
|
|
|
|
if (!o.bare) {
|
|
|
|
preludeExps = (function() {
|
|
|
|
var _i, _len, _ref2, _results;
|
|
|
|
_ref2 = this.expressions;
|
|
|
|
_results = [];
|
|
|
|
for (i = _i = 0, _len = _ref2.length; _i < _len; i = ++_i) {
|
|
|
|
exp = _ref2[i];
|
|
|
|
if (!(exp.unwrap() instanceof Comment)) break;
|
|
|
|
_results.push(exp);
|
|
|
|
}
|
|
|
|
return _results;
|
|
|
|
}).call(this);
|
|
|
|
rest = this.expressions.slice(preludeExps.length);
|
|
|
|
this.expressions = preludeExps;
|
|
|
|
if (preludeExps.length) {
|
|
|
|
prelude = "" + (this.compileNode(merge(o, {
|
|
|
|
indent: ''
|
|
|
|
}))) + "\n";
|
|
|
|
}
|
|
|
|
this.expressions = rest;
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
code = this.compileWithDeclarations(o);
|
|
|
|
if (o.bare) return code;
|
|
|
|
return "" + prelude + "(function() {\n" + code + "\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) {
|
2012-07-05 06:37:09 +00:00
|
|
|
var assigns, code, declars, exp, i, post, rest, scope, spaced, _i, _len, _ref2, _ref3, _ref4;
|
2012-02-06 20:59:17 +00:00
|
|
|
code = post = '';
|
|
|
|
_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();
|
2012-07-05 06:37:09 +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];
|
|
|
|
_ref4 = [this.compileNode(o), spaced], code = _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) {
|
|
|
|
if (i) code += '\n';
|
|
|
|
code += "" + this.tab + "var ";
|
|
|
|
if (declars) code += scope.declaredVariables().join(', ');
|
|
|
|
if (assigns) {
|
|
|
|
if (declars) code += ",\n" + (this.tab + TAB);
|
|
|
|
code += scope.assignedVariables().join(",\n" + (this.tab + TAB));
|
|
|
|
}
|
|
|
|
code += ';\n';
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return code + post;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Block.wrap = function(nodes) {
|
2012-07-05 06:37:09 +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);
|
|
|
|
|
|
|
|
Literal.name = 'Literal';
|
|
|
|
|
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;
|
|
|
|
}
|
2012-07-05 06:37:09 +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) {
|
2012-07-05 06:37:09 +00:00
|
|
|
var code, _ref2;
|
|
|
|
code = this.isUndefined ? o.level >= LEVEL_ACCESS ? '(void 0)' : 'void 0' : 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;
|
2012-02-06 20:59:17 +00:00
|
|
|
if (this.isStatement()) {
|
|
|
|
return "" + this.tab + code + ";";
|
|
|
|
} else {
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
};
|
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);
|
|
|
|
|
|
|
|
exports.Return = Return = (function(_super) {
|
|
|
|
|
|
|
|
__extends(Return, _super);
|
|
|
|
|
|
|
|
Return.name = 'Return';
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
function Return(expr) {
|
2012-07-05 06:37:09 +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
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Return.prototype.compile = function(o, level) {
|
|
|
|
var expr, _ref2;
|
|
|
|
expr = (_ref2 = this.expression) != null ? _ref2.makeReturn() : void 0;
|
|
|
|
if (expr && !(expr instanceof Return)) {
|
|
|
|
return expr.compile(o, level);
|
|
|
|
} else {
|
|
|
|
return Return.__super__.compile.call(this, o, level);
|
|
|
|
}
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Return.prototype.compileNode = function(o) {
|
2012-07-05 06:37:09 +00:00
|
|
|
return this.tab + ("return" + [this.expression ? " " + (this.expression.compile(o, LEVEL_PAREN)) : 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
|
|
|
return Return;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
})(Base);
|
|
|
|
|
|
|
|
exports.Value = Value = (function(_super) {
|
|
|
|
|
|
|
|
__extends(Value, _super);
|
|
|
|
|
|
|
|
Value.name = 'Value';
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
function Value(base, props, tag) {
|
2012-07-05 06:37:09 +00:00
|
|
|
if (!props && base instanceof Value) return base;
|
2012-02-06 20:59:17 +00:00
|
|
|
this.base = base;
|
|
|
|
this.properties = props || [];
|
2012-07-05 06:37:09 +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
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Value.prototype.isArray = function() {
|
|
|
|
return !this.properties.length && this.base instanceof Arr;
|
|
|
|
};
|
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() {
|
|
|
|
return this.base instanceof Literal && SIMPLENUM.test(this.base.value);
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
Value.prototype.isString = function() {
|
|
|
|
return this.base instanceof Literal && IS_STRING.test(this.base.value);
|
|
|
|
};
|
|
|
|
|
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];
|
2012-07-05 06:37:09 +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
|
|
|
|
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) {
|
2012-07-05 06:37:09 +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
|
|
|
|
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)));
|
|
|
|
}
|
2012-07-05 06:37:09 +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) {
|
|
|
|
var code, prop, props, _i, _len;
|
|
|
|
this.base.front = this.front;
|
|
|
|
props = this.properties;
|
|
|
|
code = this.base.compile(o, props.length ? LEVEL_ACCESS : null);
|
2012-07-05 06:37:09 +00:00
|
|
|
if ((this.base instanceof Parens || props.length) && SIMPLENUM.test(code)) {
|
|
|
|
code = "" + code + ".";
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
for (_i = 0, _len = props.length; _i < _len; _i++) {
|
|
|
|
prop = props[_i];
|
|
|
|
code += prop.compile(o);
|
|
|
|
}
|
|
|
|
return code;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Value.prototype.unfoldSoak = function(o) {
|
2012-07-05 06:37:09 +00:00
|
|
|
var result,
|
|
|
|
_this = this;
|
|
|
|
if (this.unfoldedSoak != null) return this.unfoldedSoak;
|
|
|
|
result = (function() {
|
|
|
|
var fst, i, ifn, prop, ref, snd, _i, _len, _ref2;
|
|
|
|
if (ifn = _this.base.unfoldSoak(o)) {
|
|
|
|
Array.prototype.push.apply(ifn.body.properties, _this.properties);
|
2012-02-06 20:59:17 +00:00
|
|
|
return ifn;
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
_ref2 = _this.properties;
|
|
|
|
for (i = _i = 0, _len = _ref2.length; _i < _len; i = ++_i) {
|
2012-02-06 20:59:17 +00:00
|
|
|
prop = _ref2[i];
|
2012-07-05 06:37:09 +00:00
|
|
|
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;
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
return new If(new Existence(fst), snd, {
|
|
|
|
soak: true
|
|
|
|
});
|
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
|
|
|
return this.unfoldedSoak = result || false;
|
|
|
|
};
|
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);
|
|
|
|
|
|
|
|
Comment.name = 'Comment';
|
|
|
|
|
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) {
|
|
|
|
var code;
|
2012-07-05 06:37:09 +00:00
|
|
|
code = '/*' + multident(this.comment, this.tab) + ("\n" + this.tab + "*/\n");
|
|
|
|
if ((level || o.level) === LEVEL_TOP) code = o.indent + code;
|
2012-02-06 20:59:17 +00:00
|
|
|
return code;
|
|
|
|
};
|
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);
|
|
|
|
|
|
|
|
Call.name = 'Call';
|
|
|
|
|
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;
|
|
|
|
}
|
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) {
|
2012-07-05 06:37:09 +00:00
|
|
|
var accesses, method, name;
|
2012-02-06 20:59:17 +00:00
|
|
|
method = o.scope.method;
|
2012-07-05 06:37:09 +00:00
|
|
|
if (!method) throw SyntaxError('cannot call super outside of a function.');
|
2012-02-06 20:59:17 +00:00
|
|
|
name = method.name;
|
2012-07-05 06:37:09 +00:00
|
|
|
if (name == null) {
|
2012-02-06 20:59:17 +00:00
|
|
|
throw SyntaxError('cannot call super on an anonymous function.');
|
|
|
|
}
|
|
|
|
if (method.klass) {
|
2012-07-05 06:37:09 +00:00
|
|
|
accesses = [new Access(new Literal('__super__'))];
|
|
|
|
if (method["static"]) {
|
|
|
|
accesses.push(new Access(new Literal('constructor')));
|
|
|
|
}
|
|
|
|
accesses.push(new Access(new Literal(name)));
|
|
|
|
return (new Value(new Literal(method.klass), accesses)).compile(o);
|
2012-02-06 20:59:17 +00:00
|
|
|
} else {
|
|
|
|
return "" + name + ".__super__.constructor";
|
|
|
|
}
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
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) {
|
2012-07-05 06:37:09 +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;
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
if (!(call.variable instanceof Value)) break;
|
2012-02-06 20:59:17 +00:00
|
|
|
list.push(call);
|
2012-07-05 06:37:09 +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.filterImplicitObjects = function(list) {
|
2012-07-05 06:37:09 +00:00
|
|
|
var node, nodes, obj, prop, properties, _i, _j, _len, _len1, _ref2;
|
2012-02-06 20:59:17 +00:00
|
|
|
nodes = [];
|
|
|
|
for (_i = 0, _len = list.length; _i < _len; _i++) {
|
|
|
|
node = list[_i];
|
|
|
|
if (!((typeof node.isObject === "function" ? node.isObject() : void 0) && node.base.generated)) {
|
|
|
|
nodes.push(node);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
obj = null;
|
|
|
|
_ref2 = node.base.properties;
|
2012-07-05 06:37:09 +00:00
|
|
|
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
|
2012-02-06 20:59:17 +00:00
|
|
|
prop = _ref2[_j];
|
2012-07-05 06:37:09 +00:00
|
|
|
if (prop instanceof Assign || prop instanceof Comment) {
|
|
|
|
if (!obj) nodes.push(obj = new Obj(properties = [], true));
|
2012-02-06 20:59:17 +00:00
|
|
|
properties.push(prop);
|
|
|
|
} else {
|
|
|
|
nodes.push(prop);
|
|
|
|
obj = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nodes;
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Call.prototype.compileNode = function(o) {
|
|
|
|
var arg, args, code, _ref2;
|
2012-07-05 06:37:09 +00:00
|
|
|
if ((_ref2 = this.variable) != null) _ref2.front = this.front;
|
2012-02-06 20:59:17 +00:00
|
|
|
if (code = Splat.compileSplattedArray(o, this.args, true)) {
|
|
|
|
return this.compileSplat(o, code);
|
|
|
|
}
|
|
|
|
args = this.filterImplicitObjects(this.args);
|
|
|
|
args = ((function() {
|
|
|
|
var _i, _len, _results;
|
|
|
|
_results = [];
|
|
|
|
for (_i = 0, _len = args.length; _i < _len; _i++) {
|
|
|
|
arg = args[_i];
|
|
|
|
_results.push(arg.compile(o, LEVEL_LIST));
|
|
|
|
}
|
|
|
|
return _results;
|
|
|
|
})()).join(', ');
|
|
|
|
if (this.isSuper) {
|
|
|
|
return this.superReference(o) + (".call(this" + (args && ', ' + args) + ")");
|
|
|
|
} else {
|
|
|
|
return (this.isNew ? 'new ' : '') + this.variable.compile(o, LEVEL_ACCESS) + ("(" + args + ")");
|
|
|
|
}
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Call.prototype.compileSuper = function(args, o) {
|
|
|
|
return "" + (this.superReference(o)) + ".call(this" + (args.length ? ', ' : '') + args + ")";
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Call.prototype.compileSplat = function(o, splatArgs) {
|
|
|
|
var base, fun, idt, name, ref;
|
|
|
|
if (this.isSuper) {
|
|
|
|
return "" + (this.superReference(o)) + ".apply(this, " + splatArgs + ")";
|
|
|
|
}
|
|
|
|
if (this.isNew) {
|
|
|
|
idt = this.tab + TAB;
|
2012-07-05 06:37:09 +00:00
|
|
|
return "(function(func, args, ctor) {\n" + idt + "ctor.prototype = func.prototype;\n" + idt + "var child = new ctor, result = func.apply(child, args), t = typeof result;\n" + idt + "return t == \"object\" || t == \"function\" ? result || child : child;\n" + this.tab + "})(" + (this.variable.compile(o, LEVEL_LIST)) + ", " + splatArgs + ", function(){})";
|
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');
|
|
|
|
fun = "(" + ref + " = " + (base.compile(o, LEVEL_LIST)) + ")" + (name.compile(o));
|
|
|
|
} else {
|
|
|
|
fun = base.compile(o, LEVEL_ACCESS);
|
2012-07-05 06:37:09 +00:00
|
|
|
if (SIMPLENUM.test(fun)) fun = "(" + fun + ")";
|
2012-02-06 20:59:17 +00:00
|
|
|
if (name) {
|
|
|
|
ref = fun;
|
|
|
|
fun += name.compile(o);
|
|
|
|
} else {
|
|
|
|
ref = 'null';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "" + fun + ".apply(" + ref + ", " + splatArgs + ")";
|
|
|
|
};
|
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);
|
|
|
|
|
|
|
|
Extends.name = 'Extends';
|
|
|
|
|
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
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Extends.prototype.compile = function(o) {
|
|
|
|
return new Call(new Value(new Literal(utility('extends'))), [this.child, this.parent]).compile(o);
|
|
|
|
};
|
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);
|
|
|
|
|
|
|
|
Access.name = 'Access';
|
|
|
|
|
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
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Access.prototype.compile = function(o) {
|
|
|
|
var name;
|
|
|
|
name = this.name.compile(o);
|
2012-07-05 06:37:09 +00:00
|
|
|
if (IDENTIFIER.test(name)) {
|
|
|
|
return "." + name;
|
|
|
|
} else {
|
|
|
|
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);
|
|
|
|
|
|
|
|
Index.name = 'Index';
|
|
|
|
|
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
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Index.prototype.compile = function(o) {
|
2012-07-05 06:37:09 +00:00
|
|
|
return "[" + (this.index.compile(o, LEVEL_PAREN)) + "]";
|
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);
|
|
|
|
|
|
|
|
Range.name = 'Range';
|
|
|
|
|
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
|
|
|
|
});
|
2012-07-05 06:37:09 +00:00
|
|
|
_ref2 = this.from.cache(o, LEVEL_LIST), this.fromC = _ref2[0], this.fromVar = _ref2[1];
|
|
|
|
_ref3 = 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')) {
|
|
|
|
_ref4 = step.cache(o, LEVEL_LIST), this.step = _ref4[0], this.stepVar = _ref4[1];
|
|
|
|
}
|
|
|
|
_ref5 = [this.fromVar.match(SIMPLENUM), this.toVar.match(SIMPLENUM)], this.fromNum = _ref5[0], this.toNum = _ref5[1];
|
2012-07-05 06:37:09 +00:00
|
|
|
if (this.stepVar) return this.stepNum = this.stepVar.match(SIMPLENUM);
|
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;
|
|
|
|
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;
|
|
|
|
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];
|
2012-07-05 06:37:09 +00:00
|
|
|
condPart = this.stepNum ? +this.stepNum > 0 ? "" + lt + " " + this.toVar : "" + gt + " " + this.toVar : known ? ((_ref3 = [+this.fromNum, +this.toNum], from = _ref3[0], to = _ref3[1], _ref3), from <= to ? "" + lt + " " + to : "" + gt + " " + to) : (cond = "" + this.fromVar + " <= " + this.toVar, "" + cond + " ? " + lt + " " + this.toVar + " : " + gt + " " + this.toVar);
|
|
|
|
stepPart = this.stepVar ? "" + idx + " += " + this.stepVar : known ? namedIndex ? from <= to ? "++" + idx : "--" + idx : from <= to ? "" + idx + "++" : "" + idx + "--" : namedIndex ? "" + cond + " ? ++" + idx + " : --" + idx : "" + cond + " ? " + idx + "++ : " + idx + "--";
|
|
|
|
if (namedIndex) varPart = "" + idxName + " = " + varPart;
|
|
|
|
if (namedIndex) stepPart = "" + idxName + " = " + stepPart;
|
2012-02-06 20:59:17 +00:00
|
|
|
return "" + varPart + "; " + condPart + "; " + stepPart;
|
|
|
|
};
|
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);
|
|
|
|
if (this.exclusive) range.pop();
|
2012-02-06 20:59:17 +00:00
|
|
|
return "[" + (range.join(', ')) + "]";
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
body = this.compileNode(o);
|
|
|
|
} 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) {
|
|
|
|
return node != null ? node.contains(function(n) {
|
|
|
|
return n instanceof Literal && n.value === 'arguments' && !n.asKey;
|
|
|
|
}) : void 0;
|
|
|
|
};
|
|
|
|
if (hasArgs(this.from) || hasArgs(this.to)) args = ', arguments';
|
|
|
|
return "(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);
|
|
|
|
|
|
|
|
Slice.name = 'Slice';
|
|
|
|
|
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) {
|
|
|
|
var compiled, from, fromStr, to, toStr, _ref2;
|
|
|
|
_ref2 = this.range, to = _ref2.to, from = _ref2.from;
|
|
|
|
fromStr = from && from.compile(o, LEVEL_PAREN) || '0';
|
|
|
|
compiled = to && to.compile(o, LEVEL_PAREN);
|
|
|
|
if (to && !(!this.range.exclusive && +compiled === -1)) {
|
2012-07-05 06:37:09 +00:00
|
|
|
toStr = ', ' + (this.range.exclusive ? compiled : SIMPLENUM.test(compiled) ? "" + (+compiled + 1) : (compiled = to.compile(o, LEVEL_ACCESS), "" + compiled + " + 1 || 9e9"));
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
return ".slice(" + fromStr + (toStr || '') + ")";
|
|
|
|
};
|
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);
|
|
|
|
|
|
|
|
Obj.name = 'Obj';
|
|
|
|
|
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
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Obj.prototype.children = ['properties'];
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Obj.prototype.compileNode = function(o) {
|
2012-07-05 06:37:09 +00:00
|
|
|
var i, idt, indent, join, lastNoncom, node, obj, prop, propName, propNames, props, _i, _j, _len, _len1, _ref2;
|
2012-02-06 20:59:17 +00:00
|
|
|
props = this.properties;
|
2012-07-05 06:37:09 +00:00
|
|
|
propNames = [];
|
|
|
|
_ref2 = this.properties;
|
|
|
|
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
|
|
|
prop = _ref2[_i];
|
|
|
|
if (prop.isComplex()) prop = prop.variable;
|
|
|
|
if (prop != null) {
|
|
|
|
propName = prop.unwrapAll().value.toString();
|
|
|
|
if (__indexOf.call(propNames, propName) >= 0) {
|
|
|
|
throw SyntaxError("multiple object literal properties named \"" + propName + "\"");
|
|
|
|
}
|
|
|
|
propNames.push(propName);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
if (!props.length) return (this.front ? '({})' : '{}');
|
2012-02-06 20:59:17 +00:00
|
|
|
if (this.generated) {
|
2012-07-05 06:37:09 +00:00
|
|
|
for (_j = 0, _len1 = props.length; _j < _len1; _j++) {
|
|
|
|
node = props[_j];
|
2012-02-06 20:59:17 +00:00
|
|
|
if (node instanceof Value) {
|
|
|
|
throw new Error('cannot have an implicit value in an implicit object');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
idt = o.indent += TAB;
|
|
|
|
lastNoncom = this.lastNonComment(this.properties);
|
|
|
|
props = (function() {
|
2012-07-05 06:37:09 +00:00
|
|
|
var _k, _len2, _results;
|
2012-02-06 20:59:17 +00:00
|
|
|
_results = [];
|
2012-07-05 06:37:09 +00:00
|
|
|
for (i = _k = 0, _len2 = props.length; _k < _len2; i = ++_k) {
|
2012-02-06 20:59:17 +00:00
|
|
|
prop = props[i];
|
|
|
|
join = i === props.length - 1 ? '' : prop === lastNoncom || prop instanceof Comment ? '\n' : ',\n';
|
|
|
|
indent = prop instanceof Comment ? '' : idt;
|
|
|
|
if (prop instanceof Value && prop["this"]) {
|
|
|
|
prop = new Assign(prop.properties[0].name, prop, 'object');
|
|
|
|
}
|
|
|
|
if (!(prop instanceof Comment)) {
|
2012-07-05 06:37:09 +00:00
|
|
|
if (!(prop instanceof Assign)) prop = new Assign(prop, prop, 'object');
|
2012-02-06 20:59:17 +00:00
|
|
|
(prop.variable.base || prop.variable).asKey = true;
|
|
|
|
}
|
|
|
|
_results.push(indent + prop.compile(o, LEVEL_TOP) + join);
|
|
|
|
}
|
|
|
|
return _results;
|
|
|
|
})();
|
|
|
|
props = props.join('');
|
|
|
|
obj = "{" + (props && '\n' + props + '\n' + this.tab) + "}";
|
|
|
|
if (this.front) {
|
|
|
|
return "(" + obj + ")";
|
|
|
|
} else {
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
};
|
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];
|
2012-07-05 06:37:09 +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);
|
|
|
|
|
|
|
|
Arr.name = 'Arr';
|
|
|
|
|
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.filterImplicitObjects = Call.prototype.filterImplicitObjects;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Arr.prototype.compileNode = function(o) {
|
|
|
|
var code, obj, objs;
|
2012-07-05 06:37:09 +00:00
|
|
|
if (!this.objects.length) return '[]';
|
2012-02-06 20:59:17 +00:00
|
|
|
o.indent += TAB;
|
|
|
|
objs = this.filterImplicitObjects(this.objects);
|
2012-07-05 06:37:09 +00:00
|
|
|
if (code = Splat.compileSplattedArray(o, objs)) return code;
|
2012-02-06 20:59:17 +00:00
|
|
|
code = ((function() {
|
|
|
|
var _i, _len, _results;
|
|
|
|
_results = [];
|
|
|
|
for (_i = 0, _len = objs.length; _i < _len; _i++) {
|
|
|
|
obj = objs[_i];
|
|
|
|
_results.push(obj.compile(o, LEVEL_LIST));
|
|
|
|
}
|
|
|
|
return _results;
|
|
|
|
})()).join(', ');
|
|
|
|
if (code.indexOf('\n') >= 0) {
|
|
|
|
return "[\n" + o.indent + code + "\n" + this.tab + "]";
|
|
|
|
} else {
|
|
|
|
return "[" + code + "]";
|
|
|
|
}
|
|
|
|
};
|
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];
|
2012-07-05 06:37:09 +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);
|
|
|
|
|
|
|
|
Class.name = 'Class';
|
|
|
|
|
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;
|
2012-07-05 06:37:09 +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) {
|
|
|
|
throw SyntaxError("variable name may not be " + decl);
|
|
|
|
}
|
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) {
|
2012-07-05 06:37:09 +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;
|
2012-07-05 06:37:09 +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) {
|
2012-07-05 06:37:09 +00:00
|
|
|
var bvar, lhs, _i, _len, _ref2, _results;
|
2012-02-06 20:59:17 +00:00
|
|
|
if (this.boundFuncs.length) {
|
|
|
|
_ref2 = this.boundFuncs;
|
|
|
|
_results = [];
|
|
|
|
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
|
|
|
bvar = _ref2[_i];
|
2012-07-05 06:37:09 +00:00
|
|
|
lhs = (new Value(new Literal("this"), [new Access(bvar)])).compile(o);
|
|
|
|
_results.push(this.ctor.body.unshift(new Literal("" + lhs + " = " + (utility('bind')) + "(" + lhs + ", this)")));
|
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
|
|
|
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) {
|
|
|
|
throw new Error('cannot define more than one constructor in a class');
|
|
|
|
}
|
|
|
|
if (func.bound) {
|
|
|
|
throw new Error('cannot define a constructor as a bound function');
|
|
|
|
}
|
|
|
|
if (func instanceof Code) {
|
|
|
|
assign = this.ctor = func;
|
|
|
|
} else {
|
|
|
|
this.externalCtor = o.scope.freeVariable('class');
|
|
|
|
assign = new Assign(new Literal(this.externalCtor), func);
|
|
|
|
}
|
|
|
|
} else {
|
2012-07-05 06:37:09 +00:00
|
|
|
if (assign.variable["this"]) {
|
|
|
|
func["static"] = true;
|
|
|
|
if (func.bound) func.context = name;
|
|
|
|
} 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) {
|
2012-07-05 06:37:09 +00:00
|
|
|
var _this = this;
|
|
|
|
return this.traverseChildren(false, function(child) {
|
|
|
|
var exps, i, node, _i, _len, _ref2;
|
|
|
|
if (child instanceof Class) return false;
|
2012-02-06 20:59:17 +00:00
|
|
|
if (child instanceof Block) {
|
|
|
|
_ref2 = exps = child.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
|
|
|
node = _ref2[i];
|
|
|
|
if (node instanceof Value && node.isObject(true)) {
|
2012-07-05 06:37:09 +00:00
|
|
|
exps[i] = _this.addProperties(node, name, o);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return child.expressions = exps = flatten(exps);
|
|
|
|
}
|
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.parent) {
|
|
|
|
this.ctor.body.push(new Literal("" + name + ".__super__.constructor.apply(this, arguments)"));
|
|
|
|
}
|
|
|
|
if (this.externalCtor) {
|
|
|
|
this.ctor.body.push(new Literal("" + this.externalCtor + ".apply(this, arguments)"));
|
|
|
|
}
|
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) {
|
2012-07-05 06:37:09 +00:00
|
|
|
var call, decl, klass, lname, name, params, _ref2;
|
2012-02-06 20:59:17 +00:00
|
|
|
decl = this.determineName();
|
2012-07-05 06:37:09 +00:00
|
|
|
name = decl || '_Class';
|
|
|
|
if (name.reserved) name = "_" + name;
|
2012-02-06 20:59:17 +00:00
|
|
|
lname = new Literal(name);
|
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);
|
2012-07-05 06:37:09 +00:00
|
|
|
this.body.spaced = true;
|
|
|
|
if (!(this.ctor instanceof Code)) this.body.expressions.unshift(this.ctor);
|
|
|
|
if (decl) {
|
|
|
|
this.body.expressions.unshift(new Assign(new Value(new Literal(name), [new Access(new Literal('name'))]), new Literal("'" + name + "'")));
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
this.body.expressions.push(lname);
|
2012-07-05 06:37:09 +00:00
|
|
|
(_ref2 = this.body.expressions).unshift.apply(_ref2, this.directives);
|
2012-02-06 20:59:17 +00:00
|
|
|
this.addBoundFunctions(o);
|
2012-07-05 06:37:09 +00:00
|
|
|
call = Closure.wrap(this.body);
|
|
|
|
if (this.parent) {
|
|
|
|
this.superClass = new Literal(o.scope.freeVariable('super', false));
|
|
|
|
this.body.expressions.unshift(new Extends(lname, this.superClass));
|
|
|
|
call.args.push(this.parent);
|
|
|
|
params = call.variable.params || call.variable.base.params;
|
|
|
|
params.push(new Param(this.superClass));
|
|
|
|
}
|
|
|
|
klass = new Parens(call, true);
|
|
|
|
if (this.variable) klass = new Assign(this.variable, klass);
|
2012-02-06 20:59:17 +00:00
|
|
|
return klass.compile(o);
|
|
|
|
};
|
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);
|
|
|
|
|
|
|
|
Assign.name = 'Assign';
|
|
|
|
|
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') {
|
|
|
|
throw SyntaxError("variable name may not be \"" + 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
|
|
|
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) {
|
2012-07-05 06:37:09 +00:00
|
|
|
var isValue, match, name, val, varBase, _ref2, _ref3, _ref4, _ref5;
|
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);
|
|
|
|
}
|
2012-07-05 06:37:09 +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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
name = this.variable.compile(o, LEVEL_LIST);
|
2012-07-05 06:37:09 +00:00
|
|
|
if (!this.context) {
|
|
|
|
if (!(varBase = this.variable.unwrapAll()).isAssignable()) {
|
|
|
|
throw SyntaxError("\"" + (this.variable.compile(o)) + "\" cannot be assigned.");
|
|
|
|
}
|
|
|
|
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))) {
|
2012-07-05 06:37:09 +00:00
|
|
|
if (match[1]) this.value.klass = match[1];
|
|
|
|
this.value.name = (_ref3 = (_ref4 = (_ref5 = match[2]) != null ? _ref5 : match[3]) != null ? _ref4 : match[4]) != null ? _ref3 : match[5];
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
val = this.value.compile(o, LEVEL_LIST);
|
2012-07-05 06:37:09 +00:00
|
|
|
if (this.context === 'object') return "" + name + ": " + val;
|
2012-02-06 20:59:17 +00:00
|
|
|
val = name + (" " + (this.context || '=') + " ") + val;
|
|
|
|
if (o.level <= LEVEL_LIST) {
|
|
|
|
return val;
|
|
|
|
} else {
|
|
|
|
return "(" + val + ")";
|
|
|
|
}
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Assign.prototype.compilePatternMatch = function(o) {
|
2012-07-05 06:37:09 +00:00
|
|
|
var acc, assigns, code, i, idx, isObject, ivar, name, obj, objects, olen, ref, rest, splat, top, val, value, vvar, _i, _len, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8;
|
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)) {
|
|
|
|
code = value.compile(o);
|
|
|
|
if (o.level >= LEVEL_OP) {
|
|
|
|
return "(" + code + ")";
|
|
|
|
} 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 {
|
|
|
|
if (obj.base instanceof Parens) {
|
2012-07-05 06:37:09 +00:00
|
|
|
_ref4 = new Value(obj.unwrapAll()).cacheReference(o), obj = _ref4[0], idx = _ref4[1];
|
2012-02-06 20:59:17 +00:00
|
|
|
} else {
|
|
|
|
idx = isObject ? obj["this"] ? obj.properties[0].name : obj : new Literal(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
acc = IDENTIFIER.test(idx.unwrap().value || 0);
|
|
|
|
value = new Value(value);
|
|
|
|
value.properties.push(new (acc ? Access : Index)(idx));
|
2012-07-05 06:37:09 +00:00
|
|
|
if (_ref5 = obj.unwrap().value, __indexOf.call(RESERVED, _ref5) >= 0) {
|
|
|
|
throw new SyntaxError("assignment to a reserved word: " + (obj.compile(o)) + " = " + (value.compile(o)));
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
return new Assign(obj, value, null, {
|
|
|
|
param: this.param
|
|
|
|
}).compile(o, LEVEL_TOP);
|
|
|
|
}
|
|
|
|
vvar = value.compile(o, LEVEL_LIST);
|
|
|
|
assigns = [];
|
|
|
|
splat = false;
|
|
|
|
if (!IDENTIFIER.test(vvar) || this.variable.assigns(vvar)) {
|
|
|
|
assigns.push("" + (ref = o.scope.freeVariable('ref')) + " = " + vvar);
|
|
|
|
vvar = ref;
|
|
|
|
}
|
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) {
|
2012-07-05 06:37:09 +00:00
|
|
|
_ref6 = obj, (_ref7 = _ref6.variable, idx = _ref7.base), obj = _ref6.value;
|
2012-02-06 20:59:17 +00:00
|
|
|
} else {
|
|
|
|
if (obj.base instanceof Parens) {
|
2012-07-05 06:37:09 +00:00
|
|
|
_ref8 = new Value(obj.unwrapAll()).cacheReference(o), obj = _ref8[0], idx = _ref8[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();
|
2012-02-06 20:59:17 +00:00
|
|
|
val = "" + olen + " <= " + vvar + ".length ? " + (utility('slice')) + ".call(" + vvar + ", " + i;
|
|
|
|
if (rest = olen - i - 1) {
|
|
|
|
ivar = o.scope.freeVariable('i');
|
|
|
|
val += ", " + ivar + " = " + vvar + ".length - " + rest + ") : (" + ivar + " = " + i + ", [])";
|
|
|
|
} 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) {
|
|
|
|
obj = obj.name.compile(o);
|
2012-07-05 06:37:09 +00:00
|
|
|
throw new SyntaxError("multiple splats are disallowed in an assignment: " + obj + "...");
|
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);
|
|
|
|
}
|
|
|
|
val = new Value(new Literal(vvar), [new (acc ? Access : Index)(idx)]);
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
if ((name != null) && __indexOf.call(RESERVED, name) >= 0) {
|
|
|
|
throw new SyntaxError("assignment to a reserved word: " + (obj.compile(o)) + " = " + (val.compile(o)));
|
|
|
|
}
|
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
|
|
|
|
}).compile(o, LEVEL_LIST));
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
if (!(top || this.subpattern)) assigns.push(vvar);
|
2012-02-06 20:59:17 +00:00
|
|
|
code = assigns.join(', ');
|
|
|
|
if (o.level < LEVEL_LIST) {
|
|
|
|
return code;
|
|
|
|
} else {
|
|
|
|
return "(" + code + ")";
|
|
|
|
}
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Assign.prototype.compileConditional = function(o) {
|
2012-07-05 06:37:09 +00:00
|
|
|
var left, right, _ref2;
|
|
|
|
_ref2 = this.variable.cacheReference(o), left = _ref2[0], right = _ref2[1];
|
|
|
|
if (left.base instanceof Literal && left.base.value !== "this" && !o.scope.check(left.base.value)) {
|
|
|
|
throw new Error("the variable \"" + left.base.value + "\" can't be assigned with " + this.context + " because it has not been defined.");
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
if (__indexOf.call(this.context, "?") >= 0) o.isExistentialEquals = true;
|
|
|
|
return new Op(this.context.slice(0, -1), left, new Assign(right, this.value, '=')).compile(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
|
|
|
Assign.prototype.compileSplice = function(o) {
|
|
|
|
var code, exclusive, from, fromDecl, fromRef, name, to, valDef, valRef, _ref2, _ref3, _ref4;
|
|
|
|
_ref2 = this.variable.properties.pop().range, from = _ref2.from, to = _ref2.to, exclusive = _ref2.exclusive;
|
|
|
|
name = this.variable.compile(o);
|
|
|
|
_ref3 = (from != null ? from.cache(o, LEVEL_OP) : void 0) || ['0', '0'], fromDecl = _ref3[0], fromRef = _ref3[1];
|
|
|
|
if (to) {
|
|
|
|
if ((from != null ? from.isSimpleNumber() : void 0) && to.isSimpleNumber()) {
|
|
|
|
to = +to.compile(o) - +fromRef;
|
2012-07-05 06:37:09 +00:00
|
|
|
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;
|
|
|
|
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];
|
|
|
|
code = "[].splice.apply(" + name + ", [" + fromDecl + ", " + to + "].concat(" + valDef + ")), " + valRef;
|
|
|
|
if (o.level > LEVEL_TOP) {
|
|
|
|
return "(" + code + ")";
|
|
|
|
} else {
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
};
|
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);
|
|
|
|
|
|
|
|
Code.name = 'Code';
|
|
|
|
|
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
|
|
|
if (this.bound) this.context = '_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
|
|
|
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
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Code.prototype.compileNode = function(o) {
|
2012-07-05 06:37:09 +00:00
|
|
|
var code, exprs, i, idt, lit, name, p, param, params, ref, splats, uniqs, val, wasEmpty, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _len5, _m, _n, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8;
|
2012-02-06 20:59:17 +00:00
|
|
|
o.scope = new Scope(o.scope, this.body, this);
|
|
|
|
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
|
|
|
_ref2 = this.paramNames();
|
2012-02-06 20:59:17 +00:00
|
|
|
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
2012-07-05 06:37:09 +00:00
|
|
|
name = _ref2[_i];
|
|
|
|
if (!o.scope.check(name)) o.scope.parameter(name);
|
|
|
|
}
|
|
|
|
_ref3 = this.params;
|
|
|
|
for (_j = 0, _len1 = _ref3.length; _j < _len1; _j++) {
|
|
|
|
param = _ref3[_j];
|
|
|
|
if (!param.splat) continue;
|
|
|
|
_ref4 = this.params;
|
|
|
|
for (_k = 0, _len2 = _ref4.length; _k < _len2; _k++) {
|
|
|
|
p = _ref4[_k];
|
|
|
|
if (p.name.value) o.scope.add(p.name.value, 'var', true);
|
|
|
|
}
|
|
|
|
splats = new Assign(new Value(new Arr((function() {
|
|
|
|
var _l, _len3, _ref5, _results;
|
|
|
|
_ref5 = this.params;
|
|
|
|
_results = [];
|
|
|
|
for (_l = 0, _len3 = _ref5.length; _l < _len3; _l++) {
|
|
|
|
p = _ref5[_l];
|
|
|
|
_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
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
_ref5 = this.params;
|
|
|
|
for (_l = 0, _len3 = _ref5.length; _l < _len3; _l++) {
|
|
|
|
param = _ref5[_l];
|
2012-02-06 20:59:17 +00:00
|
|
|
if (param.isComplex()) {
|
|
|
|
val = ref = param.asReference(o);
|
2012-07-05 06:37:09 +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));
|
|
|
|
}
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
if (!splats) params.push(ref);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
wasEmpty = this.body.isEmpty();
|
2012-07-05 06:37:09 +00:00
|
|
|
if (splats) exprs.unshift(splats);
|
2012-02-06 20:59:17 +00:00
|
|
|
if (exprs.length) {
|
2012-07-05 06:37:09 +00:00
|
|
|
(_ref6 = this.body.expressions).unshift.apply(_ref6, 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];
|
|
|
|
o.scope.parameter(params[i] = p.compile(o));
|
|
|
|
}
|
|
|
|
uniqs = [];
|
|
|
|
_ref7 = this.paramNames();
|
|
|
|
for (_n = 0, _len5 = _ref7.length; _n < _len5; _n++) {
|
|
|
|
name = _ref7[_n];
|
|
|
|
if (__indexOf.call(uniqs, name) >= 0) {
|
|
|
|
throw SyntaxError("multiple parameters named '" + name + "'");
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
uniqs.push(name);
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
if (!(wasEmpty || this.noReturn)) this.body.makeReturn();
|
|
|
|
if (this.bound) {
|
|
|
|
if ((_ref8 = o.scope.parent.method) != null ? _ref8.bound : void 0) {
|
|
|
|
this.bound = this.context = o.scope.parent.method.context;
|
|
|
|
} else if (!this["static"]) {
|
|
|
|
o.scope.parent.assign('_this', 'this');
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
idt = o.indent;
|
|
|
|
code = 'function';
|
2012-07-05 06:37:09 +00:00
|
|
|
if (this.ctor) code += ' ' + this.name;
|
|
|
|
code += '(' + params.join(', ') + ') {';
|
2012-02-06 20:59:17 +00:00
|
|
|
if (!this.body.isEmpty()) {
|
|
|
|
code += "\n" + (this.body.compileWithDeclarations(o)) + "\n" + this.tab;
|
|
|
|
}
|
|
|
|
code += '}';
|
2012-07-05 06:37:09 +00:00
|
|
|
if (this.ctor) return this.tab + code;
|
2012-02-06 20:59:17 +00:00
|
|
|
if (this.front || (o.level >= LEVEL_ACCESS)) {
|
|
|
|
return "(" + code + ")";
|
|
|
|
} else {
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
Code.prototype.paramNames = function() {
|
|
|
|
var names, param, _i, _len, _ref2;
|
|
|
|
names = [];
|
|
|
|
_ref2 = this.params;
|
|
|
|
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
|
|
|
param = _ref2[_i];
|
|
|
|
names.push.apply(names, param.names());
|
|
|
|
}
|
|
|
|
return names;
|
|
|
|
};
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
Param.name = 'Param';
|
|
|
|
|
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) {
|
|
|
|
throw SyntaxError("parameter name \"" + name + "\" is not allowed");
|
|
|
|
}
|
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
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Param.prototype.compile = function(o) {
|
|
|
|
return this.name.compile(o, LEVEL_LIST);
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Param.prototype.asReference = function(o) {
|
|
|
|
var node;
|
2012-07-05 06:37:09 +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);
|
2012-07-05 06:37:09 +00:00
|
|
|
if (this.splat) node = new Splat(node);
|
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
|
|
|
|
|
|
|
Param.prototype.names = function(name) {
|
|
|
|
var atParam, names, obj, _i, _len, _ref2;
|
|
|
|
if (name == null) name = this.name;
|
|
|
|
atParam = function(obj) {
|
|
|
|
var value;
|
|
|
|
value = obj.properties[0].name.value;
|
|
|
|
if (value.reserved) {
|
|
|
|
return [];
|
|
|
|
} else {
|
|
|
|
return [value];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
if (name instanceof Literal) return [name.value];
|
|
|
|
if (name instanceof Value) return atParam(name);
|
|
|
|
names = [];
|
|
|
|
_ref2 = name.objects;
|
|
|
|
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
|
|
|
obj = _ref2[_i];
|
|
|
|
if (obj instanceof Assign) {
|
|
|
|
names.push(obj.variable.base.value);
|
|
|
|
} else if (obj.isArray() || obj.isObject()) {
|
|
|
|
names.push.apply(names, this.names(obj.base));
|
|
|
|
} else if (obj["this"]) {
|
|
|
|
names.push.apply(names, atParam(obj));
|
|
|
|
} else {
|
|
|
|
names.push(obj.base.value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return names;
|
|
|
|
};
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
Splat.name = 'Splat';
|
|
|
|
|
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
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Splat.prototype.compile = function(o) {
|
|
|
|
if (this.index != null) {
|
|
|
|
return this.compileParam(o);
|
|
|
|
} else {
|
|
|
|
return this.name.compile(o);
|
|
|
|
}
|
|
|
|
};
|
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) {
|
2012-07-05 06:37:09 +00:00
|
|
|
var args, base, code, i, index, node, _i, _len;
|
2012-02-06 20:59:17 +00:00
|
|
|
index = -1;
|
|
|
|
while ((node = list[++index]) && !(node instanceof Splat)) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
if (index >= list.length) return '';
|
2012-02-06 20:59:17 +00:00
|
|
|
if (list.length === 1) {
|
|
|
|
code = list[0].compile(o, LEVEL_LIST);
|
2012-07-05 06:37:09 +00:00
|
|
|
if (apply) return code;
|
2012-02-06 20:59:17 +00:00
|
|
|
return "" + (utility('slice')) + ".call(" + code + ")";
|
|
|
|
}
|
|
|
|
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];
|
|
|
|
code = node.compile(o, LEVEL_LIST);
|
|
|
|
args[i] = node instanceof Splat ? "" + (utility('slice')) + ".call(" + code + ")" : "[" + code + "]";
|
|
|
|
}
|
|
|
|
if (index === 0) {
|
|
|
|
return args[0] + (".concat(" + (args.slice(1).join(', ')) + ")");
|
|
|
|
}
|
|
|
|
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];
|
2012-02-06 20:59:17 +00:00
|
|
|
_results.push(node.compile(o, LEVEL_LIST));
|
|
|
|
}
|
|
|
|
return _results;
|
|
|
|
})();
|
|
|
|
return "[" + (base.join(', ')) + "].concat(" + (args.join(', ')) + ")";
|
|
|
|
};
|
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);
|
|
|
|
|
|
|
|
While.name = 'While';
|
|
|
|
|
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() {
|
|
|
|
var expressions, node, _i, _len;
|
|
|
|
expressions = this.body.expressions;
|
2012-07-05 06:37:09 +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];
|
|
|
|
if (node.jumps({
|
|
|
|
loop: true
|
2012-07-05 06:37:09 +00:00
|
|
|
})) return node;
|
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) {
|
|
|
|
var body, code, rvar, set;
|
|
|
|
o.indent += TAB;
|
|
|
|
set = '';
|
|
|
|
body = this.body;
|
|
|
|
if (body.isEmpty()) {
|
|
|
|
body = '';
|
|
|
|
} 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 {
|
|
|
|
if (this.guard) body = Block.wrap([new If(this.guard, body)]);
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
body = "\n" + (body.compile(o, LEVEL_TOP)) + "\n" + this.tab;
|
|
|
|
}
|
|
|
|
code = set + this.tab + ("while (" + (this.condition.compile(o, LEVEL_PAREN)) + ") {" + body + "}");
|
2012-07-05 06:37:09 +00:00
|
|
|
if (this.returns) code += "\n" + this.tab + "return " + rvar + ";";
|
2012-02-06 20:59:17 +00:00
|
|
|
return code;
|
|
|
|
};
|
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);
|
|
|
|
|
|
|
|
Op.name = 'Op';
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
function Op(op, first, second, flip) {
|
2012-07-05 06:37:09 +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;
|
|
|
|
}
|
2012-07-05 06:37:09 +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;
|
2012-07-05 06:37:09 +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) {
|
|
|
|
var code, isChain, _ref2, _ref3;
|
|
|
|
isChain = this.isChainable() && this.first.isChainable();
|
|
|
|
if (!isChain) this.first.front = this.front;
|
|
|
|
if (this.operator === 'delete' && o.scope.check(this.first.unwrapAll().value)) {
|
|
|
|
throw SyntaxError('delete operand may not be argument or var');
|
|
|
|
}
|
|
|
|
if (((_ref2 = this.operator) === '--' || _ref2 === '++') && (_ref3 = this.first.unwrapAll().value, __indexOf.call(STRICT_PROSCRIBED, _ref3) >= 0)) {
|
|
|
|
throw SyntaxError('prefix increment/decrement may not have eval or arguments operand');
|
|
|
|
}
|
|
|
|
if (this.isUnary()) return this.compileUnary(o);
|
|
|
|
if (isChain) return this.compileChain(o);
|
|
|
|
if (this.operator === '?') return this.compileExistence(o);
|
2012-02-06 20:59:17 +00:00
|
|
|
code = this.first.compile(o, LEVEL_OP) + ' ' + this.operator + ' ' + this.second.compile(o, LEVEL_OP);
|
|
|
|
if (o.level <= LEVEL_OP) {
|
|
|
|
return code;
|
|
|
|
} else {
|
|
|
|
return "(" + code + ")";
|
|
|
|
}
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Op.prototype.compileChain = function(o) {
|
|
|
|
var code, fst, shared, _ref2;
|
|
|
|
_ref2 = this.first.second.cache(o), this.first.second = _ref2[0], shared = _ref2[1];
|
|
|
|
fst = this.first.compile(o, LEVEL_OP);
|
|
|
|
code = "" + fst + " " + (this.invert ? '&&' : '||') + " " + (shared.compile(o)) + " " + this.operator + " " + (this.second.compile(o, LEVEL_OP));
|
|
|
|
return "(" + code + ")";
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Op.prototype.compileExistence = function(o) {
|
|
|
|
var fst, ref;
|
2012-07-05 06:37:09 +00:00
|
|
|
if (this.first.isComplex() && o.level > LEVEL_TOP) {
|
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'
|
|
|
|
}).addElse(this.second).compile(o);
|
|
|
|
};
|
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;
|
|
|
|
if (o.level >= LEVEL_ACCESS) return (new Parens(this)).compile(o);
|
2012-02-06 20:59:17 +00:00
|
|
|
parts = [op = this.operator];
|
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) {
|
2012-02-06 20:59:17 +00:00
|
|
|
parts.push(' ');
|
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
parts.push(this.first.compile(o, LEVEL_OP));
|
2012-07-05 06:37:09 +00:00
|
|
|
if (this.flip) parts.reverse();
|
2012-02-06 20:59:17 +00:00
|
|
|
return parts.join('');
|
|
|
|
};
|
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);
|
|
|
|
|
|
|
|
In.name = 'In';
|
|
|
|
|
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];
|
2012-07-05 06:37:09 +00:00
|
|
|
if (!(obj instanceof Splat)) continue;
|
|
|
|
hasSplat = true;
|
|
|
|
break;
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
2012-07-05 06:37:09 +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) {
|
|
|
|
var cmp, cnj, i, item, ref, sub, tests, _ref2, _ref3;
|
2012-07-05 06:37:09 +00:00
|
|
|
if (this.array.base.objects.length === 0) return "" + (!!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];
|
|
|
|
tests = (function() {
|
2012-07-05 06:37:09 +00:00
|
|
|
var _i, _len, _ref4, _results;
|
2012-02-06 20:59:17 +00:00
|
|
|
_ref4 = this.array.base.objects;
|
|
|
|
_results = [];
|
2012-07-05 06:37:09 +00:00
|
|
|
for (i = _i = 0, _len = _ref4.length; _i < _len; i = ++_i) {
|
2012-02-06 20:59:17 +00:00
|
|
|
item = _ref4[i];
|
2012-07-05 06:37:09 +00:00
|
|
|
_results.push((i ? ref : sub) + cmp + item.compile(o, LEVEL_ACCESS));
|
2012-02-06 20:59:17 +00:00
|
|
|
}
|
|
|
|
return _results;
|
|
|
|
}).call(this);
|
|
|
|
tests = tests.join(cnj);
|
|
|
|
if (o.level < LEVEL_OP) {
|
|
|
|
return tests;
|
|
|
|
} else {
|
|
|
|
return "(" + tests + ")";
|
|
|
|
}
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
In.prototype.compileLoopTest = function(o) {
|
|
|
|
var code, ref, sub, _ref2;
|
|
|
|
_ref2 = this.object.cache(o, LEVEL_LIST), sub = _ref2[0], ref = _ref2[1];
|
|
|
|
code = utility('indexOf') + (".call(" + (this.array.compile(o, LEVEL_LIST)) + ", " + ref + ") ") + (this.negated ? '< 0' : '>= 0');
|
2012-07-05 06:37:09 +00:00
|
|
|
if (sub === ref) return code;
|
2012-02-06 20:59:17 +00:00
|
|
|
code = sub + ', ' + code;
|
|
|
|
if (o.level < LEVEL_LIST) {
|
|
|
|
return code;
|
|
|
|
} else {
|
|
|
|
return "(" + code + ")";
|
|
|
|
}
|
|
|
|
};
|
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);
|
|
|
|
|
|
|
|
Try.name = 'Try';
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
function Try(attempt, error, recovery, ensure) {
|
|
|
|
this.attempt = attempt;
|
|
|
|
this.error = error;
|
|
|
|
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) {
|
|
|
|
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) {
|
2012-07-05 06:37:09 +00:00
|
|
|
var catchPart, ensurePart, errorPart, tryPart;
|
2012-02-06 20:59:17 +00:00
|
|
|
o.indent += TAB;
|
|
|
|
errorPart = this.error ? " (" + (this.error.compile(o)) + ") " : ' ';
|
2012-07-05 06:37:09 +00:00
|
|
|
tryPart = this.attempt.compile(o, LEVEL_TOP);
|
|
|
|
catchPart = (function() {
|
|
|
|
var _ref2;
|
|
|
|
if (this.recovery) {
|
|
|
|
if (_ref2 = this.error.value, __indexOf.call(STRICT_PROSCRIBED, _ref2) >= 0) {
|
|
|
|
throw SyntaxError("catch variable may not be \"" + this.error.value + "\"");
|
|
|
|
}
|
|
|
|
if (!o.scope.check(this.error.value)) {
|
|
|
|
o.scope.add(this.error.value, 'param');
|
|
|
|
}
|
|
|
|
return " catch" + errorPart + "{\n" + (this.recovery.compile(o, LEVEL_TOP)) + "\n" + this.tab + "}";
|
|
|
|
} else if (!(this.ensure || this.recovery)) {
|
|
|
|
return ' catch (_error) {}';
|
|
|
|
}
|
|
|
|
}).call(this);
|
|
|
|
ensurePart = this.ensure ? " finally {\n" + (this.ensure.compile(o, LEVEL_TOP)) + "\n" + this.tab + "}" : '';
|
|
|
|
return "" + this.tab + "try {\n" + tryPart + "\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);
|
|
|
|
|
|
|
|
Throw.name = 'Throw';
|
|
|
|
|
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) {
|
|
|
|
return this.tab + ("throw " + (this.expression.compile(o)) + ";");
|
|
|
|
};
|
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);
|
|
|
|
|
|
|
|
Existence.name = 'Existence';
|
|
|
|
|
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";
|
|
|
|
}
|
2012-02-06 20:59:17 +00:00
|
|
|
if (o.level <= LEVEL_COND) {
|
|
|
|
return code;
|
|
|
|
} else {
|
|
|
|
return "(" + code + ")";
|
|
|
|
}
|
|
|
|
};
|
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);
|
|
|
|
|
|
|
|
Parens.name = 'Parens';
|
|
|
|
|
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) {
|
|
|
|
var bare, code, expr;
|
|
|
|
expr = this.body.unwrap();
|
|
|
|
if (expr instanceof Value && expr.isAtomic()) {
|
|
|
|
expr.front = this.front;
|
|
|
|
return expr.compile(o);
|
|
|
|
}
|
|
|
|
code = expr.compile(o, LEVEL_PAREN);
|
|
|
|
bare = o.level < LEVEL_OP && (expr instanceof Op || expr instanceof Call || (expr instanceof For && expr.returns));
|
|
|
|
if (bare) {
|
|
|
|
return code;
|
|
|
|
} else {
|
|
|
|
return "(" + code + ")";
|
|
|
|
}
|
|
|
|
};
|
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);
|
|
|
|
|
|
|
|
For.name = 'For';
|
|
|
|
|
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) {
|
|
|
|
throw SyntaxError('index cannot be a pattern matching expression');
|
|
|
|
}
|
|
|
|
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) {
|
|
|
|
throw SyntaxError('indexes do not apply to range loops');
|
|
|
|
}
|
|
|
|
if (this.range && this.pattern) {
|
|
|
|
throw SyntaxError('cannot pattern match over range loops');
|
|
|
|
}
|
|
|
|
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) {
|
2012-07-05 06:37:09 +00:00
|
|
|
var body, defPart, forPart, forVarPart, guardPart, idt1, index, ivar, kvar, kvarAssign, lastJumps, lvar, name, namePart, ref, resultPart, returnResult, rvar, scope, source, stepPart, stepvar, svar, varPart, _ref2;
|
2012-02-06 20:59:17 +00:00
|
|
|
body = Block.wrap([this.body]);
|
|
|
|
lastJumps = (_ref2 = last(body.expressions)) != null ? _ref2.jumps() : void 0;
|
2012-07-05 06:37:09 +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;
|
|
|
|
name = this.name && this.name.compile(o, LEVEL_LIST);
|
|
|
|
index = this.index && this.index.compile(o, LEVEL_LIST);
|
|
|
|
if (name && !this.pattern) {
|
|
|
|
scope.find(name, {
|
|
|
|
immediate: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (index) {
|
|
|
|
scope.find(index, {
|
|
|
|
immediate: true
|
|
|
|
});
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
if (this.returns) rvar = scope.freeVariable('results');
|
|
|
|
ivar = (this.object && index) || scope.freeVariable('i');
|
|
|
|
kvar = (this.range && name) || index || ivar;
|
|
|
|
kvarAssign = kvar !== ivar ? "" + kvar + " = " : "";
|
|
|
|
if (this.step && !this.range) stepvar = scope.freeVariable("step");
|
|
|
|
if (this.pattern) name = ivar;
|
2012-02-06 20:59:17 +00:00
|
|
|
varPart = '';
|
|
|
|
guardPart = '';
|
|
|
|
defPart = '';
|
|
|
|
idt1 = this.tab + TAB;
|
|
|
|
if (this.range) {
|
|
|
|
forPart = source.compile(merge(o, {
|
|
|
|
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)) {
|
|
|
|
defPart = "" + this.tab + (ref = scope.freeVariable('ref')) + " = " + svar + ";\n";
|
|
|
|
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) {
|
|
|
|
lvar = scope.freeVariable('len');
|
2012-07-05 06:37:09 +00:00
|
|
|
forVarPart = "" + kvarAssign + ivar + " = 0, " + lvar + " = " + svar + ".length";
|
|
|
|
if (this.step) {
|
|
|
|
forVarPart += ", " + stepvar + " = " + (this.step.compile(o, LEVEL_OP));
|
|
|
|
}
|
|
|
|
stepPart = "" + kvarAssign + (this.step ? "" + ivar + " += " + stepvar : (kvar !== ivar ? "++" + ivar : "" + ivar + "++"));
|
2012-02-06 20:59:17 +00:00
|
|
|
forPart = "" + forVarPart + "; " + ivar + " < " + lvar + "; " + stepPart;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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 {
|
|
|
|
if (this.guard) body = Block.wrap([new If(this.guard, body)]);
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
defPart += this.pluckDirectCall(o, body);
|
2012-07-05 06:37:09 +00:00
|
|
|
if (namePart) varPart = "\n" + idt1 + namePart + ";";
|
2012-02-06 20:59:17 +00:00
|
|
|
if (this.object) {
|
2012-07-05 06:37:09 +00:00
|
|
|
forPart = "" + 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
|
|
|
}
|
|
|
|
}
|
|
|
|
body = body.compile(merge(o, {
|
|
|
|
indent: idt1
|
|
|
|
}), LEVEL_TOP);
|
2012-07-05 06:37:09 +00:00
|
|
|
if (body) body = '\n' + body + '\n';
|
2012-02-06 20:59:17 +00:00
|
|
|
return "" + defPart + (resultPart || '') + this.tab + "for (" + forPart + ") {" + guardPart + varPart + body + this.tab + "}" + (returnResult || '');
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
For.prototype.pluckDirectCall = function(o, body) {
|
2012-07-05 06:37:09 +00:00
|
|
|
var base, defs, expr, fn, idx, ref, val, _i, _len, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7;
|
2012-02-06 20:59:17 +00:00
|
|
|
defs = '';
|
|
|
|
_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();
|
2012-07-05 06:37:09 +00:00
|
|
|
if (!(expr instanceof Call)) continue;
|
2012-02-06 20:59:17 +00:00
|
|
|
val = expr.variable.unwrapAll();
|
|
|
|
if (!((val instanceof Code) || (val instanceof Value && ((_ref3 = val.base) != null ? _ref3.unwrapAll() : void 0) instanceof Code && val.properties.length === 1 && ((_ref4 = (_ref5 = val.properties[0].name) != null ? _ref5.value : void 0) === 'call' || _ref4 === 'apply')))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
fn = ((_ref6 = val.base) != null ? _ref6.unwrapAll() : void 0) || val;
|
|
|
|
ref = new Literal(o.scope.freeVariable('fn'));
|
|
|
|
base = new Value(ref);
|
2012-07-05 06:37:09 +00:00
|
|
|
if (val.base) _ref7 = [base, val], val.base = _ref7[0], base = _ref7[1];
|
2012-02-06 20:59:17 +00:00
|
|
|
body.expressions[idx] = new Call(base, expr.args);
|
|
|
|
defs += this.tab + new Assign(ref, fn).compile(o, LEVEL_TOP) + ';\n';
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
|
|
|
|
Switch.name = 'Switch';
|
|
|
|
|
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) {
|
|
|
|
var block, conds, _i, _len, _ref2, _ref3, _ref4;
|
|
|
|
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];
|
2012-07-05 06:37:09 +00:00
|
|
|
if (block.jumps(o)) return block;
|
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
|
|
|
}
|
2012-07-05 06:37:09 +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) {
|
2012-07-05 06:37:09 +00:00
|
|
|
var block, body, code, cond, conditions, expr, i, idt1, idt2, _i, _j, _len, _len1, _ref2, _ref3, _ref4, _ref5;
|
2012-02-06 20:59:17 +00:00
|
|
|
idt1 = o.indent + TAB;
|
|
|
|
idt2 = o.indent = idt1 + TAB;
|
|
|
|
code = this.tab + ("switch (" + (((_ref2 = this.subject) != null ? _ref2.compile(o, LEVEL_PAREN) : void 0) || false) + ") {\n");
|
|
|
|
_ref3 = this.cases;
|
2012-07-05 06:37:09 +00:00
|
|
|
for (i = _i = 0, _len = _ref3.length; _i < _len; i = ++_i) {
|
2012-02-06 20:59:17 +00:00
|
|
|
_ref4 = _ref3[i], conditions = _ref4[0], block = _ref4[1];
|
|
|
|
_ref5 = flatten([conditions]);
|
2012-07-05 06:37:09 +00:00
|
|
|
for (_j = 0, _len1 = _ref5.length; _j < _len1; _j++) {
|
|
|
|
cond = _ref5[_j];
|
|
|
|
if (!this.subject) cond = cond.invert();
|
2012-02-06 20:59:17 +00:00
|
|
|
code += idt1 + ("case " + (cond.compile(o, LEVEL_PAREN)) + ":\n");
|
|
|
|
}
|
2012-07-05 06:37:09 +00:00
|
|
|
if (body = block.compile(o, LEVEL_TOP)) code += body + '\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;
|
|
|
|
}
|
|
|
|
code += idt2 + 'break;\n';
|
|
|
|
}
|
|
|
|
if (this.otherwise && this.otherwise.expressions.length) {
|
|
|
|
code += idt1 + ("default:\n" + (this.otherwise.compile(o, LEVEL_TOP)) + "\n");
|
|
|
|
}
|
|
|
|
return code + this.tab + '}';
|
|
|
|
};
|
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);
|
|
|
|
|
|
|
|
If.name = 'If';
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
function If(condition, body, options) {
|
|
|
|
this.body = body;
|
2012-07-05 06:37:09 +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);
|
|
|
|
}
|
|
|
|
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) {
|
2012-07-05 06:37:09 +00:00
|
|
|
var body, bodyc, child, cond, exeq, ifPart, _ref2;
|
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'
|
|
|
|
}).compile(o);
|
|
|
|
}
|
|
|
|
cond = this.condition.compile(o, LEVEL_PAREN);
|
|
|
|
o.indent += TAB;
|
2012-07-05 06:37:09 +00:00
|
|
|
body = this.ensureBlock(this.body);
|
|
|
|
bodyc = body.compile(o);
|
|
|
|
if (1 === ((_ref2 = body.expressions) != null ? _ref2.length : void 0) && !this.elseBody && !child && bodyc && cond && -1 === (bodyc.indexOf('\n')) && 80 > cond.length + bodyc.length) {
|
|
|
|
return "" + this.tab + "if (" + cond + ") " + (bodyc.replace(/^\s+/, ''));
|
|
|
|
}
|
|
|
|
if (bodyc) bodyc = "\n" + bodyc + "\n" + this.tab;
|
|
|
|
ifPart = "if (" + cond + ") {" + bodyc + "}";
|
|
|
|
if (!child) ifPart = this.tab + ifPart;
|
|
|
|
if (!this.elseBody) return ifPart;
|
2012-02-06 20:59:17 +00:00
|
|
|
return ifPart + ' else ' + (this.isChain ? (o.indent = this.tab, o.chainChild = true, this.elseBody.unwrap().compile(o, LEVEL_TOP)) : "{\n" + (this.elseBody.compile(o, LEVEL_TOP)) + "\n" + this.tab + "}");
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
If.prototype.compileExpression = function(o) {
|
|
|
|
var alt, body, code, cond;
|
|
|
|
cond = this.condition.compile(o, LEVEL_COND);
|
|
|
|
body = this.bodyNode().compile(o, LEVEL_LIST);
|
|
|
|
alt = this.elseBodyNode() ? this.elseBodyNode().compile(o, LEVEL_LIST) : 'void 0';
|
|
|
|
code = "" + cond + " ? " + body + " : " + alt;
|
|
|
|
if (o.level >= LEVEL_COND) {
|
|
|
|
return "(" + code + ")";
|
|
|
|
} else {
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
};
|
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
|
|
|
Closure = {
|
|
|
|
wrap: function(expressions, statement, noReturn) {
|
|
|
|
var args, call, func, mentionsArgs, meth;
|
2012-07-05 06:37:09 +00:00
|
|
|
if (expressions.jumps()) return expressions;
|
2012-02-06 20:59:17 +00:00
|
|
|
func = new Code([], Block.wrap([expressions]));
|
|
|
|
args = [];
|
|
|
|
if ((mentionsArgs = expressions.contains(this.literalArgs)) || expressions.contains(this.literalThis)) {
|
|
|
|
meth = new Literal(mentionsArgs ? 'apply' : 'call');
|
|
|
|
args = [new Literal('this')];
|
2012-07-05 06:37:09 +00:00
|
|
|
if (mentionsArgs) args.push(new Literal('arguments'));
|
2012-02-06 20:59:17 +00:00
|
|
|
func = new Value(func, [new Access(meth)]);
|
|
|
|
}
|
|
|
|
func.noReturn = noReturn;
|
|
|
|
call = new Call(func, args);
|
|
|
|
if (statement) {
|
|
|
|
return Block.wrap([call]);
|
|
|
|
} else {
|
|
|
|
return call;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
literalArgs: function(node) {
|
|
|
|
return node instanceof Literal && node.value === 'arguments' && !node.asKey;
|
|
|
|
},
|
|
|
|
literalThis: function(node) {
|
|
|
|
return (node instanceof Literal && node.value === 'this' && !node.asKey) || (node instanceof Code && node.bound);
|
|
|
|
}
|
|
|
|
};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
unfoldSoak = function(o, parent, name) {
|
|
|
|
var ifn;
|
2012-07-05 06:37:09 +00:00
|
|
|
if (!(ifn = parent[name].unfoldSoak(o))) return;
|
2012-02-06 20:59:17 +00:00
|
|
|
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
|
|
|
UTILITIES = {
|
2012-07-05 06:37:09 +00:00
|
|
|
"extends": function() {
|
|
|
|
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; }";
|
|
|
|
},
|
|
|
|
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
|
|
|
|
|
|
|
METHOD_DEF = RegExp("^(?:(" + IDENTIFIER_STR + ")\\.prototype(?:\\.(" + IDENTIFIER_STR + ")|\\[(\"(?:[^\\\\\"\\r\\n]|\\\\.)*\"|'(?:[^\\\\'\\r\\n]|\\\\.)*')\\]|\\[(0x[\\da-fA-F]+|\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\]))|(" + IDENTIFIER_STR + ")$");
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
IS_STRING = /^['"]/;
|
2012-07-05 06:37:09 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
// Generated by CoffeeScript 1.2.1-pre
|
|
|
|
|
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() {
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
Scope.name = 'Scope';
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
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 = {};
|
2012-07-05 06:37:09 +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) {
|
2012-07-05 06:37:09 +00:00
|
|
|
if (this.shared && !immediate) return this.parent.add(name, type, immediate);
|
|
|
|
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
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Scope.prototype.find = function(name, options) {
|
2012-07-05 06:37:09 +00:00
|
|
|
if (this.check(name, options)) 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) {
|
2012-07-05 06:37:09 +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
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
Scope.prototype.check = function(name, immediate) {
|
2012-07-05 06:37:09 +00:00
|
|
|
var found, _ref1;
|
2012-02-06 20:59:17 +00:00
|
|
|
found = !!this.type(name);
|
2012-07-05 06:37:09 +00:00
|
|
|
if (found || immediate) return found;
|
|
|
|
return !!((_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];
|
|
|
|
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;
|
2012-07-05 06:37:09 +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++;
|
|
|
|
}
|
2012-07-05 06:37:09 +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];
|
|
|
|
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
|
|
|
|
|
|
|
|
2012-02-06 20:59:17 +00:00
|
|
|
});
|