d8e55e28d680c6765e74e9504ea1db3e.js 102 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511
  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. });