Bez popisu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

worker-lua.js 99KB

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