worker-lua.js 103 KB

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