d8e55e28d680c6765e74e9504ea1db3e.js 102 KB

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