datagram 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.env.sample +7 -0
- data/.gitignore +20 -0
- data/.rbenv-version +1 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +22 -0
- data/Procfile +1 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/config.ru +5 -0
- data/datagram.gemspec +23 -0
- data/db/migrate/1_create_queries.rb +9 -0
- data/db/migrate/2_add_name_to_queries.rb +5 -0
- data/lib/datagram/version.rb +3 -0
- data/lib/datagram.rb +135 -0
- data/lib/views/application.coffee +222 -0
- data/lib/views/index.haml +47 -0
- data/lib/views/layout.haml +17 -0
- data/lib/views/style.sass +179 -0
- data/public/ace/ace.js +15209 -0
- data/public/ace/ext-elastic_tabstops_lite.js +301 -0
- data/public/ace/ext-emmet.js +253 -0
- data/public/ace/ext-searchbox.js +441 -0
- data/public/ace/ext-spellcheck.js +67 -0
- data/public/ace/ext-static_highlight.js +96 -0
- data/public/ace/ext-textarea.js +492 -0
- data/public/ace/ext-whitespace.js +204 -0
- data/public/ace/keybinding-emacs.js +962 -0
- data/public/ace/keybinding-vim.js +1704 -0
- data/public/ace/mode-abap.js +260 -0
- data/public/ace/mode-asciidoc.js +372 -0
- data/public/ace/mode-c9search.js +182 -0
- data/public/ace/mode-c_cpp.js +737 -0
- data/public/ace/mode-clojure.js +299 -0
- data/public/ace/mode-coffee.js +426 -0
- data/public/ace/mode-coldfusion.js +1753 -0
- data/public/ace/mode-csharp.js +612 -0
- data/public/ace/mode-css.js +773 -0
- data/public/ace/mode-curly.js +1950 -0
- data/public/ace/mode-dart.js +945 -0
- data/public/ace/mode-diff.js +166 -0
- data/public/ace/mode-django.js +1969 -0
- data/public/ace/mode-dot.js +320 -0
- data/public/ace/mode-ftl.js +907 -0
- data/public/ace/mode-glsl.js +810 -0
- data/public/ace/mode-golang.js +632 -0
- data/public/ace/mode-groovy.js +1037 -0
- data/public/ace/mode-haml.js +487 -0
- data/public/ace/mode-haxe.js +609 -0
- data/public/ace/mode-html.js +1881 -0
- data/public/ace/mode-jade.js +1951 -0
- data/public/ace/mode-java.js +996 -0
- data/public/ace/mode-javascript.js +876 -0
- data/public/ace/mode-json.js +578 -0
- data/public/ace/mode-jsp.js +1351 -0
- data/public/ace/mode-jsx.js +635 -0
- data/public/ace/mode-latex.js +189 -0
- data/public/ace/mode-less.js +807 -0
- data/public/ace/mode-liquid.js +862 -0
- data/public/ace/mode-lisp.js +138 -0
- data/public/ace/mode-livescript.js +288 -0
- data/public/ace/mode-logiql.js +664 -0
- data/public/ace/mode-lsl.js +828 -0
- data/public/ace/mode-lua.js +455 -0
- data/public/ace/mode-luapage.js +2340 -0
- data/public/ace/mode-lucene.js +64 -0
- data/public/ace/mode-makefile.js +313 -0
- data/public/ace/mode-markdown.js +2280 -0
- data/public/ace/mode-mushcode.js +704 -0
- data/public/ace/mode-mushcode_high_rules.js +569 -0
- data/public/ace/mode-objectivec.js +659 -0
- data/public/ace/mode-ocaml.js +443 -0
- data/public/ace/mode-pascal.js +233 -0
- data/public/ace/mode-perl.js +316 -0
- data/public/ace/mode-pgsql.js +908 -0
- data/public/ace/mode-php.js +2291 -0
- data/public/ace/mode-powershell.js +618 -0
- data/public/ace/mode-python.js +264 -0
- data/public/ace/mode-r.js +404 -0
- data/public/ace/mode-rdoc.js +184 -0
- data/public/ace/mode-rhtml.js +2168 -0
- data/public/ace/mode-ruby.js +431 -0
- data/public/ace/mode-sass.js +442 -0
- data/public/ace/mode-scad.js +670 -0
- data/public/ace/mode-scala.js +1025 -0
- data/public/ace/mode-scheme.js +144 -0
- data/public/ace/mode-scss.js +832 -0
- data/public/ace/mode-sh.js +204 -0
- data/public/ace/mode-sql.js +118 -0
- data/public/ace/mode-stylus.js +483 -0
- data/public/ace/mode-svg.js +1442 -0
- data/public/ace/mode-tcl.js +319 -0
- data/public/ace/mode-tex.js +166 -0
- data/public/ace/mode-text.js +0 -0
- data/public/ace/mode-textile.js +170 -0
- data/public/ace/mode-tmsnippet.js +200 -0
- data/public/ace/mode-toml.js +180 -0
- data/public/ace/mode-typescript.js +961 -0
- data/public/ace/mode-vbscript.js +281 -0
- data/public/ace/mode-velocity.js +962 -0
- data/public/ace/mode-xml.js +789 -0
- data/public/ace/mode-xquery.js +2750 -0
- data/public/ace/mode-yaml.js +289 -0
- data/public/ace/theme-ambiance.js +202 -0
- data/public/ace/theme-chaos.js +182 -0
- data/public/ace/theme-chrome.js +161 -0
- data/public/ace/theme-clouds.js +135 -0
- data/public/ace/theme-clouds_midnight.js +136 -0
- data/public/ace/theme-cobalt.js +150 -0
- data/public/ace/theme-crimson_editor.js +154 -0
- data/public/ace/theme-dawn.js +146 -0
- data/public/ace/theme-dreamweaver.js +173 -0
- data/public/ace/theme-eclipse.js +122 -0
- data/public/ace/theme-github.js +136 -0
- data/public/ace/theme-idle_fingers.js +136 -0
- data/public/ace/theme-kr.js +143 -0
- data/public/ace/theme-merbivore.js +135 -0
- data/public/ace/theme-merbivore_soft.js +136 -0
- data/public/ace/theme-mono_industrial.js +148 -0
- data/public/ace/theme-monokai.js +140 -0
- data/public/ace/theme-pastel_on_dark.js +148 -0
- data/public/ace/theme-solarized_dark.js +128 -0
- data/public/ace/theme-solarized_light.js +131 -0
- data/public/ace/theme-terminal.js +154 -0
- data/public/ace/theme-textmate.js +0 -0
- data/public/ace/theme-tomorrow.js +147 -0
- data/public/ace/theme-tomorrow_night.js +147 -0
- data/public/ace/theme-tomorrow_night_blue.js +145 -0
- data/public/ace/theme-tomorrow_night_bright.js +147 -0
- data/public/ace/theme-tomorrow_night_eighties.js +144 -0
- data/public/ace/theme-twilight.js +147 -0
- data/public/ace/theme-vibrant_ink.js +131 -0
- data/public/ace/theme-xcode.js +125 -0
- data/public/ace/worker-coffee.js +7091 -0
- data/public/ace/worker-css.js +8289 -0
- data/public/ace/worker-javascript.js +6496 -0
- data/public/ace/worker-json.js +2305 -0
- data/public/ace/worker-lua.js +3313 -0
- data/public/ace/worker-php.js +6743 -0
- data/public/ace/worker-xquery.js +21897 -0
- data/public/font/FontAwesome.otf +0 -0
- data/public/font/fontawesome-webfont.eot +0 -0
- data/public/font/fontawesome-webfont.svg +284 -0
- data/public/font/fontawesome-webfont.ttf +0 -0
- data/public/font/fontawesome-webfont.woff +0 -0
- data/public/font-awesome.css +540 -0
- data/public/jquery.js +9597 -0
- data/script/migrate.sh +2 -0
- metadata +242 -0
|
@@ -0,0 +1,3313 @@
|
|
|
1
|
+
"no use strict";
|
|
2
|
+
;(function(window) {
|
|
3
|
+
if (typeof window.window != "undefined" && window.document) {
|
|
4
|
+
return;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
window.console = {
|
|
8
|
+
log: function() {
|
|
9
|
+
var msgs = Array.prototype.slice.call(arguments, 0);
|
|
10
|
+
postMessage({type: "log", data: msgs});
|
|
11
|
+
},
|
|
12
|
+
error: function() {
|
|
13
|
+
var msgs = Array.prototype.slice.call(arguments, 0);
|
|
14
|
+
postMessage({type: "log", data: msgs});
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
window.window = window;
|
|
18
|
+
window.ace = window;
|
|
19
|
+
|
|
20
|
+
window.normalizeModule = function(parentId, moduleName) {
|
|
21
|
+
// normalize plugin requires
|
|
22
|
+
if (moduleName.indexOf("!") !== -1) {
|
|
23
|
+
var chunks = moduleName.split("!");
|
|
24
|
+
return normalizeModule(parentId, chunks[0]) + "!" + normalizeModule(parentId, chunks[1]);
|
|
25
|
+
}
|
|
26
|
+
// normalize relative requires
|
|
27
|
+
if (moduleName.charAt(0) == ".") {
|
|
28
|
+
var base = parentId.split("/").slice(0, -1).join("/");
|
|
29
|
+
moduleName = base + "/" + moduleName;
|
|
30
|
+
|
|
31
|
+
while(moduleName.indexOf(".") !== -1 && previous != moduleName) {
|
|
32
|
+
var previous = moduleName;
|
|
33
|
+
moduleName = moduleName.replace(/\/\.\//, "/").replace(/[^\/]+\/\.\.\//, "");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return moduleName;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
window.require = function(parentId, id) {
|
|
41
|
+
if (!id.charAt)
|
|
42
|
+
throw new Error("worker.js require() accepts only (parentId, id) as arguments");
|
|
43
|
+
|
|
44
|
+
id = normalizeModule(parentId, id);
|
|
45
|
+
|
|
46
|
+
var module = require.modules[id];
|
|
47
|
+
if (module) {
|
|
48
|
+
if (!module.initialized) {
|
|
49
|
+
module.initialized = true;
|
|
50
|
+
module.exports = module.factory().exports;
|
|
51
|
+
}
|
|
52
|
+
return module.exports;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
var chunks = id.split("/");
|
|
56
|
+
chunks[0] = require.tlns[chunks[0]] || chunks[0];
|
|
57
|
+
var path = chunks.join("/") + ".js";
|
|
58
|
+
|
|
59
|
+
require.id = id;
|
|
60
|
+
importScripts(path);
|
|
61
|
+
return require(parentId, id);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
require.modules = {};
|
|
65
|
+
require.tlns = {};
|
|
66
|
+
|
|
67
|
+
window.define = function(id, deps, factory) {
|
|
68
|
+
if (arguments.length == 2) {
|
|
69
|
+
factory = deps;
|
|
70
|
+
if (typeof id != "string") {
|
|
71
|
+
deps = id;
|
|
72
|
+
id = require.id;
|
|
73
|
+
}
|
|
74
|
+
} else if (arguments.length == 1) {
|
|
75
|
+
factory = id;
|
|
76
|
+
id = require.id;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (id.indexOf("text!") === 0)
|
|
80
|
+
return;
|
|
81
|
+
|
|
82
|
+
var req = function(deps, factory) {
|
|
83
|
+
return require(id, deps, factory);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
require.modules[id] = {
|
|
87
|
+
factory: function() {
|
|
88
|
+
var module = {
|
|
89
|
+
exports: {}
|
|
90
|
+
};
|
|
91
|
+
var returnExports = factory(req, module.exports, module);
|
|
92
|
+
if (returnExports)
|
|
93
|
+
module.exports = returnExports;
|
|
94
|
+
return module;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
window.initBaseUrls = function initBaseUrls(topLevelNamespaces) {
|
|
100
|
+
require.tlns = topLevelNamespaces;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
window.initSender = function initSender() {
|
|
104
|
+
|
|
105
|
+
var EventEmitter = require(null, "ace/lib/event_emitter").EventEmitter;
|
|
106
|
+
var oop = require(null, "ace/lib/oop");
|
|
107
|
+
|
|
108
|
+
var Sender = function() {};
|
|
109
|
+
|
|
110
|
+
(function() {
|
|
111
|
+
|
|
112
|
+
oop.implement(this, EventEmitter);
|
|
113
|
+
|
|
114
|
+
this.callback = function(data, callbackId) {
|
|
115
|
+
postMessage({
|
|
116
|
+
type: "call",
|
|
117
|
+
id: callbackId,
|
|
118
|
+
data: data
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
this.emit = function(name, data) {
|
|
123
|
+
postMessage({
|
|
124
|
+
type: "event",
|
|
125
|
+
name: name,
|
|
126
|
+
data: data
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
}).call(Sender.prototype);
|
|
131
|
+
|
|
132
|
+
return new Sender();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
window.main = null;
|
|
136
|
+
window.sender = null;
|
|
137
|
+
|
|
138
|
+
window.onmessage = function(e) {
|
|
139
|
+
var msg = e.data;
|
|
140
|
+
if (msg.command) {
|
|
141
|
+
if (main[msg.command])
|
|
142
|
+
main[msg.command].apply(main, msg.args);
|
|
143
|
+
else
|
|
144
|
+
throw new Error("Unknown command:" + msg.command);
|
|
145
|
+
}
|
|
146
|
+
else if (msg.init) {
|
|
147
|
+
initBaseUrls(msg.tlns);
|
|
148
|
+
require(null, "ace/lib/fixoldbrowsers");
|
|
149
|
+
sender = initSender();
|
|
150
|
+
var clazz = require(null, msg.module)[msg.classname];
|
|
151
|
+
main = new clazz(sender);
|
|
152
|
+
}
|
|
153
|
+
else if (msg.event && sender) {
|
|
154
|
+
sender._emit(msg.event, msg.data);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
})(this);// vim:set ts=4 sts=4 sw=4 st:
|
|
158
|
+
|
|
159
|
+
define('ace/lib/fixoldbrowsers', ['require', 'exports', 'module' , 'ace/lib/regexp', 'ace/lib/es5-shim'], function(require, exports, module) {
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
require("./regexp");
|
|
163
|
+
require("./es5-shim");
|
|
164
|
+
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
define('ace/lib/regexp', ['require', 'exports', 'module' ], function(require, exports, module) {
|
|
168
|
+
|
|
169
|
+
var real = {
|
|
170
|
+
exec: RegExp.prototype.exec,
|
|
171
|
+
test: RegExp.prototype.test,
|
|
172
|
+
match: String.prototype.match,
|
|
173
|
+
replace: String.prototype.replace,
|
|
174
|
+
split: String.prototype.split
|
|
175
|
+
},
|
|
176
|
+
compliantExecNpcg = real.exec.call(/()??/, "")[1] === undefined, // check `exec` handling of nonparticipating capturing groups
|
|
177
|
+
compliantLastIndexIncrement = function () {
|
|
178
|
+
var x = /^/g;
|
|
179
|
+
real.test.call(x, "");
|
|
180
|
+
return !x.lastIndex;
|
|
181
|
+
}();
|
|
182
|
+
|
|
183
|
+
if (compliantLastIndexIncrement && compliantExecNpcg)
|
|
184
|
+
return;
|
|
185
|
+
RegExp.prototype.exec = function (str) {
|
|
186
|
+
var match = real.exec.apply(this, arguments),
|
|
187
|
+
name, r2;
|
|
188
|
+
if ( typeof(str) == 'string' && match) {
|
|
189
|
+
if (!compliantExecNpcg && match.length > 1 && indexOf(match, "") > -1) {
|
|
190
|
+
r2 = RegExp(this.source, real.replace.call(getNativeFlags(this), "g", ""));
|
|
191
|
+
real.replace.call(str.slice(match.index), r2, function () {
|
|
192
|
+
for (var i = 1; i < arguments.length - 2; i++) {
|
|
193
|
+
if (arguments[i] === undefined)
|
|
194
|
+
match[i] = undefined;
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
if (this._xregexp && this._xregexp.captureNames) {
|
|
199
|
+
for (var i = 1; i < match.length; i++) {
|
|
200
|
+
name = this._xregexp.captureNames[i - 1];
|
|
201
|
+
if (name)
|
|
202
|
+
match[name] = match[i];
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
if (!compliantLastIndexIncrement && this.global && !match[0].length && (this.lastIndex > match.index))
|
|
206
|
+
this.lastIndex--;
|
|
207
|
+
}
|
|
208
|
+
return match;
|
|
209
|
+
};
|
|
210
|
+
if (!compliantLastIndexIncrement) {
|
|
211
|
+
RegExp.prototype.test = function (str) {
|
|
212
|
+
var match = real.exec.call(this, str);
|
|
213
|
+
if (match && this.global && !match[0].length && (this.lastIndex > match.index))
|
|
214
|
+
this.lastIndex--;
|
|
215
|
+
return !!match;
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function getNativeFlags (regex) {
|
|
220
|
+
return (regex.global ? "g" : "") +
|
|
221
|
+
(regex.ignoreCase ? "i" : "") +
|
|
222
|
+
(regex.multiline ? "m" : "") +
|
|
223
|
+
(regex.extended ? "x" : "") + // Proposed for ES4; included in AS3
|
|
224
|
+
(regex.sticky ? "y" : "");
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function indexOf (array, item, from) {
|
|
228
|
+
if (Array.prototype.indexOf) // Use the native array method if available
|
|
229
|
+
return array.indexOf(item, from);
|
|
230
|
+
for (var i = from || 0; i < array.length; i++) {
|
|
231
|
+
if (array[i] === item)
|
|
232
|
+
return i;
|
|
233
|
+
}
|
|
234
|
+
return -1;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
define('ace/lib/es5-shim', ['require', 'exports', 'module' ], function(require, exports, module) {
|
|
240
|
+
|
|
241
|
+
function Empty() {}
|
|
242
|
+
|
|
243
|
+
if (!Function.prototype.bind) {
|
|
244
|
+
Function.prototype.bind = function bind(that) { // .length is 1
|
|
245
|
+
var target = this;
|
|
246
|
+
if (typeof target != "function") {
|
|
247
|
+
throw new TypeError("Function.prototype.bind called on incompatible " + target);
|
|
248
|
+
}
|
|
249
|
+
var args = slice.call(arguments, 1); // for normal call
|
|
250
|
+
var bound = function () {
|
|
251
|
+
|
|
252
|
+
if (this instanceof bound) {
|
|
253
|
+
|
|
254
|
+
var result = target.apply(
|
|
255
|
+
this,
|
|
256
|
+
args.concat(slice.call(arguments))
|
|
257
|
+
);
|
|
258
|
+
if (Object(result) === result) {
|
|
259
|
+
return result;
|
|
260
|
+
}
|
|
261
|
+
return this;
|
|
262
|
+
|
|
263
|
+
} else {
|
|
264
|
+
return target.apply(
|
|
265
|
+
that,
|
|
266
|
+
args.concat(slice.call(arguments))
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
};
|
|
272
|
+
if(target.prototype) {
|
|
273
|
+
Empty.prototype = target.prototype;
|
|
274
|
+
bound.prototype = new Empty();
|
|
275
|
+
Empty.prototype = null;
|
|
276
|
+
}
|
|
277
|
+
return bound;
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
var call = Function.prototype.call;
|
|
281
|
+
var prototypeOfArray = Array.prototype;
|
|
282
|
+
var prototypeOfObject = Object.prototype;
|
|
283
|
+
var slice = prototypeOfArray.slice;
|
|
284
|
+
var _toString = call.bind(prototypeOfObject.toString);
|
|
285
|
+
var owns = call.bind(prototypeOfObject.hasOwnProperty);
|
|
286
|
+
var defineGetter;
|
|
287
|
+
var defineSetter;
|
|
288
|
+
var lookupGetter;
|
|
289
|
+
var lookupSetter;
|
|
290
|
+
var supportsAccessors;
|
|
291
|
+
if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) {
|
|
292
|
+
defineGetter = call.bind(prototypeOfObject.__defineGetter__);
|
|
293
|
+
defineSetter = call.bind(prototypeOfObject.__defineSetter__);
|
|
294
|
+
lookupGetter = call.bind(prototypeOfObject.__lookupGetter__);
|
|
295
|
+
lookupSetter = call.bind(prototypeOfObject.__lookupSetter__);
|
|
296
|
+
}
|
|
297
|
+
if ([1,2].splice(0).length != 2) {
|
|
298
|
+
if(function() { // test IE < 9 to splice bug - see issue #138
|
|
299
|
+
function makeArray(l) {
|
|
300
|
+
var a = new Array(l+2);
|
|
301
|
+
a[0] = a[1] = 0;
|
|
302
|
+
return a;
|
|
303
|
+
}
|
|
304
|
+
var array = [], lengthBefore;
|
|
305
|
+
|
|
306
|
+
array.splice.apply(array, makeArray(20));
|
|
307
|
+
array.splice.apply(array, makeArray(26));
|
|
308
|
+
|
|
309
|
+
lengthBefore = array.length; //46
|
|
310
|
+
array.splice(5, 0, "XXX"); // add one element
|
|
311
|
+
|
|
312
|
+
lengthBefore + 1 == array.length
|
|
313
|
+
|
|
314
|
+
if (lengthBefore + 1 == array.length) {
|
|
315
|
+
return true;// has right splice implementation without bugs
|
|
316
|
+
}
|
|
317
|
+
}()) {//IE 6/7
|
|
318
|
+
var array_splice = Array.prototype.splice;
|
|
319
|
+
Array.prototype.splice = function(start, deleteCount) {
|
|
320
|
+
if (!arguments.length) {
|
|
321
|
+
return [];
|
|
322
|
+
} else {
|
|
323
|
+
return array_splice.apply(this, [
|
|
324
|
+
start === void 0 ? 0 : start,
|
|
325
|
+
deleteCount === void 0 ? (this.length - start) : deleteCount
|
|
326
|
+
].concat(slice.call(arguments, 2)))
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
} else {//IE8
|
|
330
|
+
Array.prototype.splice = function(pos, removeCount){
|
|
331
|
+
var length = this.length;
|
|
332
|
+
if (pos > 0) {
|
|
333
|
+
if (pos > length)
|
|
334
|
+
pos = length;
|
|
335
|
+
} else if (pos == void 0) {
|
|
336
|
+
pos = 0;
|
|
337
|
+
} else if (pos < 0) {
|
|
338
|
+
pos = Math.max(length + pos, 0);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
if (!(pos+removeCount < length))
|
|
342
|
+
removeCount = length - pos;
|
|
343
|
+
|
|
344
|
+
var removed = this.slice(pos, pos+removeCount);
|
|
345
|
+
var insert = slice.call(arguments, 2);
|
|
346
|
+
var add = insert.length;
|
|
347
|
+
if (pos === length) {
|
|
348
|
+
if (add) {
|
|
349
|
+
this.push.apply(this, insert);
|
|
350
|
+
}
|
|
351
|
+
} else {
|
|
352
|
+
var remove = Math.min(removeCount, length - pos);
|
|
353
|
+
var tailOldPos = pos + remove;
|
|
354
|
+
var tailNewPos = tailOldPos + add - remove;
|
|
355
|
+
var tailCount = length - tailOldPos;
|
|
356
|
+
var lengthAfterRemove = length - remove;
|
|
357
|
+
|
|
358
|
+
if (tailNewPos < tailOldPos) { // case A
|
|
359
|
+
for (var i = 0; i < tailCount; ++i) {
|
|
360
|
+
this[tailNewPos+i] = this[tailOldPos+i];
|
|
361
|
+
}
|
|
362
|
+
} else if (tailNewPos > tailOldPos) { // case B
|
|
363
|
+
for (i = tailCount; i--; ) {
|
|
364
|
+
this[tailNewPos+i] = this[tailOldPos+i];
|
|
365
|
+
}
|
|
366
|
+
} // else, add == remove (nothing to do)
|
|
367
|
+
|
|
368
|
+
if (add && pos === lengthAfterRemove) {
|
|
369
|
+
this.length = lengthAfterRemove; // truncate array
|
|
370
|
+
this.push.apply(this, insert);
|
|
371
|
+
} else {
|
|
372
|
+
this.length = lengthAfterRemove + add; // reserves space
|
|
373
|
+
for (i = 0; i < add; ++i) {
|
|
374
|
+
this[pos+i] = insert[i];
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
return removed;
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
if (!Array.isArray) {
|
|
383
|
+
Array.isArray = function isArray(obj) {
|
|
384
|
+
return _toString(obj) == "[object Array]";
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
var boxedString = Object("a"),
|
|
388
|
+
splitString = boxedString[0] != "a" || !(0 in boxedString);
|
|
389
|
+
|
|
390
|
+
if (!Array.prototype.forEach) {
|
|
391
|
+
Array.prototype.forEach = function forEach(fun /*, thisp*/) {
|
|
392
|
+
var object = toObject(this),
|
|
393
|
+
self = splitString && _toString(this) == "[object String]" ?
|
|
394
|
+
this.split("") :
|
|
395
|
+
object,
|
|
396
|
+
thisp = arguments[1],
|
|
397
|
+
i = -1,
|
|
398
|
+
length = self.length >>> 0;
|
|
399
|
+
if (_toString(fun) != "[object Function]") {
|
|
400
|
+
throw new TypeError(); // TODO message
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
while (++i < length) {
|
|
404
|
+
if (i in self) {
|
|
405
|
+
fun.call(thisp, self[i], i, object);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
if (!Array.prototype.map) {
|
|
411
|
+
Array.prototype.map = function map(fun /*, thisp*/) {
|
|
412
|
+
var object = toObject(this),
|
|
413
|
+
self = splitString && _toString(this) == "[object String]" ?
|
|
414
|
+
this.split("") :
|
|
415
|
+
object,
|
|
416
|
+
length = self.length >>> 0,
|
|
417
|
+
result = Array(length),
|
|
418
|
+
thisp = arguments[1];
|
|
419
|
+
if (_toString(fun) != "[object Function]") {
|
|
420
|
+
throw new TypeError(fun + " is not a function");
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
for (var i = 0; i < length; i++) {
|
|
424
|
+
if (i in self)
|
|
425
|
+
result[i] = fun.call(thisp, self[i], i, object);
|
|
426
|
+
}
|
|
427
|
+
return result;
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
if (!Array.prototype.filter) {
|
|
431
|
+
Array.prototype.filter = function filter(fun /*, thisp */) {
|
|
432
|
+
var object = toObject(this),
|
|
433
|
+
self = splitString && _toString(this) == "[object String]" ?
|
|
434
|
+
this.split("") :
|
|
435
|
+
object,
|
|
436
|
+
length = self.length >>> 0,
|
|
437
|
+
result = [],
|
|
438
|
+
value,
|
|
439
|
+
thisp = arguments[1];
|
|
440
|
+
if (_toString(fun) != "[object Function]") {
|
|
441
|
+
throw new TypeError(fun + " is not a function");
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
for (var i = 0; i < length; i++) {
|
|
445
|
+
if (i in self) {
|
|
446
|
+
value = self[i];
|
|
447
|
+
if (fun.call(thisp, value, i, object)) {
|
|
448
|
+
result.push(value);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
return result;
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
if (!Array.prototype.every) {
|
|
456
|
+
Array.prototype.every = function every(fun /*, thisp */) {
|
|
457
|
+
var object = toObject(this),
|
|
458
|
+
self = splitString && _toString(this) == "[object String]" ?
|
|
459
|
+
this.split("") :
|
|
460
|
+
object,
|
|
461
|
+
length = self.length >>> 0,
|
|
462
|
+
thisp = arguments[1];
|
|
463
|
+
if (_toString(fun) != "[object Function]") {
|
|
464
|
+
throw new TypeError(fun + " is not a function");
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
for (var i = 0; i < length; i++) {
|
|
468
|
+
if (i in self && !fun.call(thisp, self[i], i, object)) {
|
|
469
|
+
return false;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
return true;
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
if (!Array.prototype.some) {
|
|
476
|
+
Array.prototype.some = function some(fun /*, thisp */) {
|
|
477
|
+
var object = toObject(this),
|
|
478
|
+
self = splitString && _toString(this) == "[object String]" ?
|
|
479
|
+
this.split("") :
|
|
480
|
+
object,
|
|
481
|
+
length = self.length >>> 0,
|
|
482
|
+
thisp = arguments[1];
|
|
483
|
+
if (_toString(fun) != "[object Function]") {
|
|
484
|
+
throw new TypeError(fun + " is not a function");
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
for (var i = 0; i < length; i++) {
|
|
488
|
+
if (i in self && fun.call(thisp, self[i], i, object)) {
|
|
489
|
+
return true;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
return false;
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
if (!Array.prototype.reduce) {
|
|
496
|
+
Array.prototype.reduce = function reduce(fun /*, initial*/) {
|
|
497
|
+
var object = toObject(this),
|
|
498
|
+
self = splitString && _toString(this) == "[object String]" ?
|
|
499
|
+
this.split("") :
|
|
500
|
+
object,
|
|
501
|
+
length = self.length >>> 0;
|
|
502
|
+
if (_toString(fun) != "[object Function]") {
|
|
503
|
+
throw new TypeError(fun + " is not a function");
|
|
504
|
+
}
|
|
505
|
+
if (!length && arguments.length == 1) {
|
|
506
|
+
throw new TypeError("reduce of empty array with no initial value");
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
var i = 0;
|
|
510
|
+
var result;
|
|
511
|
+
if (arguments.length >= 2) {
|
|
512
|
+
result = arguments[1];
|
|
513
|
+
} else {
|
|
514
|
+
do {
|
|
515
|
+
if (i in self) {
|
|
516
|
+
result = self[i++];
|
|
517
|
+
break;
|
|
518
|
+
}
|
|
519
|
+
if (++i >= length) {
|
|
520
|
+
throw new TypeError("reduce of empty array with no initial value");
|
|
521
|
+
}
|
|
522
|
+
} while (true);
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
for (; i < length; i++) {
|
|
526
|
+
if (i in self) {
|
|
527
|
+
result = fun.call(void 0, result, self[i], i, object);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
return result;
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
if (!Array.prototype.reduceRight) {
|
|
535
|
+
Array.prototype.reduceRight = function reduceRight(fun /*, initial*/) {
|
|
536
|
+
var object = toObject(this),
|
|
537
|
+
self = splitString && _toString(this) == "[object String]" ?
|
|
538
|
+
this.split("") :
|
|
539
|
+
object,
|
|
540
|
+
length = self.length >>> 0;
|
|
541
|
+
if (_toString(fun) != "[object Function]") {
|
|
542
|
+
throw new TypeError(fun + " is not a function");
|
|
543
|
+
}
|
|
544
|
+
if (!length && arguments.length == 1) {
|
|
545
|
+
throw new TypeError("reduceRight of empty array with no initial value");
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
var result, i = length - 1;
|
|
549
|
+
if (arguments.length >= 2) {
|
|
550
|
+
result = arguments[1];
|
|
551
|
+
} else {
|
|
552
|
+
do {
|
|
553
|
+
if (i in self) {
|
|
554
|
+
result = self[i--];
|
|
555
|
+
break;
|
|
556
|
+
}
|
|
557
|
+
if (--i < 0) {
|
|
558
|
+
throw new TypeError("reduceRight of empty array with no initial value");
|
|
559
|
+
}
|
|
560
|
+
} while (true);
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
do {
|
|
564
|
+
if (i in this) {
|
|
565
|
+
result = fun.call(void 0, result, self[i], i, object);
|
|
566
|
+
}
|
|
567
|
+
} while (i--);
|
|
568
|
+
|
|
569
|
+
return result;
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
if (!Array.prototype.indexOf || ([0, 1].indexOf(1, 2) != -1)) {
|
|
573
|
+
Array.prototype.indexOf = function indexOf(sought /*, fromIndex */ ) {
|
|
574
|
+
var self = splitString && _toString(this) == "[object String]" ?
|
|
575
|
+
this.split("") :
|
|
576
|
+
toObject(this),
|
|
577
|
+
length = self.length >>> 0;
|
|
578
|
+
|
|
579
|
+
if (!length) {
|
|
580
|
+
return -1;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
var i = 0;
|
|
584
|
+
if (arguments.length > 1) {
|
|
585
|
+
i = toInteger(arguments[1]);
|
|
586
|
+
}
|
|
587
|
+
i = i >= 0 ? i : Math.max(0, length + i);
|
|
588
|
+
for (; i < length; i++) {
|
|
589
|
+
if (i in self && self[i] === sought) {
|
|
590
|
+
return i;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
return -1;
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
if (!Array.prototype.lastIndexOf || ([0, 1].lastIndexOf(0, -3) != -1)) {
|
|
597
|
+
Array.prototype.lastIndexOf = function lastIndexOf(sought /*, fromIndex */) {
|
|
598
|
+
var self = splitString && _toString(this) == "[object String]" ?
|
|
599
|
+
this.split("") :
|
|
600
|
+
toObject(this),
|
|
601
|
+
length = self.length >>> 0;
|
|
602
|
+
|
|
603
|
+
if (!length) {
|
|
604
|
+
return -1;
|
|
605
|
+
}
|
|
606
|
+
var i = length - 1;
|
|
607
|
+
if (arguments.length > 1) {
|
|
608
|
+
i = Math.min(i, toInteger(arguments[1]));
|
|
609
|
+
}
|
|
610
|
+
i = i >= 0 ? i : length - Math.abs(i);
|
|
611
|
+
for (; i >= 0; i--) {
|
|
612
|
+
if (i in self && sought === self[i]) {
|
|
613
|
+
return i;
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
return -1;
|
|
617
|
+
};
|
|
618
|
+
}
|
|
619
|
+
if (!Object.getPrototypeOf) {
|
|
620
|
+
Object.getPrototypeOf = function getPrototypeOf(object) {
|
|
621
|
+
return object.__proto__ || (
|
|
622
|
+
object.constructor ?
|
|
623
|
+
object.constructor.prototype :
|
|
624
|
+
prototypeOfObject
|
|
625
|
+
);
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
if (!Object.getOwnPropertyDescriptor) {
|
|
629
|
+
var ERR_NON_OBJECT = "Object.getOwnPropertyDescriptor called on a " +
|
|
630
|
+
"non-object: ";
|
|
631
|
+
Object.getOwnPropertyDescriptor = function getOwnPropertyDescriptor(object, property) {
|
|
632
|
+
if ((typeof object != "object" && typeof object != "function") || object === null)
|
|
633
|
+
throw new TypeError(ERR_NON_OBJECT + object);
|
|
634
|
+
if (!owns(object, property))
|
|
635
|
+
return;
|
|
636
|
+
|
|
637
|
+
var descriptor, getter, setter;
|
|
638
|
+
descriptor = { enumerable: true, configurable: true };
|
|
639
|
+
if (supportsAccessors) {
|
|
640
|
+
var prototype = object.__proto__;
|
|
641
|
+
object.__proto__ = prototypeOfObject;
|
|
642
|
+
|
|
643
|
+
var getter = lookupGetter(object, property);
|
|
644
|
+
var setter = lookupSetter(object, property);
|
|
645
|
+
object.__proto__ = prototype;
|
|
646
|
+
|
|
647
|
+
if (getter || setter) {
|
|
648
|
+
if (getter) descriptor.get = getter;
|
|
649
|
+
if (setter) descriptor.set = setter;
|
|
650
|
+
return descriptor;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
descriptor.value = object[property];
|
|
654
|
+
return descriptor;
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
if (!Object.getOwnPropertyNames) {
|
|
658
|
+
Object.getOwnPropertyNames = function getOwnPropertyNames(object) {
|
|
659
|
+
return Object.keys(object);
|
|
660
|
+
};
|
|
661
|
+
}
|
|
662
|
+
if (!Object.create) {
|
|
663
|
+
var createEmpty;
|
|
664
|
+
if (Object.prototype.__proto__ === null) {
|
|
665
|
+
createEmpty = function () {
|
|
666
|
+
return { "__proto__": null };
|
|
667
|
+
};
|
|
668
|
+
} else {
|
|
669
|
+
createEmpty = function () {
|
|
670
|
+
var empty = {};
|
|
671
|
+
for (var i in empty)
|
|
672
|
+
empty[i] = null;
|
|
673
|
+
empty.constructor =
|
|
674
|
+
empty.hasOwnProperty =
|
|
675
|
+
empty.propertyIsEnumerable =
|
|
676
|
+
empty.isPrototypeOf =
|
|
677
|
+
empty.toLocaleString =
|
|
678
|
+
empty.toString =
|
|
679
|
+
empty.valueOf =
|
|
680
|
+
empty.__proto__ = null;
|
|
681
|
+
return empty;
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
Object.create = function create(prototype, properties) {
|
|
686
|
+
var object;
|
|
687
|
+
if (prototype === null) {
|
|
688
|
+
object = createEmpty();
|
|
689
|
+
} else {
|
|
690
|
+
if (typeof prototype != "object")
|
|
691
|
+
throw new TypeError("typeof prototype["+(typeof prototype)+"] != 'object'");
|
|
692
|
+
var Type = function () {};
|
|
693
|
+
Type.prototype = prototype;
|
|
694
|
+
object = new Type();
|
|
695
|
+
object.__proto__ = prototype;
|
|
696
|
+
}
|
|
697
|
+
if (properties !== void 0)
|
|
698
|
+
Object.defineProperties(object, properties);
|
|
699
|
+
return object;
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
function doesDefinePropertyWork(object) {
|
|
704
|
+
try {
|
|
705
|
+
Object.defineProperty(object, "sentinel", {});
|
|
706
|
+
return "sentinel" in object;
|
|
707
|
+
} catch (exception) {
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
if (Object.defineProperty) {
|
|
711
|
+
var definePropertyWorksOnObject = doesDefinePropertyWork({});
|
|
712
|
+
var definePropertyWorksOnDom = typeof document == "undefined" ||
|
|
713
|
+
doesDefinePropertyWork(document.createElement("div"));
|
|
714
|
+
if (!definePropertyWorksOnObject || !definePropertyWorksOnDom) {
|
|
715
|
+
var definePropertyFallback = Object.defineProperty;
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
if (!Object.defineProperty || definePropertyFallback) {
|
|
720
|
+
var ERR_NON_OBJECT_DESCRIPTOR = "Property description must be an object: ";
|
|
721
|
+
var ERR_NON_OBJECT_TARGET = "Object.defineProperty called on non-object: "
|
|
722
|
+
var ERR_ACCESSORS_NOT_SUPPORTED = "getters & setters can not be defined " +
|
|
723
|
+
"on this javascript engine";
|
|
724
|
+
|
|
725
|
+
Object.defineProperty = function defineProperty(object, property, descriptor) {
|
|
726
|
+
if ((typeof object != "object" && typeof object != "function") || object === null)
|
|
727
|
+
throw new TypeError(ERR_NON_OBJECT_TARGET + object);
|
|
728
|
+
if ((typeof descriptor != "object" && typeof descriptor != "function") || descriptor === null)
|
|
729
|
+
throw new TypeError(ERR_NON_OBJECT_DESCRIPTOR + descriptor);
|
|
730
|
+
if (definePropertyFallback) {
|
|
731
|
+
try {
|
|
732
|
+
return definePropertyFallback.call(Object, object, property, descriptor);
|
|
733
|
+
} catch (exception) {
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
if (owns(descriptor, "value")) {
|
|
737
|
+
|
|
738
|
+
if (supportsAccessors && (lookupGetter(object, property) ||
|
|
739
|
+
lookupSetter(object, property)))
|
|
740
|
+
{
|
|
741
|
+
var prototype = object.__proto__;
|
|
742
|
+
object.__proto__ = prototypeOfObject;
|
|
743
|
+
delete object[property];
|
|
744
|
+
object[property] = descriptor.value;
|
|
745
|
+
object.__proto__ = prototype;
|
|
746
|
+
} else {
|
|
747
|
+
object[property] = descriptor.value;
|
|
748
|
+
}
|
|
749
|
+
} else {
|
|
750
|
+
if (!supportsAccessors)
|
|
751
|
+
throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
|
|
752
|
+
if (owns(descriptor, "get"))
|
|
753
|
+
defineGetter(object, property, descriptor.get);
|
|
754
|
+
if (owns(descriptor, "set"))
|
|
755
|
+
defineSetter(object, property, descriptor.set);
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
return object;
|
|
759
|
+
};
|
|
760
|
+
}
|
|
761
|
+
if (!Object.defineProperties) {
|
|
762
|
+
Object.defineProperties = function defineProperties(object, properties) {
|
|
763
|
+
for (var property in properties) {
|
|
764
|
+
if (owns(properties, property))
|
|
765
|
+
Object.defineProperty(object, property, properties[property]);
|
|
766
|
+
}
|
|
767
|
+
return object;
|
|
768
|
+
};
|
|
769
|
+
}
|
|
770
|
+
if (!Object.seal) {
|
|
771
|
+
Object.seal = function seal(object) {
|
|
772
|
+
return object;
|
|
773
|
+
};
|
|
774
|
+
}
|
|
775
|
+
if (!Object.freeze) {
|
|
776
|
+
Object.freeze = function freeze(object) {
|
|
777
|
+
return object;
|
|
778
|
+
};
|
|
779
|
+
}
|
|
780
|
+
try {
|
|
781
|
+
Object.freeze(function () {});
|
|
782
|
+
} catch (exception) {
|
|
783
|
+
Object.freeze = (function freeze(freezeObject) {
|
|
784
|
+
return function freeze(object) {
|
|
785
|
+
if (typeof object == "function") {
|
|
786
|
+
return object;
|
|
787
|
+
} else {
|
|
788
|
+
return freezeObject(object);
|
|
789
|
+
}
|
|
790
|
+
};
|
|
791
|
+
})(Object.freeze);
|
|
792
|
+
}
|
|
793
|
+
if (!Object.preventExtensions) {
|
|
794
|
+
Object.preventExtensions = function preventExtensions(object) {
|
|
795
|
+
return object;
|
|
796
|
+
};
|
|
797
|
+
}
|
|
798
|
+
if (!Object.isSealed) {
|
|
799
|
+
Object.isSealed = function isSealed(object) {
|
|
800
|
+
return false;
|
|
801
|
+
};
|
|
802
|
+
}
|
|
803
|
+
if (!Object.isFrozen) {
|
|
804
|
+
Object.isFrozen = function isFrozen(object) {
|
|
805
|
+
return false;
|
|
806
|
+
};
|
|
807
|
+
}
|
|
808
|
+
if (!Object.isExtensible) {
|
|
809
|
+
Object.isExtensible = function isExtensible(object) {
|
|
810
|
+
if (Object(object) === object) {
|
|
811
|
+
throw new TypeError(); // TODO message
|
|
812
|
+
}
|
|
813
|
+
var name = '';
|
|
814
|
+
while (owns(object, name)) {
|
|
815
|
+
name += '?';
|
|
816
|
+
}
|
|
817
|
+
object[name] = true;
|
|
818
|
+
var returnValue = owns(object, name);
|
|
819
|
+
delete object[name];
|
|
820
|
+
return returnValue;
|
|
821
|
+
};
|
|
822
|
+
}
|
|
823
|
+
if (!Object.keys) {
|
|
824
|
+
var hasDontEnumBug = true,
|
|
825
|
+
dontEnums = [
|
|
826
|
+
"toString",
|
|
827
|
+
"toLocaleString",
|
|
828
|
+
"valueOf",
|
|
829
|
+
"hasOwnProperty",
|
|
830
|
+
"isPrototypeOf",
|
|
831
|
+
"propertyIsEnumerable",
|
|
832
|
+
"constructor"
|
|
833
|
+
],
|
|
834
|
+
dontEnumsLength = dontEnums.length;
|
|
835
|
+
|
|
836
|
+
for (var key in {"toString": null}) {
|
|
837
|
+
hasDontEnumBug = false;
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
Object.keys = function keys(object) {
|
|
841
|
+
|
|
842
|
+
if (
|
|
843
|
+
(typeof object != "object" && typeof object != "function") ||
|
|
844
|
+
object === null
|
|
845
|
+
) {
|
|
846
|
+
throw new TypeError("Object.keys called on a non-object");
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
var keys = [];
|
|
850
|
+
for (var name in object) {
|
|
851
|
+
if (owns(object, name)) {
|
|
852
|
+
keys.push(name);
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
if (hasDontEnumBug) {
|
|
857
|
+
for (var i = 0, ii = dontEnumsLength; i < ii; i++) {
|
|
858
|
+
var dontEnum = dontEnums[i];
|
|
859
|
+
if (owns(object, dontEnum)) {
|
|
860
|
+
keys.push(dontEnum);
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
return keys;
|
|
865
|
+
};
|
|
866
|
+
|
|
867
|
+
}
|
|
868
|
+
if (!Date.now) {
|
|
869
|
+
Date.now = function now() {
|
|
870
|
+
return new Date().getTime();
|
|
871
|
+
};
|
|
872
|
+
}
|
|
873
|
+
var ws = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003" +
|
|
874
|
+
"\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028" +
|
|
875
|
+
"\u2029\uFEFF";
|
|
876
|
+
if (!String.prototype.trim || ws.trim()) {
|
|
877
|
+
ws = "[" + ws + "]";
|
|
878
|
+
var trimBeginRegexp = new RegExp("^" + ws + ws + "*"),
|
|
879
|
+
trimEndRegexp = new RegExp(ws + ws + "*$");
|
|
880
|
+
String.prototype.trim = function trim() {
|
|
881
|
+
return String(this).replace(trimBeginRegexp, "").replace(trimEndRegexp, "");
|
|
882
|
+
};
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
function toInteger(n) {
|
|
886
|
+
n = +n;
|
|
887
|
+
if (n !== n) { // isNaN
|
|
888
|
+
n = 0;
|
|
889
|
+
} else if (n !== 0 && n !== (1/0) && n !== -(1/0)) {
|
|
890
|
+
n = (n > 0 || -1) * Math.floor(Math.abs(n));
|
|
891
|
+
}
|
|
892
|
+
return n;
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
function isPrimitive(input) {
|
|
896
|
+
var type = typeof input;
|
|
897
|
+
return (
|
|
898
|
+
input === null ||
|
|
899
|
+
type === "undefined" ||
|
|
900
|
+
type === "boolean" ||
|
|
901
|
+
type === "number" ||
|
|
902
|
+
type === "string"
|
|
903
|
+
);
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
function toPrimitive(input) {
|
|
907
|
+
var val, valueOf, toString;
|
|
908
|
+
if (isPrimitive(input)) {
|
|
909
|
+
return input;
|
|
910
|
+
}
|
|
911
|
+
valueOf = input.valueOf;
|
|
912
|
+
if (typeof valueOf === "function") {
|
|
913
|
+
val = valueOf.call(input);
|
|
914
|
+
if (isPrimitive(val)) {
|
|
915
|
+
return val;
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
toString = input.toString;
|
|
919
|
+
if (typeof toString === "function") {
|
|
920
|
+
val = toString.call(input);
|
|
921
|
+
if (isPrimitive(val)) {
|
|
922
|
+
return val;
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
throw new TypeError();
|
|
926
|
+
}
|
|
927
|
+
var toObject = function (o) {
|
|
928
|
+
if (o == null) { // this matches both null and undefined
|
|
929
|
+
throw new TypeError("can't convert "+o+" to object");
|
|
930
|
+
}
|
|
931
|
+
return Object(o);
|
|
932
|
+
};
|
|
933
|
+
|
|
934
|
+
});
|
|
935
|
+
|
|
936
|
+
define('ace/lib/event_emitter', ['require', 'exports', 'module' ], function(require, exports, module) {
|
|
937
|
+
|
|
938
|
+
|
|
939
|
+
var EventEmitter = {};
|
|
940
|
+
var stopPropagation = function() { this.propagationStopped = true; };
|
|
941
|
+
var preventDefault = function() { this.defaultPrevented = true; };
|
|
942
|
+
|
|
943
|
+
EventEmitter._emit =
|
|
944
|
+
EventEmitter._dispatchEvent = function(eventName, e) {
|
|
945
|
+
this._eventRegistry || (this._eventRegistry = {});
|
|
946
|
+
this._defaultHandlers || (this._defaultHandlers = {});
|
|
947
|
+
|
|
948
|
+
var listeners = this._eventRegistry[eventName] || [];
|
|
949
|
+
var defaultHandler = this._defaultHandlers[eventName];
|
|
950
|
+
if (!listeners.length && !defaultHandler)
|
|
951
|
+
return;
|
|
952
|
+
|
|
953
|
+
if (typeof e != "object" || !e)
|
|
954
|
+
e = {};
|
|
955
|
+
|
|
956
|
+
if (!e.type)
|
|
957
|
+
e.type = eventName;
|
|
958
|
+
if (!e.stopPropagation)
|
|
959
|
+
e.stopPropagation = stopPropagation;
|
|
960
|
+
if (!e.preventDefault)
|
|
961
|
+
e.preventDefault = preventDefault;
|
|
962
|
+
|
|
963
|
+
for (var i=0; i<listeners.length; i++) {
|
|
964
|
+
listeners[i](e, this);
|
|
965
|
+
if (e.propagationStopped)
|
|
966
|
+
break;
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
if (defaultHandler && !e.defaultPrevented)
|
|
970
|
+
return defaultHandler(e, this);
|
|
971
|
+
};
|
|
972
|
+
|
|
973
|
+
|
|
974
|
+
EventEmitter._signal = function(eventName, e) {
|
|
975
|
+
var listeners = (this._eventRegistry || {})[eventName];
|
|
976
|
+
if (!listeners)
|
|
977
|
+
return;
|
|
978
|
+
|
|
979
|
+
for (var i=0; i<listeners.length; i++)
|
|
980
|
+
listeners[i](e, this);
|
|
981
|
+
};
|
|
982
|
+
|
|
983
|
+
EventEmitter.once = function(eventName, callback) {
|
|
984
|
+
var _self = this;
|
|
985
|
+
callback && this.addEventListener(eventName, function newCallback() {
|
|
986
|
+
_self.removeEventListener(eventName, newCallback);
|
|
987
|
+
callback.apply(null, arguments);
|
|
988
|
+
});
|
|
989
|
+
};
|
|
990
|
+
|
|
991
|
+
|
|
992
|
+
EventEmitter.setDefaultHandler = function(eventName, callback) {
|
|
993
|
+
this._defaultHandlers = this._defaultHandlers || {};
|
|
994
|
+
|
|
995
|
+
if (this._defaultHandlers[eventName])
|
|
996
|
+
throw new Error("The default handler for '" + eventName + "' is already set");
|
|
997
|
+
|
|
998
|
+
this._defaultHandlers[eventName] = callback;
|
|
999
|
+
};
|
|
1000
|
+
|
|
1001
|
+
EventEmitter.on =
|
|
1002
|
+
EventEmitter.addEventListener = function(eventName, callback, capturing) {
|
|
1003
|
+
this._eventRegistry = this._eventRegistry || {};
|
|
1004
|
+
|
|
1005
|
+
var listeners = this._eventRegistry[eventName];
|
|
1006
|
+
if (!listeners)
|
|
1007
|
+
listeners = this._eventRegistry[eventName] = [];
|
|
1008
|
+
|
|
1009
|
+
if (listeners.indexOf(callback) == -1)
|
|
1010
|
+
listeners[capturing ? "unshift" : "push"](callback);
|
|
1011
|
+
return callback;
|
|
1012
|
+
};
|
|
1013
|
+
|
|
1014
|
+
EventEmitter.off =
|
|
1015
|
+
EventEmitter.removeListener =
|
|
1016
|
+
EventEmitter.removeEventListener = function(eventName, callback) {
|
|
1017
|
+
this._eventRegistry = this._eventRegistry || {};
|
|
1018
|
+
|
|
1019
|
+
var listeners = this._eventRegistry[eventName];
|
|
1020
|
+
if (!listeners)
|
|
1021
|
+
return;
|
|
1022
|
+
|
|
1023
|
+
var index = listeners.indexOf(callback);
|
|
1024
|
+
if (index !== -1)
|
|
1025
|
+
listeners.splice(index, 1);
|
|
1026
|
+
};
|
|
1027
|
+
|
|
1028
|
+
EventEmitter.removeAllListeners = function(eventName) {
|
|
1029
|
+
if (this._eventRegistry) this._eventRegistry[eventName] = [];
|
|
1030
|
+
};
|
|
1031
|
+
|
|
1032
|
+
exports.EventEmitter = EventEmitter;
|
|
1033
|
+
|
|
1034
|
+
});
|
|
1035
|
+
|
|
1036
|
+
define('ace/lib/oop', ['require', 'exports', 'module' ], function(require, exports, module) {
|
|
1037
|
+
|
|
1038
|
+
|
|
1039
|
+
exports.inherits = (function() {
|
|
1040
|
+
var tempCtor = function() {};
|
|
1041
|
+
return function(ctor, superCtor) {
|
|
1042
|
+
tempCtor.prototype = superCtor.prototype;
|
|
1043
|
+
ctor.super_ = superCtor.prototype;
|
|
1044
|
+
ctor.prototype = new tempCtor();
|
|
1045
|
+
ctor.prototype.constructor = ctor;
|
|
1046
|
+
};
|
|
1047
|
+
}());
|
|
1048
|
+
|
|
1049
|
+
exports.mixin = function(obj, mixin) {
|
|
1050
|
+
for (var key in mixin) {
|
|
1051
|
+
obj[key] = mixin[key];
|
|
1052
|
+
}
|
|
1053
|
+
return obj;
|
|
1054
|
+
};
|
|
1055
|
+
|
|
1056
|
+
exports.implement = function(proto, mixin) {
|
|
1057
|
+
exports.mixin(proto, mixin);
|
|
1058
|
+
};
|
|
1059
|
+
|
|
1060
|
+
});
|
|
1061
|
+
|
|
1062
|
+
define('ace/mode/lua_worker', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/worker/mirror', 'ace/mode/lua/luaparse'], function(require, exports, module) {
|
|
1063
|
+
|
|
1064
|
+
|
|
1065
|
+
var oop = require("../lib/oop");
|
|
1066
|
+
var Mirror = require("../worker/mirror").Mirror;
|
|
1067
|
+
var luaparse = require("../mode/lua/luaparse");
|
|
1068
|
+
|
|
1069
|
+
var Worker = exports.Worker = function(sender) {
|
|
1070
|
+
Mirror.call(this, sender);
|
|
1071
|
+
this.setTimeout(500);
|
|
1072
|
+
};
|
|
1073
|
+
|
|
1074
|
+
oop.inherits(Worker, Mirror);
|
|
1075
|
+
|
|
1076
|
+
(function() {
|
|
1077
|
+
|
|
1078
|
+
this.onUpdate = function() {
|
|
1079
|
+
var value = this.doc.getValue();
|
|
1080
|
+
try {
|
|
1081
|
+
luaparse.parse(value);
|
|
1082
|
+
} catch(e) {
|
|
1083
|
+
if (e instanceof SyntaxError) {
|
|
1084
|
+
this.sender.emit("error", {
|
|
1085
|
+
row: e.line - 1,
|
|
1086
|
+
column: e.column,
|
|
1087
|
+
text: e.message,
|
|
1088
|
+
type: "error"
|
|
1089
|
+
});
|
|
1090
|
+
}
|
|
1091
|
+
return;
|
|
1092
|
+
}
|
|
1093
|
+
this.sender.emit("ok");
|
|
1094
|
+
};
|
|
1095
|
+
|
|
1096
|
+
}).call(Worker.prototype);
|
|
1097
|
+
|
|
1098
|
+
});
|
|
1099
|
+
define('ace/worker/mirror', ['require', 'exports', 'module' , 'ace/document', 'ace/lib/lang'], function(require, exports, module) {
|
|
1100
|
+
|
|
1101
|
+
|
|
1102
|
+
var Document = require("../document").Document;
|
|
1103
|
+
var lang = require("../lib/lang");
|
|
1104
|
+
|
|
1105
|
+
var Mirror = exports.Mirror = function(sender) {
|
|
1106
|
+
this.sender = sender;
|
|
1107
|
+
var doc = this.doc = new Document("");
|
|
1108
|
+
|
|
1109
|
+
var deferredUpdate = this.deferredUpdate = lang.delayedCall(this.onUpdate.bind(this));
|
|
1110
|
+
|
|
1111
|
+
var _self = this;
|
|
1112
|
+
sender.on("change", function(e) {
|
|
1113
|
+
doc.applyDeltas([e.data]);
|
|
1114
|
+
deferredUpdate.schedule(_self.$timeout);
|
|
1115
|
+
});
|
|
1116
|
+
};
|
|
1117
|
+
|
|
1118
|
+
(function() {
|
|
1119
|
+
|
|
1120
|
+
this.$timeout = 500;
|
|
1121
|
+
|
|
1122
|
+
this.setTimeout = function(timeout) {
|
|
1123
|
+
this.$timeout = timeout;
|
|
1124
|
+
};
|
|
1125
|
+
|
|
1126
|
+
this.setValue = function(value) {
|
|
1127
|
+
this.doc.setValue(value);
|
|
1128
|
+
this.deferredUpdate.schedule(this.$timeout);
|
|
1129
|
+
};
|
|
1130
|
+
|
|
1131
|
+
this.getValue = function(callbackId) {
|
|
1132
|
+
this.sender.callback(this.doc.getValue(), callbackId);
|
|
1133
|
+
};
|
|
1134
|
+
|
|
1135
|
+
this.onUpdate = function() {
|
|
1136
|
+
};
|
|
1137
|
+
|
|
1138
|
+
}).call(Mirror.prototype);
|
|
1139
|
+
|
|
1140
|
+
});
|
|
1141
|
+
|
|
1142
|
+
define('ace/document', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/event_emitter', 'ace/range', 'ace/anchor'], function(require, exports, module) {
|
|
1143
|
+
|
|
1144
|
+
|
|
1145
|
+
var oop = require("./lib/oop");
|
|
1146
|
+
var EventEmitter = require("./lib/event_emitter").EventEmitter;
|
|
1147
|
+
var Range = require("./range").Range;
|
|
1148
|
+
var Anchor = require("./anchor").Anchor;
|
|
1149
|
+
|
|
1150
|
+
var Document = function(text) {
|
|
1151
|
+
this.$lines = [];
|
|
1152
|
+
if (text.length == 0) {
|
|
1153
|
+
this.$lines = [""];
|
|
1154
|
+
} else if (Array.isArray(text)) {
|
|
1155
|
+
this.insertLines(0, text);
|
|
1156
|
+
} else {
|
|
1157
|
+
this.insert({row: 0, column:0}, text);
|
|
1158
|
+
}
|
|
1159
|
+
};
|
|
1160
|
+
|
|
1161
|
+
(function() {
|
|
1162
|
+
|
|
1163
|
+
oop.implement(this, EventEmitter);
|
|
1164
|
+
this.setValue = function(text) {
|
|
1165
|
+
var len = this.getLength();
|
|
1166
|
+
this.remove(new Range(0, 0, len, this.getLine(len-1).length));
|
|
1167
|
+
this.insert({row: 0, column:0}, text);
|
|
1168
|
+
};
|
|
1169
|
+
this.getValue = function() {
|
|
1170
|
+
return this.getAllLines().join(this.getNewLineCharacter());
|
|
1171
|
+
};
|
|
1172
|
+
this.createAnchor = function(row, column) {
|
|
1173
|
+
return new Anchor(this, row, column);
|
|
1174
|
+
};
|
|
1175
|
+
if ("aaa".split(/a/).length == 0)
|
|
1176
|
+
this.$split = function(text) {
|
|
1177
|
+
return text.replace(/\r\n|\r/g, "\n").split("\n");
|
|
1178
|
+
}
|
|
1179
|
+
else
|
|
1180
|
+
this.$split = function(text) {
|
|
1181
|
+
return text.split(/\r\n|\r|\n/);
|
|
1182
|
+
};
|
|
1183
|
+
|
|
1184
|
+
|
|
1185
|
+
|
|
1186
|
+
this.$detectNewLine = function(text) {
|
|
1187
|
+
var match = text.match(/^.*?(\r\n|\r|\n)/m);
|
|
1188
|
+
if (match) {
|
|
1189
|
+
this.$autoNewLine = match[1];
|
|
1190
|
+
} else {
|
|
1191
|
+
this.$autoNewLine = "\n";
|
|
1192
|
+
}
|
|
1193
|
+
};
|
|
1194
|
+
this.getNewLineCharacter = function() {
|
|
1195
|
+
switch (this.$newLineMode) {
|
|
1196
|
+
case "windows":
|
|
1197
|
+
return "\r\n";
|
|
1198
|
+
|
|
1199
|
+
case "unix":
|
|
1200
|
+
return "\n";
|
|
1201
|
+
|
|
1202
|
+
default:
|
|
1203
|
+
return this.$autoNewLine;
|
|
1204
|
+
}
|
|
1205
|
+
};
|
|
1206
|
+
|
|
1207
|
+
this.$autoNewLine = "\n";
|
|
1208
|
+
this.$newLineMode = "auto";
|
|
1209
|
+
this.setNewLineMode = function(newLineMode) {
|
|
1210
|
+
if (this.$newLineMode === newLineMode)
|
|
1211
|
+
return;
|
|
1212
|
+
|
|
1213
|
+
this.$newLineMode = newLineMode;
|
|
1214
|
+
};
|
|
1215
|
+
this.getNewLineMode = function() {
|
|
1216
|
+
return this.$newLineMode;
|
|
1217
|
+
};
|
|
1218
|
+
this.isNewLine = function(text) {
|
|
1219
|
+
return (text == "\r\n" || text == "\r" || text == "\n");
|
|
1220
|
+
};
|
|
1221
|
+
this.getLine = function(row) {
|
|
1222
|
+
return this.$lines[row] || "";
|
|
1223
|
+
};
|
|
1224
|
+
this.getLines = function(firstRow, lastRow) {
|
|
1225
|
+
return this.$lines.slice(firstRow, lastRow + 1);
|
|
1226
|
+
};
|
|
1227
|
+
this.getAllLines = function() {
|
|
1228
|
+
return this.getLines(0, this.getLength());
|
|
1229
|
+
};
|
|
1230
|
+
this.getLength = function() {
|
|
1231
|
+
return this.$lines.length;
|
|
1232
|
+
};
|
|
1233
|
+
this.getTextRange = function(range) {
|
|
1234
|
+
if (range.start.row == range.end.row) {
|
|
1235
|
+
return this.$lines[range.start.row].substring(range.start.column,
|
|
1236
|
+
range.end.column);
|
|
1237
|
+
}
|
|
1238
|
+
else {
|
|
1239
|
+
var lines = this.getLines(range.start.row+1, range.end.row-1);
|
|
1240
|
+
lines.unshift((this.$lines[range.start.row] || "").substring(range.start.column));
|
|
1241
|
+
lines.push((this.$lines[range.end.row] || "").substring(0, range.end.column));
|
|
1242
|
+
return lines.join(this.getNewLineCharacter());
|
|
1243
|
+
}
|
|
1244
|
+
};
|
|
1245
|
+
|
|
1246
|
+
this.$clipPosition = function(position) {
|
|
1247
|
+
var length = this.getLength();
|
|
1248
|
+
if (position.row >= length) {
|
|
1249
|
+
position.row = Math.max(0, length - 1);
|
|
1250
|
+
position.column = this.getLine(length-1).length;
|
|
1251
|
+
} else if (position.row < 0)
|
|
1252
|
+
position.row = 0;
|
|
1253
|
+
return position;
|
|
1254
|
+
};
|
|
1255
|
+
this.insert = function(position, text) {
|
|
1256
|
+
if (!text || text.length === 0)
|
|
1257
|
+
return position;
|
|
1258
|
+
|
|
1259
|
+
position = this.$clipPosition(position);
|
|
1260
|
+
if (this.getLength() <= 1)
|
|
1261
|
+
this.$detectNewLine(text);
|
|
1262
|
+
|
|
1263
|
+
var lines = this.$split(text);
|
|
1264
|
+
var firstLine = lines.splice(0, 1)[0];
|
|
1265
|
+
var lastLine = lines.length == 0 ? null : lines.splice(lines.length - 1, 1)[0];
|
|
1266
|
+
|
|
1267
|
+
position = this.insertInLine(position, firstLine);
|
|
1268
|
+
if (lastLine !== null) {
|
|
1269
|
+
position = this.insertNewLine(position); // terminate first line
|
|
1270
|
+
position = this.insertLines(position.row, lines);
|
|
1271
|
+
position = this.insertInLine(position, lastLine || "");
|
|
1272
|
+
}
|
|
1273
|
+
return position;
|
|
1274
|
+
};
|
|
1275
|
+
this.insertLines = function(row, lines) {
|
|
1276
|
+
if (lines.length == 0)
|
|
1277
|
+
return {row: row, column: 0};
|
|
1278
|
+
if (lines.length > 0xFFFF) {
|
|
1279
|
+
var end = this.insertLines(row, lines.slice(0xFFFF));
|
|
1280
|
+
lines = lines.slice(0, 0xFFFF);
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
var args = [row, 0];
|
|
1284
|
+
args.push.apply(args, lines);
|
|
1285
|
+
this.$lines.splice.apply(this.$lines, args);
|
|
1286
|
+
|
|
1287
|
+
var range = new Range(row, 0, row + lines.length, 0);
|
|
1288
|
+
var delta = {
|
|
1289
|
+
action: "insertLines",
|
|
1290
|
+
range: range,
|
|
1291
|
+
lines: lines
|
|
1292
|
+
};
|
|
1293
|
+
this._emit("change", { data: delta });
|
|
1294
|
+
return end || range.end;
|
|
1295
|
+
};
|
|
1296
|
+
this.insertNewLine = function(position) {
|
|
1297
|
+
position = this.$clipPosition(position);
|
|
1298
|
+
var line = this.$lines[position.row] || "";
|
|
1299
|
+
|
|
1300
|
+
this.$lines[position.row] = line.substring(0, position.column);
|
|
1301
|
+
this.$lines.splice(position.row + 1, 0, line.substring(position.column, line.length));
|
|
1302
|
+
|
|
1303
|
+
var end = {
|
|
1304
|
+
row : position.row + 1,
|
|
1305
|
+
column : 0
|
|
1306
|
+
};
|
|
1307
|
+
|
|
1308
|
+
var delta = {
|
|
1309
|
+
action: "insertText",
|
|
1310
|
+
range: Range.fromPoints(position, end),
|
|
1311
|
+
text: this.getNewLineCharacter()
|
|
1312
|
+
};
|
|
1313
|
+
this._emit("change", { data: delta });
|
|
1314
|
+
|
|
1315
|
+
return end;
|
|
1316
|
+
};
|
|
1317
|
+
this.insertInLine = function(position, text) {
|
|
1318
|
+
if (text.length == 0)
|
|
1319
|
+
return position;
|
|
1320
|
+
|
|
1321
|
+
var line = this.$lines[position.row] || "";
|
|
1322
|
+
|
|
1323
|
+
this.$lines[position.row] = line.substring(0, position.column) + text
|
|
1324
|
+
+ line.substring(position.column);
|
|
1325
|
+
|
|
1326
|
+
var end = {
|
|
1327
|
+
row : position.row,
|
|
1328
|
+
column : position.column + text.length
|
|
1329
|
+
};
|
|
1330
|
+
|
|
1331
|
+
var delta = {
|
|
1332
|
+
action: "insertText",
|
|
1333
|
+
range: Range.fromPoints(position, end),
|
|
1334
|
+
text: text
|
|
1335
|
+
};
|
|
1336
|
+
this._emit("change", { data: delta });
|
|
1337
|
+
|
|
1338
|
+
return end;
|
|
1339
|
+
};
|
|
1340
|
+
this.remove = function(range) {
|
|
1341
|
+
range.start = this.$clipPosition(range.start);
|
|
1342
|
+
range.end = this.$clipPosition(range.end);
|
|
1343
|
+
|
|
1344
|
+
if (range.isEmpty())
|
|
1345
|
+
return range.start;
|
|
1346
|
+
|
|
1347
|
+
var firstRow = range.start.row;
|
|
1348
|
+
var lastRow = range.end.row;
|
|
1349
|
+
|
|
1350
|
+
if (range.isMultiLine()) {
|
|
1351
|
+
var firstFullRow = range.start.column == 0 ? firstRow : firstRow + 1;
|
|
1352
|
+
var lastFullRow = lastRow - 1;
|
|
1353
|
+
|
|
1354
|
+
if (range.end.column > 0)
|
|
1355
|
+
this.removeInLine(lastRow, 0, range.end.column);
|
|
1356
|
+
|
|
1357
|
+
if (lastFullRow >= firstFullRow)
|
|
1358
|
+
this.removeLines(firstFullRow, lastFullRow);
|
|
1359
|
+
|
|
1360
|
+
if (firstFullRow != firstRow) {
|
|
1361
|
+
this.removeInLine(firstRow, range.start.column, this.getLine(firstRow).length);
|
|
1362
|
+
this.removeNewLine(range.start.row);
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
else {
|
|
1366
|
+
this.removeInLine(firstRow, range.start.column, range.end.column);
|
|
1367
|
+
}
|
|
1368
|
+
return range.start;
|
|
1369
|
+
};
|
|
1370
|
+
this.removeInLine = function(row, startColumn, endColumn) {
|
|
1371
|
+
if (startColumn == endColumn)
|
|
1372
|
+
return;
|
|
1373
|
+
|
|
1374
|
+
var range = new Range(row, startColumn, row, endColumn);
|
|
1375
|
+
var line = this.getLine(row);
|
|
1376
|
+
var removed = line.substring(startColumn, endColumn);
|
|
1377
|
+
var newLine = line.substring(0, startColumn) + line.substring(endColumn, line.length);
|
|
1378
|
+
this.$lines.splice(row, 1, newLine);
|
|
1379
|
+
|
|
1380
|
+
var delta = {
|
|
1381
|
+
action: "removeText",
|
|
1382
|
+
range: range,
|
|
1383
|
+
text: removed
|
|
1384
|
+
};
|
|
1385
|
+
this._emit("change", { data: delta });
|
|
1386
|
+
return range.start;
|
|
1387
|
+
};
|
|
1388
|
+
this.removeLines = function(firstRow, lastRow) {
|
|
1389
|
+
var range = new Range(firstRow, 0, lastRow + 1, 0);
|
|
1390
|
+
var removed = this.$lines.splice(firstRow, lastRow - firstRow + 1);
|
|
1391
|
+
|
|
1392
|
+
var delta = {
|
|
1393
|
+
action: "removeLines",
|
|
1394
|
+
range: range,
|
|
1395
|
+
nl: this.getNewLineCharacter(),
|
|
1396
|
+
lines: removed
|
|
1397
|
+
};
|
|
1398
|
+
this._emit("change", { data: delta });
|
|
1399
|
+
return removed;
|
|
1400
|
+
};
|
|
1401
|
+
this.removeNewLine = function(row) {
|
|
1402
|
+
var firstLine = this.getLine(row);
|
|
1403
|
+
var secondLine = this.getLine(row+1);
|
|
1404
|
+
|
|
1405
|
+
var range = new Range(row, firstLine.length, row+1, 0);
|
|
1406
|
+
var line = firstLine + secondLine;
|
|
1407
|
+
|
|
1408
|
+
this.$lines.splice(row, 2, line);
|
|
1409
|
+
|
|
1410
|
+
var delta = {
|
|
1411
|
+
action: "removeText",
|
|
1412
|
+
range: range,
|
|
1413
|
+
text: this.getNewLineCharacter()
|
|
1414
|
+
};
|
|
1415
|
+
this._emit("change", { data: delta });
|
|
1416
|
+
};
|
|
1417
|
+
this.replace = function(range, text) {
|
|
1418
|
+
if (text.length == 0 && range.isEmpty())
|
|
1419
|
+
return range.start;
|
|
1420
|
+
if (text == this.getTextRange(range))
|
|
1421
|
+
return range.end;
|
|
1422
|
+
|
|
1423
|
+
this.remove(range);
|
|
1424
|
+
if (text) {
|
|
1425
|
+
var end = this.insert(range.start, text);
|
|
1426
|
+
}
|
|
1427
|
+
else {
|
|
1428
|
+
end = range.start;
|
|
1429
|
+
}
|
|
1430
|
+
|
|
1431
|
+
return end;
|
|
1432
|
+
};
|
|
1433
|
+
this.applyDeltas = function(deltas) {
|
|
1434
|
+
for (var i=0; i<deltas.length; i++) {
|
|
1435
|
+
var delta = deltas[i];
|
|
1436
|
+
var range = Range.fromPoints(delta.range.start, delta.range.end);
|
|
1437
|
+
|
|
1438
|
+
if (delta.action == "insertLines")
|
|
1439
|
+
this.insertLines(range.start.row, delta.lines);
|
|
1440
|
+
else if (delta.action == "insertText")
|
|
1441
|
+
this.insert(range.start, delta.text);
|
|
1442
|
+
else if (delta.action == "removeLines")
|
|
1443
|
+
this.removeLines(range.start.row, range.end.row - 1);
|
|
1444
|
+
else if (delta.action == "removeText")
|
|
1445
|
+
this.remove(range);
|
|
1446
|
+
}
|
|
1447
|
+
};
|
|
1448
|
+
this.revertDeltas = function(deltas) {
|
|
1449
|
+
for (var i=deltas.length-1; i>=0; i--) {
|
|
1450
|
+
var delta = deltas[i];
|
|
1451
|
+
|
|
1452
|
+
var range = Range.fromPoints(delta.range.start, delta.range.end);
|
|
1453
|
+
|
|
1454
|
+
if (delta.action == "insertLines")
|
|
1455
|
+
this.removeLines(range.start.row, range.end.row - 1);
|
|
1456
|
+
else if (delta.action == "insertText")
|
|
1457
|
+
this.remove(range);
|
|
1458
|
+
else if (delta.action == "removeLines")
|
|
1459
|
+
this.insertLines(range.start.row, delta.lines);
|
|
1460
|
+
else if (delta.action == "removeText")
|
|
1461
|
+
this.insert(range.start, delta.text);
|
|
1462
|
+
}
|
|
1463
|
+
};
|
|
1464
|
+
this.indexToPosition = function(index, startRow) {
|
|
1465
|
+
var lines = this.$lines || this.getAllLines();
|
|
1466
|
+
var newlineLength = this.getNewLineCharacter().length;
|
|
1467
|
+
for (var i = startRow || 0, l = lines.length; i < l; i++) {
|
|
1468
|
+
index -= lines[i].length + newlineLength;
|
|
1469
|
+
if (index < 0)
|
|
1470
|
+
return {row: i, column: index + lines[i].length + newlineLength};
|
|
1471
|
+
}
|
|
1472
|
+
return {row: l-1, column: lines[l-1].length};
|
|
1473
|
+
};
|
|
1474
|
+
this.positionToIndex = function(pos, startRow) {
|
|
1475
|
+
var lines = this.$lines || this.getAllLines();
|
|
1476
|
+
var newlineLength = this.getNewLineCharacter().length;
|
|
1477
|
+
var index = 0;
|
|
1478
|
+
var row = Math.min(pos.row, lines.length);
|
|
1479
|
+
for (var i = startRow || 0; i < row; ++i)
|
|
1480
|
+
index += lines[i].length;
|
|
1481
|
+
|
|
1482
|
+
return index + newlineLength * i + pos.column;
|
|
1483
|
+
};
|
|
1484
|
+
|
|
1485
|
+
}).call(Document.prototype);
|
|
1486
|
+
|
|
1487
|
+
exports.Document = Document;
|
|
1488
|
+
});
|
|
1489
|
+
|
|
1490
|
+
define('ace/range', ['require', 'exports', 'module' ], function(require, exports, module) {
|
|
1491
|
+
|
|
1492
|
+
var comparePoints = function(p1, p2) {
|
|
1493
|
+
return p1.row - p2.row || p1.column - p2.column;
|
|
1494
|
+
};
|
|
1495
|
+
var Range = function(startRow, startColumn, endRow, endColumn) {
|
|
1496
|
+
this.start = {
|
|
1497
|
+
row: startRow,
|
|
1498
|
+
column: startColumn
|
|
1499
|
+
};
|
|
1500
|
+
|
|
1501
|
+
this.end = {
|
|
1502
|
+
row: endRow,
|
|
1503
|
+
column: endColumn
|
|
1504
|
+
};
|
|
1505
|
+
};
|
|
1506
|
+
|
|
1507
|
+
(function() {
|
|
1508
|
+
this.isEqual = function(range) {
|
|
1509
|
+
return this.start.row === range.start.row &&
|
|
1510
|
+
this.end.row === range.end.row &&
|
|
1511
|
+
this.start.column === range.start.column &&
|
|
1512
|
+
this.end.column === range.end.column;
|
|
1513
|
+
};
|
|
1514
|
+
this.toString = function() {
|
|
1515
|
+
return ("Range: [" + this.start.row + "/" + this.start.column +
|
|
1516
|
+
"] -> [" + this.end.row + "/" + this.end.column + "]");
|
|
1517
|
+
};
|
|
1518
|
+
|
|
1519
|
+
this.contains = function(row, column) {
|
|
1520
|
+
return this.compare(row, column) == 0;
|
|
1521
|
+
};
|
|
1522
|
+
this.compareRange = function(range) {
|
|
1523
|
+
var cmp,
|
|
1524
|
+
end = range.end,
|
|
1525
|
+
start = range.start;
|
|
1526
|
+
|
|
1527
|
+
cmp = this.compare(end.row, end.column);
|
|
1528
|
+
if (cmp == 1) {
|
|
1529
|
+
cmp = this.compare(start.row, start.column);
|
|
1530
|
+
if (cmp == 1) {
|
|
1531
|
+
return 2;
|
|
1532
|
+
} else if (cmp == 0) {
|
|
1533
|
+
return 1;
|
|
1534
|
+
} else {
|
|
1535
|
+
return 0;
|
|
1536
|
+
}
|
|
1537
|
+
} else if (cmp == -1) {
|
|
1538
|
+
return -2;
|
|
1539
|
+
} else {
|
|
1540
|
+
cmp = this.compare(start.row, start.column);
|
|
1541
|
+
if (cmp == -1) {
|
|
1542
|
+
return -1;
|
|
1543
|
+
} else if (cmp == 1) {
|
|
1544
|
+
return 42;
|
|
1545
|
+
} else {
|
|
1546
|
+
return 0;
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1549
|
+
};
|
|
1550
|
+
this.comparePoint = function(p) {
|
|
1551
|
+
return this.compare(p.row, p.column);
|
|
1552
|
+
};
|
|
1553
|
+
this.containsRange = function(range) {
|
|
1554
|
+
return this.comparePoint(range.start) == 0 && this.comparePoint(range.end) == 0;
|
|
1555
|
+
};
|
|
1556
|
+
this.intersects = function(range) {
|
|
1557
|
+
var cmp = this.compareRange(range);
|
|
1558
|
+
return (cmp == -1 || cmp == 0 || cmp == 1);
|
|
1559
|
+
};
|
|
1560
|
+
this.isEnd = function(row, column) {
|
|
1561
|
+
return this.end.row == row && this.end.column == column;
|
|
1562
|
+
};
|
|
1563
|
+
this.isStart = function(row, column) {
|
|
1564
|
+
return this.start.row == row && this.start.column == column;
|
|
1565
|
+
};
|
|
1566
|
+
this.setStart = function(row, column) {
|
|
1567
|
+
if (typeof row == "object") {
|
|
1568
|
+
this.start.column = row.column;
|
|
1569
|
+
this.start.row = row.row;
|
|
1570
|
+
} else {
|
|
1571
|
+
this.start.row = row;
|
|
1572
|
+
this.start.column = column;
|
|
1573
|
+
}
|
|
1574
|
+
};
|
|
1575
|
+
this.setEnd = function(row, column) {
|
|
1576
|
+
if (typeof row == "object") {
|
|
1577
|
+
this.end.column = row.column;
|
|
1578
|
+
this.end.row = row.row;
|
|
1579
|
+
} else {
|
|
1580
|
+
this.end.row = row;
|
|
1581
|
+
this.end.column = column;
|
|
1582
|
+
}
|
|
1583
|
+
};
|
|
1584
|
+
this.inside = function(row, column) {
|
|
1585
|
+
if (this.compare(row, column) == 0) {
|
|
1586
|
+
if (this.isEnd(row, column) || this.isStart(row, column)) {
|
|
1587
|
+
return false;
|
|
1588
|
+
} else {
|
|
1589
|
+
return true;
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
return false;
|
|
1593
|
+
};
|
|
1594
|
+
this.insideStart = function(row, column) {
|
|
1595
|
+
if (this.compare(row, column) == 0) {
|
|
1596
|
+
if (this.isEnd(row, column)) {
|
|
1597
|
+
return false;
|
|
1598
|
+
} else {
|
|
1599
|
+
return true;
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
return false;
|
|
1603
|
+
};
|
|
1604
|
+
this.insideEnd = function(row, column) {
|
|
1605
|
+
if (this.compare(row, column) == 0) {
|
|
1606
|
+
if (this.isStart(row, column)) {
|
|
1607
|
+
return false;
|
|
1608
|
+
} else {
|
|
1609
|
+
return true;
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
return false;
|
|
1613
|
+
};
|
|
1614
|
+
this.compare = function(row, column) {
|
|
1615
|
+
if (!this.isMultiLine()) {
|
|
1616
|
+
if (row === this.start.row) {
|
|
1617
|
+
return column < this.start.column ? -1 : (column > this.end.column ? 1 : 0);
|
|
1618
|
+
};
|
|
1619
|
+
}
|
|
1620
|
+
|
|
1621
|
+
if (row < this.start.row)
|
|
1622
|
+
return -1;
|
|
1623
|
+
|
|
1624
|
+
if (row > this.end.row)
|
|
1625
|
+
return 1;
|
|
1626
|
+
|
|
1627
|
+
if (this.start.row === row)
|
|
1628
|
+
return column >= this.start.column ? 0 : -1;
|
|
1629
|
+
|
|
1630
|
+
if (this.end.row === row)
|
|
1631
|
+
return column <= this.end.column ? 0 : 1;
|
|
1632
|
+
|
|
1633
|
+
return 0;
|
|
1634
|
+
};
|
|
1635
|
+
this.compareStart = function(row, column) {
|
|
1636
|
+
if (this.start.row == row && this.start.column == column) {
|
|
1637
|
+
return -1;
|
|
1638
|
+
} else {
|
|
1639
|
+
return this.compare(row, column);
|
|
1640
|
+
}
|
|
1641
|
+
};
|
|
1642
|
+
this.compareEnd = function(row, column) {
|
|
1643
|
+
if (this.end.row == row && this.end.column == column) {
|
|
1644
|
+
return 1;
|
|
1645
|
+
} else {
|
|
1646
|
+
return this.compare(row, column);
|
|
1647
|
+
}
|
|
1648
|
+
};
|
|
1649
|
+
this.compareInside = function(row, column) {
|
|
1650
|
+
if (this.end.row == row && this.end.column == column) {
|
|
1651
|
+
return 1;
|
|
1652
|
+
} else if (this.start.row == row && this.start.column == column) {
|
|
1653
|
+
return -1;
|
|
1654
|
+
} else {
|
|
1655
|
+
return this.compare(row, column);
|
|
1656
|
+
}
|
|
1657
|
+
};
|
|
1658
|
+
this.clipRows = function(firstRow, lastRow) {
|
|
1659
|
+
if (this.end.row > lastRow)
|
|
1660
|
+
var end = {row: lastRow + 1, column: 0};
|
|
1661
|
+
else if (this.end.row < firstRow)
|
|
1662
|
+
var end = {row: firstRow, column: 0};
|
|
1663
|
+
|
|
1664
|
+
if (this.start.row > lastRow)
|
|
1665
|
+
var start = {row: lastRow + 1, column: 0};
|
|
1666
|
+
else if (this.start.row < firstRow)
|
|
1667
|
+
var start = {row: firstRow, column: 0};
|
|
1668
|
+
|
|
1669
|
+
return Range.fromPoints(start || this.start, end || this.end);
|
|
1670
|
+
};
|
|
1671
|
+
this.extend = function(row, column) {
|
|
1672
|
+
var cmp = this.compare(row, column);
|
|
1673
|
+
|
|
1674
|
+
if (cmp == 0)
|
|
1675
|
+
return this;
|
|
1676
|
+
else if (cmp == -1)
|
|
1677
|
+
var start = {row: row, column: column};
|
|
1678
|
+
else
|
|
1679
|
+
var end = {row: row, column: column};
|
|
1680
|
+
|
|
1681
|
+
return Range.fromPoints(start || this.start, end || this.end);
|
|
1682
|
+
};
|
|
1683
|
+
|
|
1684
|
+
this.isEmpty = function() {
|
|
1685
|
+
return (this.start.row === this.end.row && this.start.column === this.end.column);
|
|
1686
|
+
};
|
|
1687
|
+
this.isMultiLine = function() {
|
|
1688
|
+
return (this.start.row !== this.end.row);
|
|
1689
|
+
};
|
|
1690
|
+
this.clone = function() {
|
|
1691
|
+
return Range.fromPoints(this.start, this.end);
|
|
1692
|
+
};
|
|
1693
|
+
this.collapseRows = function() {
|
|
1694
|
+
if (this.end.column == 0)
|
|
1695
|
+
return new Range(this.start.row, 0, Math.max(this.start.row, this.end.row-1), 0)
|
|
1696
|
+
else
|
|
1697
|
+
return new Range(this.start.row, 0, this.end.row, 0)
|
|
1698
|
+
};
|
|
1699
|
+
this.toScreenRange = function(session) {
|
|
1700
|
+
var screenPosStart = session.documentToScreenPosition(this.start);
|
|
1701
|
+
var screenPosEnd = session.documentToScreenPosition(this.end);
|
|
1702
|
+
|
|
1703
|
+
return new Range(
|
|
1704
|
+
screenPosStart.row, screenPosStart.column,
|
|
1705
|
+
screenPosEnd.row, screenPosEnd.column
|
|
1706
|
+
);
|
|
1707
|
+
};
|
|
1708
|
+
this.moveBy = function(row, column) {
|
|
1709
|
+
this.start.row += row;
|
|
1710
|
+
this.start.column += column;
|
|
1711
|
+
this.end.row += row;
|
|
1712
|
+
this.end.column += column;
|
|
1713
|
+
};
|
|
1714
|
+
|
|
1715
|
+
}).call(Range.prototype);
|
|
1716
|
+
Range.fromPoints = function(start, end) {
|
|
1717
|
+
return new Range(start.row, start.column, end.row, end.column);
|
|
1718
|
+
};
|
|
1719
|
+
Range.comparePoints = comparePoints;
|
|
1720
|
+
|
|
1721
|
+
Range.comparePoints = function(p1, p2) {
|
|
1722
|
+
return p1.row - p2.row || p1.column - p2.column;
|
|
1723
|
+
};
|
|
1724
|
+
|
|
1725
|
+
|
|
1726
|
+
exports.Range = Range;
|
|
1727
|
+
});
|
|
1728
|
+
|
|
1729
|
+
define('ace/anchor', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/event_emitter'], function(require, exports, module) {
|
|
1730
|
+
|
|
1731
|
+
|
|
1732
|
+
var oop = require("./lib/oop");
|
|
1733
|
+
var EventEmitter = require("./lib/event_emitter").EventEmitter;
|
|
1734
|
+
|
|
1735
|
+
var Anchor = exports.Anchor = function(doc, row, column) {
|
|
1736
|
+
this.document = doc;
|
|
1737
|
+
|
|
1738
|
+
if (typeof column == "undefined")
|
|
1739
|
+
this.setPosition(row.row, row.column);
|
|
1740
|
+
else
|
|
1741
|
+
this.setPosition(row, column);
|
|
1742
|
+
|
|
1743
|
+
this.$onChange = this.onChange.bind(this);
|
|
1744
|
+
doc.on("change", this.$onChange);
|
|
1745
|
+
};
|
|
1746
|
+
|
|
1747
|
+
(function() {
|
|
1748
|
+
|
|
1749
|
+
oop.implement(this, EventEmitter);
|
|
1750
|
+
|
|
1751
|
+
this.getPosition = function() {
|
|
1752
|
+
return this.$clipPositionToDocument(this.row, this.column);
|
|
1753
|
+
};
|
|
1754
|
+
|
|
1755
|
+
this.getDocument = function() {
|
|
1756
|
+
return this.document;
|
|
1757
|
+
};
|
|
1758
|
+
|
|
1759
|
+
this.onChange = function(e) {
|
|
1760
|
+
var delta = e.data;
|
|
1761
|
+
var range = delta.range;
|
|
1762
|
+
|
|
1763
|
+
if (range.start.row == range.end.row && range.start.row != this.row)
|
|
1764
|
+
return;
|
|
1765
|
+
|
|
1766
|
+
if (range.start.row > this.row)
|
|
1767
|
+
return;
|
|
1768
|
+
|
|
1769
|
+
if (range.start.row == this.row && range.start.column > this.column)
|
|
1770
|
+
return;
|
|
1771
|
+
|
|
1772
|
+
var row = this.row;
|
|
1773
|
+
var column = this.column;
|
|
1774
|
+
var start = range.start;
|
|
1775
|
+
var end = range.end;
|
|
1776
|
+
|
|
1777
|
+
if (delta.action === "insertText") {
|
|
1778
|
+
if (start.row === row && start.column <= column) {
|
|
1779
|
+
if (start.row === end.row) {
|
|
1780
|
+
column += end.column - start.column;
|
|
1781
|
+
} else {
|
|
1782
|
+
column -= start.column;
|
|
1783
|
+
row += end.row - start.row;
|
|
1784
|
+
}
|
|
1785
|
+
} else if (start.row !== end.row && start.row < row) {
|
|
1786
|
+
row += end.row - start.row;
|
|
1787
|
+
}
|
|
1788
|
+
} else if (delta.action === "insertLines") {
|
|
1789
|
+
if (start.row <= row) {
|
|
1790
|
+
row += end.row - start.row;
|
|
1791
|
+
}
|
|
1792
|
+
} else if (delta.action === "removeText") {
|
|
1793
|
+
if (start.row === row && start.column < column) {
|
|
1794
|
+
if (end.column >= column)
|
|
1795
|
+
column = start.column;
|
|
1796
|
+
else
|
|
1797
|
+
column = Math.max(0, column - (end.column - start.column));
|
|
1798
|
+
|
|
1799
|
+
} else if (start.row !== end.row && start.row < row) {
|
|
1800
|
+
if (end.row === row)
|
|
1801
|
+
column = Math.max(0, column - end.column) + start.column;
|
|
1802
|
+
row -= (end.row - start.row);
|
|
1803
|
+
} else if (end.row === row) {
|
|
1804
|
+
row -= end.row - start.row;
|
|
1805
|
+
column = Math.max(0, column - end.column) + start.column;
|
|
1806
|
+
}
|
|
1807
|
+
} else if (delta.action == "removeLines") {
|
|
1808
|
+
if (start.row <= row) {
|
|
1809
|
+
if (end.row <= row)
|
|
1810
|
+
row -= end.row - start.row;
|
|
1811
|
+
else {
|
|
1812
|
+
row = start.row;
|
|
1813
|
+
column = 0;
|
|
1814
|
+
}
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
1817
|
+
|
|
1818
|
+
this.setPosition(row, column, true);
|
|
1819
|
+
};
|
|
1820
|
+
|
|
1821
|
+
this.setPosition = function(row, column, noClip) {
|
|
1822
|
+
var pos;
|
|
1823
|
+
if (noClip) {
|
|
1824
|
+
pos = {
|
|
1825
|
+
row: row,
|
|
1826
|
+
column: column
|
|
1827
|
+
};
|
|
1828
|
+
} else {
|
|
1829
|
+
pos = this.$clipPositionToDocument(row, column);
|
|
1830
|
+
}
|
|
1831
|
+
|
|
1832
|
+
if (this.row == pos.row && this.column == pos.column)
|
|
1833
|
+
return;
|
|
1834
|
+
|
|
1835
|
+
var old = {
|
|
1836
|
+
row: this.row,
|
|
1837
|
+
column: this.column
|
|
1838
|
+
};
|
|
1839
|
+
|
|
1840
|
+
this.row = pos.row;
|
|
1841
|
+
this.column = pos.column;
|
|
1842
|
+
this._emit("change", {
|
|
1843
|
+
old: old,
|
|
1844
|
+
value: pos
|
|
1845
|
+
});
|
|
1846
|
+
};
|
|
1847
|
+
|
|
1848
|
+
this.detach = function() {
|
|
1849
|
+
this.document.removeEventListener("change", this.$onChange);
|
|
1850
|
+
};
|
|
1851
|
+
this.$clipPositionToDocument = function(row, column) {
|
|
1852
|
+
var pos = {};
|
|
1853
|
+
|
|
1854
|
+
if (row >= this.document.getLength()) {
|
|
1855
|
+
pos.row = Math.max(0, this.document.getLength() - 1);
|
|
1856
|
+
pos.column = this.document.getLine(pos.row).length;
|
|
1857
|
+
}
|
|
1858
|
+
else if (row < 0) {
|
|
1859
|
+
pos.row = 0;
|
|
1860
|
+
pos.column = 0;
|
|
1861
|
+
}
|
|
1862
|
+
else {
|
|
1863
|
+
pos.row = row;
|
|
1864
|
+
pos.column = Math.min(this.document.getLine(pos.row).length, Math.max(0, column));
|
|
1865
|
+
}
|
|
1866
|
+
|
|
1867
|
+
if (column < 0)
|
|
1868
|
+
pos.column = 0;
|
|
1869
|
+
|
|
1870
|
+
return pos;
|
|
1871
|
+
};
|
|
1872
|
+
|
|
1873
|
+
}).call(Anchor.prototype);
|
|
1874
|
+
|
|
1875
|
+
});
|
|
1876
|
+
|
|
1877
|
+
define('ace/lib/lang', ['require', 'exports', 'module' ], function(require, exports, module) {
|
|
1878
|
+
|
|
1879
|
+
|
|
1880
|
+
exports.stringReverse = function(string) {
|
|
1881
|
+
return string.split("").reverse().join("");
|
|
1882
|
+
};
|
|
1883
|
+
|
|
1884
|
+
exports.stringRepeat = function (string, count) {
|
|
1885
|
+
var result = '';
|
|
1886
|
+
while (count > 0) {
|
|
1887
|
+
if (count & 1)
|
|
1888
|
+
result += string;
|
|
1889
|
+
|
|
1890
|
+
if (count >>= 1)
|
|
1891
|
+
string += string;
|
|
1892
|
+
}
|
|
1893
|
+
return result;
|
|
1894
|
+
};
|
|
1895
|
+
|
|
1896
|
+
var trimBeginRegexp = /^\s\s*/;
|
|
1897
|
+
var trimEndRegexp = /\s\s*$/;
|
|
1898
|
+
|
|
1899
|
+
exports.stringTrimLeft = function (string) {
|
|
1900
|
+
return string.replace(trimBeginRegexp, '');
|
|
1901
|
+
};
|
|
1902
|
+
|
|
1903
|
+
exports.stringTrimRight = function (string) {
|
|
1904
|
+
return string.replace(trimEndRegexp, '');
|
|
1905
|
+
};
|
|
1906
|
+
|
|
1907
|
+
exports.copyObject = function(obj) {
|
|
1908
|
+
var copy = {};
|
|
1909
|
+
for (var key in obj) {
|
|
1910
|
+
copy[key] = obj[key];
|
|
1911
|
+
}
|
|
1912
|
+
return copy;
|
|
1913
|
+
};
|
|
1914
|
+
|
|
1915
|
+
exports.copyArray = function(array){
|
|
1916
|
+
var copy = [];
|
|
1917
|
+
for (var i=0, l=array.length; i<l; i++) {
|
|
1918
|
+
if (array[i] && typeof array[i] == "object")
|
|
1919
|
+
copy[i] = this.copyObject( array[i] );
|
|
1920
|
+
else
|
|
1921
|
+
copy[i] = array[i];
|
|
1922
|
+
}
|
|
1923
|
+
return copy;
|
|
1924
|
+
};
|
|
1925
|
+
|
|
1926
|
+
exports.deepCopy = function (obj) {
|
|
1927
|
+
if (typeof obj != "object") {
|
|
1928
|
+
return obj;
|
|
1929
|
+
}
|
|
1930
|
+
|
|
1931
|
+
var copy = obj.constructor();
|
|
1932
|
+
for (var key in obj) {
|
|
1933
|
+
if (typeof obj[key] == "object") {
|
|
1934
|
+
copy[key] = this.deepCopy(obj[key]);
|
|
1935
|
+
} else {
|
|
1936
|
+
copy[key] = obj[key];
|
|
1937
|
+
}
|
|
1938
|
+
}
|
|
1939
|
+
return copy;
|
|
1940
|
+
};
|
|
1941
|
+
|
|
1942
|
+
exports.arrayToMap = function(arr) {
|
|
1943
|
+
var map = {};
|
|
1944
|
+
for (var i=0; i<arr.length; i++) {
|
|
1945
|
+
map[arr[i]] = 1;
|
|
1946
|
+
}
|
|
1947
|
+
return map;
|
|
1948
|
+
|
|
1949
|
+
};
|
|
1950
|
+
|
|
1951
|
+
exports.createMap = function(props) {
|
|
1952
|
+
var map = Object.create(null);
|
|
1953
|
+
for (var i in props) {
|
|
1954
|
+
map[i] = props[i];
|
|
1955
|
+
}
|
|
1956
|
+
return map;
|
|
1957
|
+
};
|
|
1958
|
+
exports.arrayRemove = function(array, value) {
|
|
1959
|
+
for (var i = 0; i <= array.length; i++) {
|
|
1960
|
+
if (value === array[i]) {
|
|
1961
|
+
array.splice(i, 1);
|
|
1962
|
+
}
|
|
1963
|
+
}
|
|
1964
|
+
};
|
|
1965
|
+
|
|
1966
|
+
exports.escapeRegExp = function(str) {
|
|
1967
|
+
return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1');
|
|
1968
|
+
};
|
|
1969
|
+
|
|
1970
|
+
exports.escapeHTML = function(str) {
|
|
1971
|
+
return str.replace(/&/g, "&").replace(/"/g, """).replace(/'/g, "'").replace(/</g, "<");
|
|
1972
|
+
};
|
|
1973
|
+
|
|
1974
|
+
exports.getMatchOffsets = function(string, regExp) {
|
|
1975
|
+
var matches = [];
|
|
1976
|
+
|
|
1977
|
+
string.replace(regExp, function(str) {
|
|
1978
|
+
matches.push({
|
|
1979
|
+
offset: arguments[arguments.length-2],
|
|
1980
|
+
length: str.length
|
|
1981
|
+
});
|
|
1982
|
+
});
|
|
1983
|
+
|
|
1984
|
+
return matches;
|
|
1985
|
+
};
|
|
1986
|
+
exports.deferredCall = function(fcn) {
|
|
1987
|
+
|
|
1988
|
+
var timer = null;
|
|
1989
|
+
var callback = function() {
|
|
1990
|
+
timer = null;
|
|
1991
|
+
fcn();
|
|
1992
|
+
};
|
|
1993
|
+
|
|
1994
|
+
var deferred = function(timeout) {
|
|
1995
|
+
deferred.cancel();
|
|
1996
|
+
timer = setTimeout(callback, timeout || 0);
|
|
1997
|
+
return deferred;
|
|
1998
|
+
};
|
|
1999
|
+
|
|
2000
|
+
deferred.schedule = deferred;
|
|
2001
|
+
|
|
2002
|
+
deferred.call = function() {
|
|
2003
|
+
this.cancel();
|
|
2004
|
+
fcn();
|
|
2005
|
+
return deferred;
|
|
2006
|
+
};
|
|
2007
|
+
|
|
2008
|
+
deferred.cancel = function() {
|
|
2009
|
+
clearTimeout(timer);
|
|
2010
|
+
timer = null;
|
|
2011
|
+
return deferred;
|
|
2012
|
+
};
|
|
2013
|
+
|
|
2014
|
+
return deferred;
|
|
2015
|
+
};
|
|
2016
|
+
|
|
2017
|
+
|
|
2018
|
+
exports.delayedCall = function(fcn, defaultTimeout) {
|
|
2019
|
+
var timer = null;
|
|
2020
|
+
var callback = function() {
|
|
2021
|
+
timer = null;
|
|
2022
|
+
fcn();
|
|
2023
|
+
};
|
|
2024
|
+
|
|
2025
|
+
var _self = function(timeout) {
|
|
2026
|
+
timer && clearTimeout(timer);
|
|
2027
|
+
timer = setTimeout(callback, timeout || defaultTimeout);
|
|
2028
|
+
};
|
|
2029
|
+
|
|
2030
|
+
_self.delay = _self;
|
|
2031
|
+
_self.schedule = function(timeout) {
|
|
2032
|
+
if (timer == null)
|
|
2033
|
+
timer = setTimeout(callback, timeout || 0);
|
|
2034
|
+
};
|
|
2035
|
+
|
|
2036
|
+
_self.call = function() {
|
|
2037
|
+
this.cancel();
|
|
2038
|
+
fcn();
|
|
2039
|
+
};
|
|
2040
|
+
|
|
2041
|
+
_self.cancel = function() {
|
|
2042
|
+
timer && clearTimeout(timer);
|
|
2043
|
+
timer = null;
|
|
2044
|
+
};
|
|
2045
|
+
|
|
2046
|
+
_self.isPending = function() {
|
|
2047
|
+
return timer;
|
|
2048
|
+
};
|
|
2049
|
+
|
|
2050
|
+
return _self;
|
|
2051
|
+
};
|
|
2052
|
+
});
|
|
2053
|
+
define('ace/mode/lua/luaparse', ['require', 'exports', 'module' , 'exports'], function(require, exports, module) {
|
|
2054
|
+
|
|
2055
|
+
(function (root, name, factory) {
|
|
2056
|
+
|
|
2057
|
+
|
|
2058
|
+
if (typeof exports !== 'undefined') {
|
|
2059
|
+
factory(exports);
|
|
2060
|
+
} else if (typeof define === 'function' && define.amd) {
|
|
2061
|
+
define(['exports'], factory);
|
|
2062
|
+
} else {
|
|
2063
|
+
factory((root[name] = {}));
|
|
2064
|
+
}
|
|
2065
|
+
}(this, 'luaparse', function (exports) {
|
|
2066
|
+
|
|
2067
|
+
|
|
2068
|
+
exports.version = '0.0.1';
|
|
2069
|
+
|
|
2070
|
+
var input, options, length;
|
|
2071
|
+
|
|
2072
|
+
var defaultOptions = exports.defaultOptions = {
|
|
2073
|
+
wait: false
|
|
2074
|
+
, comments: true
|
|
2075
|
+
};
|
|
2076
|
+
|
|
2077
|
+
var EOF = 1, StringLiteral = 2, Keyword = 4, Identifier = 8
|
|
2078
|
+
, NumericLiteral = 16, Punctuator = 32, BooleanLiteral = 64
|
|
2079
|
+
, NilLiteral = 128;
|
|
2080
|
+
|
|
2081
|
+
var errors = exports.errors = {
|
|
2082
|
+
unexpected: 'Unexpected %1 \'%2\' near \'%3\''
|
|
2083
|
+
, expected: '\'%1\' expected near \'%2\''
|
|
2084
|
+
, expectedToken: '%1 expected near \'%2\''
|
|
2085
|
+
, unfinishedString: 'unfinished string near \'%1\''
|
|
2086
|
+
, malformedNumber: 'malformed number near \'%1\''
|
|
2087
|
+
};
|
|
2088
|
+
|
|
2089
|
+
var ast = exports.ast = {
|
|
2090
|
+
labelStatement: function(label) {
|
|
2091
|
+
return {
|
|
2092
|
+
type: 'LabelStatement'
|
|
2093
|
+
, label: label
|
|
2094
|
+
};
|
|
2095
|
+
}
|
|
2096
|
+
|
|
2097
|
+
, breakStatement: function() {
|
|
2098
|
+
return {
|
|
2099
|
+
type: 'BreakStatement'
|
|
2100
|
+
};
|
|
2101
|
+
}
|
|
2102
|
+
|
|
2103
|
+
, gotoStatement: function(label) {
|
|
2104
|
+
return {
|
|
2105
|
+
type: 'GotoStatement'
|
|
2106
|
+
, label: label
|
|
2107
|
+
};
|
|
2108
|
+
}
|
|
2109
|
+
|
|
2110
|
+
, returnStatement: function(args) {
|
|
2111
|
+
return {
|
|
2112
|
+
type: 'ReturnStatement'
|
|
2113
|
+
, 'arguments': args
|
|
2114
|
+
};
|
|
2115
|
+
}
|
|
2116
|
+
|
|
2117
|
+
, ifStatement: function(clauses) {
|
|
2118
|
+
return {
|
|
2119
|
+
type: 'IfStatement'
|
|
2120
|
+
, clauses: clauses
|
|
2121
|
+
};
|
|
2122
|
+
}
|
|
2123
|
+
, elseifClause: function(condition, body) {
|
|
2124
|
+
return {
|
|
2125
|
+
type: 'ElseifClause'
|
|
2126
|
+
, condition: condition
|
|
2127
|
+
, body: body
|
|
2128
|
+
};
|
|
2129
|
+
}
|
|
2130
|
+
, elseClause: function(body) {
|
|
2131
|
+
return {
|
|
2132
|
+
type: 'ElseClause'
|
|
2133
|
+
, body: body
|
|
2134
|
+
};
|
|
2135
|
+
}
|
|
2136
|
+
|
|
2137
|
+
, whileStatement: function(condition, body) {
|
|
2138
|
+
return {
|
|
2139
|
+
type: 'WhileStatement'
|
|
2140
|
+
, condition: condition
|
|
2141
|
+
, body: body
|
|
2142
|
+
};
|
|
2143
|
+
}
|
|
2144
|
+
|
|
2145
|
+
, doStatement: function(body) {
|
|
2146
|
+
return {
|
|
2147
|
+
type: 'DoStatement'
|
|
2148
|
+
, body: body
|
|
2149
|
+
};
|
|
2150
|
+
}
|
|
2151
|
+
|
|
2152
|
+
, repeatStatement: function(condition, body) {
|
|
2153
|
+
return {
|
|
2154
|
+
type: 'RepeatStatement'
|
|
2155
|
+
, condition: condition
|
|
2156
|
+
, body: body
|
|
2157
|
+
};
|
|
2158
|
+
}
|
|
2159
|
+
|
|
2160
|
+
, localStatement: function(variables, init) {
|
|
2161
|
+
return {
|
|
2162
|
+
type: 'LocalStatement'
|
|
2163
|
+
, variables: variables
|
|
2164
|
+
, init: init
|
|
2165
|
+
};
|
|
2166
|
+
}
|
|
2167
|
+
|
|
2168
|
+
, assignmentStatement: function(variables, init) {
|
|
2169
|
+
return {
|
|
2170
|
+
type: 'AssignmentStatement'
|
|
2171
|
+
, variables: variables
|
|
2172
|
+
, init: init
|
|
2173
|
+
};
|
|
2174
|
+
}
|
|
2175
|
+
|
|
2176
|
+
, callStatement: function(expression) {
|
|
2177
|
+
return {
|
|
2178
|
+
type: 'CallStatement'
|
|
2179
|
+
, expression: expression
|
|
2180
|
+
};
|
|
2181
|
+
}
|
|
2182
|
+
|
|
2183
|
+
, functionStatement: function(identifier, parameters, isVararg, isLocal, body) {
|
|
2184
|
+
return {
|
|
2185
|
+
type: 'FunctionDeclaration'
|
|
2186
|
+
, identifier: identifier
|
|
2187
|
+
, vararg: isVararg
|
|
2188
|
+
, local: isLocal
|
|
2189
|
+
, parameters: parameters
|
|
2190
|
+
, body: body
|
|
2191
|
+
};
|
|
2192
|
+
}
|
|
2193
|
+
|
|
2194
|
+
, forNumericStatement: function(variable, start, end, step, body) {
|
|
2195
|
+
return {
|
|
2196
|
+
type: 'ForNumericStatement'
|
|
2197
|
+
, variable: variable
|
|
2198
|
+
, start: start
|
|
2199
|
+
, end: end
|
|
2200
|
+
, step: step
|
|
2201
|
+
, body: body
|
|
2202
|
+
};
|
|
2203
|
+
}
|
|
2204
|
+
|
|
2205
|
+
, forGenericStatement: function(variables, iterators, body) {
|
|
2206
|
+
return {
|
|
2207
|
+
type: 'ForGenericStatement'
|
|
2208
|
+
, variables: variables
|
|
2209
|
+
, iterators: iterators
|
|
2210
|
+
, body: body
|
|
2211
|
+
};
|
|
2212
|
+
}
|
|
2213
|
+
|
|
2214
|
+
, chunk: function(body) {
|
|
2215
|
+
return {
|
|
2216
|
+
type: 'Chunk'
|
|
2217
|
+
, body: body
|
|
2218
|
+
};
|
|
2219
|
+
}
|
|
2220
|
+
|
|
2221
|
+
, identifier: function(name) {
|
|
2222
|
+
return {
|
|
2223
|
+
type: 'Identifier'
|
|
2224
|
+
, name: name
|
|
2225
|
+
};
|
|
2226
|
+
}
|
|
2227
|
+
|
|
2228
|
+
, literal: function(value, raw) {
|
|
2229
|
+
return {
|
|
2230
|
+
type: 'Literal'
|
|
2231
|
+
, value: value
|
|
2232
|
+
, raw: raw
|
|
2233
|
+
};
|
|
2234
|
+
}
|
|
2235
|
+
, varargLiteral: function() {
|
|
2236
|
+
return {
|
|
2237
|
+
type: 'VarargLiteral'
|
|
2238
|
+
};
|
|
2239
|
+
}
|
|
2240
|
+
|
|
2241
|
+
, tableKey: function(key, value) {
|
|
2242
|
+
return {
|
|
2243
|
+
type: 'TableKey'
|
|
2244
|
+
, key: key
|
|
2245
|
+
, value: value
|
|
2246
|
+
};
|
|
2247
|
+
}
|
|
2248
|
+
, tableKeyString: function(key, value) {
|
|
2249
|
+
return {
|
|
2250
|
+
type: 'TableKeyString'
|
|
2251
|
+
, key: key
|
|
2252
|
+
, value: value
|
|
2253
|
+
};
|
|
2254
|
+
}
|
|
2255
|
+
, tableValue: function(value) {
|
|
2256
|
+
return {
|
|
2257
|
+
type: 'TableValue'
|
|
2258
|
+
, value: value
|
|
2259
|
+
};
|
|
2260
|
+
}
|
|
2261
|
+
|
|
2262
|
+
|
|
2263
|
+
, tableConstructorExpression: function(fields) {
|
|
2264
|
+
return {
|
|
2265
|
+
type: 'TableConstructorExpression'
|
|
2266
|
+
, fields: fields
|
|
2267
|
+
};
|
|
2268
|
+
}
|
|
2269
|
+
, binaryExpression: function(operator, left, right) {
|
|
2270
|
+
var type = ('and' === operator || 'or' === operator) ?
|
|
2271
|
+
'LogicalExpression' :
|
|
2272
|
+
'BinaryExpression';
|
|
2273
|
+
|
|
2274
|
+
return {
|
|
2275
|
+
type: type
|
|
2276
|
+
, operator: operator
|
|
2277
|
+
, left: left
|
|
2278
|
+
, right: right
|
|
2279
|
+
};
|
|
2280
|
+
}
|
|
2281
|
+
, unaryExpression: function(operator, argument) {
|
|
2282
|
+
return {
|
|
2283
|
+
type: 'UnaryExpression'
|
|
2284
|
+
, operator: operator
|
|
2285
|
+
, argument: argument
|
|
2286
|
+
};
|
|
2287
|
+
}
|
|
2288
|
+
, memberExpression: function(base, indexer, identifier) {
|
|
2289
|
+
return {
|
|
2290
|
+
type: 'MemberExpression'
|
|
2291
|
+
, indexer: indexer
|
|
2292
|
+
, identifier: identifier
|
|
2293
|
+
, base: base
|
|
2294
|
+
};
|
|
2295
|
+
}
|
|
2296
|
+
|
|
2297
|
+
, indexExpression: function(base, index) {
|
|
2298
|
+
return {
|
|
2299
|
+
type: 'IndexExpression'
|
|
2300
|
+
, base: base
|
|
2301
|
+
, index: index
|
|
2302
|
+
};
|
|
2303
|
+
}
|
|
2304
|
+
|
|
2305
|
+
, callExpression: function(base, args) {
|
|
2306
|
+
return {
|
|
2307
|
+
type: 'CallExpression'
|
|
2308
|
+
, base: base
|
|
2309
|
+
, 'arguments': args
|
|
2310
|
+
};
|
|
2311
|
+
}
|
|
2312
|
+
|
|
2313
|
+
, tableCallExpression: function(base, args) {
|
|
2314
|
+
return {
|
|
2315
|
+
type: 'TableCallExpression'
|
|
2316
|
+
, base: base
|
|
2317
|
+
, 'arguments': args
|
|
2318
|
+
};
|
|
2319
|
+
}
|
|
2320
|
+
|
|
2321
|
+
, stringCallExpression: function(base, argument) {
|
|
2322
|
+
return {
|
|
2323
|
+
type: 'StringCallExpression'
|
|
2324
|
+
, base: base
|
|
2325
|
+
, argument: argument
|
|
2326
|
+
};
|
|
2327
|
+
}
|
|
2328
|
+
};
|
|
2329
|
+
|
|
2330
|
+
var slice = Array.prototype.slice
|
|
2331
|
+
, toString = Object.prototype.toString;
|
|
2332
|
+
|
|
2333
|
+
function sprintf(format) {
|
|
2334
|
+
var args = slice.call(arguments, 1);
|
|
2335
|
+
format = format.replace(/%(\d)/g, function (match, index) {
|
|
2336
|
+
match = ''; // jshint
|
|
2337
|
+
return '' + args[index - 1] || '';
|
|
2338
|
+
});
|
|
2339
|
+
return format;
|
|
2340
|
+
}
|
|
2341
|
+
|
|
2342
|
+
function extend() {
|
|
2343
|
+
var args = slice.call(arguments)
|
|
2344
|
+
, dest = {}
|
|
2345
|
+
, src, prop;
|
|
2346
|
+
|
|
2347
|
+
for (var i = 0, l = args.length; i < l; i++) {
|
|
2348
|
+
src = args[i];
|
|
2349
|
+
for (prop in src) if (src.hasOwnProperty(prop)) {
|
|
2350
|
+
dest[prop] = src[prop];
|
|
2351
|
+
}
|
|
2352
|
+
}
|
|
2353
|
+
return dest;
|
|
2354
|
+
}
|
|
2355
|
+
|
|
2356
|
+
function raise(token) {
|
|
2357
|
+
var message = sprintf.apply(null, slice.call(arguments, 1))
|
|
2358
|
+
, error, col;
|
|
2359
|
+
|
|
2360
|
+
if ('undefined' !== typeof token.line) {
|
|
2361
|
+
col = token.range[0] - token.lineStart;
|
|
2362
|
+
error = new SyntaxError(sprintf('[%1:%2] %3', token.line, col, message));
|
|
2363
|
+
error.line = token.line;
|
|
2364
|
+
error.index = token.range[0];
|
|
2365
|
+
error.column = col;
|
|
2366
|
+
} else {
|
|
2367
|
+
col = index - lineStart + 1;
|
|
2368
|
+
error = new SyntaxError(sprintf('[%1:%2] %3', line, col, message));
|
|
2369
|
+
error.index = index;
|
|
2370
|
+
error.line = line;
|
|
2371
|
+
error.column = col;
|
|
2372
|
+
}
|
|
2373
|
+
throw error;
|
|
2374
|
+
}
|
|
2375
|
+
|
|
2376
|
+
function raiseUnexpectedToken(type, token) {
|
|
2377
|
+
raise(token, errors.expectedToken, type, token.value);
|
|
2378
|
+
}
|
|
2379
|
+
|
|
2380
|
+
function unexpected(found, near) {
|
|
2381
|
+
if ('undefined' === typeof near) near = lookahead.value;
|
|
2382
|
+
if ('undefined' !== typeof found.type) {
|
|
2383
|
+
var type;
|
|
2384
|
+
switch (found.type) {
|
|
2385
|
+
case StringLiteral: type = 'string'; break;
|
|
2386
|
+
case Keyword: type = 'keyword'; break;
|
|
2387
|
+
case Identifier: type = 'identifier'; break;
|
|
2388
|
+
case NumericLiteral: type = 'number'; break;
|
|
2389
|
+
case Punctuator: type = 'symbol'; break;
|
|
2390
|
+
case BooleanLiteral: type = 'boolean'; break;
|
|
2391
|
+
case NilLiteral:
|
|
2392
|
+
return raise(found, errors.unexpected, 'symbol', 'nil', near);
|
|
2393
|
+
}
|
|
2394
|
+
return raise(found, errors.unexpected, type, found.value, near);
|
|
2395
|
+
}
|
|
2396
|
+
return raise(found, errors.unexpected, 'symbol', found, near);
|
|
2397
|
+
}
|
|
2398
|
+
|
|
2399
|
+
var index
|
|
2400
|
+
, token
|
|
2401
|
+
, lookahead
|
|
2402
|
+
, comments
|
|
2403
|
+
, tokenStart
|
|
2404
|
+
, line
|
|
2405
|
+
, lineStart;
|
|
2406
|
+
|
|
2407
|
+
function readToken() {
|
|
2408
|
+
skipWhiteSpace();
|
|
2409
|
+
while (45 === input.charCodeAt(index) &&
|
|
2410
|
+
45 === input.charCodeAt(index + 1)) {
|
|
2411
|
+
scanComment();
|
|
2412
|
+
skipWhiteSpace();
|
|
2413
|
+
}
|
|
2414
|
+
if (index >= length) return {
|
|
2415
|
+
type : EOF
|
|
2416
|
+
, value: '<eof>'
|
|
2417
|
+
, line: line
|
|
2418
|
+
, lineStart: lineStart
|
|
2419
|
+
, range: [index, index]
|
|
2420
|
+
};
|
|
2421
|
+
|
|
2422
|
+
var char = input.charCodeAt(index)
|
|
2423
|
+
, next = input.charCodeAt(index + 1);
|
|
2424
|
+
tokenStart = index;
|
|
2425
|
+
if (isIdentifierStart(char)) return scanIdentifierOrKeyword();
|
|
2426
|
+
|
|
2427
|
+
switch (char) {
|
|
2428
|
+
case 39: case 34: // '"
|
|
2429
|
+
return scanStringLiteral();
|
|
2430
|
+
case 48: case 49: case 50: case 51: case 52: case 53:
|
|
2431
|
+
case 54: case 55: case 56: case 57:
|
|
2432
|
+
return scanNumericLiteral();
|
|
2433
|
+
|
|
2434
|
+
case 46: // .
|
|
2435
|
+
if (isDecDigit(next)) return scanNumericLiteral();
|
|
2436
|
+
if (46 === next) {
|
|
2437
|
+
if (46 === input.charCodeAt(index + 2)) return scanPunctuator('...');
|
|
2438
|
+
return scanPunctuator('..');
|
|
2439
|
+
}
|
|
2440
|
+
return scanPunctuator('.');
|
|
2441
|
+
|
|
2442
|
+
case 61: // =
|
|
2443
|
+
if (61 === next) return scanPunctuator('==');
|
|
2444
|
+
return scanPunctuator('=');
|
|
2445
|
+
|
|
2446
|
+
case 62: // >
|
|
2447
|
+
if (61 === next) return scanPunctuator('>=');
|
|
2448
|
+
return scanPunctuator('>');
|
|
2449
|
+
|
|
2450
|
+
case 60: // <
|
|
2451
|
+
if (61 === next) return scanPunctuator('<=');
|
|
2452
|
+
return scanPunctuator('<');
|
|
2453
|
+
|
|
2454
|
+
case 126: // ~
|
|
2455
|
+
if (61 === next) return scanPunctuator('~=');
|
|
2456
|
+
return raise({}, errors.expected, '=', '~');
|
|
2457
|
+
|
|
2458
|
+
case 58: // :
|
|
2459
|
+
if (58 === next) return scanPunctuator('::');
|
|
2460
|
+
return scanPunctuator(':');
|
|
2461
|
+
|
|
2462
|
+
case 91: // [
|
|
2463
|
+
if (91 === next || 61 === next) return scanLongStringLiteral();
|
|
2464
|
+
return scanPunctuator('[');
|
|
2465
|
+
case 42: case 47: case 94: case 37: case 44: case 123: case 125:
|
|
2466
|
+
case 93: case 40: case 41: case 59: case 35: case 45: case 43:
|
|
2467
|
+
return scanPunctuator(input.charAt(index));
|
|
2468
|
+
}
|
|
2469
|
+
|
|
2470
|
+
return unexpected(input.charAt(index));
|
|
2471
|
+
}
|
|
2472
|
+
|
|
2473
|
+
function skipWhiteSpace() {
|
|
2474
|
+
while (index < length) {
|
|
2475
|
+
var char = input.charCodeAt(index);
|
|
2476
|
+
if (isWhiteSpace(char)) {
|
|
2477
|
+
index++;
|
|
2478
|
+
} else if (isLineTerminator(char)) {
|
|
2479
|
+
line++;
|
|
2480
|
+
lineStart = ++index;
|
|
2481
|
+
} else {
|
|
2482
|
+
break;
|
|
2483
|
+
}
|
|
2484
|
+
}
|
|
2485
|
+
}
|
|
2486
|
+
|
|
2487
|
+
function scanIdentifierOrKeyword() {
|
|
2488
|
+
var value, type;
|
|
2489
|
+
while (isIdentifierPart(input.charCodeAt(++index)));
|
|
2490
|
+
value = input.slice(tokenStart, index);
|
|
2491
|
+
if (isKeyword(value)) {
|
|
2492
|
+
type = Keyword;
|
|
2493
|
+
} else if ('true' === value || 'false' === value) {
|
|
2494
|
+
type = BooleanLiteral;
|
|
2495
|
+
value = ('true' === value);
|
|
2496
|
+
} else if ('nil' === value) {
|
|
2497
|
+
type = NilLiteral;
|
|
2498
|
+
value = null;
|
|
2499
|
+
} else {
|
|
2500
|
+
type = Identifier;
|
|
2501
|
+
}
|
|
2502
|
+
|
|
2503
|
+
return {
|
|
2504
|
+
type: type
|
|
2505
|
+
, value: value
|
|
2506
|
+
, line: line
|
|
2507
|
+
, lineStart: lineStart
|
|
2508
|
+
, range: [tokenStart, index]
|
|
2509
|
+
};
|
|
2510
|
+
}
|
|
2511
|
+
|
|
2512
|
+
function scanPunctuator(value) {
|
|
2513
|
+
index += value.length;
|
|
2514
|
+
return {
|
|
2515
|
+
type: Punctuator
|
|
2516
|
+
, value: value
|
|
2517
|
+
, line: line
|
|
2518
|
+
, lineStart: lineStart
|
|
2519
|
+
, range: [tokenStart, index]
|
|
2520
|
+
};
|
|
2521
|
+
}
|
|
2522
|
+
|
|
2523
|
+
function scanStringLiteral() {
|
|
2524
|
+
var delimiter = input.charCodeAt(index++)
|
|
2525
|
+
, stringStart = index
|
|
2526
|
+
, string = ''
|
|
2527
|
+
, char;
|
|
2528
|
+
|
|
2529
|
+
while (index < length) {
|
|
2530
|
+
char = input.charCodeAt(index++);
|
|
2531
|
+
if (delimiter === char) break;
|
|
2532
|
+
if (92 === char) { // \
|
|
2533
|
+
string += input.slice(stringStart, index - 1) + readEscapeSequence();
|
|
2534
|
+
stringStart = index;
|
|
2535
|
+
}
|
|
2536
|
+
else if (index >= length || isLineTerminator(char)) {
|
|
2537
|
+
string += input.slice(stringStart, index - 1);
|
|
2538
|
+
raise({}, errors.unfinishedString, string + String.fromCharCode(char));
|
|
2539
|
+
}
|
|
2540
|
+
}
|
|
2541
|
+
string += input.slice(stringStart, index - 1);
|
|
2542
|
+
|
|
2543
|
+
return {
|
|
2544
|
+
type: StringLiteral
|
|
2545
|
+
, value: string
|
|
2546
|
+
, line: line
|
|
2547
|
+
, lineStart: lineStart
|
|
2548
|
+
, range: [tokenStart, index]
|
|
2549
|
+
};
|
|
2550
|
+
}
|
|
2551
|
+
|
|
2552
|
+
function scanLongStringLiteral() {
|
|
2553
|
+
var string = readLongString();
|
|
2554
|
+
if (false === string) raise(token, errors.expected, '[', token.value);
|
|
2555
|
+
|
|
2556
|
+
return {
|
|
2557
|
+
type: StringLiteral
|
|
2558
|
+
, value: string
|
|
2559
|
+
, line: line
|
|
2560
|
+
, lineStart: lineStart
|
|
2561
|
+
, range: [tokenStart, index]
|
|
2562
|
+
};
|
|
2563
|
+
}
|
|
2564
|
+
|
|
2565
|
+
function scanNumericLiteral() {
|
|
2566
|
+
var char = input.charAt(index)
|
|
2567
|
+
, next = input.charAt(index + 1);
|
|
2568
|
+
|
|
2569
|
+
var value = ('0' === char && ~'xX'.indexOf(next || null)) ?
|
|
2570
|
+
readHexLiteral() : readDecLiteral();
|
|
2571
|
+
|
|
2572
|
+
return {
|
|
2573
|
+
type: NumericLiteral
|
|
2574
|
+
, value: value
|
|
2575
|
+
, line: line
|
|
2576
|
+
, lineStart: lineStart
|
|
2577
|
+
, range: [tokenStart, index]
|
|
2578
|
+
};
|
|
2579
|
+
}
|
|
2580
|
+
|
|
2581
|
+
function readHexLiteral() {
|
|
2582
|
+
var fraction = 0 // defaults to 0 as it gets summed
|
|
2583
|
+
, binaryExponent = 1 // defaults to 1 as it gets multiplied
|
|
2584
|
+
, binarySign = 1 // positive
|
|
2585
|
+
, digit, fractionStart, exponentStart, digitStart;
|
|
2586
|
+
|
|
2587
|
+
digitStart = index += 2; // Skip 0x part
|
|
2588
|
+
if (!isHexDigit(input.charCodeAt(index)))
|
|
2589
|
+
raise({}, errors.malformedNumber, input.slice(tokenStart, index));
|
|
2590
|
+
|
|
2591
|
+
while (isHexDigit(input.charCodeAt(index))) index++;
|
|
2592
|
+
digit = parseInt(input.slice(digitStart, index), 16);
|
|
2593
|
+
if ('.' === input.charAt(index)) {
|
|
2594
|
+
fractionStart = ++index;
|
|
2595
|
+
|
|
2596
|
+
while (isHexDigit(input.charCodeAt(index))) index++;
|
|
2597
|
+
fraction = input.slice(fractionStart, index);
|
|
2598
|
+
fraction = (fractionStart === index) ? 0
|
|
2599
|
+
: parseInt(fraction, 16) / Math.pow(16, index - fractionStart);
|
|
2600
|
+
}
|
|
2601
|
+
if (~'pP'.indexOf(input.charAt(index) || null)) {
|
|
2602
|
+
index++;
|
|
2603
|
+
if (~'+-'.indexOf(input.charAt(index) || null))
|
|
2604
|
+
binarySign = ('+' === input.charAt(index++)) ? 1 : -1;
|
|
2605
|
+
|
|
2606
|
+
exponentStart = index;
|
|
2607
|
+
if (!isDecDigit(input.charCodeAt(index)))
|
|
2608
|
+
raise({}, errors.malformedNumber, input.slice(tokenStart, index));
|
|
2609
|
+
|
|
2610
|
+
while (isDecDigit(input.charCodeAt(index))) index++;
|
|
2611
|
+
binaryExponent = input.slice(exponentStart, index);
|
|
2612
|
+
binaryExponent = Math.pow(2, binaryExponent * binarySign);
|
|
2613
|
+
}
|
|
2614
|
+
|
|
2615
|
+
return (digit + fraction) * binaryExponent;
|
|
2616
|
+
}
|
|
2617
|
+
|
|
2618
|
+
function readDecLiteral() {
|
|
2619
|
+
while (isDecDigit(input.charCodeAt(index))) index++;
|
|
2620
|
+
if ('.' === input.charAt(index)) {
|
|
2621
|
+
index++;
|
|
2622
|
+
while (isDecDigit(input.charCodeAt(index))) index++;
|
|
2623
|
+
}
|
|
2624
|
+
if (~'eE'.indexOf(input.charAt(index) || null)) {
|
|
2625
|
+
index++;
|
|
2626
|
+
if (~'+-'.indexOf(input.charAt(index) || null)) index++;
|
|
2627
|
+
if (!isDecDigit(input.charCodeAt(index)))
|
|
2628
|
+
raise({}, errors.malformedNumber, input.slice(tokenStart, index));
|
|
2629
|
+
|
|
2630
|
+
while (isDecDigit(input.charCodeAt(index))) index++;
|
|
2631
|
+
}
|
|
2632
|
+
|
|
2633
|
+
return parseFloat(input.slice(tokenStart, index));
|
|
2634
|
+
}
|
|
2635
|
+
|
|
2636
|
+
function readEscapeSequence() {
|
|
2637
|
+
var sequenceStart = index;
|
|
2638
|
+
switch (input.charAt(index)) {
|
|
2639
|
+
case 'n': index++; return '\n';
|
|
2640
|
+
case 'r': index++; return '\r';
|
|
2641
|
+
case 't': index++; return '\t';
|
|
2642
|
+
case 'v': index++; return '\v';
|
|
2643
|
+
case 'b': index++; return '\b';
|
|
2644
|
+
case 'f': index++; return '\f';
|
|
2645
|
+
case 'z': index++; skipWhiteSpace(); return '';
|
|
2646
|
+
case 'x':
|
|
2647
|
+
if (isHexDigit(input.charCodeAt(index + 1)) &&
|
|
2648
|
+
isHexDigit(input.charCodeAt(index + 2))) {
|
|
2649
|
+
index += 3;
|
|
2650
|
+
return '\\' + input.slice(sequenceStart, index);
|
|
2651
|
+
}
|
|
2652
|
+
return '\\' + input.charAt(index++);
|
|
2653
|
+
default:
|
|
2654
|
+
if (isDecDigit(input.charCodeAt(index))) {
|
|
2655
|
+
while (isDecDigit(input.charCodeAt(++index)));
|
|
2656
|
+
return '\\' + input.slice(sequenceStart, index);
|
|
2657
|
+
}
|
|
2658
|
+
return input.charAt(index++);
|
|
2659
|
+
}
|
|
2660
|
+
}
|
|
2661
|
+
|
|
2662
|
+
function scanComment() {
|
|
2663
|
+
tokenStart = index;
|
|
2664
|
+
index += 2; // --
|
|
2665
|
+
|
|
2666
|
+
var char = input.charAt(index)
|
|
2667
|
+
, content = ''
|
|
2668
|
+
, isLong = false
|
|
2669
|
+
, commentStart = index;
|
|
2670
|
+
|
|
2671
|
+
if ('[' === char) {
|
|
2672
|
+
content = readLongString();
|
|
2673
|
+
if (false === content) content = char;
|
|
2674
|
+
else {
|
|
2675
|
+
isLong = true;
|
|
2676
|
+
index += 2; // Trailing --
|
|
2677
|
+
}
|
|
2678
|
+
}
|
|
2679
|
+
if (!isLong) {
|
|
2680
|
+
while (index < length) {
|
|
2681
|
+
if (isLineTerminator(input.charCodeAt(index))) break;
|
|
2682
|
+
index++;
|
|
2683
|
+
}
|
|
2684
|
+
content = input.slice(commentStart, index);
|
|
2685
|
+
}
|
|
2686
|
+
|
|
2687
|
+
if (options.comments) {
|
|
2688
|
+
comments.push({
|
|
2689
|
+
type: 'Comment'
|
|
2690
|
+
, value: content
|
|
2691
|
+
, raw: input.slice(tokenStart, index)
|
|
2692
|
+
});
|
|
2693
|
+
}
|
|
2694
|
+
}
|
|
2695
|
+
|
|
2696
|
+
function readLongString() {
|
|
2697
|
+
var level = 0
|
|
2698
|
+
, content = ''
|
|
2699
|
+
, terminator = false
|
|
2700
|
+
, char, stringStart;
|
|
2701
|
+
|
|
2702
|
+
index++; // [
|
|
2703
|
+
while ('=' === input.charAt(index + level)) level++;
|
|
2704
|
+
if ('[' !== input.charAt(index + level)) return false;
|
|
2705
|
+
|
|
2706
|
+
index += level + 1;
|
|
2707
|
+
if (isLineTerminator(input.charCodeAt(index))) {
|
|
2708
|
+
line++;
|
|
2709
|
+
lineStart = index++;
|
|
2710
|
+
}
|
|
2711
|
+
|
|
2712
|
+
stringStart = index;
|
|
2713
|
+
while (index < length) {
|
|
2714
|
+
char = input.charAt(index++);
|
|
2715
|
+
if (isLineTerminator(char.charCodeAt(0))) {
|
|
2716
|
+
line++;
|
|
2717
|
+
lineStart = index;
|
|
2718
|
+
}
|
|
2719
|
+
|
|
2720
|
+
if (']' === char) {
|
|
2721
|
+
terminator = true;
|
|
2722
|
+
for (var i = 0; i < level; i++) {
|
|
2723
|
+
if ('=' !== input.charAt(index + i)) terminator = false;
|
|
2724
|
+
}
|
|
2725
|
+
if (']' !== input.charAt(index + level)) terminator = false;
|
|
2726
|
+
}
|
|
2727
|
+
if (terminator) break;
|
|
2728
|
+
|
|
2729
|
+
if ('\\' === char) {
|
|
2730
|
+
content += input.slice(stringStart, index - 1) + readEscapeSequence();
|
|
2731
|
+
stringStart = index;
|
|
2732
|
+
}
|
|
2733
|
+
}
|
|
2734
|
+
content += input.slice(stringStart, index - 1);
|
|
2735
|
+
index += level + 1;
|
|
2736
|
+
|
|
2737
|
+
return content;
|
|
2738
|
+
}
|
|
2739
|
+
|
|
2740
|
+
function next() {
|
|
2741
|
+
token = lookahead;
|
|
2742
|
+
lookahead = readToken();
|
|
2743
|
+
}
|
|
2744
|
+
|
|
2745
|
+
function consume(value) {
|
|
2746
|
+
if (value === token.value) {
|
|
2747
|
+
next();
|
|
2748
|
+
return true;
|
|
2749
|
+
}
|
|
2750
|
+
return false;
|
|
2751
|
+
}
|
|
2752
|
+
|
|
2753
|
+
function expectExpression(expression) {
|
|
2754
|
+
if (null == expression) raiseUnexpectedToken('<expression>', token);
|
|
2755
|
+
else return expression;
|
|
2756
|
+
}
|
|
2757
|
+
|
|
2758
|
+
function expect(value) {
|
|
2759
|
+
if (value === token.value) next();
|
|
2760
|
+
else raise(token, errors.expected, value, token.value);
|
|
2761
|
+
}
|
|
2762
|
+
|
|
2763
|
+
function isWhiteSpace(char) {
|
|
2764
|
+
return 9 === char || 32 === char || 0xB === char || 0xC === char;
|
|
2765
|
+
}
|
|
2766
|
+
|
|
2767
|
+
function isLineTerminator(char) {
|
|
2768
|
+
return 10 === char || 13 === char;
|
|
2769
|
+
}
|
|
2770
|
+
|
|
2771
|
+
function isDecDigit(char) {
|
|
2772
|
+
return char >= 48 && char <= 57;
|
|
2773
|
+
}
|
|
2774
|
+
|
|
2775
|
+
function isHexDigit(char) {
|
|
2776
|
+
return (char >= 48 && char <= 57) || (char >= 97 && char <= 102) || (char >= 65 && char <= 70);
|
|
2777
|
+
}
|
|
2778
|
+
|
|
2779
|
+
function isIdentifierStart(char) {
|
|
2780
|
+
return (char >= 65 && char <= 90) || (char >= 97 && char <= 122) || 95 === char;
|
|
2781
|
+
}
|
|
2782
|
+
|
|
2783
|
+
function isIdentifierPart(char) {
|
|
2784
|
+
return (char >= 65 && char <= 90) || (char >= 97 && char <= 122) || 95 === char || (char >= 48 && char <= 57);
|
|
2785
|
+
}
|
|
2786
|
+
|
|
2787
|
+
function isKeyword(id) {
|
|
2788
|
+
switch (id.length) {
|
|
2789
|
+
case 2:
|
|
2790
|
+
return 'do' === id || 'if' === id || 'in' === id || 'or' === id;
|
|
2791
|
+
case 3:
|
|
2792
|
+
return 'and' === id || 'end' === id || 'for' === id || 'not' === id;
|
|
2793
|
+
case 4:
|
|
2794
|
+
return 'else' === id || 'goto' === id || 'then' === id;
|
|
2795
|
+
case 5:
|
|
2796
|
+
return 'break' === id || 'local' === id || 'until' === id || 'while' === id;
|
|
2797
|
+
case 6:
|
|
2798
|
+
return 'elseif' === id || 'repeat' === id || 'return' === id;
|
|
2799
|
+
case 8:
|
|
2800
|
+
return 'function' === id;
|
|
2801
|
+
}
|
|
2802
|
+
return false;
|
|
2803
|
+
}
|
|
2804
|
+
|
|
2805
|
+
function isUnary(token) {
|
|
2806
|
+
if (Punctuator === token.type) return ~'#-'.indexOf(token.value);
|
|
2807
|
+
if (Keyword === token.type) return 'not' === token.value;
|
|
2808
|
+
return false;
|
|
2809
|
+
}
|
|
2810
|
+
function isCallExpression(expression) {
|
|
2811
|
+
switch (expression.type) {
|
|
2812
|
+
case 'CallExpression':
|
|
2813
|
+
case 'TableCallExpression':
|
|
2814
|
+
case 'StringCallExpression':
|
|
2815
|
+
return true;
|
|
2816
|
+
}
|
|
2817
|
+
return false;
|
|
2818
|
+
}
|
|
2819
|
+
|
|
2820
|
+
function isBlockFollow(token) {
|
|
2821
|
+
if (EOF === token.type) return true;
|
|
2822
|
+
if (Keyword !== token.type) return false;
|
|
2823
|
+
switch (token.value) {
|
|
2824
|
+
case 'else': case 'elseif':
|
|
2825
|
+
case 'end': case 'until':
|
|
2826
|
+
return true;
|
|
2827
|
+
default:
|
|
2828
|
+
return false;
|
|
2829
|
+
}
|
|
2830
|
+
}
|
|
2831
|
+
|
|
2832
|
+
function parseChunk() {
|
|
2833
|
+
next();
|
|
2834
|
+
var body = parseBlock();
|
|
2835
|
+
if (EOF !== token.type) unexpected(token);
|
|
2836
|
+
return ast.chunk(body);
|
|
2837
|
+
}
|
|
2838
|
+
|
|
2839
|
+
function parseBlock(terminator) {
|
|
2840
|
+
var block = []
|
|
2841
|
+
, statement;
|
|
2842
|
+
|
|
2843
|
+
while (!isBlockFollow(token)) {
|
|
2844
|
+
if ('return' === token.value) {
|
|
2845
|
+
block.push(parseStatement());
|
|
2846
|
+
break;
|
|
2847
|
+
}
|
|
2848
|
+
statement = parseStatement();
|
|
2849
|
+
if (statement) block.push(statement);
|
|
2850
|
+
}
|
|
2851
|
+
return block;
|
|
2852
|
+
}
|
|
2853
|
+
|
|
2854
|
+
function parseStatement() {
|
|
2855
|
+
if (Keyword === token.type) {
|
|
2856
|
+
switch (token.value) {
|
|
2857
|
+
case 'local': next(); return parseLocalStatement();
|
|
2858
|
+
case 'if': next(); return parseIfStatement();
|
|
2859
|
+
case 'return': next(); return parseReturnStatement();
|
|
2860
|
+
case 'function': next();
|
|
2861
|
+
var name = parseFunctionName();
|
|
2862
|
+
return parseFunctionDeclaration(name);
|
|
2863
|
+
case 'while': next(); return parseWhileStatement();
|
|
2864
|
+
case 'for': next(); return parseForStatement();
|
|
2865
|
+
case 'repeat': next(); return parseRepeatStatement();
|
|
2866
|
+
case 'break': next(); return parseBreakStatement();
|
|
2867
|
+
case 'do': next(); return parseDoStatement();
|
|
2868
|
+
case 'goto': next(); return parseGotoStatement();
|
|
2869
|
+
}
|
|
2870
|
+
}
|
|
2871
|
+
|
|
2872
|
+
if (Punctuator === token.type) {
|
|
2873
|
+
if (consume('::')) return parseLabelStatement();
|
|
2874
|
+
}
|
|
2875
|
+
if (consume(';')) return;
|
|
2876
|
+
|
|
2877
|
+
return parseAssignmentOrCallStatement();
|
|
2878
|
+
}
|
|
2879
|
+
|
|
2880
|
+
function parseLabelStatement() {
|
|
2881
|
+
var label = parseIdentifier();
|
|
2882
|
+
expect('::');
|
|
2883
|
+
return ast.labelStatement(label);
|
|
2884
|
+
}
|
|
2885
|
+
|
|
2886
|
+
function parseBreakStatement() {
|
|
2887
|
+
return ast.breakStatement();
|
|
2888
|
+
}
|
|
2889
|
+
|
|
2890
|
+
function parseGotoStatement() {
|
|
2891
|
+
var label = parseIdentifier();
|
|
2892
|
+
return ast.gotoStatement(label);
|
|
2893
|
+
}
|
|
2894
|
+
|
|
2895
|
+
function parseDoStatement() {
|
|
2896
|
+
var body = parseBlock();
|
|
2897
|
+
expect('end');
|
|
2898
|
+
return ast.doStatement(body);
|
|
2899
|
+
}
|
|
2900
|
+
|
|
2901
|
+
function parseWhileStatement() {
|
|
2902
|
+
var condition = parseExpression();
|
|
2903
|
+
expect('do');
|
|
2904
|
+
var body = parseBlock();
|
|
2905
|
+
expect('end');
|
|
2906
|
+
return ast.whileStatement(condition, body);
|
|
2907
|
+
}
|
|
2908
|
+
|
|
2909
|
+
function parseRepeatStatement() {
|
|
2910
|
+
var body = parseBlock();
|
|
2911
|
+
expect('until');
|
|
2912
|
+
var condition = expectExpression(parseExpression());
|
|
2913
|
+
return ast.repeatStatement(condition, body);
|
|
2914
|
+
}
|
|
2915
|
+
|
|
2916
|
+
function parseReturnStatement() {
|
|
2917
|
+
var expressions = [];
|
|
2918
|
+
|
|
2919
|
+
if ('end' !== token.value) {
|
|
2920
|
+
var expression = parseExpression();
|
|
2921
|
+
if (null != expression) expressions.push(expression);
|
|
2922
|
+
while (consume(',')) {
|
|
2923
|
+
expression = expectExpression(parseExpression());
|
|
2924
|
+
expressions.push(expression);
|
|
2925
|
+
}
|
|
2926
|
+
consume(';'); // grammar tells us ; is optional here.
|
|
2927
|
+
}
|
|
2928
|
+
return ast.returnStatement(expressions);
|
|
2929
|
+
}
|
|
2930
|
+
|
|
2931
|
+
function parseIfStatement() {
|
|
2932
|
+
var clauses = []
|
|
2933
|
+
, condition
|
|
2934
|
+
, body;
|
|
2935
|
+
|
|
2936
|
+
do {
|
|
2937
|
+
condition = parseExpression();
|
|
2938
|
+
expect('then');
|
|
2939
|
+
body = parseBlock();
|
|
2940
|
+
clauses.push(ast.elseifClause(condition, body));
|
|
2941
|
+
} while (consume('elseif'));
|
|
2942
|
+
|
|
2943
|
+
if (consume('else')) {
|
|
2944
|
+
body = parseBlock();
|
|
2945
|
+
clauses.push(ast.elseClause(body));
|
|
2946
|
+
}
|
|
2947
|
+
|
|
2948
|
+
expect('end');
|
|
2949
|
+
return ast.ifStatement(clauses);
|
|
2950
|
+
}
|
|
2951
|
+
|
|
2952
|
+
function parseForStatement() {
|
|
2953
|
+
var variable = parseIdentifier()
|
|
2954
|
+
, body;
|
|
2955
|
+
if (consume('=')) {
|
|
2956
|
+
var start = expectExpression(parseExpression());
|
|
2957
|
+
expect(',');
|
|
2958
|
+
var end = expectExpression(parseExpression());
|
|
2959
|
+
var step = consume(',') ? expectExpression(parseExpression()) : null;
|
|
2960
|
+
|
|
2961
|
+
expect('do');
|
|
2962
|
+
body = parseBlock();
|
|
2963
|
+
expect('end');
|
|
2964
|
+
|
|
2965
|
+
return ast.forNumericStatement(variable, start, end, step, body);
|
|
2966
|
+
} else {
|
|
2967
|
+
var variables = [variable];
|
|
2968
|
+
while (consume(',')) variables.push(parseIdentifier());
|
|
2969
|
+
expect('in');
|
|
2970
|
+
var iterators = [];
|
|
2971
|
+
do {
|
|
2972
|
+
var expression = expectExpression(parseExpression());
|
|
2973
|
+
iterators.push(expression);
|
|
2974
|
+
} while (consume(','));
|
|
2975
|
+
|
|
2976
|
+
expect('do');
|
|
2977
|
+
body = parseBlock();
|
|
2978
|
+
expect('end');
|
|
2979
|
+
|
|
2980
|
+
return ast.forGenericStatement(variables, iterators, body);
|
|
2981
|
+
}
|
|
2982
|
+
}
|
|
2983
|
+
|
|
2984
|
+
function parseLocalStatement() {
|
|
2985
|
+
if (Identifier === token.type) {
|
|
2986
|
+
var variables = [];
|
|
2987
|
+
var init = [];
|
|
2988
|
+
|
|
2989
|
+
do {
|
|
2990
|
+
variables.push(parseIdentifier());
|
|
2991
|
+
} while (consume(','));
|
|
2992
|
+
|
|
2993
|
+
if (consume('=')) {
|
|
2994
|
+
do {
|
|
2995
|
+
var expression = expectExpression(parseExpression());
|
|
2996
|
+
init.push(expression);
|
|
2997
|
+
} while (consume(','));
|
|
2998
|
+
}
|
|
2999
|
+
|
|
3000
|
+
return ast.localStatement(variables, init);
|
|
3001
|
+
}
|
|
3002
|
+
if (consume('function')) {
|
|
3003
|
+
var name = parseIdentifier();
|
|
3004
|
+
return parseFunctionDeclaration(name, true);
|
|
3005
|
+
} else {
|
|
3006
|
+
raiseUnexpectedToken('<name>', token);
|
|
3007
|
+
}
|
|
3008
|
+
}
|
|
3009
|
+
|
|
3010
|
+
function parseAssignmentOrCallStatement() {
|
|
3011
|
+
var previous = token
|
|
3012
|
+
, expression = parsePrefixExpression();
|
|
3013
|
+
|
|
3014
|
+
if (null == expression) return unexpected(token);
|
|
3015
|
+
if (~',='.indexOf(token.value)) {
|
|
3016
|
+
var variables = [expression]
|
|
3017
|
+
, init = []
|
|
3018
|
+
, exp;
|
|
3019
|
+
|
|
3020
|
+
while (consume(',')) {
|
|
3021
|
+
exp = expectExpression(parsePrefixExpression());
|
|
3022
|
+
variables.push(exp);
|
|
3023
|
+
}
|
|
3024
|
+
expect('=');
|
|
3025
|
+
do {
|
|
3026
|
+
exp = expectExpression(parseExpression());
|
|
3027
|
+
init.push(exp);
|
|
3028
|
+
} while (consume(','));
|
|
3029
|
+
return ast.assignmentStatement(variables, init);
|
|
3030
|
+
}
|
|
3031
|
+
if (isCallExpression(expression)) {
|
|
3032
|
+
return ast.callStatement(expression);
|
|
3033
|
+
}
|
|
3034
|
+
return unexpected(previous);
|
|
3035
|
+
}
|
|
3036
|
+
|
|
3037
|
+
function parseIdentifier() {
|
|
3038
|
+
var identifier = token.value;
|
|
3039
|
+
if (Identifier !== token.type) raiseUnexpectedToken('<name>', token);
|
|
3040
|
+
next();
|
|
3041
|
+
return ast.identifier(identifier);
|
|
3042
|
+
}
|
|
3043
|
+
|
|
3044
|
+
function parseFunctionDeclaration(name, isLocal) {
|
|
3045
|
+
var isVararg = false;
|
|
3046
|
+
var parameters = [];
|
|
3047
|
+
expect('(');
|
|
3048
|
+
|
|
3049
|
+
if (consume('...')) isVararg = true;
|
|
3050
|
+
else if (Identifier === token.type) {
|
|
3051
|
+
do {
|
|
3052
|
+
if (consume('...')) {
|
|
3053
|
+
isVararg = true;
|
|
3054
|
+
break;
|
|
3055
|
+
}
|
|
3056
|
+
parameters.push(parseIdentifier());
|
|
3057
|
+
} while (consume(','));
|
|
3058
|
+
}
|
|
3059
|
+
if (isVararg) expect(')');
|
|
3060
|
+
else if (!consume(')')) raiseUnexpectedToken('<name> or \'...\'', token);
|
|
3061
|
+
|
|
3062
|
+
var body = parseBlock();
|
|
3063
|
+
expect('end');
|
|
3064
|
+
|
|
3065
|
+
isLocal = isLocal || false;
|
|
3066
|
+
return ast.functionStatement(name, parameters, isVararg, isLocal, body);
|
|
3067
|
+
}
|
|
3068
|
+
|
|
3069
|
+
function parseFunctionName() {
|
|
3070
|
+
var base = parseIdentifier();
|
|
3071
|
+
|
|
3072
|
+
while (consume('.')) {
|
|
3073
|
+
base = ast.memberExpression(base, '.', parseIdentifier());
|
|
3074
|
+
}
|
|
3075
|
+
|
|
3076
|
+
if (consume(':')) {
|
|
3077
|
+
base = ast.memberExpression(base, ':', parseIdentifier());
|
|
3078
|
+
}
|
|
3079
|
+
|
|
3080
|
+
return base;
|
|
3081
|
+
}
|
|
3082
|
+
|
|
3083
|
+
function parseTableConstructor() {
|
|
3084
|
+
var fields = []
|
|
3085
|
+
, key, value;
|
|
3086
|
+
|
|
3087
|
+
while (true) {
|
|
3088
|
+
if (Punctuator === token.type && consume('[')) {
|
|
3089
|
+
key = parseExpression();
|
|
3090
|
+
expect(']');
|
|
3091
|
+
expect('=');
|
|
3092
|
+
value = expectExpression(parseExpression());
|
|
3093
|
+
fields.push(ast.tableKey(key, value));
|
|
3094
|
+
} else if (Identifier === token.type) {
|
|
3095
|
+
key = parseExpression();
|
|
3096
|
+
if (consume('=')) {
|
|
3097
|
+
value = parseExpression();
|
|
3098
|
+
fields.push(ast.tableKeyString(key, value));
|
|
3099
|
+
} else {
|
|
3100
|
+
fields.push(ast.tableValue(key));
|
|
3101
|
+
}
|
|
3102
|
+
} else {
|
|
3103
|
+
if (null == (value = parseExpression())) break;
|
|
3104
|
+
fields.push(ast.tableValue(value));
|
|
3105
|
+
}
|
|
3106
|
+
if (~',;'.indexOf(token.value)) {
|
|
3107
|
+
next();
|
|
3108
|
+
continue;
|
|
3109
|
+
}
|
|
3110
|
+
if ('}' === token.value) break;
|
|
3111
|
+
}
|
|
3112
|
+
expect('}');
|
|
3113
|
+
return ast.tableConstructorExpression(fields);
|
|
3114
|
+
}
|
|
3115
|
+
|
|
3116
|
+
function parseExpression() {
|
|
3117
|
+
var expression = parseSubExpression(0);
|
|
3118
|
+
return expression;
|
|
3119
|
+
}
|
|
3120
|
+
|
|
3121
|
+
function binaryPrecedence(operator) {
|
|
3122
|
+
var char = operator.charCodeAt(0)
|
|
3123
|
+
, length = operator.length;
|
|
3124
|
+
|
|
3125
|
+
if (1 === length) {
|
|
3126
|
+
switch (char) {
|
|
3127
|
+
case 94: return 10; // ^
|
|
3128
|
+
case 42: case 47: case 37: return 7; // * / %
|
|
3129
|
+
case 43: case 45: return 6; // + -
|
|
3130
|
+
case 60: case 62: return 3; // < >
|
|
3131
|
+
}
|
|
3132
|
+
} else if (2 === length) {
|
|
3133
|
+
switch (char) {
|
|
3134
|
+
case 46: return 5; // ..
|
|
3135
|
+
case 60: case 62: case 61: case 126: return 3; // <= >= == ~=
|
|
3136
|
+
case 111: return 1; // or
|
|
3137
|
+
}
|
|
3138
|
+
} else if (97 === char && 'and' === operator) return 2;
|
|
3139
|
+
return 0;
|
|
3140
|
+
}
|
|
3141
|
+
|
|
3142
|
+
function parseSubExpression(minPrecedence) {
|
|
3143
|
+
var operator = token.value;
|
|
3144
|
+
var expression;
|
|
3145
|
+
if (isUnary(token)) {
|
|
3146
|
+
next();
|
|
3147
|
+
var argument = expectExpression(parseSubExpression(8));
|
|
3148
|
+
expression = ast.unaryExpression(operator, argument);
|
|
3149
|
+
}
|
|
3150
|
+
if (null == expression) {
|
|
3151
|
+
expression = parsePrimaryExpression();
|
|
3152
|
+
if (null == expression) {
|
|
3153
|
+
expression = parsePrefixExpression();
|
|
3154
|
+
}
|
|
3155
|
+
}
|
|
3156
|
+
if (null == expression) return null;
|
|
3157
|
+
|
|
3158
|
+
var precedence;
|
|
3159
|
+
while (true) {
|
|
3160
|
+
operator = token.value;
|
|
3161
|
+
|
|
3162
|
+
precedence = (Punctuator === token.type || Keyword === token.type) ?
|
|
3163
|
+
binaryPrecedence(operator) : 0;
|
|
3164
|
+
|
|
3165
|
+
if (precedence === 0 || precedence <= minPrecedence) break;
|
|
3166
|
+
if ('^' === operator || '..' === operator) precedence--;
|
|
3167
|
+
next();
|
|
3168
|
+
var right = expectExpression(parseSubExpression(precedence));
|
|
3169
|
+
expression = ast.binaryExpression(operator, expression, right);
|
|
3170
|
+
}
|
|
3171
|
+
return expression;
|
|
3172
|
+
}
|
|
3173
|
+
|
|
3174
|
+
function parsePrefixExpression() {
|
|
3175
|
+
var base;
|
|
3176
|
+
if (Identifier === token.type) {
|
|
3177
|
+
base = parseIdentifier();
|
|
3178
|
+
} else if (consume('(')) {
|
|
3179
|
+
base = parseExpression();
|
|
3180
|
+
expect(')');
|
|
3181
|
+
} else {
|
|
3182
|
+
return null;
|
|
3183
|
+
}
|
|
3184
|
+
var expression, identifier;
|
|
3185
|
+
while (true) {
|
|
3186
|
+
expectExpression(base);
|
|
3187
|
+
if (Punctuator === token.type) {
|
|
3188
|
+
switch (token.value) {
|
|
3189
|
+
case '[':
|
|
3190
|
+
next();
|
|
3191
|
+
expression = parseExpression();
|
|
3192
|
+
base = ast.indexExpression(base, expression);
|
|
3193
|
+
expect(']');
|
|
3194
|
+
break;
|
|
3195
|
+
case '.':
|
|
3196
|
+
next();
|
|
3197
|
+
identifier = parseIdentifier();
|
|
3198
|
+
base = ast.memberExpression(base, '.', identifier);
|
|
3199
|
+
break;
|
|
3200
|
+
case ':':
|
|
3201
|
+
next();
|
|
3202
|
+
identifier = parseIdentifier();
|
|
3203
|
+
base = ast.memberExpression(base, ':', identifier);
|
|
3204
|
+
base = parseCallExpression(base);
|
|
3205
|
+
break;
|
|
3206
|
+
case '(': case '{': // args
|
|
3207
|
+
base = parseCallExpression(base);
|
|
3208
|
+
break;
|
|
3209
|
+
default:
|
|
3210
|
+
return base;
|
|
3211
|
+
}
|
|
3212
|
+
} else if (StringLiteral === token.type) {
|
|
3213
|
+
base = parseCallExpression(base);
|
|
3214
|
+
} else {
|
|
3215
|
+
break;
|
|
3216
|
+
}
|
|
3217
|
+
}
|
|
3218
|
+
|
|
3219
|
+
return base;
|
|
3220
|
+
}
|
|
3221
|
+
|
|
3222
|
+
function parseCallExpression(base) {
|
|
3223
|
+
if (Punctuator === token.type) {
|
|
3224
|
+
switch (token.value) {
|
|
3225
|
+
case '(':
|
|
3226
|
+
next();
|
|
3227
|
+
var expressions = [];
|
|
3228
|
+
var expression = parseExpression();
|
|
3229
|
+
if (null != expression) expressions.push(expression);
|
|
3230
|
+
while (consume(',')) {
|
|
3231
|
+
expression = expectExpression(parseExpression());
|
|
3232
|
+
expressions.push(expression);
|
|
3233
|
+
}
|
|
3234
|
+
|
|
3235
|
+
expect(')');
|
|
3236
|
+
return ast.callExpression(base, expressions);
|
|
3237
|
+
|
|
3238
|
+
case '{':
|
|
3239
|
+
next();
|
|
3240
|
+
var table = parseTableConstructor();
|
|
3241
|
+
return ast.tableCallExpression(base, table);
|
|
3242
|
+
}
|
|
3243
|
+
|
|
3244
|
+
} else if (StringLiteral === token.type) {
|
|
3245
|
+
var string = token.value;
|
|
3246
|
+
next();
|
|
3247
|
+
return ast.stringCallExpression(base, string);
|
|
3248
|
+
}
|
|
3249
|
+
|
|
3250
|
+
raiseUnexpectedToken('function arguments', token);
|
|
3251
|
+
}
|
|
3252
|
+
|
|
3253
|
+
function parsePrimaryExpression() {
|
|
3254
|
+
var literals = StringLiteral | NumericLiteral | BooleanLiteral | NilLiteral
|
|
3255
|
+
, value = token.value;
|
|
3256
|
+
|
|
3257
|
+
if (token.type & literals) {
|
|
3258
|
+
var raw = input.slice(token.range[0], token.range[1]);
|
|
3259
|
+
next();
|
|
3260
|
+
return ast.literal(value, raw);
|
|
3261
|
+
} else if (Keyword === token.type && 'function' === token.value) {
|
|
3262
|
+
next();
|
|
3263
|
+
return parseFunctionDeclaration(null);
|
|
3264
|
+
} else if (Punctuator === token.type) {
|
|
3265
|
+
if (consume('...')) return ast.varargLiteral(value);
|
|
3266
|
+
if (consume('{')) return parseTableConstructor();
|
|
3267
|
+
}
|
|
3268
|
+
}
|
|
3269
|
+
|
|
3270
|
+
exports.parse = parse;
|
|
3271
|
+
|
|
3272
|
+
function parse(_input, _options) {
|
|
3273
|
+
if ('undefined' === typeof _options && 'object' === typeof _input) {
|
|
3274
|
+
_options = _input;
|
|
3275
|
+
_input = undefined;
|
|
3276
|
+
}
|
|
3277
|
+
if (!_options) _options = {};
|
|
3278
|
+
|
|
3279
|
+
input = _input || '';
|
|
3280
|
+
options = extend(defaultOptions, _options);
|
|
3281
|
+
index = 0;
|
|
3282
|
+
line = 1;
|
|
3283
|
+
lineStart = 0;
|
|
3284
|
+
length = input.length;
|
|
3285
|
+
|
|
3286
|
+
if (options.comments) comments = [];
|
|
3287
|
+
if (!options.wait) return end();
|
|
3288
|
+
return exports;
|
|
3289
|
+
}
|
|
3290
|
+
exports.write = write;
|
|
3291
|
+
|
|
3292
|
+
function write(_input) {
|
|
3293
|
+
input += String(_input);
|
|
3294
|
+
length = input.length;
|
|
3295
|
+
return exports;
|
|
3296
|
+
}
|
|
3297
|
+
exports.end = end;
|
|
3298
|
+
|
|
3299
|
+
function end(_input) {
|
|
3300
|
+
if ('undefined' !== typeof _input) write(_input);
|
|
3301
|
+
|
|
3302
|
+
length = input.length;
|
|
3303
|
+
lookahead = readToken();
|
|
3304
|
+
|
|
3305
|
+
var chunk = parseChunk();
|
|
3306
|
+
if (options.comments) chunk.comments = comments;
|
|
3307
|
+
return chunk;
|
|
3308
|
+
}
|
|
3309
|
+
exports.lex = readToken;
|
|
3310
|
+
|
|
3311
|
+
}));
|
|
3312
|
+
|
|
3313
|
+
});
|