worker-lua.js 82 KB

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