UNPKG

imdone

Version:

A task board and wiki in one!

1,681 lines (1,462 loc) 1.16 MB
"no use strict"; ;(function(window) { if (typeof window.window != "undefined" && window.document) { return; } window.console = function() { var msgs = Array.prototype.slice.call(arguments, 0); postMessage({type: "log", data: msgs}); }; window.console.error = window.console.warn = window.console.log = window.console.trace = window.console; window.window = window; window.ace = window; window.onerror = function(message, file, line, col, err) { console.error("Worker " + (err ? err.stack : message)); }; window.normalizeModule = function(parentId, moduleName) { if (moduleName.indexOf("!") !== -1) { var chunks = moduleName.split("!"); return window.normalizeModule(parentId, chunks[0]) + "!" + window.normalizeModule(parentId, chunks[1]); } if (moduleName.charAt(0) == ".") { var base = parentId.split("/").slice(0, -1).join("/"); moduleName = (base ? base + "/" : "") + moduleName; while(moduleName.indexOf(".") !== -1 && previous != moduleName) { var previous = moduleName; moduleName = moduleName.replace(/^\.\//, "").replace(/\/\.\//, "/").replace(/[^\/]+\/\.\.\//, ""); } } return moduleName; }; window.require = function(parentId, id) { if (!id) { id = parentId; parentId = null; } if (!id.charAt) throw new Error("worker.js require() accepts only (parentId, id) as arguments"); id = window.normalizeModule(parentId, id); var module = window.require.modules[id]; if (module) { if (!module.initialized) { module.initialized = true; module.exports = module.factory().exports; } return module.exports; } var chunks = id.split("/"); if (!window.require.tlns) return console.log("unable to load " + id); chunks[0] = window.require.tlns[chunks[0]] || chunks[0]; var path = chunks.join("/") + ".js"; window.require.id = id; importScripts(path); return window.require(parentId, id); }; window.require.modules = {}; window.require.tlns = {}; window.define = function(id, deps, factory) { if (arguments.length == 2) { factory = deps; if (typeof id != "string") { deps = id; id = window.require.id; } } else if (arguments.length == 1) { factory = id; deps = []; id = window.require.id; } if (!deps.length) deps = ['require', 'exports', 'module']; if (id.indexOf("text!") === 0) return; var req = function(childId) { return window.require(id, childId); }; window.require.modules[id] = { exports: {}, factory: function() { var module = this; var returnExports = factory.apply(this, deps.map(function(dep) { switch(dep) { case 'require': return req; case 'exports': return module.exports; case 'module': return module; default: return req(dep); } })); if (returnExports) module.exports = returnExports; return module; } }; }; window.define.amd = {}; window.initBaseUrls = function initBaseUrls(topLevelNamespaces) { require.tlns = topLevelNamespaces; }; window.initSender = function initSender() { var EventEmitter = window.require("ace/lib/event_emitter").EventEmitter; var oop = window.require("ace/lib/oop"); var Sender = function() {}; (function() { oop.implement(this, EventEmitter); this.callback = function(data, callbackId) { postMessage({ type: "call", id: callbackId, data: data }); }; this.emit = function(name, data) { postMessage({ type: "event", name: name, data: data }); }; }).call(Sender.prototype); return new Sender(); }; var main = window.main = null; var sender = window.sender = null; window.onmessage = function(e) { var msg = e.data; if (msg.command) { if (main[msg.command]) main[msg.command].apply(main, msg.args); else throw new Error("Unknown command:" + msg.command); } else if (msg.init) { initBaseUrls(msg.tlns); require("ace/lib/es5-shim"); sender = window.sender = initSender(); var clazz = require(msg.module)[msg.classname]; main = window.main = new clazz(sender); } else if (msg.event && sender) { sender._signal(msg.event, msg.data); } }; })(this); ace.define('ace/lib/oop', ['require', 'exports', 'module' ], function(require, exports, module) { exports.inherits = function(ctor, superCtor) { ctor.super_ = superCtor; ctor.prototype = Object.create(superCtor.prototype, { constructor: { value: ctor, enumerable: false, writable: true, configurable: true } }); }; exports.mixin = function(obj, mixin) { for (var key in mixin) { obj[key] = mixin[key]; } return obj; }; exports.implement = function(proto, mixin) { exports.mixin(proto, mixin); }; }); ace.define('ace/worker/mirror', ['require', 'exports', 'module' , 'ace/document', 'ace/lib/lang'], function(require, exports, module) { var Document = require("../document").Document; var lang = require("../lib/lang"); var Mirror = exports.Mirror = function(sender) { this.sender = sender; var doc = this.doc = new Document(""); var deferredUpdate = this.deferredUpdate = lang.delayedCall(this.onUpdate.bind(this)); var _self = this; sender.on("change", function(e) { doc.applyDeltas(e.data); if (_self.$timeout) return deferredUpdate.schedule(_self.$timeout); _self.onUpdate(); }); }; (function() { this.$timeout = 500; this.setTimeout = function(timeout) { this.$timeout = timeout; }; this.setValue = function(value) { this.doc.setValue(value); this.deferredUpdate.schedule(this.$timeout); }; this.getValue = function(callbackId) { this.sender.callback(this.doc.getValue(), callbackId); }; this.onUpdate = function() { }; this.isPending = function() { return this.deferredUpdate.isPending(); }; }).call(Mirror.prototype); }); ace.define('ace/document', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/event_emitter', 'ace/range', 'ace/anchor'], function(require, exports, module) { var oop = require("./lib/oop"); var EventEmitter = require("./lib/event_emitter").EventEmitter; var Range = require("./range").Range; var Anchor = require("./anchor").Anchor; var Document = function(text) { this.$lines = []; if (text.length === 0) { this.$lines = [""]; } else if (Array.isArray(text)) { this._insertLines(0, text); } else { this.insert({row: 0, column:0}, text); } }; (function() { oop.implement(this, EventEmitter); this.setValue = function(text) { var len = this.getLength(); this.remove(new Range(0, 0, len, this.getLine(len-1).length)); this.insert({row: 0, column:0}, text); }; this.getValue = function() { return this.getAllLines().join(this.getNewLineCharacter()); }; this.createAnchor = function(row, column) { return new Anchor(this, row, column); }; if ("aaa".split(/a/).length === 0) this.$split = function(text) { return text.replace(/\r\n|\r/g, "\n").split("\n"); }; else this.$split = function(text) { return text.split(/\r\n|\r|\n/); }; this.$detectNewLine = function(text) { var match = text.match(/^.*?(\r\n|\r|\n)/m); this.$autoNewLine = match ? match[1] : "\n"; this._signal("changeNewLineMode"); }; this.getNewLineCharacter = function() { switch (this.$newLineMode) { case "windows": return "\r\n"; case "unix": return "\n"; default: return this.$autoNewLine || "\n"; } }; this.$autoNewLine = ""; this.$newLineMode = "auto"; this.setNewLineMode = function(newLineMode) { if (this.$newLineMode === newLineMode) return; this.$newLineMode = newLineMode; this._signal("changeNewLineMode"); }; this.getNewLineMode = function() { return this.$newLineMode; }; this.isNewLine = function(text) { return (text == "\r\n" || text == "\r" || text == "\n"); }; this.getLine = function(row) { return this.$lines[row] || ""; }; this.getLines = function(firstRow, lastRow) { return this.$lines.slice(firstRow, lastRow + 1); }; this.getAllLines = function() { return this.getLines(0, this.getLength()); }; this.getLength = function() { return this.$lines.length; }; this.getTextRange = function(range) { if (range.start.row == range.end.row) { return this.getLine(range.start.row) .substring(range.start.column, range.end.column); } var lines = this.getLines(range.start.row, range.end.row); lines[0] = (lines[0] || "").substring(range.start.column); var l = lines.length - 1; if (range.end.row - range.start.row == l) lines[l] = lines[l].substring(0, range.end.column); return lines.join(this.getNewLineCharacter()); }; this.$clipPosition = function(position) { var length = this.getLength(); if (position.row >= length) { position.row = Math.max(0, length - 1); position.column = this.getLine(length-1).length; } else if (position.row < 0) position.row = 0; return position; }; this.insert = function(position, text) { if (!text || text.length === 0) return position; position = this.$clipPosition(position); if (this.getLength() <= 1) this.$detectNewLine(text); var lines = this.$split(text); var firstLine = lines.splice(0, 1)[0]; var lastLine = lines.length == 0 ? null : lines.splice(lines.length - 1, 1)[0]; position = this.insertInLine(position, firstLine); if (lastLine !== null) { position = this.insertNewLine(position); // terminate first line position = this._insertLines(position.row, lines); position = this.insertInLine(position, lastLine || ""); } return position; }; this.insertLines = function(row, lines) { if (row >= this.getLength()) return this.insert({row: row, column: 0}, "\n" + lines.join("\n")); return this._insertLines(Math.max(row, 0), lines); }; this._insertLines = function(row, lines) { if (lines.length == 0) return {row: row, column: 0}; while (lines.length > 0xF000) { var end = this._insertLines(row, lines.slice(0, 0xF000)); lines = lines.slice(0xF000); row = end.row; } var args = [row, 0]; args.push.apply(args, lines); this.$lines.splice.apply(this.$lines, args); var range = new Range(row, 0, row + lines.length, 0); var delta = { action: "insertLines", range: range, lines: lines }; this._signal("change", { data: delta }); return range.end; }; this.insertNewLine = function(position) { position = this.$clipPosition(position); var line = this.$lines[position.row] || ""; this.$lines[position.row] = line.substring(0, position.column); this.$lines.splice(position.row + 1, 0, line.substring(position.column, line.length)); var end = { row : position.row + 1, column : 0 }; var delta = { action: "insertText", range: Range.fromPoints(position, end), text: this.getNewLineCharacter() }; this._signal("change", { data: delta }); return end; }; this.insertInLine = function(position, text) { if (text.length == 0) return position; var line = this.$lines[position.row] || ""; this.$lines[position.row] = line.substring(0, position.column) + text + line.substring(position.column); var end = { row : position.row, column : position.column + text.length }; var delta = { action: "insertText", range: Range.fromPoints(position, end), text: text }; this._signal("change", { data: delta }); return end; }; this.remove = function(range) { if (!(range instanceof Range)) range = Range.fromPoints(range.start, range.end); range.start = this.$clipPosition(range.start); range.end = this.$clipPosition(range.end); if (range.isEmpty()) return range.start; var firstRow = range.start.row; var lastRow = range.end.row; if (range.isMultiLine()) { var firstFullRow = range.start.column == 0 ? firstRow : firstRow + 1; var lastFullRow = lastRow - 1; if (range.end.column > 0) this.removeInLine(lastRow, 0, range.end.column); if (lastFullRow >= firstFullRow) this._removeLines(firstFullRow, lastFullRow); if (firstFullRow != firstRow) { this.removeInLine(firstRow, range.start.column, this.getLine(firstRow).length); this.removeNewLine(range.start.row); } } else { this.removeInLine(firstRow, range.start.column, range.end.column); } return range.start; }; this.removeInLine = function(row, startColumn, endColumn) { if (startColumn == endColumn) return; var range = new Range(row, startColumn, row, endColumn); var line = this.getLine(row); var removed = line.substring(startColumn, endColumn); var newLine = line.substring(0, startColumn) + line.substring(endColumn, line.length); this.$lines.splice(row, 1, newLine); var delta = { action: "removeText", range: range, text: removed }; this._signal("change", { data: delta }); return range.start; }; this.removeLines = function(firstRow, lastRow) { if (firstRow < 0 || lastRow >= this.getLength()) return this.remove(new Range(firstRow, 0, lastRow + 1, 0)); return this._removeLines(firstRow, lastRow); }; this._removeLines = function(firstRow, lastRow) { var range = new Range(firstRow, 0, lastRow + 1, 0); var removed = this.$lines.splice(firstRow, lastRow - firstRow + 1); var delta = { action: "removeLines", range: range, nl: this.getNewLineCharacter(), lines: removed }; this._signal("change", { data: delta }); return removed; }; this.removeNewLine = function(row) { var firstLine = this.getLine(row); var secondLine = this.getLine(row+1); var range = new Range(row, firstLine.length, row+1, 0); var line = firstLine + secondLine; this.$lines.splice(row, 2, line); var delta = { action: "removeText", range: range, text: this.getNewLineCharacter() }; this._signal("change", { data: delta }); }; this.replace = function(range, text) { if (!(range instanceof Range)) range = Range.fromPoints(range.start, range.end); if (text.length == 0 && range.isEmpty()) return range.start; if (text == this.getTextRange(range)) return range.end; this.remove(range); if (text) { var end = this.insert(range.start, text); } else { end = range.start; } return end; }; this.applyDeltas = function(deltas) { for (var i=0; i<deltas.length; i++) { var delta = deltas[i]; var range = Range.fromPoints(delta.range.start, delta.range.end); if (delta.action == "insertLines") this.insertLines(range.start.row, delta.lines); else if (delta.action == "insertText") this.insert(range.start, delta.text); else if (delta.action == "removeLines") this._removeLines(range.start.row, range.end.row - 1); else if (delta.action == "removeText") this.remove(range); } }; this.revertDeltas = function(deltas) { for (var i=deltas.length-1; i>=0; i--) { var delta = deltas[i]; var range = Range.fromPoints(delta.range.start, delta.range.end); if (delta.action == "insertLines") this._removeLines(range.start.row, range.end.row - 1); else if (delta.action == "insertText") this.remove(range); else if (delta.action == "removeLines") this._insertLines(range.start.row, delta.lines); else if (delta.action == "removeText") this.insert(range.start, delta.text); } }; this.indexToPosition = function(index, startRow) { var lines = this.$lines || this.getAllLines(); var newlineLength = this.getNewLineCharacter().length; for (var i = startRow || 0, l = lines.length; i < l; i++) { index -= lines[i].length + newlineLength; if (index < 0) return {row: i, column: index + lines[i].length + newlineLength}; } return {row: l-1, column: lines[l-1].length}; }; this.positionToIndex = function(pos, startRow) { var lines = this.$lines || this.getAllLines(); var newlineLength = this.getNewLineCharacter().length; var index = 0; var row = Math.min(pos.row, lines.length); for (var i = startRow || 0; i < row; ++i) index += lines[i].length + newlineLength; return index + pos.column; }; }).call(Document.prototype); exports.Document = Document; }); ace.define('ace/mode/xquery_worker', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/worker/mirror', 'ace/mode/xquery/JSONParseTreeHandler', 'ace/mode/xquery/XQueryParser', 'ace/mode/xquery/visitors/SemanticHighlighter'], function(require, exports, module) { var oop = require("../lib/oop"); var Mirror = require("../worker/mirror").Mirror; var JSONParseTreeHandler = require("./xquery/JSONParseTreeHandler").JSONParseTreeHandler; var XQueryParser = require("./xquery/XQueryParser").XQueryParser; var SemanticHighlighter = require("./xquery/visitors/SemanticHighlighter").SemanticHighlighter; var XQueryWorker = exports.XQueryWorker = function(sender) { Mirror.call(this, sender); this.setTimeout(200); }; oop.inherits(XQueryWorker, Mirror); (function() { this.onUpdate = function() { this.sender.emit("start"); var value = this.doc.getValue(); var h = new JSONParseTreeHandler(value); var parser = new XQueryParser(value, h); try { parser.parse_XQuery(); this.sender.emit("ok"); var ast = h.getParseTree(); var highlighter = new SemanticHighlighter(ast, value); var tokens = highlighter.getTokens(); this.sender.emit("highlight", { tokens: tokens, lines: highlighter.lines }); } catch(e) { if(e instanceof parser.ParseException) { var prefix = value.substring(0, e.getBegin()); var line = prefix.split("\n").length; var column = e.getBegin() - prefix.lastIndexOf("\n"); var message = parser.getErrorMessage(e); this.sender.emit("error", { row: line - 1, column: column, text: message, type: "error" }); } else { throw e; } } }; }).call(XQueryWorker.prototype); }); ace.define('ace/range', ['require', 'exports', 'module' ], function(require, exports, module) { var comparePoints = function(p1, p2) { return p1.row - p2.row || p1.column - p2.column; }; var Range = function(startRow, startColumn, endRow, endColumn) { this.start = { row: startRow, column: startColumn }; this.end = { row: endRow, column: endColumn }; }; (function() { this.isEqual = function(range) { return this.start.row === range.start.row && this.end.row === range.end.row && this.start.column === range.start.column && this.end.column === range.end.column; }; this.toString = function() { return ("Range: [" + this.start.row + "/" + this.start.column + "] -> [" + this.end.row + "/" + this.end.column + "]"); }; this.contains = function(row, column) { return this.compare(row, column) == 0; }; this.compareRange = function(range) { var cmp, end = range.end, start = range.start; cmp = this.compare(end.row, end.column); if (cmp == 1) { cmp = this.compare(start.row, start.column); if (cmp == 1) { return 2; } else if (cmp == 0) { return 1; } else { return 0; } } else if (cmp == -1) { return -2; } else { cmp = this.compare(start.row, start.column); if (cmp == -1) { return -1; } else if (cmp == 1) { return 42; } else { return 0; } } }; this.comparePoint = function(p) { return this.compare(p.row, p.column); }; this.containsRange = function(range) { return this.comparePoint(range.start) == 0 && this.comparePoint(range.end) == 0; }; this.intersects = function(range) { var cmp = this.compareRange(range); return (cmp == -1 || cmp == 0 || cmp == 1); }; this.isEnd = function(row, column) { return this.end.row == row && this.end.column == column; }; this.isStart = function(row, column) { return this.start.row == row && this.start.column == column; }; this.setStart = function(row, column) { if (typeof row == "object") { this.start.column = row.column; this.start.row = row.row; } else { this.start.row = row; this.start.column = column; } }; this.setEnd = function(row, column) { if (typeof row == "object") { this.end.column = row.column; this.end.row = row.row; } else { this.end.row = row; this.end.column = column; } }; this.inside = function(row, column) { if (this.compare(row, column) == 0) { if (this.isEnd(row, column) || this.isStart(row, column)) { return false; } else { return true; } } return false; }; this.insideStart = function(row, column) { if (this.compare(row, column) == 0) { if (this.isEnd(row, column)) { return false; } else { return true; } } return false; }; this.insideEnd = function(row, column) { if (this.compare(row, column) == 0) { if (this.isStart(row, column)) { return false; } else { return true; } } return false; }; this.compare = function(row, column) { if (!this.isMultiLine()) { if (row === this.start.row) { return column < this.start.column ? -1 : (column > this.end.column ? 1 : 0); }; } if (row < this.start.row) return -1; if (row > this.end.row) return 1; if (this.start.row === row) return column >= this.start.column ? 0 : -1; if (this.end.row === row) return column <= this.end.column ? 0 : 1; return 0; }; this.compareStart = function(row, column) { if (this.start.row == row && this.start.column == column) { return -1; } else { return this.compare(row, column); } }; this.compareEnd = function(row, column) { if (this.end.row == row && this.end.column == column) { return 1; } else { return this.compare(row, column); } }; this.compareInside = function(row, column) { if (this.end.row == row && this.end.column == column) { return 1; } else if (this.start.row == row && this.start.column == column) { return -1; } else { return this.compare(row, column); } }; this.clipRows = function(firstRow, lastRow) { if (this.end.row > lastRow) var end = {row: lastRow + 1, column: 0}; else if (this.end.row < firstRow) var end = {row: firstRow, column: 0}; if (this.start.row > lastRow) var start = {row: lastRow + 1, column: 0}; else if (this.start.row < firstRow) var start = {row: firstRow, column: 0}; return Range.fromPoints(start || this.start, end || this.end); }; this.extend = function(row, column) { var cmp = this.compare(row, column); if (cmp == 0) return this; else if (cmp == -1) var start = {row: row, column: column}; else var end = {row: row, column: column}; return Range.fromPoints(start || this.start, end || this.end); }; this.isEmpty = function() { return (this.start.row === this.end.row && this.start.column === this.end.column); }; this.isMultiLine = function() { return (this.start.row !== this.end.row); }; this.clone = function() { return Range.fromPoints(this.start, this.end); }; this.collapseRows = function() { if (this.end.column == 0) return new Range(this.start.row, 0, Math.max(this.start.row, this.end.row-1), 0) else return new Range(this.start.row, 0, this.end.row, 0) }; this.toScreenRange = function(session) { var screenPosStart = session.documentToScreenPosition(this.start); var screenPosEnd = session.documentToScreenPosition(this.end); return new Range( screenPosStart.row, screenPosStart.column, screenPosEnd.row, screenPosEnd.column ); }; this.moveBy = function(row, column) { this.start.row += row; this.start.column += column; this.end.row += row; this.end.column += column; }; }).call(Range.prototype); Range.fromPoints = function(start, end) { return new Range(start.row, start.column, end.row, end.column); }; Range.comparePoints = comparePoints; Range.comparePoints = function(p1, p2) { return p1.row - p2.row || p1.column - p2.column; }; exports.Range = Range; }); ace.define('ace/anchor', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/event_emitter'], function(require, exports, module) { var oop = require("./lib/oop"); var EventEmitter = require("./lib/event_emitter").EventEmitter; var Anchor = exports.Anchor = function(doc, row, column) { this.$onChange = this.onChange.bind(this); this.attach(doc); if (typeof column == "undefined") this.setPosition(row.row, row.column); else this.setPosition(row, column); }; (function() { oop.implement(this, EventEmitter); this.getPosition = function() { return this.$clipPositionToDocument(this.row, this.column); }; this.getDocument = function() { return this.document; }; this.$insertRight = false; this.onChange = function(e) { var delta = e.data; var range = delta.range; if (range.start.row == range.end.row && range.start.row != this.row) return; if (range.start.row > this.row) return; if (range.start.row == this.row && range.start.column > this.column) return; var row = this.row; var column = this.column; var start = range.start; var end = range.end; if (delta.action === "insertText") { if (start.row === row && start.column <= column) { if (start.column === column && this.$insertRight) { } else if (start.row === end.row) { column += end.column - start.column; } else { column -= start.column; row += end.row - start.row; } } else if (start.row !== end.row && start.row < row) { row += end.row - start.row; } } else if (delta.action === "insertLines") { if (start.row <= row) { row += end.row - start.row; } } else if (delta.action === "removeText") { if (start.row === row && start.column < column) { if (end.column >= column) column = start.column; else column = Math.max(0, column - (end.column - start.column)); } else if (start.row !== end.row && start.row < row) { if (end.row === row) column = Math.max(0, column - end.column) + start.column; row -= (end.row - start.row); } else if (end.row === row) { row -= end.row - start.row; column = Math.max(0, column - end.column) + start.column; } } else if (delta.action == "removeLines") { if (start.row <= row) { if (end.row <= row) row -= end.row - start.row; else { row = start.row; column = 0; } } } this.setPosition(row, column, true); }; this.setPosition = function(row, column, noClip) { var pos; if (noClip) { pos = { row: row, column: column }; } else { pos = this.$clipPositionToDocument(row, column); } if (this.row == pos.row && this.column == pos.column) return; var old = { row: this.row, column: this.column }; this.row = pos.row; this.column = pos.column; this._signal("change", { old: old, value: pos }); }; this.detach = function() { this.document.removeEventListener("change", this.$onChange); }; this.attach = function(doc) { this.document = doc || this.document; this.document.on("change", this.$onChange); }; this.$clipPositionToDocument = function(row, column) { var pos = {}; if (row >= this.document.getLength()) { pos.row = Math.max(0, this.document.getLength() - 1); pos.column = this.document.getLine(pos.row).length; } else if (row < 0) { pos.row = 0; pos.column = 0; } else { pos.row = row; pos.column = Math.min(this.document.getLine(pos.row).length, Math.max(0, column)); } if (column < 0) pos.column = 0; return pos; }; }).call(Anchor.prototype); }); ace.define('ace/lib/lang', ['require', 'exports', 'module' ], function(require, exports, module) { exports.last = function(a) { return a[a.length - 1]; }; exports.stringReverse = function(string) { return string.split("").reverse().join(""); }; exports.stringRepeat = function (string, count) { var result = ''; while (count > 0) { if (count & 1) result += string; if (count >>= 1) string += string; } return result; }; var trimBeginRegexp = /^\s\s*/; var trimEndRegexp = /\s\s*$/; exports.stringTrimLeft = function (string) { return string.replace(trimBeginRegexp, ''); }; exports.stringTrimRight = function (string) { return string.replace(trimEndRegexp, ''); }; exports.copyObject = function(obj) { var copy = {}; for (var key in obj) { copy[key] = obj[key]; } return copy; }; exports.copyArray = function(array){ var copy = []; for (var i=0, l=array.length; i<l; i++) { if (array[i] && typeof array[i] == "object") copy[i] = this.copyObject( array[i] ); else copy[i] = array[i]; } return copy; }; exports.deepCopy = function (obj) { if (typeof obj !== "object" || !obj) return obj; var cons = obj.constructor; if (cons === RegExp) return obj; var copy = cons(); for (var key in obj) { if (typeof obj[key] === "object") { copy[key] = exports.deepCopy(obj[key]); } else { copy[key] = obj[key]; } } return copy; }; exports.arrayToMap = function(arr) { var map = {}; for (var i=0; i<arr.length; i++) { map[arr[i]] = 1; } return map; }; exports.createMap = function(props) { var map = Object.create(null); for (var i in props) { map[i] = props[i]; } return map; }; exports.arrayRemove = function(array, value) { for (var i = 0; i <= array.length; i++) { if (value === array[i]) { array.splice(i, 1); } } }; exports.escapeRegExp = function(str) { return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1'); }; exports.escapeHTML = function(str) { return str.replace(/&/g, "&#38;").replace(/"/g, "&#34;").replace(/'/g, "&#39;").replace(/</g, "&#60;"); }; exports.getMatchOffsets = function(string, regExp) { var matches = []; string.replace(regExp, function(str) { matches.push({ offset: arguments[arguments.length-2], length: str.length }); }); return matches; }; exports.deferredCall = function(fcn) { var timer = null; var callback = function() { timer = null; fcn(); }; var deferred = function(timeout) { deferred.cancel(); timer = setTimeout(callback, timeout || 0); return deferred; }; deferred.schedule = deferred; deferred.call = function() { this.cancel(); fcn(); return deferred; }; deferred.cancel = function() { clearTimeout(timer); timer = null; return deferred; }; deferred.isPending = function() { return timer; }; return deferred; }; exports.delayedCall = function(fcn, defaultTimeout) { var timer = null; var callback = function() { timer = null; fcn(); }; var _self = function(timeout) { if (timer == null) timer = setTimeout(callback, timeout || defaultTimeout); }; _self.delay = function(timeout) { timer && clearTimeout(timer); timer = setTimeout(callback, timeout || defaultTimeout); }; _self.schedule = _self; _self.call = function() { this.cancel(); fcn(); }; _self.cancel = function() { timer && clearTimeout(timer); timer = null; }; _self.isPending = function() { return timer; }; return _self; }; }); ace.define('ace/mode/xquery/JSONParseTreeHandler', ['require', 'exports', 'module' ], function(require, exports, module) { var JSONParseTreeHandler = exports.JSONParseTreeHandler = function(code) { var list = [ "OrExpr", "AndExpr", "ComparisonExpr", "StringConcatExpr", "RangeExpr" , "UnionExpr", "IntersectExceptExpr", "InstanceofExpr", "TreatExpr", "CastableExpr" , "CastExpr", "UnaryExpr", "ValueExpr", "FTContainsExpr", "SimpleMapExpr", "PathExpr", "RelativePathExpr" , "PostfixExpr", "StepExpr" ]; var ast = null; var ptr = null; var remains = code; var cursor = 0; var lineCursor = 0; var line = 0; var col = 0; function createNode(name){ return { name: name, children: [], getParent: null, pos: { sl: 0, sc: 0, el: 0, ec: 0 } }; } function pushNode(name, begin){ var node = createNode(name); if(ast === null) { ast = node; ptr = node; } else { node.getParent = ptr; ptr.children.push(node); ptr = ptr.children[ptr.children.length - 1]; } } function popNode(){ if(ptr.children.length > 0) { var s = ptr.children[0]; var e = null; for(var i= ptr.children.length - 1; i >= 0;i--) { e = ptr.children[i]; if(e.pos.el !== 0 || e.pos.ec !== 0) { break; } } ptr.pos.sl = s.pos.sl; ptr.pos.sc = s.pos.sc; ptr.pos.el = e.pos.el; ptr.pos.ec = e.pos.ec; } if(ptr.name === "FunctionName") { ptr.name = "EQName"; } if(ptr.name === "EQName" && ptr.value === undefined) { ptr.value = ptr.children[0].value; ptr.children.pop(); } if(ptr.getParent !== null) { ptr = ptr.getParent; } else { } if(ptr.children.length > 0) { var lastChild = ptr.children[ptr.children.length - 1]; if(lastChild.children.length === 1 && list.indexOf(lastChild.name) !== -1) { ptr.children[ptr.children.length - 1] = lastChild.children[0]; } } } this.closeParseTree = function() { while(ptr.getParent !== null) { popNode(); } popNode(); }; this.peek = function() { return ptr; }; this.getParseTree = function() { return ast; }; this.reset = function(input) {}; this.startNonterminal = function(name, begin) { pushNode(name, begin); }; this.endNonterminal = function(name, end) { popNode(); }; this.terminal = function(name, begin, end) { name = (name.substring(0, 1) === "'" && name.substring(name.length - 1) === "'") ? "TOKEN" : name; pushNode(name, begin); setValue(ptr, begin, end); popNode(); }; this.whitespace = function(begin, end) { var name = "WS"; pushNode(name, begin); setValue(ptr, begin, end); popNode(); }; function setValue(node, begin, end) { var e = end - cursor; ptr.value = remains.substring(0, e); remains = remains.substring(e); cursor = end; var sl = line; var sc = lineCursor; var el = sl + ptr.value.split("\n").length - 1; var lastIdx = ptr.value.lastIndexOf("\n"); var ec = lastIdx === -1 ? sc + ptr.value.length : ptr.value.substring(lastIdx + 1).length; line = el; lineCursor = ec; ptr.pos.sl = sl; ptr.pos.sc = sc; ptr.pos.el = el; ptr.pos.ec = ec; } }; }); ace.define('ace/mode/xquery/XQueryParser', ['require', 'exports', 'module' ], function(require, exports, module) { var XQueryParser = exports.XQueryParser = function XQueryParser(string, parsingEventHandler) { init(string, parsingEventHandler); var self = this; this.ParseException = function(b, e, s, o, x) { var begin = b, end = e, state = s, offending = o, expected = x; this.getBegin = function() {return begin;}; this.getEnd = function() {return end;}; this.getState = function() {return state;}; this.getExpected = function() {return expected;}; this.getOffending = function() {return offending;}; this.getMessage = function() { return offending < 0 ? "lexical analysis failed" : "syntax error"; }; }; function init(string, parsingEventHandler) { eventHandler = parsingEventHandler; input = string; size = string.length; reset(0, 0, 0); } this.getInput = function() { return input; }; function reset(l, b, e) { b0 = b; e0 = b; l1 = l; b1 = b; e1 = e; l2 = 0; end = e; ex = -1; memo = {}; eventHandler.reset(input); } this.getOffendingToken = function(e) { var o = e.getOffending(); return o >= 0 ? XQueryParser.TOKEN[o] : null; }; this.getExpectedTokenSet = function(e) { var expected; if (e.getExpected() < 0) { expected = XQueryParser.getTokenSet(- e.getState()); } else { expected = [XQueryParser.TOKEN[e.getExpected()]]; } return expected; }; this.getErrorMessage = function(e) { var tokenSet = this.getExpectedTokenSet(e); var found = this.getOffendingToken(e); var prefix = input.substring(0, e.getBegin()); var lines = prefix.split("\n"); var line = lines.length; var column = lines[line - 1].length + 1; var size = e.getEnd() - e.getBegin(); return e.getMessage() + (found == null ? "" : ", found " + found) + "\nwhile expecting " + (tokenSet.length == 1 ? tokenSet[0] : ("[" + tokenSet.join(", ") + "]")) + "\n" + (size == 0 || found != null ? "" : "after successfully scanning " + size + " characters beginning ") + "at line " + line + ", column " + column + ":\n..." + input.substring(e.getBegin(), Math.min(input.length, e.getBegin() + 64)) + "..."; }; this.parse_XQuery = function() { eventHandler.startNonterminal("XQuery", e0); lookahead1W(268); // Wildcard | EQName^Token | IntegerLiteral | DecimalLiteral | DoubleLiteral | whitespace(); parse_Module(); shift(25); // EOF eventHandler.endNonterminal("XQuery", e0); }; function parse_Module() { eventHandler.startNonterminal("Module", e0); switch (l1) { case 274: // 'xquery' lookahead2W(199); // S^WS | EOF | '!' | '!=' | '#' | '(' | '(:' | '*' | '+' | ',' | '-' | '/' | '//' | break; default: lk = l1; } if (lk == 64274 // 'xquery' 'encoding' || lk == 134930) // 'xquery' 'version' { parse_VersionDecl(); } lookahead1W(268); // Wildcard | EQName^Token | IntegerLiteral | DecimalLiteral | DoubleLiteral | switch (l1) { case 182: // 'module' lookahead2W(194); // S^WS | EOF | '!' | '!=' | '#' | '(' | '(:' | '*' | '+' | ',' | '-' | '/' | '//' | break; default: lk = l1; } switch (lk) { case 94390: // 'module' 'namespace' whitespace(); parse_LibraryModule(); break; default: whitespace(); parse_MainModule(); } eventHandler.endNonterminal("Module", e0); } function parse_VersionDecl() { eventHandler.startNonterminal("VersionDecl", e0); shift(274); // 'xquery' lookahead1W(116); // S^WS | '(:' | 'encoding' | 'version' switch (l1) { case 125: // 'encoding' shift(125); // 'encoding' lookahead1W(17); // StringLiteral | S^WS | '(:' shift(11); // StringLiteral break; default: shift(263); // 'version' lookahead1W(17); // StringLiteral | S^WS | '(:' shift(11); // StringLiteral lookahead1W(109); // S^WS | '(:' | ';' | 'encoding' if (l1 == 125) // 'encoding' { shift(125); // 'encoding' lookahead1W(17); // StringLiteral | S^WS | '(:' shift(11); // StringLiteral } } lookahead1W(28); // S^WS | '(:' | ';' whitespace(); parse_Separator(); eventHandler.endNonterminal("VersionDecl", e0); } function parse_LibraryModule() { eventHandler.startNonterminal("LibraryModule", e0); parse_ModuleDecl(); lookahead1W(138); // S^WS | EOF | '(:' | 'declare' | 'import' whitespace(); parse_Prolog(); eventHandler.endNonterminal("LibraryModule", e0); } function parse_ModuleDecl() { eventHandler.startNonterminal("ModuleDecl", e0); shift(182); // 'module' lookahead1W(61); // S^WS | '(:' | 'namespace' shift(184); // 'namespace' lookahead1W(247); // NCName^Token | S^WS | '(:' | 'after' | 'allowing' | 'ancestor' | whitespace(); parse_NCName(); lookahead1W(29); // S^WS | '(:' | '=' shift(60); // '=' lookahead1W(15); // URILiteral | S^WS | '(:' shift(7); // URILiteral lookahead1W(28); // S^WS | '(:' | ';' whitespace(); parse_Separator(); eventHandler.endNonterminal("ModuleDecl", e0); } function parse_Prolog() { eventHandler.startNonterminal("Prolog", e0); for (;;) { lookahead1W(268); // Wildcard | EQName^Token | IntegerLiteral | DecimalLiteral | DoubleLiteral | switch (l1) { case 108: // 'declare' lookahead2W(213); // S^WS | EOF | '!' | '!=' | '#' | '%' | '(' | '(:' | '*' | '+' | ',' | '-' | '/' | break; case 153: // 'import' lookahead2W(201); // S^WS | EOF | '!' | '!=' | '#' | '(' | '(:' | '*' | '+' | ',' | '-' | '/' | '//' | break; default: lk = l1; } if (lk != 42604 // 'declare' 'base-uri' && lk != 43628 // 'declare' 'boundary-space' && lk != 50284 // 'declare' 'construction' && lk != 53356 // 'declare' 'copy-namespaces' && lk != 54380 // 'declare' 'decimal-format' && lk != 55916 // 'declare' 'default' && lk != 72300 // 'declare' 'ft-option' && lk != 93337 // 'import' 'module' && lk != 94316 // 'declare' 'namespace' && lk != 104044 // 'declare' 'ordering' && lk != 113772 // 'declare' 'revalidation' && lk != 115353) // 'import' 'schema' { break; } switch (l1) { case 108: // 'declare' lookahead2W(178); // S^WS | '(:' | 'base-uri' | 'boundary-space' | 'construction' | break; default: lk = l1; } if (lk == 55916) // 'declare' 'default' { lk = memoized(0, e0); if (lk == 0) { var b0A = b0; var e0A = e0; var l1A = l1; var b1A = b1; var e1A = e1; var l2A = l2; var b2A = b2; var e2A = e2; try { try_DefaultNamespaceDecl(); lk = -1; } catch (p1A) { lk = -2; } b0 = b0A; e0 = e0A; l1 = l1A; if (l1 == 0) {end = e0A;} else { b1 = b1A; e1 = e1A; l2 = l2A; if (l2 == 0) {end = e1A;} else { b2 = b2A; e2 = e2A; end = e2A; }} memoize(0, e0, lk); } } switch (lk) { case -1: whitespace(); parse_DefaultNamespaceDecl(); break; case 94316: // 'declare' 'namespace' whitespace(); parse_NamespaceDecl(); break; case 153: // 'import' whitespace(); parse_Import(); break; case 72300: // 'declare' 'ft-option' whitespace(); parse_FTOptionDecl(); break; default: whitespace(); parse_Setter(); } lookahead1W(28); // S^WS | '(:' | ';' whitespace(); parse_Separator(); } for (;;) { lookahead1W(268); // Wildcard | EQName^Token | IntegerLiteral | DecimalLiteral | DoubleLiteral | switch (l1) { case 108: // 'declare' lookahead2W(210); // S^WS | EOF | '!' | '!=' | '#' | '%' | '(' | '(:' | '*' | '+' | ',' | '-' | '/' | break; default: lk = l1; } if (lk != 16492 // 'declare' '%' && lk != 48748 // 'declare' 'collection' && lk != 51820 // 'declare' 'context' && lk != 74348 // 'declare' 'function' && lk != 79468 // 'declare' 'index' && lk != 82540 // 'declare' 'integrity' && lk != 101996 // 'declare' 'option' && lk != 131692 // 'declare' 'updating' && lk != 134252) // 'declare' 'variable' { break; } switch (l1) { case 108: //