worker-lua.js 99 KB

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