worker-lua.js 103 KB

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