worker-json.js 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715
  1. "no use strict";
  2. !(function(window) {
  3. if (typeof window.window != "undefined" && window.document)
  4. return;
  5. if (window.require && window.define)
  6. return;
  7. if (!window.console) {
  8. window.console = function() {
  9. var msgs = Array.prototype.slice.call(arguments, 0);
  10. postMessage({type: "log", data: msgs});
  11. };
  12. window.console.error =
  13. window.console.warn =
  14. window.console.log =
  15. window.console.trace = window.console;
  16. }
  17. window.window = window;
  18. window.ace = window;
  19. window.onerror = function(message, file, line, col, err) {
  20. postMessage({type: "error", data: {
  21. message: message,
  22. data: err.data,
  23. file: file,
  24. line: line,
  25. col: col,
  26. stack: err.stack
  27. }});
  28. };
  29. window.normalizeModule = function(parentId, moduleName) {
  30. // normalize plugin requires
  31. if (moduleName.indexOf("!") !== -1) {
  32. var chunks = moduleName.split("!");
  33. return window.normalizeModule(parentId, chunks[0]) + "!" + window.normalizeModule(parentId, chunks[1]);
  34. }
  35. // normalize relative requires
  36. if (moduleName.charAt(0) == ".") {
  37. var base = parentId.split("/").slice(0, -1).join("/");
  38. moduleName = (base ? base + "/" : "") + moduleName;
  39. while (moduleName.indexOf(".") !== -1 && previous != moduleName) {
  40. var previous = moduleName;
  41. moduleName = moduleName.replace(/^\.\//, "").replace(/\/\.\//, "/").replace(/[^\/]+\/\.\.\//, "");
  42. }
  43. }
  44. return moduleName;
  45. };
  46. window.require = function require(parentId, id) {
  47. if (!id) {
  48. id = parentId;
  49. parentId = null;
  50. }
  51. if (!id.charAt)
  52. throw new Error("worker.js require() accepts only (parentId, id) as arguments");
  53. id = window.normalizeModule(parentId, id);
  54. var module = window.require.modules[id];
  55. if (module) {
  56. if (!module.initialized) {
  57. module.initialized = true;
  58. module.exports = module.factory().exports;
  59. }
  60. return module.exports;
  61. }
  62. if (!window.require.tlns)
  63. return console.log("unable to load " + id);
  64. var path = resolveModuleId(id, window.require.tlns);
  65. if (path.slice(-3) != ".js") path += ".js";
  66. window.require.id = id;
  67. window.require.modules[id] = {}; // prevent infinite loop on broken modules
  68. importScripts(path);
  69. return window.require(parentId, id);
  70. };
  71. function resolveModuleId(id, paths) {
  72. var testPath = id, tail = "";
  73. while (testPath) {
  74. var alias = paths[testPath];
  75. if (typeof alias == "string") {
  76. return alias + tail;
  77. } else if (alias) {
  78. return alias.location.replace(/\/*$/, "/") + (tail || alias.main || alias.name);
  79. } else if (alias === false) {
  80. return "";
  81. }
  82. var i = testPath.lastIndexOf("/");
  83. if (i === -1) break;
  84. tail = testPath.substr(i) + tail;
  85. testPath = testPath.slice(0, i);
  86. }
  87. return id;
  88. }
  89. window.require.modules = {};
  90. window.require.tlns = {};
  91. window.define = function(id, deps, factory) {
  92. if (arguments.length == 2) {
  93. factory = deps;
  94. if (typeof id != "string") {
  95. deps = id;
  96. id = window.require.id;
  97. }
  98. } else if (arguments.length == 1) {
  99. factory = id;
  100. deps = [];
  101. id = window.require.id;
  102. }
  103. if (typeof factory != "function") {
  104. window.require.modules[id] = {
  105. exports: factory,
  106. initialized: true
  107. };
  108. return;
  109. }
  110. if (!deps.length)
  111. // If there is no dependencies, we inject "require", "exports" and
  112. // "module" as dependencies, to provide CommonJS compatibility.
  113. deps = ["require", "exports", "module"];
  114. var req = function(childId) {
  115. return window.require(id, childId);
  116. };
  117. window.require.modules[id] = {
  118. exports: {},
  119. factory: function() {
  120. var module = this;
  121. var returnExports = factory.apply(this, deps.slice(0, factory.length).map(function(dep) {
  122. switch (dep) {
  123. // Because "require", "exports" and "module" aren't actual
  124. // dependencies, we must handle them seperately.
  125. case "require": return req;
  126. case "exports": return module.exports;
  127. case "module": return module;
  128. // But for all other dependencies, we can just go ahead and
  129. // require them.
  130. default: return req(dep);
  131. }
  132. }));
  133. if (returnExports)
  134. module.exports = returnExports;
  135. return module;
  136. }
  137. };
  138. };
  139. window.define.amd = {};
  140. require.tlns = {};
  141. window.initBaseUrls = function initBaseUrls(topLevelNamespaces) {
  142. for (var i in topLevelNamespaces)
  143. require.tlns[i] = topLevelNamespaces[i];
  144. };
  145. window.initSender = function initSender() {
  146. var EventEmitter = window.require("ace/lib/event_emitter").EventEmitter;
  147. var oop = window.require("ace/lib/oop");
  148. var Sender = function() {};
  149. (function() {
  150. oop.implement(this, EventEmitter);
  151. this.callback = function(data, callbackId) {
  152. postMessage({
  153. type: "call",
  154. id: callbackId,
  155. data: data
  156. });
  157. };
  158. this.emit = function(name, data) {
  159. postMessage({
  160. type: "event",
  161. name: name,
  162. data: data
  163. });
  164. };
  165. }).call(Sender.prototype);
  166. return new Sender();
  167. };
  168. var main = window.main = null;
  169. var sender = window.sender = null;
  170. window.onmessage = function(e) {
  171. var msg = e.data;
  172. if (msg.event && sender) {
  173. sender._signal(msg.event, msg.data);
  174. }
  175. else if (msg.command) {
  176. if (main[msg.command])
  177. main[msg.command].apply(main, msg.args);
  178. else if (window[msg.command])
  179. window[msg.command].apply(window, msg.args);
  180. else
  181. throw new Error("Unknown command:" + msg.command);
  182. }
  183. else if (msg.init) {
  184. window.initBaseUrls(msg.tlns);
  185. sender = window.sender = window.initSender();
  186. var clazz = require(msg.module)[msg.classname];
  187. main = window.main = new clazz(sender);
  188. }
  189. };
  190. })(this);
  191. ace.define("ace/lib/oop",[], function(require, exports, module) {
  192. "use strict";
  193. exports.inherits = function(ctor, superCtor) {
  194. ctor.super_ = superCtor;
  195. ctor.prototype = Object.create(superCtor.prototype, {
  196. constructor: {
  197. value: ctor,
  198. enumerable: false,
  199. writable: true,
  200. configurable: true
  201. }
  202. });
  203. };
  204. exports.mixin = function(obj, mixin) {
  205. for (var key in mixin) {
  206. obj[key] = mixin[key];
  207. }
  208. return obj;
  209. };
  210. exports.implement = function(proto, mixin) {
  211. exports.mixin(proto, mixin);
  212. };
  213. });
  214. ace.define("ace/range",[], function(require, exports, module) {
  215. "use strict";
  216. var comparePoints = function(p1, p2) {
  217. return p1.row - p2.row || p1.column - p2.column;
  218. };
  219. var Range = function(startRow, startColumn, endRow, endColumn) {
  220. this.start = {
  221. row: startRow,
  222. column: startColumn
  223. };
  224. this.end = {
  225. row: endRow,
  226. column: endColumn
  227. };
  228. };
  229. (function() {
  230. this.isEqual = function(range) {
  231. return this.start.row === range.start.row &&
  232. this.end.row === range.end.row &&
  233. this.start.column === range.start.column &&
  234. this.end.column === range.end.column;
  235. };
  236. this.toString = function() {
  237. return ("Range: [" + this.start.row + "/" + this.start.column +
  238. "] -> [" + this.end.row + "/" + this.end.column + "]");
  239. };
  240. this.contains = function(row, column) {
  241. return this.compare(row, column) == 0;
  242. };
  243. this.compareRange = function(range) {
  244. var cmp,
  245. end = range.end,
  246. start = range.start;
  247. cmp = this.compare(end.row, end.column);
  248. if (cmp == 1) {
  249. cmp = this.compare(start.row, start.column);
  250. if (cmp == 1) {
  251. return 2;
  252. } else if (cmp == 0) {
  253. return 1;
  254. } else {
  255. return 0;
  256. }
  257. } else if (cmp == -1) {
  258. return -2;
  259. } else {
  260. cmp = this.compare(start.row, start.column);
  261. if (cmp == -1) {
  262. return -1;
  263. } else if (cmp == 1) {
  264. return 42;
  265. } else {
  266. return 0;
  267. }
  268. }
  269. };
  270. this.comparePoint = function(p) {
  271. return this.compare(p.row, p.column);
  272. };
  273. this.containsRange = function(range) {
  274. return this.comparePoint(range.start) == 0 && this.comparePoint(range.end) == 0;
  275. };
  276. this.intersects = function(range) {
  277. var cmp = this.compareRange(range);
  278. return (cmp == -1 || cmp == 0 || cmp == 1);
  279. };
  280. this.isEnd = function(row, column) {
  281. return this.end.row == row && this.end.column == column;
  282. };
  283. this.isStart = function(row, column) {
  284. return this.start.row == row && this.start.column == column;
  285. };
  286. this.setStart = function(row, column) {
  287. if (typeof row == "object") {
  288. this.start.column = row.column;
  289. this.start.row = row.row;
  290. } else {
  291. this.start.row = row;
  292. this.start.column = column;
  293. }
  294. };
  295. this.setEnd = function(row, column) {
  296. if (typeof row == "object") {
  297. this.end.column = row.column;
  298. this.end.row = row.row;
  299. } else {
  300. this.end.row = row;
  301. this.end.column = column;
  302. }
  303. };
  304. this.inside = function(row, column) {
  305. if (this.compare(row, column) == 0) {
  306. if (this.isEnd(row, column) || this.isStart(row, column)) {
  307. return false;
  308. } else {
  309. return true;
  310. }
  311. }
  312. return false;
  313. };
  314. this.insideStart = function(row, column) {
  315. if (this.compare(row, column) == 0) {
  316. if (this.isEnd(row, column)) {
  317. return false;
  318. } else {
  319. return true;
  320. }
  321. }
  322. return false;
  323. };
  324. this.insideEnd = function(row, column) {
  325. if (this.compare(row, column) == 0) {
  326. if (this.isStart(row, column)) {
  327. return false;
  328. } else {
  329. return true;
  330. }
  331. }
  332. return false;
  333. };
  334. this.compare = function(row, column) {
  335. if (!this.isMultiLine()) {
  336. if (row === this.start.row) {
  337. return column < this.start.column ? -1 : (column > this.end.column ? 1 : 0);
  338. }
  339. }
  340. if (row < this.start.row)
  341. return -1;
  342. if (row > this.end.row)
  343. return 1;
  344. if (this.start.row === row)
  345. return column >= this.start.column ? 0 : -1;
  346. if (this.end.row === row)
  347. return column <= this.end.column ? 0 : 1;
  348. return 0;
  349. };
  350. this.compareStart = function(row, column) {
  351. if (this.start.row == row && this.start.column == column) {
  352. return -1;
  353. } else {
  354. return this.compare(row, column);
  355. }
  356. };
  357. this.compareEnd = function(row, column) {
  358. if (this.end.row == row && this.end.column == column) {
  359. return 1;
  360. } else {
  361. return this.compare(row, column);
  362. }
  363. };
  364. this.compareInside = function(row, column) {
  365. if (this.end.row == row && this.end.column == column) {
  366. return 1;
  367. } else if (this.start.row == row && this.start.column == column) {
  368. return -1;
  369. } else {
  370. return this.compare(row, column);
  371. }
  372. };
  373. this.clipRows = function(firstRow, lastRow) {
  374. if (this.end.row > lastRow)
  375. var end = {row: lastRow + 1, column: 0};
  376. else if (this.end.row < firstRow)
  377. var end = {row: firstRow, column: 0};
  378. if (this.start.row > lastRow)
  379. var start = {row: lastRow + 1, column: 0};
  380. else if (this.start.row < firstRow)
  381. var start = {row: firstRow, column: 0};
  382. return Range.fromPoints(start || this.start, end || this.end);
  383. };
  384. this.extend = function(row, column) {
  385. var cmp = this.compare(row, column);
  386. if (cmp == 0)
  387. return this;
  388. else if (cmp == -1)
  389. var start = {row: row, column: column};
  390. else
  391. var end = {row: row, column: column};
  392. return Range.fromPoints(start || this.start, end || this.end);
  393. };
  394. this.isEmpty = function() {
  395. return (this.start.row === this.end.row && this.start.column === this.end.column);
  396. };
  397. this.isMultiLine = function() {
  398. return (this.start.row !== this.end.row);
  399. };
  400. this.clone = function() {
  401. return Range.fromPoints(this.start, this.end);
  402. };
  403. this.collapseRows = function() {
  404. if (this.end.column == 0)
  405. return new Range(this.start.row, 0, Math.max(this.start.row, this.end.row-1), 0);
  406. else
  407. return new Range(this.start.row, 0, this.end.row, 0);
  408. };
  409. this.toScreenRange = function(session) {
  410. var screenPosStart = session.documentToScreenPosition(this.start);
  411. var screenPosEnd = session.documentToScreenPosition(this.end);
  412. return new Range(
  413. screenPosStart.row, screenPosStart.column,
  414. screenPosEnd.row, screenPosEnd.column
  415. );
  416. };
  417. this.moveBy = function(row, column) {
  418. this.start.row += row;
  419. this.start.column += column;
  420. this.end.row += row;
  421. this.end.column += column;
  422. };
  423. }).call(Range.prototype);
  424. Range.fromPoints = function(start, end) {
  425. return new Range(start.row, start.column, end.row, end.column);
  426. };
  427. Range.comparePoints = comparePoints;
  428. Range.comparePoints = function(p1, p2) {
  429. return p1.row - p2.row || p1.column - p2.column;
  430. };
  431. exports.Range = Range;
  432. });
  433. ace.define("ace/apply_delta",[], function(require, exports, module) {
  434. "use strict";
  435. function throwDeltaError(delta, errorText){
  436. console.log("Invalid Delta:", delta);
  437. throw "Invalid Delta: " + errorText;
  438. }
  439. function positionInDocument(docLines, position) {
  440. return position.row >= 0 && position.row < docLines.length &&
  441. position.column >= 0 && position.column <= docLines[position.row].length;
  442. }
  443. function validateDelta(docLines, delta) {
  444. if (delta.action != "insert" && delta.action != "remove")
  445. throwDeltaError(delta, "delta.action must be 'insert' or 'remove'");
  446. if (!(delta.lines instanceof Array))
  447. throwDeltaError(delta, "delta.lines must be an Array");
  448. if (!delta.start || !delta.end)
  449. throwDeltaError(delta, "delta.start/end must be an present");
  450. var start = delta.start;
  451. if (!positionInDocument(docLines, delta.start))
  452. throwDeltaError(delta, "delta.start must be contained in document");
  453. var end = delta.end;
  454. if (delta.action == "remove" && !positionInDocument(docLines, end))
  455. throwDeltaError(delta, "delta.end must contained in document for 'remove' actions");
  456. var numRangeRows = end.row - start.row;
  457. var numRangeLastLineChars = (end.column - (numRangeRows == 0 ? start.column : 0));
  458. if (numRangeRows != delta.lines.length - 1 || delta.lines[numRangeRows].length != numRangeLastLineChars)
  459. throwDeltaError(delta, "delta.range must match delta lines");
  460. }
  461. exports.applyDelta = function(docLines, delta, doNotValidate) {
  462. var row = delta.start.row;
  463. var startColumn = delta.start.column;
  464. var line = docLines[row] || "";
  465. switch (delta.action) {
  466. case "insert":
  467. var lines = delta.lines;
  468. if (lines.length === 1) {
  469. docLines[row] = line.substring(0, startColumn) + delta.lines[0] + line.substring(startColumn);
  470. } else {
  471. var args = [row, 1].concat(delta.lines);
  472. docLines.splice.apply(docLines, args);
  473. docLines[row] = line.substring(0, startColumn) + docLines[row];
  474. docLines[row + delta.lines.length - 1] += line.substring(startColumn);
  475. }
  476. break;
  477. case "remove":
  478. var endColumn = delta.end.column;
  479. var endRow = delta.end.row;
  480. if (row === endRow) {
  481. docLines[row] = line.substring(0, startColumn) + line.substring(endColumn);
  482. } else {
  483. docLines.splice(
  484. row, endRow - row + 1,
  485. line.substring(0, startColumn) + docLines[endRow].substring(endColumn)
  486. );
  487. }
  488. break;
  489. }
  490. };
  491. });
  492. ace.define("ace/lib/event_emitter",[], function(require, exports, module) {
  493. "use strict";
  494. var EventEmitter = {};
  495. var stopPropagation = function() { this.propagationStopped = true; };
  496. var preventDefault = function() { this.defaultPrevented = true; };
  497. EventEmitter._emit =
  498. EventEmitter._dispatchEvent = function(eventName, e) {
  499. this._eventRegistry || (this._eventRegistry = {});
  500. this._defaultHandlers || (this._defaultHandlers = {});
  501. var listeners = this._eventRegistry[eventName] || [];
  502. var defaultHandler = this._defaultHandlers[eventName];
  503. if (!listeners.length && !defaultHandler)
  504. return;
  505. if (typeof e != "object" || !e)
  506. e = {};
  507. if (!e.type)
  508. e.type = eventName;
  509. if (!e.stopPropagation)
  510. e.stopPropagation = stopPropagation;
  511. if (!e.preventDefault)
  512. e.preventDefault = preventDefault;
  513. listeners = listeners.slice();
  514. for (var i=0; i<listeners.length; i++) {
  515. listeners[i](e, this);
  516. if (e.propagationStopped)
  517. break;
  518. }
  519. if (defaultHandler && !e.defaultPrevented)
  520. return defaultHandler(e, this);
  521. };
  522. EventEmitter._signal = function(eventName, e) {
  523. var listeners = (this._eventRegistry || {})[eventName];
  524. if (!listeners)
  525. return;
  526. listeners = listeners.slice();
  527. for (var i=0; i<listeners.length; i++)
  528. listeners[i](e, this);
  529. };
  530. EventEmitter.once = function(eventName, callback) {
  531. var _self = this;
  532. this.on(eventName, function newCallback() {
  533. _self.off(eventName, newCallback);
  534. callback.apply(null, arguments);
  535. });
  536. if (!callback) {
  537. return new Promise(function(resolve) {
  538. callback = resolve;
  539. });
  540. }
  541. };
  542. EventEmitter.setDefaultHandler = function(eventName, callback) {
  543. var handlers = this._defaultHandlers;
  544. if (!handlers)
  545. handlers = this._defaultHandlers = {_disabled_: {}};
  546. if (handlers[eventName]) {
  547. var old = handlers[eventName];
  548. var disabled = handlers._disabled_[eventName];
  549. if (!disabled)
  550. handlers._disabled_[eventName] = disabled = [];
  551. disabled.push(old);
  552. var i = disabled.indexOf(callback);
  553. if (i != -1)
  554. disabled.splice(i, 1);
  555. }
  556. handlers[eventName] = callback;
  557. };
  558. EventEmitter.removeDefaultHandler = function(eventName, callback) {
  559. var handlers = this._defaultHandlers;
  560. if (!handlers)
  561. return;
  562. var disabled = handlers._disabled_[eventName];
  563. if (handlers[eventName] == callback) {
  564. if (disabled)
  565. this.setDefaultHandler(eventName, disabled.pop());
  566. } else if (disabled) {
  567. var i = disabled.indexOf(callback);
  568. if (i != -1)
  569. disabled.splice(i, 1);
  570. }
  571. };
  572. EventEmitter.on =
  573. EventEmitter.addEventListener = function(eventName, callback, capturing) {
  574. this._eventRegistry = this._eventRegistry || {};
  575. var listeners = this._eventRegistry[eventName];
  576. if (!listeners)
  577. listeners = this._eventRegistry[eventName] = [];
  578. if (listeners.indexOf(callback) == -1)
  579. listeners[capturing ? "unshift" : "push"](callback);
  580. return callback;
  581. };
  582. EventEmitter.off =
  583. EventEmitter.removeListener =
  584. EventEmitter.removeEventListener = function(eventName, callback) {
  585. this._eventRegistry = this._eventRegistry || {};
  586. var listeners = this._eventRegistry[eventName];
  587. if (!listeners)
  588. return;
  589. var index = listeners.indexOf(callback);
  590. if (index !== -1)
  591. listeners.splice(index, 1);
  592. };
  593. EventEmitter.removeAllListeners = function(eventName) {
  594. if (!eventName) this._eventRegistry = this._defaultHandlers = undefined;
  595. if (this._eventRegistry) this._eventRegistry[eventName] = undefined;
  596. if (this._defaultHandlers) this._defaultHandlers[eventName] = undefined;
  597. };
  598. exports.EventEmitter = EventEmitter;
  599. });
  600. ace.define("ace/anchor",[], function(require, exports, module) {
  601. "use strict";
  602. var oop = require("./lib/oop");
  603. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  604. var Anchor = exports.Anchor = function(doc, row, column) {
  605. this.$onChange = this.onChange.bind(this);
  606. this.attach(doc);
  607. if (typeof column == "undefined")
  608. this.setPosition(row.row, row.column);
  609. else
  610. this.setPosition(row, column);
  611. };
  612. (function() {
  613. oop.implement(this, EventEmitter);
  614. this.getPosition = function() {
  615. return this.$clipPositionToDocument(this.row, this.column);
  616. };
  617. this.getDocument = function() {
  618. return this.document;
  619. };
  620. this.$insertRight = false;
  621. this.onChange = function(delta) {
  622. if (delta.start.row == delta.end.row && delta.start.row != this.row)
  623. return;
  624. if (delta.start.row > this.row)
  625. return;
  626. var point = $getTransformedPoint(delta, {row: this.row, column: this.column}, this.$insertRight);
  627. this.setPosition(point.row, point.column, true);
  628. };
  629. function $pointsInOrder(point1, point2, equalPointsInOrder) {
  630. var bColIsAfter = equalPointsInOrder ? point1.column <= point2.column : point1.column < point2.column;
  631. return (point1.row < point2.row) || (point1.row == point2.row && bColIsAfter);
  632. }
  633. function $getTransformedPoint(delta, point, moveIfEqual) {
  634. var deltaIsInsert = delta.action == "insert";
  635. var deltaRowShift = (deltaIsInsert ? 1 : -1) * (delta.end.row - delta.start.row);
  636. var deltaColShift = (deltaIsInsert ? 1 : -1) * (delta.end.column - delta.start.column);
  637. var deltaStart = delta.start;
  638. var deltaEnd = deltaIsInsert ? deltaStart : delta.end; // Collapse insert range.
  639. if ($pointsInOrder(point, deltaStart, moveIfEqual)) {
  640. return {
  641. row: point.row,
  642. column: point.column
  643. };
  644. }
  645. if ($pointsInOrder(deltaEnd, point, !moveIfEqual)) {
  646. return {
  647. row: point.row + deltaRowShift,
  648. column: point.column + (point.row == deltaEnd.row ? deltaColShift : 0)
  649. };
  650. }
  651. return {
  652. row: deltaStart.row,
  653. column: deltaStart.column
  654. };
  655. }
  656. this.setPosition = function(row, column, noClip) {
  657. var pos;
  658. if (noClip) {
  659. pos = {
  660. row: row,
  661. column: column
  662. };
  663. } else {
  664. pos = this.$clipPositionToDocument(row, column);
  665. }
  666. if (this.row == pos.row && this.column == pos.column)
  667. return;
  668. var old = {
  669. row: this.row,
  670. column: this.column
  671. };
  672. this.row = pos.row;
  673. this.column = pos.column;
  674. this._signal("change", {
  675. old: old,
  676. value: pos
  677. });
  678. };
  679. this.detach = function() {
  680. this.document.off("change", this.$onChange);
  681. };
  682. this.attach = function(doc) {
  683. this.document = doc || this.document;
  684. this.document.on("change", this.$onChange);
  685. };
  686. this.$clipPositionToDocument = function(row, column) {
  687. var pos = {};
  688. if (row >= this.document.getLength()) {
  689. pos.row = Math.max(0, this.document.getLength() - 1);
  690. pos.column = this.document.getLine(pos.row).length;
  691. }
  692. else if (row < 0) {
  693. pos.row = 0;
  694. pos.column = 0;
  695. }
  696. else {
  697. pos.row = row;
  698. pos.column = Math.min(this.document.getLine(pos.row).length, Math.max(0, column));
  699. }
  700. if (column < 0)
  701. pos.column = 0;
  702. return pos;
  703. };
  704. }).call(Anchor.prototype);
  705. });
  706. ace.define("ace/document",[], function(require, exports, module) {
  707. "use strict";
  708. var oop = require("./lib/oop");
  709. var applyDelta = require("./apply_delta").applyDelta;
  710. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  711. var Range = require("./range").Range;
  712. var Anchor = require("./anchor").Anchor;
  713. var Document = function(textOrLines) {
  714. this.$lines = [""];
  715. if (textOrLines.length === 0) {
  716. this.$lines = [""];
  717. } else if (Array.isArray(textOrLines)) {
  718. this.insertMergedLines({row: 0, column: 0}, textOrLines);
  719. } else {
  720. this.insert({row: 0, column:0}, textOrLines);
  721. }
  722. };
  723. (function() {
  724. oop.implement(this, EventEmitter);
  725. this.setValue = function(text) {
  726. var len = this.getLength() - 1;
  727. this.remove(new Range(0, 0, len, this.getLine(len).length));
  728. this.insert({row: 0, column: 0}, text);
  729. };
  730. this.getValue = function() {
  731. return this.getAllLines().join(this.getNewLineCharacter());
  732. };
  733. this.createAnchor = function(row, column) {
  734. return new Anchor(this, row, column);
  735. };
  736. if ("aaa".split(/a/).length === 0) {
  737. this.$split = function(text) {
  738. return text.replace(/\r\n|\r/g, "\n").split("\n");
  739. };
  740. } else {
  741. this.$split = function(text) {
  742. return text.split(/\r\n|\r|\n/);
  743. };
  744. }
  745. this.$detectNewLine = function(text) {
  746. var match = text.match(/^.*?(\r\n|\r|\n)/m);
  747. this.$autoNewLine = match ? match[1] : "\n";
  748. this._signal("changeNewLineMode");
  749. };
  750. this.getNewLineCharacter = function() {
  751. switch (this.$newLineMode) {
  752. case "windows":
  753. return "\r\n";
  754. case "unix":
  755. return "\n";
  756. default:
  757. return this.$autoNewLine || "\n";
  758. }
  759. };
  760. this.$autoNewLine = "";
  761. this.$newLineMode = "auto";
  762. this.setNewLineMode = function(newLineMode) {
  763. if (this.$newLineMode === newLineMode)
  764. return;
  765. this.$newLineMode = newLineMode;
  766. this._signal("changeNewLineMode");
  767. };
  768. this.getNewLineMode = function() {
  769. return this.$newLineMode;
  770. };
  771. this.isNewLine = function(text) {
  772. return (text == "\r\n" || text == "\r" || text == "\n");
  773. };
  774. this.getLine = function(row) {
  775. return this.$lines[row] || "";
  776. };
  777. this.getLines = function(firstRow, lastRow) {
  778. return this.$lines.slice(firstRow, lastRow + 1);
  779. };
  780. this.getAllLines = function() {
  781. return this.getLines(0, this.getLength());
  782. };
  783. this.getLength = function() {
  784. return this.$lines.length;
  785. };
  786. this.getTextRange = function(range) {
  787. return this.getLinesForRange(range).join(this.getNewLineCharacter());
  788. };
  789. this.getLinesForRange = function(range) {
  790. var lines;
  791. if (range.start.row === range.end.row) {
  792. lines = [this.getLine(range.start.row).substring(range.start.column, range.end.column)];
  793. } else {
  794. lines = this.getLines(range.start.row, range.end.row);
  795. lines[0] = (lines[0] || "").substring(range.start.column);
  796. var l = lines.length - 1;
  797. if (range.end.row - range.start.row == l)
  798. lines[l] = lines[l].substring(0, range.end.column);
  799. }
  800. return lines;
  801. };
  802. this.insertLines = function(row, lines) {
  803. console.warn("Use of document.insertLines is deprecated. Use the insertFullLines method instead.");
  804. return this.insertFullLines(row, lines);
  805. };
  806. this.removeLines = function(firstRow, lastRow) {
  807. console.warn("Use of document.removeLines is deprecated. Use the removeFullLines method instead.");
  808. return this.removeFullLines(firstRow, lastRow);
  809. };
  810. this.insertNewLine = function(position) {
  811. console.warn("Use of document.insertNewLine is deprecated. Use insertMergedLines(position, ['', '']) instead.");
  812. return this.insertMergedLines(position, ["", ""]);
  813. };
  814. this.insert = function(position, text) {
  815. if (this.getLength() <= 1)
  816. this.$detectNewLine(text);
  817. return this.insertMergedLines(position, this.$split(text));
  818. };
  819. this.insertInLine = function(position, text) {
  820. var start = this.clippedPos(position.row, position.column);
  821. var end = this.pos(position.row, position.column + text.length);
  822. this.applyDelta({
  823. start: start,
  824. end: end,
  825. action: "insert",
  826. lines: [text]
  827. }, true);
  828. return this.clonePos(end);
  829. };
  830. this.clippedPos = function(row, column) {
  831. var length = this.getLength();
  832. if (row === undefined) {
  833. row = length;
  834. } else if (row < 0) {
  835. row = 0;
  836. } else if (row >= length) {
  837. row = length - 1;
  838. column = undefined;
  839. }
  840. var line = this.getLine(row);
  841. if (column == undefined)
  842. column = line.length;
  843. column = Math.min(Math.max(column, 0), line.length);
  844. return {row: row, column: column};
  845. };
  846. this.clonePos = function(pos) {
  847. return {row: pos.row, column: pos.column};
  848. };
  849. this.pos = function(row, column) {
  850. return {row: row, column: column};
  851. };
  852. this.$clipPosition = function(position) {
  853. var length = this.getLength();
  854. if (position.row >= length) {
  855. position.row = Math.max(0, length - 1);
  856. position.column = this.getLine(length - 1).length;
  857. } else {
  858. position.row = Math.max(0, position.row);
  859. position.column = Math.min(Math.max(position.column, 0), this.getLine(position.row).length);
  860. }
  861. return position;
  862. };
  863. this.insertFullLines = function(row, lines) {
  864. row = Math.min(Math.max(row, 0), this.getLength());
  865. var column = 0;
  866. if (row < this.getLength()) {
  867. lines = lines.concat([""]);
  868. column = 0;
  869. } else {
  870. lines = [""].concat(lines);
  871. row--;
  872. column = this.$lines[row].length;
  873. }
  874. this.insertMergedLines({row: row, column: column}, lines);
  875. };
  876. this.insertMergedLines = function(position, lines) {
  877. var start = this.clippedPos(position.row, position.column);
  878. var end = {
  879. row: start.row + lines.length - 1,
  880. column: (lines.length == 1 ? start.column : 0) + lines[lines.length - 1].length
  881. };
  882. this.applyDelta({
  883. start: start,
  884. end: end,
  885. action: "insert",
  886. lines: lines
  887. });
  888. return this.clonePos(end);
  889. };
  890. this.remove = function(range) {
  891. var start = this.clippedPos(range.start.row, range.start.column);
  892. var end = this.clippedPos(range.end.row, range.end.column);
  893. this.applyDelta({
  894. start: start,
  895. end: end,
  896. action: "remove",
  897. lines: this.getLinesForRange({start: start, end: end})
  898. });
  899. return this.clonePos(start);
  900. };
  901. this.removeInLine = function(row, startColumn, endColumn) {
  902. var start = this.clippedPos(row, startColumn);
  903. var end = this.clippedPos(row, endColumn);
  904. this.applyDelta({
  905. start: start,
  906. end: end,
  907. action: "remove",
  908. lines: this.getLinesForRange({start: start, end: end})
  909. }, true);
  910. return this.clonePos(start);
  911. };
  912. this.removeFullLines = function(firstRow, lastRow) {
  913. firstRow = Math.min(Math.max(0, firstRow), this.getLength() - 1);
  914. lastRow = Math.min(Math.max(0, lastRow ), this.getLength() - 1);
  915. var deleteFirstNewLine = lastRow == this.getLength() - 1 && firstRow > 0;
  916. var deleteLastNewLine = lastRow < this.getLength() - 1;
  917. var startRow = ( deleteFirstNewLine ? firstRow - 1 : firstRow );
  918. var startCol = ( deleteFirstNewLine ? this.getLine(startRow).length : 0 );
  919. var endRow = ( deleteLastNewLine ? lastRow + 1 : lastRow );
  920. var endCol = ( deleteLastNewLine ? 0 : this.getLine(endRow).length );
  921. var range = new Range(startRow, startCol, endRow, endCol);
  922. var deletedLines = this.$lines.slice(firstRow, lastRow + 1);
  923. this.applyDelta({
  924. start: range.start,
  925. end: range.end,
  926. action: "remove",
  927. lines: this.getLinesForRange(range)
  928. });
  929. return deletedLines;
  930. };
  931. this.removeNewLine = function(row) {
  932. if (row < this.getLength() - 1 && row >= 0) {
  933. this.applyDelta({
  934. start: this.pos(row, this.getLine(row).length),
  935. end: this.pos(row + 1, 0),
  936. action: "remove",
  937. lines: ["", ""]
  938. });
  939. }
  940. };
  941. this.replace = function(range, text) {
  942. if (!(range instanceof Range))
  943. range = Range.fromPoints(range.start, range.end);
  944. if (text.length === 0 && range.isEmpty())
  945. return range.start;
  946. if (text == this.getTextRange(range))
  947. return range.end;
  948. this.remove(range);
  949. var end;
  950. if (text) {
  951. end = this.insert(range.start, text);
  952. }
  953. else {
  954. end = range.start;
  955. }
  956. return end;
  957. };
  958. this.applyDeltas = function(deltas) {
  959. for (var i=0; i<deltas.length; i++) {
  960. this.applyDelta(deltas[i]);
  961. }
  962. };
  963. this.revertDeltas = function(deltas) {
  964. for (var i=deltas.length-1; i>=0; i--) {
  965. this.revertDelta(deltas[i]);
  966. }
  967. };
  968. this.applyDelta = function(delta, doNotValidate) {
  969. var isInsert = delta.action == "insert";
  970. if (isInsert ? delta.lines.length <= 1 && !delta.lines[0]
  971. : !Range.comparePoints(delta.start, delta.end)) {
  972. return;
  973. }
  974. if (isInsert && delta.lines.length > 20000) {
  975. this.$splitAndapplyLargeDelta(delta, 20000);
  976. }
  977. else {
  978. applyDelta(this.$lines, delta, doNotValidate);
  979. this._signal("change", delta);
  980. }
  981. };
  982. this.$safeApplyDelta = function(delta) {
  983. var docLength = this.$lines.length;
  984. if (
  985. delta.action == "remove" && delta.start.row < docLength && delta.end.row < docLength
  986. || delta.action == "insert" && delta.start.row <= docLength
  987. ) {
  988. this.applyDelta(delta);
  989. }
  990. };
  991. this.$splitAndapplyLargeDelta = function(delta, MAX) {
  992. var lines = delta.lines;
  993. var l = lines.length - MAX + 1;
  994. var row = delta.start.row;
  995. var column = delta.start.column;
  996. for (var from = 0, to = 0; from < l; from = to) {
  997. to += MAX - 1;
  998. var chunk = lines.slice(from, to);
  999. chunk.push("");
  1000. this.applyDelta({
  1001. start: this.pos(row + from, column),
  1002. end: this.pos(row + to, column = 0),
  1003. action: delta.action,
  1004. lines: chunk
  1005. }, true);
  1006. }
  1007. delta.lines = lines.slice(from);
  1008. delta.start.row = row + from;
  1009. delta.start.column = column;
  1010. this.applyDelta(delta, true);
  1011. };
  1012. this.revertDelta = function(delta) {
  1013. this.$safeApplyDelta({
  1014. start: this.clonePos(delta.start),
  1015. end: this.clonePos(delta.end),
  1016. action: (delta.action == "insert" ? "remove" : "insert"),
  1017. lines: delta.lines.slice()
  1018. });
  1019. };
  1020. this.indexToPosition = function(index, startRow) {
  1021. var lines = this.$lines || this.getAllLines();
  1022. var newlineLength = this.getNewLineCharacter().length;
  1023. for (var i = startRow || 0, l = lines.length; i < l; i++) {
  1024. index -= lines[i].length + newlineLength;
  1025. if (index < 0)
  1026. return {row: i, column: index + lines[i].length + newlineLength};
  1027. }
  1028. return {row: l-1, column: index + lines[l-1].length + newlineLength};
  1029. };
  1030. this.positionToIndex = function(pos, startRow) {
  1031. var lines = this.$lines || this.getAllLines();
  1032. var newlineLength = this.getNewLineCharacter().length;
  1033. var index = 0;
  1034. var row = Math.min(pos.row, lines.length);
  1035. for (var i = startRow || 0; i < row; ++i)
  1036. index += lines[i].length + newlineLength;
  1037. return index + pos.column;
  1038. };
  1039. }).call(Document.prototype);
  1040. exports.Document = Document;
  1041. });
  1042. ace.define("ace/lib/lang",[], function(require, exports, module) {
  1043. "use strict";
  1044. exports.last = function(a) {
  1045. return a[a.length - 1];
  1046. };
  1047. exports.stringReverse = function(string) {
  1048. return string.split("").reverse().join("");
  1049. };
  1050. exports.stringRepeat = function (string, count) {
  1051. var result = '';
  1052. while (count > 0) {
  1053. if (count & 1)
  1054. result += string;
  1055. if (count >>= 1)
  1056. string += string;
  1057. }
  1058. return result;
  1059. };
  1060. var trimBeginRegexp = /^\s\s*/;
  1061. var trimEndRegexp = /\s\s*$/;
  1062. exports.stringTrimLeft = function (string) {
  1063. return string.replace(trimBeginRegexp, '');
  1064. };
  1065. exports.stringTrimRight = function (string) {
  1066. return string.replace(trimEndRegexp, '');
  1067. };
  1068. exports.copyObject = function(obj) {
  1069. var copy = {};
  1070. for (var key in obj) {
  1071. copy[key] = obj[key];
  1072. }
  1073. return copy;
  1074. };
  1075. exports.copyArray = function(array){
  1076. var copy = [];
  1077. for (var i=0, l=array.length; i<l; i++) {
  1078. if (array[i] && typeof array[i] == "object")
  1079. copy[i] = this.copyObject(array[i]);
  1080. else
  1081. copy[i] = array[i];
  1082. }
  1083. return copy;
  1084. };
  1085. exports.deepCopy = function deepCopy(obj) {
  1086. if (typeof obj !== "object" || !obj)
  1087. return obj;
  1088. var copy;
  1089. if (Array.isArray(obj)) {
  1090. copy = [];
  1091. for (var key = 0; key < obj.length; key++) {
  1092. copy[key] = deepCopy(obj[key]);
  1093. }
  1094. return copy;
  1095. }
  1096. if (Object.prototype.toString.call(obj) !== "[object Object]")
  1097. return obj;
  1098. copy = {};
  1099. for (var key in obj)
  1100. copy[key] = deepCopy(obj[key]);
  1101. return copy;
  1102. };
  1103. exports.arrayToMap = function(arr) {
  1104. var map = {};
  1105. for (var i=0; i<arr.length; i++) {
  1106. map[arr[i]] = 1;
  1107. }
  1108. return map;
  1109. };
  1110. exports.createMap = function(props) {
  1111. var map = Object.create(null);
  1112. for (var i in props) {
  1113. map[i] = props[i];
  1114. }
  1115. return map;
  1116. };
  1117. exports.arrayRemove = function(array, value) {
  1118. for (var i = 0; i <= array.length; i++) {
  1119. if (value === array[i]) {
  1120. array.splice(i, 1);
  1121. }
  1122. }
  1123. };
  1124. exports.escapeRegExp = function(str) {
  1125. return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1');
  1126. };
  1127. exports.escapeHTML = function(str) {
  1128. return ("" + str).replace(/&/g, "&#38;").replace(/"/g, "&#34;").replace(/'/g, "&#39;").replace(/</g, "&#60;");
  1129. };
  1130. exports.getMatchOffsets = function(string, regExp) {
  1131. var matches = [];
  1132. string.replace(regExp, function(str) {
  1133. matches.push({
  1134. offset: arguments[arguments.length-2],
  1135. length: str.length
  1136. });
  1137. });
  1138. return matches;
  1139. };
  1140. exports.deferredCall = function(fcn) {
  1141. var timer = null;
  1142. var callback = function() {
  1143. timer = null;
  1144. fcn();
  1145. };
  1146. var deferred = function(timeout) {
  1147. deferred.cancel();
  1148. timer = setTimeout(callback, timeout || 0);
  1149. return deferred;
  1150. };
  1151. deferred.schedule = deferred;
  1152. deferred.call = function() {
  1153. this.cancel();
  1154. fcn();
  1155. return deferred;
  1156. };
  1157. deferred.cancel = function() {
  1158. clearTimeout(timer);
  1159. timer = null;
  1160. return deferred;
  1161. };
  1162. deferred.isPending = function() {
  1163. return timer;
  1164. };
  1165. return deferred;
  1166. };
  1167. exports.delayedCall = function(fcn, defaultTimeout) {
  1168. var timer = null;
  1169. var callback = function() {
  1170. timer = null;
  1171. fcn();
  1172. };
  1173. var _self = function(timeout) {
  1174. if (timer == null)
  1175. timer = setTimeout(callback, timeout || defaultTimeout);
  1176. };
  1177. _self.delay = function(timeout) {
  1178. timer && clearTimeout(timer);
  1179. timer = setTimeout(callback, timeout || defaultTimeout);
  1180. };
  1181. _self.schedule = _self;
  1182. _self.call = function() {
  1183. this.cancel();
  1184. fcn();
  1185. };
  1186. _self.cancel = function() {
  1187. timer && clearTimeout(timer);
  1188. timer = null;
  1189. };
  1190. _self.isPending = function() {
  1191. return timer;
  1192. };
  1193. return _self;
  1194. };
  1195. });
  1196. ace.define("ace/worker/mirror",[], function(require, exports, module) {
  1197. "use strict";
  1198. var Range = require("../range").Range;
  1199. var Document = require("../document").Document;
  1200. var lang = require("../lib/lang");
  1201. var Mirror = exports.Mirror = function(sender) {
  1202. this.sender = sender;
  1203. var doc = this.doc = new Document("");
  1204. var deferredUpdate = this.deferredUpdate = lang.delayedCall(this.onUpdate.bind(this));
  1205. var _self = this;
  1206. sender.on("change", function(e) {
  1207. var data = e.data;
  1208. if (data[0].start) {
  1209. doc.applyDeltas(data);
  1210. } else {
  1211. for (var i = 0; i < data.length; i += 2) {
  1212. if (Array.isArray(data[i+1])) {
  1213. var d = {action: "insert", start: data[i], lines: data[i+1]};
  1214. } else {
  1215. var d = {action: "remove", start: data[i], end: data[i+1]};
  1216. }
  1217. doc.applyDelta(d, true);
  1218. }
  1219. }
  1220. if (_self.$timeout)
  1221. return deferredUpdate.schedule(_self.$timeout);
  1222. _self.onUpdate();
  1223. });
  1224. };
  1225. (function() {
  1226. this.$timeout = 500;
  1227. this.setTimeout = function(timeout) {
  1228. this.$timeout = timeout;
  1229. };
  1230. this.setValue = function(value) {
  1231. this.doc.setValue(value);
  1232. this.deferredUpdate.schedule(this.$timeout);
  1233. };
  1234. this.getValue = function(callbackId) {
  1235. this.sender.callback(this.doc.getValue(), callbackId);
  1236. };
  1237. this.onUpdate = function() {
  1238. };
  1239. this.isPending = function() {
  1240. return this.deferredUpdate.isPending();
  1241. };
  1242. }).call(Mirror.prototype);
  1243. });
  1244. ace.define("ace/mode/json/json_parse",[], function(require, exports, module) {
  1245. "use strict";
  1246. var at, // The index of the current character
  1247. ch, // The current character
  1248. escapee = {
  1249. '"': '"',
  1250. '\\': '\\',
  1251. '/': '/',
  1252. b: '\b',
  1253. f: '\f',
  1254. n: '\n',
  1255. r: '\r',
  1256. t: '\t'
  1257. },
  1258. text,
  1259. error = function (m) {
  1260. throw {
  1261. name: 'SyntaxError',
  1262. message: m,
  1263. at: at,
  1264. text: text
  1265. };
  1266. },
  1267. next = function (c) {
  1268. if (c && c !== ch) {
  1269. error("Expected '" + c + "' instead of '" + ch + "'");
  1270. }
  1271. ch = text.charAt(at);
  1272. at += 1;
  1273. return ch;
  1274. },
  1275. number = function () {
  1276. var number,
  1277. string = '';
  1278. if (ch === '-') {
  1279. string = '-';
  1280. next('-');
  1281. }
  1282. while (ch >= '0' && ch <= '9') {
  1283. string += ch;
  1284. next();
  1285. }
  1286. if (ch === '.') {
  1287. string += '.';
  1288. while (next() && ch >= '0' && ch <= '9') {
  1289. string += ch;
  1290. }
  1291. }
  1292. if (ch === 'e' || ch === 'E') {
  1293. string += ch;
  1294. next();
  1295. if (ch === '-' || ch === '+') {
  1296. string += ch;
  1297. next();
  1298. }
  1299. while (ch >= '0' && ch <= '9') {
  1300. string += ch;
  1301. next();
  1302. }
  1303. }
  1304. number = +string;
  1305. if (isNaN(number)) {
  1306. error("Bad number");
  1307. } else {
  1308. return number;
  1309. }
  1310. },
  1311. string = function () {
  1312. var hex,
  1313. i,
  1314. string = '',
  1315. uffff;
  1316. if (ch === '"') {
  1317. while (next()) {
  1318. if (ch === '"') {
  1319. next();
  1320. return string;
  1321. } else if (ch === '\\') {
  1322. next();
  1323. if (ch === 'u') {
  1324. uffff = 0;
  1325. for (i = 0; i < 4; i += 1) {
  1326. hex = parseInt(next(), 16);
  1327. if (!isFinite(hex)) {
  1328. break;
  1329. }
  1330. uffff = uffff * 16 + hex;
  1331. }
  1332. string += String.fromCharCode(uffff);
  1333. } else if (typeof escapee[ch] === 'string') {
  1334. string += escapee[ch];
  1335. } else {
  1336. break;
  1337. }
  1338. } else if (ch == "\n" || ch == "\r") {
  1339. break;
  1340. } else {
  1341. string += ch;
  1342. }
  1343. }
  1344. }
  1345. error("Bad string");
  1346. },
  1347. white = function () {
  1348. while (ch && ch <= ' ') {
  1349. next();
  1350. }
  1351. },
  1352. word = function () {
  1353. switch (ch) {
  1354. case 't':
  1355. next('t');
  1356. next('r');
  1357. next('u');
  1358. next('e');
  1359. return true;
  1360. case 'f':
  1361. next('f');
  1362. next('a');
  1363. next('l');
  1364. next('s');
  1365. next('e');
  1366. return false;
  1367. case 'n':
  1368. next('n');
  1369. next('u');
  1370. next('l');
  1371. next('l');
  1372. return null;
  1373. }
  1374. error("Unexpected '" + ch + "'");
  1375. },
  1376. value, // Place holder for the value function.
  1377. array = function () {
  1378. var array = [];
  1379. if (ch === '[') {
  1380. next('[');
  1381. white();
  1382. if (ch === ']') {
  1383. next(']');
  1384. return array; // empty array
  1385. }
  1386. while (ch) {
  1387. array.push(value());
  1388. white();
  1389. if (ch === ']') {
  1390. next(']');
  1391. return array;
  1392. }
  1393. next(',');
  1394. white();
  1395. }
  1396. }
  1397. error("Bad array");
  1398. },
  1399. object = function () {
  1400. var key,
  1401. object = {};
  1402. if (ch === '{') {
  1403. next('{');
  1404. white();
  1405. if (ch === '}') {
  1406. next('}');
  1407. return object; // empty object
  1408. }
  1409. while (ch) {
  1410. key = string();
  1411. white();
  1412. next(':');
  1413. if (Object.hasOwnProperty.call(object, key)) {
  1414. error('Duplicate key "' + key + '"');
  1415. }
  1416. object[key] = value();
  1417. white();
  1418. if (ch === '}') {
  1419. next('}');
  1420. return object;
  1421. }
  1422. next(',');
  1423. white();
  1424. }
  1425. }
  1426. error("Bad object");
  1427. };
  1428. value = function () {
  1429. white();
  1430. switch (ch) {
  1431. case '{':
  1432. return object();
  1433. case '[':
  1434. return array();
  1435. case '"':
  1436. return string();
  1437. case '-':
  1438. return number();
  1439. default:
  1440. return ch >= '0' && ch <= '9' ? number() : word();
  1441. }
  1442. };
  1443. return function (source, reviver) {
  1444. var result;
  1445. text = source;
  1446. at = 0;
  1447. ch = ' ';
  1448. result = value();
  1449. white();
  1450. if (ch) {
  1451. error("Syntax error");
  1452. }
  1453. return typeof reviver === 'function' ? function walk(holder, key) {
  1454. var k, v, value = holder[key];
  1455. if (value && typeof value === 'object') {
  1456. for (k in value) {
  1457. if (Object.hasOwnProperty.call(value, k)) {
  1458. v = walk(value, k);
  1459. if (v !== undefined) {
  1460. value[k] = v;
  1461. } else {
  1462. delete value[k];
  1463. }
  1464. }
  1465. }
  1466. }
  1467. return reviver.call(holder, key, value);
  1468. }({'': result}, '') : result;
  1469. };
  1470. });
  1471. ace.define("ace/mode/json_worker",[], function(require, exports, module) {
  1472. "use strict";
  1473. var oop = require("../lib/oop");
  1474. var Mirror = require("../worker/mirror").Mirror;
  1475. var parse = require("./json/json_parse");
  1476. var JsonWorker = exports.JsonWorker = function(sender) {
  1477. Mirror.call(this, sender);
  1478. this.setTimeout(200);
  1479. };
  1480. oop.inherits(JsonWorker, Mirror);
  1481. (function() {
  1482. this.onUpdate = function() {
  1483. var value = this.doc.getValue();
  1484. var errors = [];
  1485. try {
  1486. if (value)
  1487. parse(value);
  1488. } catch (e) {
  1489. var pos = this.doc.indexToPosition(e.at-1);
  1490. errors.push({
  1491. row: pos.row,
  1492. column: pos.column,
  1493. text: e.message,
  1494. type: "error"
  1495. });
  1496. }
  1497. this.sender.emit("annotate", errors);
  1498. };
  1499. }).call(JsonWorker.prototype);
  1500. });