XML editor was replaced by codemirror thridparty library and other improvements such as dynaform editor load time
This commit is contained in:
BIN
gulliver/js/codemirror/.swp.php.html
Executable file
BIN
gulliver/js/codemirror/.swp.php.html
Executable file
Binary file not shown.
74
gulliver/js/codemirror/2/index.html
Executable file
74
gulliver/js/codemirror/2/index.html
Executable file
@@ -0,0 +1,74 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror 2</title>
|
||||
<link rel="stylesheet" href="lib/codemirror.css">
|
||||
<script src="lib/codemirror.js"></script>
|
||||
<script src="mode/javascript/javascript.js"></script>
|
||||
<link rel="stylesheet" href="mode/javascript/javascript.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>CodeMirror 2</h1>
|
||||
<p>This is a new project, aiming to create a CodeMirror-style
|
||||
component without using an IFRAME.
|
||||
The <a href="http://ajaxorg.github.com/ace/">ACE</a> editor proved
|
||||
that this is viable, which motivated me to give it a shot. (Though I took a somewhat different
|
||||
approach.)</p>
|
||||
<p>No IE support so far, only tested with recent Chrome, Opera,
|
||||
and Firefox builds. The JavaScript parser is the only one I've
|
||||
ported over.</p>
|
||||
<p>Code at <a href="https://github.com/marijnh/codemirror2">https://github.com/marijnh/codemirror2</a>.</p>
|
||||
<form><textarea id="code" style="display: none" name="code">
|
||||
// Demo code (the actual new parser character stream implementation)
|
||||
|
||||
function StringStream(string) {
|
||||
this.pos = 0;
|
||||
this.string = string;
|
||||
}
|
||||
|
||||
StringStream.prototype = {
|
||||
done: function() {return this.pos >= this.string.length;},
|
||||
peek: function() {return this.string.charAt(this.pos);},
|
||||
next: function() {
|
||||
if (this.pos < this.string.length)
|
||||
return this.string.charAt(this.pos++);
|
||||
},
|
||||
eat: function(match) {
|
||||
var ch = this.string.charAt(this.pos);
|
||||
if (typeof match == "string") var ok = ch == match;
|
||||
else var ok = ch && match.test ? match.test(ch) : match(ch);
|
||||
if (ok) {this.pos++; return ch;}
|
||||
},
|
||||
eatWhile: function(match) {
|
||||
var start = this.pos;
|
||||
while (this.eat(match));
|
||||
if (this.pos > start) return this.string.slice(start, this.pos);
|
||||
},
|
||||
backUp: function(n) {this.pos -= n;},
|
||||
column: function() {return this.pos;},
|
||||
eatSpace: function() {
|
||||
var start = this.pos;
|
||||
while (/\s/.test(this.string.charAt(this.pos))) this.pos++;
|
||||
return this.pos - start;
|
||||
},
|
||||
match: function(pattern, consume, caseInsensitive) {
|
||||
if (typeof pattern == "string") {
|
||||
function cased(str) {return caseInsensitive ? str.toLowerCase() : str;}
|
||||
if (cased(this.string).indexOf(cased(pattern), this.pos) == this.pos) {
|
||||
if (consume !== false) this.pos += str.length;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
var match = this.string.slice(this.pos).match(pattern);
|
||||
if (match && consume !== false) this.pos += match[0].length;
|
||||
return match;
|
||||
}
|
||||
}
|
||||
};
|
||||
</textarea></form>
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
4
gulliver/js/codemirror/2/issues
Executable file
4
gulliver/js/codemirror/2/issues
Executable file
@@ -0,0 +1,4 @@
|
||||
* Mouse drag to copy a region in X
|
||||
* Indentation
|
||||
* Line numbers
|
||||
* Horizontal scrolling
|
||||
41
gulliver/js/codemirror/2/lib/codemirror.css
Executable file
41
gulliver/js/codemirror/2/lib/codemirror.css
Executable file
@@ -0,0 +1,41 @@
|
||||
.CodeMirror {
|
||||
position: relative;
|
||||
border: 1px solid black;
|
||||
}
|
||||
|
||||
.CodeMirror-cursor {
|
||||
width: 1px;
|
||||
height: 1.2em !important;
|
||||
background: black;
|
||||
position: absolute;
|
||||
margin-top: -.1em;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.CodeMirror-focused .CodeMirror-cursor {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.CodeMirror-code {
|
||||
position: relative;
|
||||
white-space: pre;
|
||||
overflow: auto;
|
||||
height: 300px;
|
||||
font-family: monospace;
|
||||
line-height: 1em;
|
||||
padding: .4em;
|
||||
}
|
||||
|
||||
.CodeMirror-code div {
|
||||
height: 1em;
|
||||
min-width: 1px;
|
||||
}
|
||||
|
||||
span.CodeMirror-selected {
|
||||
background: #bbb !important;
|
||||
color: white !important;
|
||||
}
|
||||
|
||||
.CodeMirror-focused .CodeMirror-selected {
|
||||
background: #88f !important;
|
||||
}
|
||||
713
gulliver/js/codemirror/2/lib/codemirror.js
Executable file
713
gulliver/js/codemirror/2/lib/codemirror.js
Executable file
@@ -0,0 +1,713 @@
|
||||
// TODO handle 0-offsets when editor is hidden
|
||||
|
||||
var CodeMirror = (function() {
|
||||
function Event(orig) {this.e = orig;}
|
||||
Event.prototype = {
|
||||
stop: function() {
|
||||
if (this.e.stopPropagation) this.e.stopPropagation();
|
||||
else this.e.cancelBubble = true;
|
||||
if (this.e.preventDefault) this.e.preventDefault();
|
||||
else this.e.returnValue = false;
|
||||
},
|
||||
target: function() {
|
||||
return this.e.target || this.e.srcElement;
|
||||
},
|
||||
button: function() {
|
||||
if (this.e.which) return this.e.which;
|
||||
else if (this.e.button & 1) return 1;
|
||||
else if (this.e.button & 2) return 3;
|
||||
else if (this.e.button & 4) return 2;
|
||||
}
|
||||
};
|
||||
|
||||
function connect(node, type, handler, disconnect) {
|
||||
function wrapHandler(event) {handler(new Event(event || window.event));}
|
||||
if (typeof node.addEventListener == "function") {
|
||||
node.addEventListener(type, wrapHandler, false);
|
||||
if (disconnect) return function() {node.removeEventListener(type, wrapHandler, false);};
|
||||
}
|
||||
else {
|
||||
node.attachEvent("on" + type, wrapHandler);
|
||||
if (disconnect) return function() {node.detachEvent("on" + type, wrapHandler);};
|
||||
}
|
||||
}
|
||||
|
||||
var lineSep = window.opera ? "\r\n" : "\n";
|
||||
|
||||
function removeElement(node) {
|
||||
if (node.parentNode) node.parentNode.removeChild(node);
|
||||
}
|
||||
function eltOffset(node) {
|
||||
var x = 0, y = 0;
|
||||
while (node) {
|
||||
x += node.offsetLeft; y += node.offsetTop;
|
||||
node = node.offsetParent;
|
||||
}
|
||||
return {left: x, top: y};
|
||||
}
|
||||
function addTextSpan(node, text) {
|
||||
var span = node.appendChild(document.createElement("span"));
|
||||
span.appendChild(document.createTextNode(text));
|
||||
return span;
|
||||
}
|
||||
|
||||
function posEq(a, b) {return a.line == b.line && a.ch == b.ch;}
|
||||
function posLess(a, b) {return a.line < b.line || (a.line == b.line && a.ch < b.ch);}
|
||||
function copyPos(x) {return {line: x.line, ch: x.ch};}
|
||||
|
||||
function htmlEscape(str) {
|
||||
return str.replace(/[<&]/, function(str) {return str == "&" ? "&" : "<";});
|
||||
}
|
||||
|
||||
var movementKeys = {};
|
||||
for (var i = 35; i <= 40; i++)
|
||||
movementKeys[i] = movementKeys["c" + i] = true;
|
||||
|
||||
function lineElt(line) {return line.selDiv || line.div;}
|
||||
|
||||
function CodeMirror(place, options) {
|
||||
var div = this.div = document.createElement("div");
|
||||
if (place.appendChild) place.appendChild(div); else place(div);
|
||||
div.className = "CodeMirror";
|
||||
var te = this.input = div.appendChild(document.createElement("textarea"));
|
||||
te.style.position = "absolute";
|
||||
te.style.width = "10000px";
|
||||
te.style.left = te.style.top = "-100000px";
|
||||
var code = this.code = div.appendChild(document.createElement("div"));
|
||||
code.className = "CodeMirror-code";
|
||||
this.cursor = code.appendChild(document.createElement("div"));
|
||||
this.cursor.className = "CodeMirror-cursor";
|
||||
this.cursor.style.display = "none";
|
||||
this.restartBlink();
|
||||
this.measure = code.appendChild(document.createElement("span"));
|
||||
this.measure.style.position = "absolute";
|
||||
this.measure.style.visibility = "hidden";
|
||||
this.measure.innerHTML = "-";
|
||||
|
||||
this.parser = parsers[options.parser || defaultParser];
|
||||
if (!this.parser) throw new Error("No parser found.");
|
||||
|
||||
this.lines = []; this.work = [];
|
||||
var zero = {line: 0, ch: 0};
|
||||
this.selection = {from: zero, to: zero}; this.prevSelection = {from: zero, to: zero};
|
||||
this.$setValue(options.value || "");
|
||||
this.endOperation();
|
||||
|
||||
var self = this;
|
||||
connect(code, "mousedown", this.operation("onMouseDown"));
|
||||
connect(te, "keyup", this.operation("onKeyUp"));
|
||||
connect(te, "keydown", this.operation("onKeyDown"));
|
||||
connect(te, "focus", function(){self.onFocus();});
|
||||
connect(te, "blur", function(){self.onBlur();});
|
||||
|
||||
connect(code, "dragenter", function(e){e.stop();});
|
||||
connect(code, "dragover", function(e){e.stop();});
|
||||
connect(code, "drop", this.operation("onDrop"));
|
||||
connect(code, "paste", function(e){self.input.focus(); self.schedulePoll(20);});
|
||||
|
||||
if (document.activeElement == te) this.onFocus();
|
||||
else this.onBlur();
|
||||
}
|
||||
|
||||
CodeMirror.prototype = {
|
||||
$setValue: function(code) {
|
||||
this.replaceLines(0, this.lines.length, code.split(/\r?\n/g));
|
||||
},
|
||||
getValue: function(code) {
|
||||
var lines = [];
|
||||
for (var i = 0, l = this.lines.length; i < l; i++)
|
||||
lines.push(this.lines[i].text);
|
||||
return lines.join("\n");
|
||||
},
|
||||
|
||||
onMouseDown: function(e) {
|
||||
// Make sure we're not clicking the scrollbar
|
||||
var corner = eltOffset(this.code);
|
||||
if (e.e.pageX - corner.left > this.code.clientWidth ||
|
||||
e.e.pageY - corner.top > this.code.clientHeight) return;
|
||||
|
||||
this.shiftSelecting = null;
|
||||
var start = this.mouseEventPos(e), last = start, self = this;
|
||||
this.setCursor(start.line, start.ch, false);
|
||||
if (e.button() != 1) return;
|
||||
|
||||
e.stop();
|
||||
function end() {
|
||||
if (!self.focused) {
|
||||
self.input.focus();
|
||||
self.onFocus();
|
||||
self.prepareInput();
|
||||
}
|
||||
self.updateInput = true;
|
||||
move(); up(); leave();
|
||||
}
|
||||
|
||||
var move = connect(this.div, "mousemove", this.operation(function(e) {
|
||||
var cur = this.clipPos(this.mouseEventPos(e));
|
||||
if (!posEq(cur, last)) {
|
||||
last = cur;
|
||||
this.setSelection(this.clipPos(start), cur);
|
||||
}
|
||||
}), true);
|
||||
var up = connect(this.div, "mouseup", this.operation(function(e) {
|
||||
this.setSelection(this.clipPos(start), this.clipPos(this.mouseEventPos(e)));
|
||||
end();
|
||||
}), true);
|
||||
// TODO dragging out of window should scroll
|
||||
var leave = connect(this.div, "mouseout", this.operation(function(e) {
|
||||
if (e.target() == this.div) end();
|
||||
}), true);
|
||||
},
|
||||
onDrop: function(e) {
|
||||
try {var text = e.e.dataTransfer.getData("Text");}
|
||||
catch(e){}
|
||||
if (!text) return;
|
||||
var pos = this.clipPos(this.mouseEventPos(e));
|
||||
this.setSelection(pos, pos);
|
||||
this.$replaceSelection(text);
|
||||
},
|
||||
onKeyDown: function(e) {
|
||||
if (!this.focused) this.onFocus();
|
||||
|
||||
var code = e.e.keyCode, ctrl = e.e.ctrlKey && !e.e.altKey;
|
||||
if (code == 33 || code == 34) { // page up/down
|
||||
this.scrollPage(code == 34);
|
||||
e.stop();
|
||||
}
|
||||
else if (ctrl && (code == 36 || code == 35)) { // ctrl-home/end
|
||||
this.scrollEnd(code == 36);
|
||||
e.stop();
|
||||
}
|
||||
else if (ctrl && code == 65) { // ctrl-a
|
||||
this.selectAll();
|
||||
e.stop();
|
||||
}
|
||||
else if (!ctrl && code == 13) { // enter
|
||||
this.insertNewline();
|
||||
e.stop();
|
||||
}
|
||||
else if (!ctrl && code == 9) { // tab
|
||||
this.handleTab();
|
||||
e.stop();
|
||||
}
|
||||
else if (code == 16) { // shift
|
||||
this.shiftSelecting = this.selection.inverted ? this.selection.to : this.selection.from;
|
||||
}
|
||||
else {
|
||||
var id = (ctrl ? "c" : "") + code;
|
||||
if (this.selection.inverted && movementKeys.hasOwnProperty(id)) {
|
||||
this.reducedSelection = {anchor: this.input.selectionStart};
|
||||
this.input.selectionEnd = this.input.selectionStart;
|
||||
}
|
||||
this.schedulePoll(20, id);
|
||||
}
|
||||
},
|
||||
onKeyUp: function(e) {
|
||||
if (this.reducedSelection) {
|
||||
this.reducedSelection = null;
|
||||
this.prepareInput();
|
||||
}
|
||||
if (e.e.keyCode == 16)
|
||||
this.shiftSelecting = null;
|
||||
},
|
||||
|
||||
onFocus: function() {
|
||||
this.focused = true;
|
||||
this.schedulePoll(2000);
|
||||
if (this.div.className.search(/\bCodeMirror-focused\b/) == -1)
|
||||
this.div.className += " CodeMirror-focused";
|
||||
},
|
||||
onBlur: function() {
|
||||
this.shiftSelecting = null;
|
||||
this.focused = false;
|
||||
this.div.className = this.div.className.replace(" CodeMirror-focused", "");
|
||||
},
|
||||
|
||||
replaceLines: function(from, to, newText) {
|
||||
// Make sure only changed lines are replaced
|
||||
var lines = this.lines;
|
||||
while (from < to && newText[0] == lines[from].text) {
|
||||
from++; newText.shift();
|
||||
}
|
||||
while (to > from + 1 && newText[newText.length-1] == lines[to-1].text) {
|
||||
to--; newText.pop();
|
||||
}
|
||||
|
||||
// Update this.lines length and the associated DIVs
|
||||
var lendiff = newText.length - (to - from);
|
||||
if (lendiff < 0) {
|
||||
var removed = lines.splice(from, -lendiff);
|
||||
for (var i = 0, l = removed.length; i < l; i++)
|
||||
removeElement(lineElt(removed[i]));
|
||||
}
|
||||
else if (lendiff > 0) {
|
||||
var spliceargs = [from, 0], before = lines[from] ? lines[from].div : null;
|
||||
for (var i = 0; i < lendiff; i++) {
|
||||
var div = this.code.insertBefore(document.createElement("div"), before);
|
||||
spliceargs.push({div: div});
|
||||
}
|
||||
lines.splice.apply(lines, spliceargs);
|
||||
}
|
||||
for (var i = 0, l = newText.length; i < l; i++) {
|
||||
var line = lines[from + i];
|
||||
var text = line.text = newText[i];
|
||||
if (line.selDiv) this.code.replaceChild(line.div, line.selDiv);
|
||||
line.stateAfter = line.selDiv = null;
|
||||
line.div.innerHTML = "";
|
||||
addTextSpan(line.div, line.text);
|
||||
}
|
||||
|
||||
var newWork = [];
|
||||
for (var i = 0, l = this.work.length; i < l; i++) {
|
||||
var task = this.work[i];
|
||||
if (task < from) newWork.push(task);
|
||||
else if (task >= to) newWork.push(task + lendiff);
|
||||
}
|
||||
if (newText.length) newWork.push(from);
|
||||
this.work = newWork;
|
||||
this.startWorker(100);
|
||||
|
||||
var selLine = this.selection.from.line;
|
||||
if (lendiff || from != selLine || to != selLine + 1)
|
||||
this.updateInput = true;
|
||||
},
|
||||
|
||||
schedulePoll: function(time, keyId) {
|
||||
var self = this;
|
||||
function pollForKey() {
|
||||
var state = self.readInput();
|
||||
if (state == "moved") movementKeys[keyId] = true;
|
||||
if (state) self.schedulePoll(200, keyId);
|
||||
else self.schedulePoll(2000);
|
||||
}
|
||||
function poll() {
|
||||
self.readInput();
|
||||
if (self.focused) self.schedulePoll(2000);
|
||||
}
|
||||
clearTimeout(this.pollTimer);
|
||||
if (time) this.pollTimer = setTimeout(this.operation(keyId ? pollForKey : poll), time);
|
||||
},
|
||||
|
||||
readInput: function() {
|
||||
var ed = this.editing, changed = false, sel = this.selection, te = this.input;
|
||||
var text = te.value, selstart = te.selectionStart, selend = te.selectionEnd;
|
||||
var changed = ed.text != text, rs = this.reducedSelection;
|
||||
var moved = changed || selstart != ed.start || selend != (rs ? ed.start : ed.end);
|
||||
if (!moved) return false;
|
||||
|
||||
function computeOffset(n, startLine) {
|
||||
var pos = 0;
|
||||
while (true) {
|
||||
var found = text.indexOf("\n", pos);
|
||||
if (found == -1 || (text.charAt(found-1) == "\r" ? found - 1 : found) >= n)
|
||||
return {line: startLine, ch: n - pos};
|
||||
startLine++;
|
||||
pos = found + 1;
|
||||
}
|
||||
}
|
||||
var from = computeOffset(selstart, ed.from),
|
||||
to = computeOffset(selend, ed.from);
|
||||
if (rs) {
|
||||
from = selstart == rs.anchor ? to : from;
|
||||
to = this.shiftSelecting ? sel.to : selstart == rs.anchor ? from : to;
|
||||
if (!posLess(from, to)) {
|
||||
this.reducedSelection = null;
|
||||
this.selection.inverted = false;
|
||||
var tmp = from; from = to; to = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
this.shiftSelecting = null;
|
||||
this.replaceLines(ed.from, ed.to, text.split(/\r?\n/g));
|
||||
}
|
||||
ed.text = text; ed.start = selstart; ed.end = selend;
|
||||
|
||||
this.setSelection(from, to);
|
||||
return changed ? "changed" : moved ? "moved" : false;
|
||||
},
|
||||
|
||||
prepareInput: function() {
|
||||
var sel = this.selection, text = [];
|
||||
var from = Math.max(0, sel.from.line - 1), to = Math.min(this.lines.length, sel.to.line + 2);
|
||||
for (var i = from; i < to; i++) text.push(this.lines[i].text);
|
||||
text = this.input.value = text.join(lineSep);
|
||||
var startch = sel.from.ch, endch = sel.to.ch;
|
||||
for (var i = from; i < sel.from.line; i++)
|
||||
startch += lineSep.length + this.lines[i].text.length;
|
||||
for (var i = from; i < sel.to.line; i++)
|
||||
endch += lineSep.length + this.lines[i].text.length;
|
||||
this.editing = {text: text, from: from, to: to, start: startch, end: endch};
|
||||
this.input.setSelectionRange(startch, this.reducedSelection ? startch : endch);
|
||||
},
|
||||
|
||||
displaySelection: function() {
|
||||
var sel = this.selection, pr = this.prevSelection;
|
||||
if (posEq(sel.from, sel.to)) {
|
||||
this.cursor.style.display = "";
|
||||
if (!posEq(pr.from, pr.to)) {
|
||||
for (var i = pr.from.line; i <= pr.to.line; i++)
|
||||
this.removeSelectedStyle(i);
|
||||
}
|
||||
var linediv = lineElt(this.lines[sel.from.line]);
|
||||
this.cursor.style.top = linediv.offsetTop + "px";
|
||||
this.cursor.style.left = (linediv.offsetLeft + this.charWidth() * sel.from.ch) + "px";
|
||||
}
|
||||
else {
|
||||
this.cursor.style.display = "none";
|
||||
if (!posEq(pr.from, pr.to)) {
|
||||
for (var i = pr.from.line, e = Math.min(sel.from.line, pr.to.line + 1); i < e; i++)
|
||||
this.removeSelectedStyle(i);
|
||||
for (var i = Math.max(sel.to.line + 1, pr.from.line); i <= pr.to.line; i++)
|
||||
this.removeSelectedStyle(i);
|
||||
}
|
||||
if (sel.from.line == sel.to.line) {
|
||||
this.setSelectedStyle(sel.from.line, sel.from.ch, sel.to.ch);
|
||||
}
|
||||
else {
|
||||
this.setSelectedStyle(sel.from.line, sel.from.ch, null);
|
||||
for (var i = sel.from.line + 1; i < sel.to.line; i++)
|
||||
this.setSelectedStyle(i, 0, null);
|
||||
this.setSelectedStyle(sel.to.line, 0, sel.to.ch);
|
||||
}
|
||||
}
|
||||
|
||||
var head = sel.inverted ? sel.from : sel.to, headLine = lineElt(this.lines[head.line]);
|
||||
var ypos = headLine.offsetTop, line = this.lineHeight(),
|
||||
screen = this.code.clientHeight, screentop = this.code.scrollTop;
|
||||
if (ypos < screentop)
|
||||
this.code.scrollTop = Math.max(0, ypos - 10);
|
||||
else if (ypos + line > screentop + screen)
|
||||
this.code.scrollTop = (ypos + line + 10) - screen;
|
||||
|
||||
var xpos = head.ch * this.charWidth(),
|
||||
screenw = headLine.offsetWidth, screenleft = this.code.scrollLeft;
|
||||
if (xpos < screenleft)
|
||||
this.code.scrollLeft = Math.max(0, xpos - 10);
|
||||
else if (xpos > screenw + screenleft)
|
||||
this.code.scrollLeft = (xpos + 10) - screenw;
|
||||
},
|
||||
|
||||
setSelection: function(from, to) {
|
||||
var sel = this.selection, sh = this.shiftSelecting;
|
||||
if (posLess(to, from)) {var tmp = to; to = from; from = tmp;}
|
||||
if (sh) {
|
||||
if (posLess(sh, from)) from = sh;
|
||||
else if (posLess(to, sh)) to = sh;
|
||||
}
|
||||
|
||||
var startEq = posEq(sel.to, to), endEq = posEq(sel.from, from);
|
||||
if (posEq(from, to)) sel.inverted = false;
|
||||
else if (startEq && !endEq) sel.inverted = true;
|
||||
else if (endEq && !startEq) sel.inverted = false;
|
||||
sel.from = from; sel.to = to;
|
||||
},
|
||||
|
||||
setCursor: function(line, ch) {
|
||||
var pos = this.clipPos({line: line, ch: ch || 0});
|
||||
this.setSelection(pos, pos);
|
||||
},
|
||||
scrollPage: function(down) {
|
||||
var linesPerPage = Math.floor(this.div.clientHeight / this.lineHeight());
|
||||
this.setCursor(this.selection.from.line + (Math.max(linesPerPage - 1, 1) * (down ? 1 : -1)));
|
||||
},
|
||||
scrollEnd: function(top) {
|
||||
this.setCursor(top ? 0 : this.lines.length - 1);
|
||||
},
|
||||
selectAll: function() {
|
||||
this.shiftSelecting = null;
|
||||
var endLine = this.lines.length - 1;
|
||||
this.setSelection({line: 0, ch: 0}, {line: endLine, ch: this.lines[endLine].text.length});
|
||||
},
|
||||
insertNewline: function() {
|
||||
this.$replaceSelection("\n", "end");
|
||||
this.indentLine(this.selection.from.line);
|
||||
},
|
||||
handleTab: function() {
|
||||
var sel = this.selection;
|
||||
for (var i = sel.from.line, e = sel.to.line; i <= e; i++)
|
||||
this.indentLine(i);
|
||||
},
|
||||
indentLine: function(n) {
|
||||
var state = this.getStateBefore(n);
|
||||
if (!state) return;
|
||||
var text = this.lines[n].text;
|
||||
var curSpace = text.match(/^\s*/)[0].length;
|
||||
var indentation = this.parser.indent(state, text.slice(curSpace)), diff = indentation - curSpace;
|
||||
if (!diff) return;
|
||||
|
||||
if (diff > 0) {
|
||||
var space = "";
|
||||
for (var i = 0; i < diff; i++) space = space + " ";
|
||||
this.replaceLines(n, n + 1, [space + text]);
|
||||
}
|
||||
else
|
||||
this.replaceLines(n, n + 1, [text.slice(-diff)]);
|
||||
var from = copyPos(this.selection.from), to = copyPos(this.selection.to);
|
||||
if (from.line == n) from.ch = Math.max(indentation, from.ch + diff);
|
||||
if (to.line == n) to.ch = Math.max(indentation, to.ch + diff);
|
||||
this.setSelection(from, to);
|
||||
},
|
||||
|
||||
$replaceSelection: function(code, collapse) {
|
||||
var lines = code.split(/\r?\n/g), sel = this.selection;
|
||||
lines[0] = this.lines[sel.from.line].text.slice(0, sel.from.ch) + lines[0];
|
||||
var endch = lines[lines.length-1].length;
|
||||
lines[lines.length-1] += this.lines[sel.to.line].text.slice(sel.to.ch);
|
||||
var from = sel.from, to = {line: sel.from.line + lines.length - 1, ch: endch};
|
||||
this.replaceLines(sel.from.line, sel.to.line + 1, lines);
|
||||
if (collapse == "end") from = to;
|
||||
else if (collapse == "start") to = from;
|
||||
this.setSelection(from, to);
|
||||
},
|
||||
|
||||
lineHeight: function() {
|
||||
var firstline = this.lines[0];
|
||||
return lineElt(firstline).offsetHeight;
|
||||
},
|
||||
charWidth: function() {
|
||||
return this.measure.offsetWidth || 1;
|
||||
},
|
||||
mouseEventPos: function(e) {
|
||||
var off = eltOffset(lineElt(this.lines[0])),
|
||||
x = e.e.pageX - off.left + this.code.scrollLeft,
|
||||
y = e.e.pageY - off.top + this.code.scrollTop;
|
||||
return {line: Math.floor(y / this.lineHeight()), ch: Math.floor(x / this.charWidth())};
|
||||
},
|
||||
clipPos: function(pos) {
|
||||
pos.line = Math.max(0, Math.min(this.lines.length - 1, pos.line));
|
||||
pos.ch = Math.max(0, Math.min(this.lines[pos.line].text.length, pos.ch));
|
||||
return pos;
|
||||
},
|
||||
|
||||
removeSelectedStyle: function(line) {
|
||||
if (line >= this.lines.length) return;
|
||||
line = this.lines[line];
|
||||
if (!line.selDiv) return;
|
||||
this.code.replaceChild(line.div, line.selDiv);
|
||||
line.selDiv = null;
|
||||
},
|
||||
setSelectedStyle: function(line, start, end) {
|
||||
line = this.lines[line];
|
||||
var div = line.selDiv, repl = line.div;
|
||||
if (div) {
|
||||
if (div.start == start && div.end == end) return;
|
||||
repl = div;
|
||||
}
|
||||
div = line.selDiv = document.createElement("div");
|
||||
if (start > 0)
|
||||
addTextSpan(div, line.text.slice(0, start));
|
||||
var seltext = line.text.slice(start, end == null ? line.text.length : end);
|
||||
if (end == null) seltext += " ";
|
||||
addTextSpan(div, seltext).className = "CodeMirror-selected";
|
||||
if (end != null && end < line.text.length)
|
||||
addTextSpan(div, line.text.slice(end));
|
||||
div.start = start; div.end = end;
|
||||
this.code.replaceChild(div, repl);
|
||||
},
|
||||
|
||||
restartBlink: function() {
|
||||
clearInterval(this.blinker);
|
||||
this.cursor.style.visibility = "";
|
||||
var self = this;
|
||||
this.blinker = setInterval(function() {
|
||||
if (!self.div.parentNode) clearInterval(self.blinker);
|
||||
var st = self.cursor.style;
|
||||
st.visibility = st.visibility ? "" : "hidden";
|
||||
}, 650);
|
||||
},
|
||||
|
||||
highlightLine: function(line, state) {
|
||||
var stream = new StringStream(line.text), html = [];
|
||||
while (!stream.done()) {
|
||||
var start = stream.pos, style = this.parser.token(stream, state, start == 0);
|
||||
var str = line.text.slice(start, stream.pos);
|
||||
html.push("<span class=\"" + style + "\">" + htmlEscape(str) + "</span>");
|
||||
}
|
||||
// TODO benchmark with removing/cloning/hiding/whatever
|
||||
line.div.innerHTML = html.join("");
|
||||
},
|
||||
getStateBefore: function(n) {
|
||||
var state;
|
||||
for (var search = n - 1, lim = n - 40;; search--) {
|
||||
if (search < 0) {state = this.parser.startState(); break;}
|
||||
if (search < lim) return null;
|
||||
if (state = this.lines[search].stateAfter) {state = copyState(state); break;}
|
||||
}
|
||||
for (search++; search < n; search++) {
|
||||
var line = this.lines[search];
|
||||
this.highlightLine(line, state);
|
||||
line.stateAfter = copyState(state);
|
||||
}
|
||||
if (!this.lines[n].stateAfter) this.work.push(n);
|
||||
return state;
|
||||
},
|
||||
highlightWorker: function(start) {
|
||||
// TODO have a mode where the document is always parsed to the end
|
||||
var end = +new Date + 200;
|
||||
while (this.work.length) {
|
||||
var task = this.work.pop()
|
||||
if (this.lines[task].stateAfter) continue;
|
||||
if (task) {
|
||||
var state = this.lines[task-1].stateAfter;
|
||||
if (!state) continue;
|
||||
state = copyState(state);
|
||||
}
|
||||
else var state = this.parser.startState();
|
||||
|
||||
for (var i = task, l = this.lines.length; i < l; i++) {
|
||||
var line = this.lines[i];
|
||||
if (line.stateAfter) break;
|
||||
if (+new Date > end) {
|
||||
this.work.push(i);
|
||||
this.startWorker(300);
|
||||
return;
|
||||
}
|
||||
this.highlightLine(line, state);
|
||||
line.stateAfter = copyState(state);
|
||||
}
|
||||
}
|
||||
},
|
||||
startWorker: function(time) {
|
||||
if (!this.work.length) return;
|
||||
var self = this;
|
||||
clearTimeout(this.highlightTimeout);
|
||||
this.highlightTimeout = setTimeout(this.operation("highlightWorker"), time);
|
||||
},
|
||||
|
||||
startOperation: function() {
|
||||
var ps = this.prevSelection, sel = this.selection;
|
||||
ps.from = sel.from; ps.to = sel.to;
|
||||
this.updateInput = false;
|
||||
},
|
||||
endOperation: function() {
|
||||
var ps = this.prevSelection, sel = this.selection;
|
||||
if (!posEq(ps.from, sel.from) || !posEq(ps.to, sel.to)) {
|
||||
this.displaySelection();
|
||||
this.restartBlink();
|
||||
}
|
||||
if (ps.from.line != sel.from.line || ps.to.line != sel.to.line || this.updateInput)
|
||||
this.prepareInput();
|
||||
},
|
||||
operation: function(f) {
|
||||
var self = this;
|
||||
if (typeof f == "string") f = this[f];
|
||||
return function() {
|
||||
self.startOperation();
|
||||
var result = f.apply(self, arguments);
|
||||
self.endOperation();
|
||||
return result;
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
// Wrap API functions as operations
|
||||
var proto = CodeMirror.prototype;
|
||||
function apiOp(name) {
|
||||
var f = proto[name];
|
||||
proto[name.slice(1)] = function() {
|
||||
this.startOperation();
|
||||
return f.apply(this, arguments);
|
||||
this.endOperation();
|
||||
};
|
||||
}
|
||||
for (var n in proto) if (n.charAt(0) == "$") apiOp(n);
|
||||
|
||||
var parsers = {}, defaultParser = null;
|
||||
CodeMirror.addParser = function(name, parser) {
|
||||
if (!defaultParser) defaultParser = name;
|
||||
parsers[name] = parser;
|
||||
};
|
||||
|
||||
CodeMirror.fromTextArea = function(textarea, options) {
|
||||
if (options && options.value == null)
|
||||
options.value = textarea.value;
|
||||
|
||||
function save() {textarea.value = instance.getValue();}
|
||||
if (textarea.form) {
|
||||
var rmSubmit = connect(textarea.form, "submit", save);
|
||||
var realSubmit = textarea.form.submit;
|
||||
function wrappedSubmit() {
|
||||
updateField();
|
||||
textarea.form.submit = realSubmit;
|
||||
textarea.form.submit();
|
||||
textarea.form.submit = wrappedSubmit;
|
||||
}
|
||||
textarea.form.submit = wrappedSubmit;
|
||||
}
|
||||
|
||||
textarea.style.display = "none";
|
||||
var instance = new CodeMirror(function(node) {
|
||||
textarea.parentNode.insertBefore(node, textarea.nextSibling);
|
||||
}, options);
|
||||
instance.save = save;
|
||||
instance.toTextArea = function() {
|
||||
save();
|
||||
textaarea.parentNode.removeChild(instance.div);
|
||||
textarea.style.display = "";
|
||||
if (textarea.form) {
|
||||
textarea.form.submit = realSubmit;
|
||||
rmSubmit();
|
||||
}
|
||||
};
|
||||
return instance;
|
||||
};
|
||||
|
||||
function StringStream(string) {
|
||||
this.pos = 0;
|
||||
this.string = string;
|
||||
}
|
||||
StringStream.prototype = {
|
||||
done: function() {return this.pos >= this.string.length;},
|
||||
peek: function() {return this.string.charAt(this.pos);},
|
||||
next: function() {
|
||||
if (this.pos < this.string.length)
|
||||
return this.string.charAt(this.pos++);
|
||||
},
|
||||
eat: function(match) {
|
||||
var ch = this.string.charAt(this.pos);
|
||||
if (typeof match == "string") var ok = ch == match;
|
||||
else var ok = ch && match.test ? match.test(ch) : match(ch);
|
||||
if (ok) {this.pos++; return ch;}
|
||||
},
|
||||
eatWhile: function(match) {
|
||||
var start = this.pos;
|
||||
while (this.eat(match));
|
||||
if (this.pos > start) return this.string.slice(start, this.pos);
|
||||
},
|
||||
backUp: function(n) {this.pos -= n;},
|
||||
column: function() {return this.pos;},
|
||||
eatSpace: function() {
|
||||
var start = this.pos;
|
||||
while (/\s/.test(this.string.charAt(this.pos))) this.pos++;
|
||||
return this.pos - start;
|
||||
},
|
||||
match: function(pattern, consume, caseInsensitive) {
|
||||
if (typeof pattern == "string") {
|
||||
function cased(str) {return caseInsensitive ? str.toLowerCase() : str;}
|
||||
if (cased(this.string).indexOf(cased(pattern), this.pos) == this.pos) {
|
||||
if (consume !== false) this.pos += str.length;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
var match = this.string.slice(this.pos).match(pattern);
|
||||
if (match && consume !== false) this.pos += match[0].length;
|
||||
return match;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function copyState(state) {
|
||||
if (state.copy) return state.copy();
|
||||
var nstate = {};
|
||||
for (var n in state) {
|
||||
var val = state[n];
|
||||
if (val instanceof Array) val = val.concat([]);
|
||||
nstate[n] = val;
|
||||
}
|
||||
return nstate;
|
||||
}
|
||||
|
||||
return CodeMirror;
|
||||
})();
|
||||
8
gulliver/js/codemirror/2/mode/javascript/javascript.css
Executable file
8
gulliver/js/codemirror/2/mode/javascript/javascript.css
Executable file
@@ -0,0 +1,8 @@
|
||||
span.js-punctuation {color: #666;}
|
||||
span.js-operator {color: #666;}
|
||||
span.js-keyword {color: #90b;}
|
||||
span.js-atom {color: #281;}
|
||||
span.js-variabledef {color: #00f;}
|
||||
span.js-localvariable {color: #049;}
|
||||
span.js-comment {color: #a70;}
|
||||
span.js-string {color: #a22;}
|
||||
328
gulliver/js/codemirror/2/mode/javascript/javascript.js
Executable file
328
gulliver/js/codemirror/2/mode/javascript/javascript.js
Executable file
@@ -0,0 +1,328 @@
|
||||
CodeMirror.addParser("javascript", (function() {
|
||||
// Tokenizer
|
||||
|
||||
var keywords = function(){
|
||||
function kw(type) {return {type: type, style: "js-keyword"};}
|
||||
var A = kw("keyword a"), B = kw("keyword b"), C = kw("keyword c");
|
||||
var operator = kw("operator"), atom = {type: "atom", style: "js-atom"};
|
||||
return {
|
||||
"if": A, "while": A, "with": A, "else": B, "do": B, "try": B, "finally": B,
|
||||
"return": C, "break": C, "continue": C, "new": C, "delete": C, "throw": C,
|
||||
"var": kw("var"), "function": kw("function"), "catch": kw("catch"),
|
||||
"for": kw("for"), "switch": kw("switch"), "case": kw("case"), "default": kw("default"),
|
||||
"in": operator, "typeof": operator, "instanceof": operator,
|
||||
"true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom
|
||||
};
|
||||
}();
|
||||
|
||||
var isOperatorChar = /[+\-*&%=<>!?|]/;
|
||||
|
||||
function chain(stream, state, f) {
|
||||
state.tokenize = f;
|
||||
return f(stream, state);
|
||||
}
|
||||
|
||||
function nextUntilUnescaped(stream, end) {
|
||||
var escaped = false, next;
|
||||
while ((next = stream.next()) != null) {
|
||||
if (next == end && !escaped)
|
||||
return false;
|
||||
escaped = !escaped && next == "\\";
|
||||
}
|
||||
return escaped;
|
||||
}
|
||||
|
||||
function jsTokenBase(stream, state) {
|
||||
function readOperator(ch) {
|
||||
return {type: "operator", style: "js-operator", content: ch + stream.eatWhile(isOperatorChar)};
|
||||
}
|
||||
|
||||
var ch = stream.next();
|
||||
if (ch == '"' || ch == "'")
|
||||
return chain(stream, state, jsTokenString(ch));
|
||||
else if (/[\[\]{}\(\),;\:\.]/.test(ch))
|
||||
return {type: ch, style: "js-punctuation"};
|
||||
else if (ch == "0" && stream.eat(/x/i)) {
|
||||
while (stream.eat(/[\da-f]/i));
|
||||
return {type: "number", style: "js-atom"};
|
||||
}
|
||||
else if (/\d/.test(ch)) {
|
||||
stream.match(/^\d*(?:\.\d*)?(?:e[+\-]?\d+)?/);
|
||||
return {type: "number", style: "js-atom"};
|
||||
}
|
||||
else if (ch == "/") {
|
||||
if (stream.eat("*")) {
|
||||
return chain(stream, state, jsTokenComment);
|
||||
}
|
||||
else if (stream.eat("/")) {
|
||||
while (stream.next() != null);
|
||||
return {type: "comment", style: "js-comment"};
|
||||
}
|
||||
else if (state.reAllowed) {
|
||||
nextUntilUnescaped(stream, "/");
|
||||
while (stream.eat(/[gimy]/)); // 'y' is "sticky" option in Mozilla
|
||||
return {type: "regexp", style: "js-string"};
|
||||
}
|
||||
else return readOperator(ch);
|
||||
}
|
||||
else if (isOperatorChar.test(ch))
|
||||
return readOperator(ch);
|
||||
else {
|
||||
var word = ch + stream.eatWhile(/[\w\$_]/);
|
||||
var known = keywords.propertyIsEnumerable(word) && keywords[word];
|
||||
return known ? {type: known.type, style: known.style, content: word} :
|
||||
{type: "variable", style: "js-variable", content: word};
|
||||
}
|
||||
}
|
||||
|
||||
function jsTokenString(quote) {
|
||||
return function(stream, state) {
|
||||
if (!nextUntilUnescaped(stream, quote))
|
||||
state.tokenize = jsTokenBase;
|
||||
return {type: "string", style: "js-string"};
|
||||
};
|
||||
}
|
||||
|
||||
function jsTokenComment(stream, state) {
|
||||
var maybeEnd = false, ch;
|
||||
while (ch = stream.next()) {
|
||||
if (ch == "/" && maybeEnd) {
|
||||
state.tokenize = jsTokenBase;
|
||||
break;
|
||||
}
|
||||
maybeEnd = (ch == "*");
|
||||
}
|
||||
return {type: "comment", style: "js-comment"};
|
||||
}
|
||||
|
||||
// Parser
|
||||
|
||||
var atomicTypes = {"atom": true, "number": true, "variable": true, "string": true, "regexp": true};
|
||||
|
||||
function JSLexical(indented, column, type, align, prev, info) {
|
||||
this.indented = indented;
|
||||
this.column = column;
|
||||
this.type = type;
|
||||
this.prev = prev;
|
||||
this.info = info;
|
||||
if (align != null) this.align = align;
|
||||
}
|
||||
|
||||
function indentJS(state, textAfter) {
|
||||
var firstChar = textAfter && textAfter.charAt(0), lexical = state.lexical,
|
||||
type = lexical.type, closing = firstChar == type, iu = state.indentUnit;
|
||||
if (type == "vardef") return lexical.indented + 4;
|
||||
else if (type == "form" && firstChar == "{") return lexical.indented;
|
||||
else if (type == "stat" || type == "form") return lexical.indented + iu;
|
||||
else if (lexical.info == "switch" && !closing)
|
||||
return lexical.indented + (/^(?:case|default)\b/.test(textAfter) ? iu : 2 * iu);
|
||||
else if (lexical.align) return lexical.column - (closing ? 1 : 0);
|
||||
else return lexical.indented + (closing ? 0 : iu);
|
||||
}
|
||||
|
||||
function startState(basecolumn, indentUnit) {
|
||||
if (!indentUnit) indentUnit = 2;
|
||||
return {
|
||||
tokenize: jsTokenBase,
|
||||
reAllowed: true,
|
||||
cc: [],
|
||||
lexical: new JSLexical((basecolumn || 0) - indentUnit, 0, "block", false),
|
||||
context: null,
|
||||
indented: 0,
|
||||
indentUnit: indentUnit
|
||||
};
|
||||
}
|
||||
|
||||
function parseJS(token, column, indent, state) {
|
||||
var cc = state.cc, type = token.type;
|
||||
|
||||
function pass() {
|
||||
for (var i = arguments.length - 1; i >= 0; i--) cc.push(arguments[i]);
|
||||
}
|
||||
var cx = {
|
||||
state: state,
|
||||
column: column,
|
||||
pass: pass,
|
||||
cont: function(){pass.apply(null, arguments); return true;},
|
||||
register: function(varname) {
|
||||
if (state.context) {
|
||||
cx.marked = "js-variabledef";
|
||||
state.context.vars[varname] = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
function inScope(varname) {
|
||||
var cursor = state.context;
|
||||
while (cursor) {
|
||||
if (cursor.vars[varname])
|
||||
return true;
|
||||
cursor = cursor.prev;
|
||||
}
|
||||
}
|
||||
|
||||
if (indent != null) {
|
||||
if (!state.lexical.hasOwnProperty("align"))
|
||||
state.lexical.align = false;
|
||||
state.indented = indent;
|
||||
}
|
||||
|
||||
if (type == "whitespace" || type == "comment")
|
||||
return token.style;
|
||||
if (!state.lexical.hasOwnProperty("align"))
|
||||
state.lexical.align = true;
|
||||
|
||||
while(true) {
|
||||
var combinator = cc.length ? cc.pop() : state.json ? expression : statement;
|
||||
if (combinator(cx, type, token.content)) {
|
||||
while(cc.length && cc[cc.length - 1].lex)
|
||||
cc.pop()(cx);
|
||||
if (cx.marked) return cx.marked;
|
||||
if (type == "variable" && inScope(token.content)) return "js-localvariable";
|
||||
return token.style;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Combinators
|
||||
|
||||
function pushcontext(cx) {
|
||||
cx.state.context = {prev: cx.state.context, vars: {"this": true, "arguments": true}};
|
||||
}
|
||||
function popcontext(cx) {
|
||||
cx.state.context = cx.state.context.prev;
|
||||
}
|
||||
function pushlex(type, info) {
|
||||
var result = function(cx) {
|
||||
var state = cx.state;
|
||||
state.lexical = new JSLexical(state.indented, cx.column, type, null, state.lexical, info)
|
||||
};
|
||||
result.lex = true;
|
||||
return result;
|
||||
}
|
||||
function poplex(cx) {
|
||||
var state = cx.state;
|
||||
if (state.lexical.type == ")")
|
||||
state.indented = state.lexical.indented;
|
||||
state.lexical = state.lexical.prev;
|
||||
}
|
||||
poplex.lex = true;
|
||||
|
||||
function expect(wanted) {
|
||||
return function expecting(cx, type) {
|
||||
if (type == wanted) return cx.cont();
|
||||
else if (wanted == ";") return;
|
||||
else return cx.cont(arguments.callee);
|
||||
};
|
||||
}
|
||||
|
||||
function statement(cx, type) {
|
||||
if (type == "var") return cx.cont(pushlex("vardef"), vardef1, expect(";"), poplex);
|
||||
if (type == "keyword a") return cx.cont(pushlex("form"), expression, statement, poplex);
|
||||
if (type == "keyword b") return cx.cont(pushlex("form"), statement, poplex);
|
||||
if (type == "{") return cx.cont(pushlex("}"), block, poplex);
|
||||
if (type == ";") return cx.cont();
|
||||
if (type == "function") return cx.cont(functiondef);
|
||||
if (type == "for") return cx.cont(pushlex("form"), expect("("), pushlex(")"), forspec1, expect(")"),
|
||||
poplex, statement, poplex);
|
||||
if (type == "variable") return cx.cont(pushlex("stat"), maybelabel);
|
||||
if (type == "switch") return cx.cont(pushlex("form"), expression, pushlex("}", "switch"), expect("{"),
|
||||
block, poplex, poplex);
|
||||
if (type == "case") return cx.cont(expression, expect(":"));
|
||||
if (type == "default") return cx.cont(expect(":"));
|
||||
if (type == "catch") return cx.cont(pushlex("form"), pushcontext, expect("("), funarg, expect(")"),
|
||||
statement, poplex, popcontext);
|
||||
return cx.pass(pushlex("stat"), expression, expect(";"), poplex);
|
||||
}
|
||||
function expression(cx, type) {
|
||||
if (atomicTypes.hasOwnProperty(type)) return cx.cont(maybeoperator);
|
||||
if (type == "function") return cx.cont(functiondef);
|
||||
if (type == "keyword c") return cx.cont(expression);
|
||||
if (type == "(") return cx.cont(pushlex(")"), expression, expect(")"), poplex, maybeoperator);
|
||||
if (type == "operator") return cx.cont(expression);
|
||||
if (type == "[") return cx.cont(pushlex("]"), commasep(expression, "]"), poplex, maybeoperator);
|
||||
if (type == "{") return cx.cont(pushlex("}"), commasep(objprop, "}"), poplex, maybeoperator);
|
||||
return cx.cont();
|
||||
}
|
||||
function maybeoperator(cx, type, value) {
|
||||
if (type == "operator" && /\+\+|--/.test(value)) return cx.cont(maybeoperator);
|
||||
if (type == "operator") return cx.cont(expression);
|
||||
if (type == ";") return;
|
||||
if (type == "(") return cx.cont(pushlex(")"), commasep(expression, ")"), poplex, maybeoperator);
|
||||
if (type == ".") return cx.cont(property, maybeoperator);
|
||||
if (type == "[") return cx.cont(pushlex("]"), expression, expect("]"), poplex, maybeoperator);
|
||||
}
|
||||
function maybelabel(cx, type) {
|
||||
if (type == ":") return cx.cont(poplex, statement);
|
||||
return cx.pass(maybeoperator, expect(";"), poplex);
|
||||
}
|
||||
function property(cx, type) {
|
||||
if (type == "variable") {cx.marked = "js-property"; return cx.cont();}
|
||||
}
|
||||
function objprop(cx, type) {
|
||||
if (type == "variable") cx.marked = "js-property";
|
||||
if (atomicTypes.hasOwnProperty(type)) return cx.cont(expect(":"), expression);
|
||||
}
|
||||
function commasep(what, end) {
|
||||
function proceed(cx, type) {
|
||||
if (type == ",") return cx.cont(what, proceed);
|
||||
if (type == end) return cx.cont();
|
||||
return cx.cont(expect(end));
|
||||
}
|
||||
return function commaSeparated(cx, type) {
|
||||
if (type == end) return cx.cont();
|
||||
else return cx.pass(what, proceed);
|
||||
};
|
||||
}
|
||||
function block(cx, type) {
|
||||
if (type == "}") return cx.cont();
|
||||
return cx.pass(statement, block);
|
||||
}
|
||||
function vardef1(cx, type, value) {
|
||||
if (type == "variable"){cx.register(value); return cx.cont(vardef2);}
|
||||
return cx.cont();
|
||||
}
|
||||
function vardef2(cx, type, value) {
|
||||
if (value == "=") return cx.cont(expression, vardef2);
|
||||
if (type == ",") return cx.cont(vardef1);
|
||||
}
|
||||
function forspec1(cx, type) {
|
||||
if (type == "var") return cx.cont(vardef1, forspec2);
|
||||
if (type == ";") return cx.pass(forspec2);
|
||||
if (type == "variable") return cx.cont(formaybein);
|
||||
return cx.pass(forspec2);
|
||||
}
|
||||
function formaybein(cx, type, value) {
|
||||
if (value == "in") return cx.cont(expression);
|
||||
return cx.cont(maybeoperator, forspec2);
|
||||
}
|
||||
function forspec2(cx, type, value) {
|
||||
if (type == ";") return cx.cont(forspec3);
|
||||
if (value == "in") return cx.cont(expression);
|
||||
return cx.cont(expression, expect(";"), forspec3);
|
||||
}
|
||||
function forspec3(cx, type) {
|
||||
if (type != ")") cx.cont(expression);
|
||||
}
|
||||
function functiondef(cx, type, value) {
|
||||
if (type == "variable") {cx.register(value); return cx.cont(functiondef);}
|
||||
if (type == "(") return cx.cont(pushcontext, commasep(funarg, ")"), statement, popcontext);
|
||||
}
|
||||
function funarg(cx, type, value) {
|
||||
if (type == "variable") {cx.register(value); return cx.cont();}
|
||||
}
|
||||
|
||||
// Interface
|
||||
|
||||
return {
|
||||
startState: startState,
|
||||
token: function(stream, state) {
|
||||
if (stream.column() == 0)
|
||||
var indent = stream.eatSpace();
|
||||
var token = state.tokenize(stream, state);
|
||||
state.reAllowed = token.type == "operator" || token.type == "keyword c" || token.type.match(/^[\[{}\(,;:]$/);
|
||||
stream.eatSpace();
|
||||
return parseJS(token, stream.column(), indent, state);
|
||||
},
|
||||
indent: indentJS
|
||||
};
|
||||
})());
|
||||
23
gulliver/js/codemirror/LICENSE
Executable file
23
gulliver/js/codemirror/LICENSE
Executable file
@@ -0,0 +1,23 @@
|
||||
Copyright (c) 2007-2010 Marijn Haverbeke
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any
|
||||
damages arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any
|
||||
purpose, including commercial applications, and to alter it and
|
||||
redistribute it freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must
|
||||
not claim that you wrote the original software. If you use this
|
||||
software in a product, an acknowledgment in the product
|
||||
documentation would be appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must
|
||||
not be misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source
|
||||
distribution.
|
||||
|
||||
Marijn Haverbeke
|
||||
marijnh@gmail.com
|
||||
60
gulliver/js/codemirror/contrib/csharp/css/csharpcolors.css
Executable file
60
gulliver/js/codemirror/contrib/csharp/css/csharpcolors.css
Executable file
@@ -0,0 +1,60 @@
|
||||
html {
|
||||
cursor: text;
|
||||
}
|
||||
|
||||
.editbox {
|
||||
margin: .4em;
|
||||
padding: 0;
|
||||
font-family: monospace;
|
||||
font-size: 10pt;
|
||||
color: black;
|
||||
}
|
||||
|
||||
pre.code, .editbox {
|
||||
color: #666666;
|
||||
}
|
||||
|
||||
.editbox p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
span.csharp-punctuation {
|
||||
color: green;
|
||||
}
|
||||
|
||||
span.csharp-operator {
|
||||
color: purple;
|
||||
}
|
||||
|
||||
span.csharp-keyword {
|
||||
color: blue;
|
||||
}
|
||||
|
||||
span.csharp-atom {
|
||||
color: brown;
|
||||
}
|
||||
|
||||
span.csharp-variable {
|
||||
color: black;
|
||||
}
|
||||
|
||||
span.csharp-variabledef {
|
||||
color: #0000FF;
|
||||
}
|
||||
|
||||
span.csharp-localvariable {
|
||||
color: #004499;
|
||||
}
|
||||
|
||||
span.csharp-property {
|
||||
color: black;
|
||||
}
|
||||
|
||||
span.csharp-comment {
|
||||
color: green;
|
||||
}
|
||||
|
||||
span.csharp-string {
|
||||
color: red;
|
||||
}
|
||||
|
||||
61
gulliver/js/codemirror/contrib/csharp/index.html
Executable file
61
gulliver/js/codemirror/contrib/csharp/index.html
Executable file
@@ -0,0 +1,61 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<script src="../../js/codemirror.js" type="text/javascript"></script>
|
||||
<title>CodeMirror: C# demonstration</title>
|
||||
<link rel="stylesheet" type="text/css" href="../../css/docs.css"/>
|
||||
</head>
|
||||
<body style="padding: 20px;">
|
||||
|
||||
<p>Demonstration of <a href="../../index.html">CodeMirror</a>'s C# highlighter.</p>
|
||||
|
||||
<p>Written by <a href="http://skilltesting.com/">Boris Gaber and Christopher Buchino</a> (<a
|
||||
href="http://skilltesting.com/codemirror-parser-license/">license</a>).</p>
|
||||
|
||||
<div style="border-top: 1px solid black; border-bottom: 1px solid black;">
|
||||
<textarea id="code" cols="120" rows="50">
|
||||
using System;
|
||||
|
||||
namespace Example
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a person employed at the company
|
||||
/// </summary>
|
||||
public class Employee : Person
|
||||
{
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the first name.
|
||||
/// </summary>
|
||||
/// <value>The first name.</value>
|
||||
public string FirstName { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the salary.
|
||||
/// </summary>
|
||||
/// <param name="grade">The grade.</param>
|
||||
/// <returns></returns>
|
||||
public decimal CalculateSalary(int grade)
|
||||
{
|
||||
if (grade > 10)
|
||||
return 1000;
|
||||
return 500;
|
||||
}
|
||||
}
|
||||
}
|
||||
</textarea>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
var editor = CodeMirror.fromTextArea('code', {
|
||||
parserfile: ["../contrib/csharp/js/tokenizecsharp.js", "../contrib/csharp/js/parsecsharp.js"],
|
||||
stylesheet: "css/csharpcolors.css",
|
||||
path: "../../js/",
|
||||
height: "500px"
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
329
gulliver/js/codemirror/contrib/csharp/js/parsecsharp.js
Executable file
329
gulliver/js/codemirror/contrib/csharp/js/parsecsharp.js
Executable file
@@ -0,0 +1,329 @@
|
||||
/* Parse function for JavaScript. Makes use of the tokenizer from
|
||||
* tokenizecsharp.js. Note that your parsers do not have to be
|
||||
* this complicated -- if you don't want to recognize local variables,
|
||||
* in many languages it is enough to just look for braces, semicolons,
|
||||
* parentheses, etc, and know when you are inside a string or comment.
|
||||
*
|
||||
* See manual.html for more info about the parser interface.
|
||||
*/
|
||||
|
||||
var JSParser = Editor.Parser = (function() {
|
||||
// Token types that can be considered to be atoms.
|
||||
var atomicTypes = {"atom": true, "number": true, "variable": true, "string": true, "regexp": true};
|
||||
// Setting that can be used to have JSON data indent properly.
|
||||
var json = false;
|
||||
// Constructor for the lexical context objects.
|
||||
function CSharpLexical(indented, column, type, align, prev, info) {
|
||||
// indentation at start of this line
|
||||
this.indented = indented;
|
||||
// column at which this scope was opened
|
||||
this.column = column;
|
||||
// type of scope ('vardef', 'stat' (statement), 'form' (special form), '[', '{', or '(')
|
||||
this.type = type;
|
||||
// '[', '{', or '(' blocks that have any text after their opening
|
||||
// character are said to be 'aligned' -- any lines below are
|
||||
// indented all the way to the opening character.
|
||||
if (align != null)
|
||||
this.align = align;
|
||||
// Parent scope, if any.
|
||||
this.prev = prev;
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
// CSharp indentation rules.
|
||||
function indentCSharp(lexical) {
|
||||
return function(firstChars) {
|
||||
var firstChar = firstChars && firstChars.charAt(0), type = lexical.type;
|
||||
var closing = firstChar == type;
|
||||
if (type == "vardef")
|
||||
return lexical.indented + 4;
|
||||
else if (type == "form" && firstChar == "{")
|
||||
return lexical.indented;
|
||||
else if (type == "stat" || type == "form")
|
||||
return lexical.indented + indentUnit;
|
||||
else if (lexical.info == "switch" && !closing)
|
||||
return lexical.indented + (/^(?:case|default)\b/.test(firstChars) ? indentUnit : 2 * indentUnit);
|
||||
else if (lexical.align)
|
||||
return lexical.column - (closing ? 1 : 0);
|
||||
else
|
||||
return lexical.indented + (closing ? 0 : indentUnit);
|
||||
};
|
||||
}
|
||||
|
||||
// The parser-iterator-producing function itself.
|
||||
function parseCSharp(input, basecolumn) {
|
||||
// Wrap the input in a token stream
|
||||
var tokens = tokenizeCSharp(input);
|
||||
// The parser state. cc is a stack of actions that have to be
|
||||
// performed to finish the current statement. For example we might
|
||||
// know that we still need to find a closing parenthesis and a
|
||||
// semicolon. Actions at the end of the stack go first. It is
|
||||
// initialized with an infinitely looping action that consumes
|
||||
// whole statements.
|
||||
var cc = [statements];
|
||||
// The lexical scope, used mostly for indentation.
|
||||
var lexical = new CSharpLexical((basecolumn || 0) - indentUnit, 0, "block", false);
|
||||
// Current column, and the indentation at the start of the current
|
||||
// line. Used to create lexical scope objects.
|
||||
var column = 0;
|
||||
var indented = 0;
|
||||
// Variables which are used by the mark, cont, and pass functions
|
||||
// below to communicate with the driver loop in the 'next'
|
||||
// function.
|
||||
var consume, marked;
|
||||
|
||||
// The iterator object.
|
||||
var parser = {next: next, copy: copy};
|
||||
|
||||
function next(){
|
||||
// Start by performing any 'lexical' actions (adjusting the
|
||||
// lexical variable), or the operations below will be working
|
||||
// with the wrong lexical state.
|
||||
while(cc[cc.length - 1].lex)
|
||||
cc.pop()();
|
||||
|
||||
// Fetch a token.
|
||||
var token = tokens.next();
|
||||
|
||||
// Adjust column and indented.
|
||||
if (token.type == "whitespace" && column == 0)
|
||||
indented = token.value.length;
|
||||
column += token.value.length;
|
||||
if (token.content == "\n"){
|
||||
indented = column = 0;
|
||||
// If the lexical scope's align property is still undefined at
|
||||
// the end of the line, it is an un-aligned scope.
|
||||
if (!("align" in lexical))
|
||||
lexical.align = false;
|
||||
// Newline tokens get an indentation function associated with
|
||||
// them.
|
||||
token.indentation = indentCSharp(lexical);
|
||||
}
|
||||
// No more processing for meaningless tokens.
|
||||
if (token.type == "whitespace" || token.type == "comment")
|
||||
return token;
|
||||
// When a meaningful token is found and the lexical scope's
|
||||
// align is undefined, it is an aligned scope.
|
||||
if (!("align" in lexical))
|
||||
lexical.align = true;
|
||||
|
||||
// Execute actions until one 'consumes' the token and we can
|
||||
// return it.
|
||||
while(true) {
|
||||
consume = marked = false;
|
||||
// Take and execute the topmost action.
|
||||
cc.pop()(token.type, token.content);
|
||||
if (consume){
|
||||
// Marked is used to change the style of the current token.
|
||||
if (marked)
|
||||
token.style = marked;
|
||||
return token;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This makes a copy of the parser state. It stores all the
|
||||
// stateful variables in a closure, and returns a function that
|
||||
// will restore them when called with a new input stream. Note
|
||||
// that the cc array has to be copied, because it is contantly
|
||||
// being modified. Lexical objects are not mutated, and context
|
||||
// objects are not mutated in a harmful way, so they can be shared
|
||||
// between runs of the parser.
|
||||
function copy(){
|
||||
var _lexical = lexical, _cc = cc.concat([]), _tokenState = tokens.state;
|
||||
|
||||
return function copyParser(input){
|
||||
lexical = _lexical;
|
||||
cc = _cc.concat([]); // copies the array
|
||||
column = indented = 0;
|
||||
tokens = tokenizeCSharp(input, _tokenState);
|
||||
return parser;
|
||||
};
|
||||
}
|
||||
|
||||
// Helper function for pushing a number of actions onto the cc
|
||||
// stack in reverse order.
|
||||
function push(fs){
|
||||
for (var i = fs.length - 1; i >= 0; i--)
|
||||
cc.push(fs[i]);
|
||||
}
|
||||
// cont and pass are used by the action functions to add other
|
||||
// actions to the stack. cont will cause the current token to be
|
||||
// consumed, pass will leave it for the next action.
|
||||
function cont(){
|
||||
push(arguments);
|
||||
consume = true;
|
||||
}
|
||||
function pass(){
|
||||
push(arguments);
|
||||
consume = false;
|
||||
}
|
||||
// Used to change the style of the current token.
|
||||
function mark(style){
|
||||
marked = style;
|
||||
}
|
||||
|
||||
// Push a new lexical context of the given type.
|
||||
function pushlex(type, info) {
|
||||
var result = function(){
|
||||
lexical = new CSharpLexical(indented, column, type, null, lexical, info)
|
||||
};
|
||||
result.lex = true;
|
||||
return result;
|
||||
}
|
||||
// Pop off the current lexical context.
|
||||
function poplex(){
|
||||
lexical = lexical.prev;
|
||||
}
|
||||
poplex.lex = true;
|
||||
// The 'lex' flag on these actions is used by the 'next' function
|
||||
// to know they can (and have to) be ran before moving on to the
|
||||
// next token.
|
||||
|
||||
// Creates an action that discards tokens until it finds one of
|
||||
// the given type.
|
||||
function expect(wanted){
|
||||
return function expecting(type){
|
||||
if (type == wanted) cont();
|
||||
else cont(arguments.callee);
|
||||
};
|
||||
}
|
||||
|
||||
// Looks for a statement, and then calls itself.
|
||||
function statements(type){
|
||||
return pass(statement, statements);
|
||||
}
|
||||
// Dispatches various types of statements based on the type of the
|
||||
// current token.
|
||||
function statement(type){
|
||||
if (type == "var") cont(pushlex("vardef"), vardef1, expect(";"), poplex);
|
||||
else if (type == "keyword a") cont(pushlex("form"), expression, statement, poplex);
|
||||
else if (type == "keyword b") cont(pushlex("form"), statement, poplex);
|
||||
else if (type == "{" && json) cont(pushlex("}"), commasep(objprop, "}"), poplex);
|
||||
else if (type == "{") cont(pushlex("}"), block, poplex);
|
||||
else if (type == "function") cont(functiondef);
|
||||
else if (type == "for") cont(pushlex("form"), expect("("), pushlex(")"), forspec1, expect(")"), poplex, statement, poplex);
|
||||
else if (type == "variable") cont(pushlex("stat"), maybelabel);
|
||||
else if (type == "switch") cont(pushlex("form"), expression, pushlex("}", "switch"), expect("{"), block, poplex, poplex);
|
||||
else if (type == "case") cont(expression, expect(":"));
|
||||
else if (type == "default") cont(expect(":"));
|
||||
else if (type == "catch") cont(pushlex("form"), expect("("), funarg, expect(")"), statement, poplex);
|
||||
|
||||
else if (type == "class") cont(classdef);
|
||||
else if (type == "keyword d") cont(statement);
|
||||
|
||||
else pass(pushlex("stat"), expression, expect(";"), poplex);
|
||||
}
|
||||
// Dispatch expression types.
|
||||
function expression(type){
|
||||
if (atomicTypes.hasOwnProperty(type)) cont(maybeoperator);
|
||||
else if (type == "function") cont(functiondef);
|
||||
else if (type == "keyword c") cont(expression);
|
||||
else if (type == "(") cont(pushlex(")"), expression, expect(")"), poplex, maybeoperator);
|
||||
else if (type == "operator") cont(expression);
|
||||
else if (type == "[") cont(pushlex("]"), commasep(expression, "]"), poplex, maybeoperator);
|
||||
else if (type == "{") cont(pushlex("}"), commasep(objprop, "}"), poplex, maybeoperator);
|
||||
}
|
||||
// Called for places where operators, function calls, or
|
||||
// subscripts are valid. Will skip on to the next action if none
|
||||
// is found.
|
||||
function maybeoperator(type){
|
||||
if (type == "operator") cont(expression);
|
||||
else if (type == "(") cont(pushlex(")"), expression, commasep(expression, ")"), poplex, maybeoperator);
|
||||
else if (type == ".") cont(property, maybeoperator);
|
||||
else if (type == "[") cont(pushlex("]"), expression, expect("]"), poplex, maybeoperator);
|
||||
}
|
||||
// When a statement starts with a variable name, it might be a
|
||||
// label. If no colon follows, it's a regular statement.
|
||||
function maybelabel(type){
|
||||
if (type == ":") cont(poplex, statement);
|
||||
else if (type == "(") cont(commasep(funarg, ")"), poplex, statement); // method definition
|
||||
else if (type == "{") cont(poplex, pushlex("}"), block, poplex); // property definition
|
||||
else pass(maybeoperator, expect(";"), poplex);
|
||||
}
|
||||
// Property names need to have their style adjusted -- the
|
||||
// tokenizer thinks they are variables.
|
||||
function property(type){
|
||||
if (type == "variable") {mark("csharp-property"); cont();}
|
||||
}
|
||||
// This parses a property and its value in an object literal.
|
||||
function objprop(type){
|
||||
if (type == "variable") mark("csharp-property");
|
||||
if (atomicTypes.hasOwnProperty(type)) cont(expect(":"), expression);
|
||||
}
|
||||
// Parses a comma-separated list of the things that are recognized
|
||||
// by the 'what' argument.
|
||||
function commasep(what, end){
|
||||
function proceed(type) {
|
||||
if (type == ",") cont(what, proceed);
|
||||
else if (type == end) cont();
|
||||
else cont(expect(end));
|
||||
};
|
||||
return function commaSeparated(type) {
|
||||
if (type == end) cont();
|
||||
else pass(what, proceed);
|
||||
};
|
||||
}
|
||||
// Look for statements until a closing brace is found.
|
||||
function block(type){
|
||||
if (type == "}") cont();
|
||||
else pass(statement, block);
|
||||
}
|
||||
// Variable definitions are split into two actions -- 1 looks for
|
||||
// a name or the end of the definition, 2 looks for an '=' sign or
|
||||
// a comma.
|
||||
function vardef1(type, value){
|
||||
if (type == "variable"){cont(vardef2);}
|
||||
else cont();
|
||||
}
|
||||
function vardef2(type, value){
|
||||
if (value == "=") cont(expression, vardef2);
|
||||
else if (type == ",") cont(vardef1);
|
||||
}
|
||||
// For loops.
|
||||
function forspec1(type){
|
||||
if (type == "var") cont(vardef1, forspec2);
|
||||
else if (type == "keyword d") cont(vardef1, forspec2);
|
||||
else if (type == ";") pass(forspec2);
|
||||
else if (type == "variable") cont(formaybein);
|
||||
else pass(forspec2);
|
||||
}
|
||||
function formaybein(type, value){
|
||||
if (value == "in") cont(expression);
|
||||
else cont(maybeoperator, forspec2);
|
||||
}
|
||||
function forspec2(type, value){
|
||||
if (type == ";") cont(forspec3);
|
||||
else if (value == "in") cont(expression);
|
||||
else cont(expression, expect(";"), forspec3);
|
||||
}
|
||||
function forspec3(type) {
|
||||
if (type == ")") pass();
|
||||
else cont(expression);
|
||||
}
|
||||
// A function definition creates a new context, and the variables
|
||||
// in its argument list have to be added to this context.
|
||||
function functiondef(type, value){
|
||||
if (type == "variable") cont(functiondef);
|
||||
else if (type == "(") cont(commasep(funarg, ")"), statement);
|
||||
}
|
||||
function funarg(type, value){
|
||||
if (type == "variable"){cont();}
|
||||
}
|
||||
|
||||
function classdef(type) {
|
||||
if (type == "variable") cont(classdef, statement);
|
||||
else if (type == ":") cont(classdef, statement);
|
||||
}
|
||||
|
||||
return parser;
|
||||
}
|
||||
|
||||
return {
|
||||
make: parseCSharp,
|
||||
electricChars: "{}:",
|
||||
configure: function(obj) {
|
||||
if (obj.json != null) json = obj.json;
|
||||
}
|
||||
};
|
||||
})();
|
||||
196
gulliver/js/codemirror/contrib/csharp/js/tokenizecsharp.js
Executable file
196
gulliver/js/codemirror/contrib/csharp/js/tokenizecsharp.js
Executable file
@@ -0,0 +1,196 @@
|
||||
/* Tokenizer for CSharp code */
|
||||
|
||||
var tokenizeCSharp = (function() {
|
||||
// Advance the stream until the given character (not preceded by a
|
||||
// backslash) is encountered, or the end of the line is reached.
|
||||
function nextUntilUnescaped(source, end) {
|
||||
var escaped = false;
|
||||
var next;
|
||||
while (!source.endOfLine()) {
|
||||
var next = source.next();
|
||||
if (next == end && !escaped)
|
||||
return false;
|
||||
escaped = !escaped && next == "\\";
|
||||
}
|
||||
return escaped;
|
||||
}
|
||||
|
||||
// A map of JavaScript's keywords. The a/b/c keyword distinction is
|
||||
// very rough, but it gives the parser enough information to parse
|
||||
// correct code correctly (we don't care that much how we parse
|
||||
// incorrect code). The style information included in these objects
|
||||
// is used by the highlighter to pick the correct CSS style for a
|
||||
// token.
|
||||
var keywords = function(){
|
||||
function result(type, style){
|
||||
return {type: type, style: "csharp-" + style};
|
||||
}
|
||||
// keywords that take a parenthised expression, and then a
|
||||
// statement (if)
|
||||
var keywordA = result("keyword a", "keyword");
|
||||
// keywords that take just a statement (else)
|
||||
var keywordB = result("keyword b", "keyword");
|
||||
// keywords that optionally take an expression, and form a
|
||||
// statement (return)
|
||||
var keywordC = result("keyword c", "keyword");
|
||||
var operator = result("operator", "keyword");
|
||||
var atom = result("atom", "atom");
|
||||
// just a keyword with no indentation implications
|
||||
var keywordD = result("keyword d", "keyword");
|
||||
|
||||
return {
|
||||
"if": keywordA, "while": keywordA, "with": keywordA,
|
||||
"else": keywordB, "do": keywordB, "try": keywordB, "finally": keywordB,
|
||||
"return": keywordC, "break": keywordC, "continue": keywordC, "new": keywordC, "delete": keywordC, "throw": keywordC,
|
||||
"in": operator, "typeof": operator, "instanceof": operator,
|
||||
"var": result("var", "keyword"), "function": result("function", "keyword"), "catch": result("catch", "keyword"),
|
||||
"for": result("for", "keyword"), "switch": result("switch", "keyword"),
|
||||
"case": result("case", "keyword"), "default": result("default", "keyword"),
|
||||
"true": atom, "false": atom, "null": atom,
|
||||
|
||||
"class": result("class", "keyword"), "namespace": result("class", "keyword"),
|
||||
|
||||
"public": keywordD, "private": keywordD, "protected": keywordD, "internal": keywordD,
|
||||
"extern": keywordD, "override": keywordD, "virtual": keywordD, "abstract": keywordD,
|
||||
"static": keywordD, "out": keywordD, "ref": keywordD, "const": keywordD,
|
||||
|
||||
"foreach": result("for", "keyword"), "using": keywordC,
|
||||
|
||||
"int": keywordD, "double": keywordD, "long": keywordD, "bool": keywordD, "char": keywordD,
|
||||
"void": keywordD, "string": keywordD, "byte": keywordD, "sbyte": keywordD, "decimal": keywordD,
|
||||
"float": keywordD, "uint": keywordD, "ulong": keywordD, "object": keywordD,
|
||||
"short": keywordD, "ushort": keywordD,
|
||||
|
||||
"get": keywordD, "set": keywordD, "value": keywordD
|
||||
};
|
||||
}();
|
||||
|
||||
// Some helper regexps
|
||||
var isOperatorChar = /[+\-*&%=<>!?|]/;
|
||||
var isHexDigit = /[0-9A-Fa-f]/;
|
||||
var isWordChar = /[\w\$_]/;
|
||||
|
||||
// Wrapper around jsToken that helps maintain parser state (whether
|
||||
// we are inside of a multi-line comment and whether the next token
|
||||
// could be a regular expression).
|
||||
function jsTokenState(inside, regexp) {
|
||||
return function(source, setState) {
|
||||
var newInside = inside;
|
||||
var type = jsToken(inside, regexp, source, function(c) {newInside = c;});
|
||||
var newRegexp = type.type == "operator" || type.type == "keyword c" || type.type.match(/^[\[{}\(,;:]$/);
|
||||
if (newRegexp != regexp || newInside != inside)
|
||||
setState(jsTokenState(newInside, newRegexp));
|
||||
return type;
|
||||
};
|
||||
}
|
||||
|
||||
// The token reader, inteded to be used by the tokenizer from
|
||||
// tokenize.js (through jsTokenState). Advances the source stream
|
||||
// over a token, and returns an object containing the type and style
|
||||
// of that token.
|
||||
function jsToken(inside, regexp, source, setInside) {
|
||||
function readHexNumber(){
|
||||
source.next(); // skip the 'x'
|
||||
source.nextWhileMatches(isHexDigit);
|
||||
return {type: "number", style: "csharp-atom"};
|
||||
}
|
||||
|
||||
function readNumber() {
|
||||
source.nextWhileMatches(/[0-9]/);
|
||||
if (source.equals(".")){
|
||||
source.next();
|
||||
source.nextWhileMatches(/[0-9]/);
|
||||
}
|
||||
if (source.equals("e") || source.equals("E")){
|
||||
source.next();
|
||||
if (source.equals("-"))
|
||||
source.next();
|
||||
source.nextWhileMatches(/[0-9]/);
|
||||
}
|
||||
return {type: "number", style: "csharp-atom"};
|
||||
}
|
||||
// Read a word, look it up in keywords. If not found, it is a
|
||||
// variable, otherwise it is a keyword of the type found.
|
||||
function readWord() {
|
||||
source.nextWhileMatches(isWordChar);
|
||||
var word = source.get();
|
||||
var known = keywords.hasOwnProperty(word) && keywords.propertyIsEnumerable(word) && keywords[word];
|
||||
return known ? {type: known.type, style: known.style, content: word} :
|
||||
{type: "variable", style: "csharp-variable", content: word};
|
||||
}
|
||||
function readRegexp() {
|
||||
nextUntilUnescaped(source, "/");
|
||||
source.nextWhileMatches(/[gi]/);
|
||||
return {type: "regexp", style: "csharp-string"};
|
||||
}
|
||||
// Mutli-line comments are tricky. We want to return the newlines
|
||||
// embedded in them as regular newline tokens, and then continue
|
||||
// returning a comment token for every line of the comment. So
|
||||
// some state has to be saved (inside) to indicate whether we are
|
||||
// inside a /* */ sequence.
|
||||
function readMultilineComment(start){
|
||||
var newInside = "/*";
|
||||
var maybeEnd = (start == "*");
|
||||
while (true) {
|
||||
if (source.endOfLine())
|
||||
break;
|
||||
var next = source.next();
|
||||
if (next == "/" && maybeEnd){
|
||||
newInside = null;
|
||||
break;
|
||||
}
|
||||
maybeEnd = (next == "*");
|
||||
}
|
||||
setInside(newInside);
|
||||
return {type: "comment", style: "csharp-comment"};
|
||||
}
|
||||
function readOperator() {
|
||||
source.nextWhileMatches(isOperatorChar);
|
||||
return {type: "operator", style: "csharp-operator"};
|
||||
}
|
||||
function readString(quote) {
|
||||
var endBackSlash = nextUntilUnescaped(source, quote);
|
||||
setInside(endBackSlash ? quote : null);
|
||||
return {type: "string", style: "csharp-string"};
|
||||
}
|
||||
|
||||
// Fetch the next token. Dispatches on first character in the
|
||||
// stream, or first two characters when the first is a slash.
|
||||
if (inside == "\"" || inside == "'")
|
||||
return readString(inside);
|
||||
var ch = source.next();
|
||||
if (inside == "/*")
|
||||
return readMultilineComment(ch);
|
||||
else if (ch == "\"" || ch == "'")
|
||||
return readString(ch);
|
||||
// with punctuation, the type of the token is the symbol itself
|
||||
else if (/[\[\]{}\(\),;\:\.]/.test(ch))
|
||||
return {type: ch, style: "csharp-punctuation"};
|
||||
else if (ch == "0" && (source.equals("x") || source.equals("X")))
|
||||
return readHexNumber();
|
||||
else if (/[0-9]/.test(ch))
|
||||
return readNumber();
|
||||
else if (ch == "/"){
|
||||
if (source.equals("*"))
|
||||
{ source.next(); return readMultilineComment(ch); }
|
||||
else if (source.equals("/"))
|
||||
{ nextUntilUnescaped(source, null); return {type: "comment", style: "csharp-comment"};}
|
||||
else if (regexp)
|
||||
return readRegexp();
|
||||
else
|
||||
return readOperator();
|
||||
}
|
||||
else if (ch == "#") { // treat c# regions like comments
|
||||
nextUntilUnescaped(source, null); return {type: "comment", style: "csharp-comment"};
|
||||
}
|
||||
else if (isOperatorChar.test(ch))
|
||||
return readOperator();
|
||||
else
|
||||
return readWord();
|
||||
}
|
||||
|
||||
// The external interface to the tokenizer.
|
||||
return function(source, startState) {
|
||||
return tokenizer(source, startState || jsTokenState(false, true));
|
||||
};
|
||||
})();
|
||||
24
gulliver/js/codemirror/contrib/freemarker/LICENSE
Executable file
24
gulliver/js/codemirror/contrib/freemarker/LICENSE
Executable file
@@ -0,0 +1,24 @@
|
||||
Copyright (c) 2010, Keybroker AB
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of Keybroker AB nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL Keybroker AB BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
63
gulliver/js/codemirror/contrib/freemarker/css/freemarkercolors.css
Executable file
63
gulliver/js/codemirror/contrib/freemarker/css/freemarkercolors.css
Executable file
@@ -0,0 +1,63 @@
|
||||
html {
|
||||
cursor: text;
|
||||
}
|
||||
|
||||
.editbox {
|
||||
margin: .4em;
|
||||
padding: 0;
|
||||
font-family: monospace;
|
||||
font-size: 12px;
|
||||
font-size-adjust: none;
|
||||
font-style: normal;
|
||||
font-variant: normal;
|
||||
font-weight: normal;
|
||||
line-height: normal;
|
||||
color: black;
|
||||
}
|
||||
|
||||
pre.code, .editbox {
|
||||
color: black;
|
||||
}
|
||||
|
||||
.editbox p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
span.freemarker-comment {
|
||||
color: #BB9977;
|
||||
}
|
||||
|
||||
span.freemarker-generic {
|
||||
}
|
||||
|
||||
span.freemarker-boundary {
|
||||
color: darkblue;
|
||||
}
|
||||
|
||||
span.freemarker-directive {
|
||||
color: darkblue;
|
||||
}
|
||||
|
||||
span.freemarker-identifier {
|
||||
color: purple;
|
||||
}
|
||||
|
||||
span.freemarker-builtin {
|
||||
color: gray;
|
||||
}
|
||||
|
||||
span.freemarker-punctuation {
|
||||
color: blue;
|
||||
}
|
||||
|
||||
span.freemarker-string {
|
||||
color: darkGreen;
|
||||
}
|
||||
|
||||
span.freemarker-number {
|
||||
color: blue;
|
||||
}
|
||||
|
||||
span.freemarker-error {
|
||||
color: #F00 !important;
|
||||
}
|
||||
75
gulliver/js/codemirror/contrib/freemarker/index.html
Executable file
75
gulliver/js/codemirror/contrib/freemarker/index.html
Executable file
@@ -0,0 +1,75 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
|
||||
<script src="../../js/codemirror.js" type="text/javascript"></script>
|
||||
<title>CodeMirror: Freemarker demonstration</title>
|
||||
<link rel="stylesheet" type="text/css" href="../../css/docs.css"/>
|
||||
<style type="text/css">
|
||||
.CodeMirror-line-numbers {
|
||||
width: 2em;
|
||||
color: #aaa;
|
||||
background-color: #eee;
|
||||
text-align: right;
|
||||
padding-right: .3em;
|
||||
font-family: tahoma, arial, helvetica, sans-serif;
|
||||
font-size: 12px;
|
||||
line-height: normal;
|
||||
padding-top: .4em;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body style="padding: 20px;">
|
||||
|
||||
<p>This page demonstrates <a href="../../index.html">CodeMirror</a>'s
|
||||
Freemarker parser. Written by Magnus Ljung, released under a BSD-style <a
|
||||
href="LICENSE">license</a>.</p>
|
||||
|
||||
<div style="border-top: 1px solid black; border-bottom: 1px solid black;">
|
||||
<textarea id="code" cols="120" rows="30">
|
||||
<!--
|
||||
example useless code to show Freemarker syntax highlighting
|
||||
this is multiline comment
|
||||
-->
|
||||
|
||||
<#macro join sequence separator>
|
||||
<#assign first="true"/>
|
||||
<#list sequence as entry><#if first=="true"><#assign first="false"/><#else>${separator} </#if>${entry}</#list>
|
||||
</#macro>
|
||||
|
||||
Here is some text that isn't Freemarker.
|
||||
|
||||
Let's join a list <@join ["foo", "bar", "baz"] ", "/>
|
||||
|
||||
Some expressions: ${test} ${another?test?substring(0, 12)}
|
||||
|
||||
Use alternative directive syntax:
|
||||
[#if user == "Big Joe"]
|
||||
Hello big ${user} xxx
|
||||
[/#if]
|
||||
</textarea>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
var editor = CodeMirror.fromTextArea('code', {
|
||||
height: "350px",
|
||||
parserfile: "../contrib/freemarker/js/parsefreemarker.js",
|
||||
stylesheet: "css/freemarkercolors.css",
|
||||
path: "../../js/",
|
||||
continuousScanning: 500,
|
||||
autoMatchParens: true,
|
||||
lineNumbers: true,
|
||||
markParen: function(node, ok) {
|
||||
node.style.backgroundColor = ok ? "#CCF" : "#FCC#";
|
||||
if(!ok) {
|
||||
node.style.color = "red";
|
||||
}
|
||||
},
|
||||
unmarkParen: function(node) {
|
||||
node.style.backgroundColor = "";
|
||||
node.style.color = "";
|
||||
},
|
||||
indentUnit: 4
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
380
gulliver/js/codemirror/contrib/freemarker/js/parsefreemarker.js
Executable file
380
gulliver/js/codemirror/contrib/freemarker/js/parsefreemarker.js
Executable file
@@ -0,0 +1,380 @@
|
||||
var FreemarkerParser = Editor.Parser = (function() {
|
||||
var autoSelfClosers = {"else": true, "elseif": true};
|
||||
|
||||
// Simple stateful tokenizer for Freemarker documents. Returns a
|
||||
// MochiKit-style iterator, with a state property that contains a
|
||||
// function encapsulating the current state. See tokenize.js.
|
||||
var tokenizeFreemarker = (function() {
|
||||
function inText(source, setState) {
|
||||
var ch = source.next();
|
||||
if (ch == "<") {
|
||||
if (source.equals("!")) {
|
||||
source.next();
|
||||
if (source.lookAhead("--", true)) {
|
||||
setState(inBlock("freemarker-comment", "-->"));
|
||||
return null;
|
||||
} else {
|
||||
return "freemarker-text";
|
||||
}
|
||||
} else {
|
||||
source.nextWhileMatches(/[\#\@\/]/);
|
||||
setState(inFreemarker(">"));
|
||||
return "freemarker-boundary";
|
||||
}
|
||||
}
|
||||
else if (ch == "[") {
|
||||
if(source.matches(/[\#\@]/)) {
|
||||
setState(pendingFreemarker(source.peek(), "]", false));
|
||||
return "freemarker-boundary";
|
||||
} else if(source.matches(/\//)) {
|
||||
setState(pendingFreemarkerEnd("]"));
|
||||
return "freemarker-boundary";
|
||||
} else {
|
||||
return "freemarker-text";
|
||||
}
|
||||
}
|
||||
else if (ch == "$") {
|
||||
if(source.matches(/[\{\w]/)) {
|
||||
setState(pendingFreemarker("{", "}", true));
|
||||
return "freemarker-boundary";
|
||||
} else {
|
||||
return "freemarker-text";
|
||||
}
|
||||
}
|
||||
else {
|
||||
source.nextWhileMatches(/[^\$<\n]/);
|
||||
return "freemarker-text";
|
||||
}
|
||||
}
|
||||
|
||||
function pendingFreemarker(startChar, endChar, nextCanBeIdentifier) {
|
||||
return function(source, setState) {
|
||||
var ch = source.next();
|
||||
if(ch == startChar) {
|
||||
setState(inFreemarker(endChar));
|
||||
return "freemarker-boundary";
|
||||
} else if(nextCanBeIdentifier) {
|
||||
source.nextWhileMatches(/\w/);
|
||||
setState(inText);
|
||||
return "freemarker-identifier";
|
||||
} else {
|
||||
setState(inText);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function pendingFreemarkerEnd(endChar) {
|
||||
return function(source, setState) {
|
||||
var ch = source.next();
|
||||
if(ch == "/") {
|
||||
setState(pendingFreemarker(source.peek(), endChar, false));
|
||||
return "freemarker-boundary";
|
||||
} else {
|
||||
setState(inText);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function inFreemarker(terminator) {
|
||||
return function(source, setState) {
|
||||
var ch = source.next();
|
||||
if (ch == terminator) {
|
||||
setState(inText);
|
||||
return "freemarker-boundary";
|
||||
} else if (/[?\/]/.test(ch) && source.equals(terminator)) {
|
||||
source.next();
|
||||
setState(inText);
|
||||
return "freemarker-boundary";
|
||||
} else if(/[?!]/.test(ch)) {
|
||||
if(ch == "?") {
|
||||
if(source.peek() == "?") {
|
||||
source.next();
|
||||
} else {
|
||||
setState(inBuiltIn(inFreemarker(terminator)));
|
||||
}
|
||||
}
|
||||
return "freemarker-punctuation";
|
||||
} else if(/[()+\/\-*%=]/.test(ch)) {
|
||||
return "freemarker-punctuation";
|
||||
} else if (/[0-9]/.test(ch)) {
|
||||
source.nextWhileMatches(/[0-9]+\.?[0-9]* /);
|
||||
return "freemarker-number";
|
||||
} else if (/\w/.test(ch)) {
|
||||
source.nextWhileMatches(/\w/);
|
||||
return "freemarker-identifier";
|
||||
} else if(/[\'\"]/.test(ch)) {
|
||||
setState(inString(ch, inFreemarker(terminator)));
|
||||
return "freemarker-string";
|
||||
} else {
|
||||
source.nextWhileMatches(/[^\s\u00a0<>\"\'\}?!\/]/);
|
||||
return "freemarker-generic";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function inBuiltIn(nextState) {
|
||||
return function(source, setState) {
|
||||
var ch = source.peek();
|
||||
if(/[a-zA-Z_]/.test(ch)) {
|
||||
source.next();
|
||||
source.nextWhileMatches(/[a-zA-Z_0-9]+/);
|
||||
setState(nextState);
|
||||
return "freemarker-builtin";
|
||||
} else {
|
||||
setState(nextState);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function inString(quote, nextState) {
|
||||
return function(source, setState) {
|
||||
while (!source.endOfLine()) {
|
||||
if (source.next() == quote) {
|
||||
setState(nextState);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return "freemarker-string";
|
||||
};
|
||||
}
|
||||
|
||||
function inBlock(style, terminator) {
|
||||
return function(source, setState) {
|
||||
while (!source.endOfLine()) {
|
||||
if (source.lookAhead(terminator, true)) {
|
||||
setState(inText);
|
||||
break;
|
||||
}
|
||||
source.next();
|
||||
}
|
||||
return style;
|
||||
};
|
||||
}
|
||||
|
||||
return function(source, startState) {
|
||||
return tokenizer(source, startState || inText);
|
||||
};
|
||||
})();
|
||||
|
||||
// The parser. The structure of this function largely follows that of
|
||||
// parseXML in parsexml.js
|
||||
function parseFreemarker(source) {
|
||||
var tokens = tokenizeFreemarker(source), token;
|
||||
var cc = [base];
|
||||
var tokenNr = 0, indented = 0;
|
||||
var currentTag = null, context = null;
|
||||
var consume;
|
||||
|
||||
function push(fs) {
|
||||
for (var i = fs.length - 1; i >= 0; i--)
|
||||
cc.push(fs[i]);
|
||||
}
|
||||
function cont() {
|
||||
push(arguments);
|
||||
consume = true;
|
||||
}
|
||||
function pass() {
|
||||
push(arguments);
|
||||
consume = false;
|
||||
}
|
||||
|
||||
function markErr() {
|
||||
token.style += " freemarker-error";
|
||||
}
|
||||
|
||||
function expect(text) {
|
||||
return function(style, content) {
|
||||
if (content == text) cont();
|
||||
else {markErr(); cont(arguments.callee);}
|
||||
};
|
||||
}
|
||||
|
||||
function pushContext(tagname, startOfLine) {
|
||||
context = {prev: context, name: tagname, indent: indented, startOfLine: startOfLine};
|
||||
}
|
||||
|
||||
function popContext() {
|
||||
context = context.prev;
|
||||
}
|
||||
|
||||
function computeIndentation(baseContext) {
|
||||
return function(nextChars, current, direction, firstToken) {
|
||||
var context = baseContext;
|
||||
|
||||
nextChars = getThreeTokens(firstToken);
|
||||
|
||||
if ((context && /^<\/\#/.test(nextChars)) ||
|
||||
(context && /^\[\/\#/.test(nextChars))) {
|
||||
context = context.prev;
|
||||
}
|
||||
|
||||
while (context && !context.startOfLine) {
|
||||
context = context.prev;
|
||||
}
|
||||
|
||||
if (context) {
|
||||
if(/^<\#else/.test(nextChars) ||
|
||||
/^\[\#else/.test(nextChars)) {
|
||||
return context.indent;
|
||||
}
|
||||
return context.indent + indentUnit;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function getThreeTokens(firstToken) {
|
||||
var secondToken = firstToken ? firstToken.nextSibling : null;
|
||||
var thirdToken = secondToken ? secondToken.nextSibling : null;
|
||||
|
||||
var nextChars = (firstToken && firstToken.currentText) ? firstToken.currentText : "";
|
||||
if(secondToken && secondToken.currentText) {
|
||||
nextChars = nextChars + secondToken.currentText;
|
||||
if(thirdToken && thirdToken.currentText) {
|
||||
nextChars = nextChars + thirdToken.currentText;
|
||||
}
|
||||
}
|
||||
|
||||
return nextChars;
|
||||
}
|
||||
|
||||
function base() {
|
||||
return pass(element, base);
|
||||
}
|
||||
|
||||
var harmlessTokens = { "freemarker-text": true, "freemarker-comment": true };
|
||||
|
||||
function element(style, content) {
|
||||
if (content == "<#") {
|
||||
cont(tagname, notEndTag, endtag("/>", ">", tokenNr == 1));
|
||||
} else if (content == "</#") {
|
||||
cont(closetagname, expect(">"));
|
||||
} else if(content == "[" && style == "freemarker-boundary") {
|
||||
cont(hashOrCloseHash);
|
||||
} else {
|
||||
cont();
|
||||
}
|
||||
}
|
||||
|
||||
function hashOrCloseHash(style, content) {
|
||||
if(content == "#") {
|
||||
cont(tagname, notHashEndTag, endtag("/]", "]", tokenNr == 2));
|
||||
} else if(content == "/") {
|
||||
cont(closeHash);
|
||||
} else {
|
||||
markErr();
|
||||
}
|
||||
}
|
||||
|
||||
function closeHash(style, content) {
|
||||
if(content == "#") {
|
||||
cont(closetagname, expect("]"));
|
||||
} else {
|
||||
markErr();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function tagname(style, content) {
|
||||
if (style == "freemarker-identifier") {
|
||||
currentTag = content.toLowerCase();
|
||||
token.style = "freemarker-directive";
|
||||
cont();
|
||||
} else {
|
||||
currentTag = null;
|
||||
pass();
|
||||
}
|
||||
}
|
||||
|
||||
function closetagname(style, content) {
|
||||
if (style == "freemarker-identifier") {
|
||||
token.style = "freemarker-directive";
|
||||
if (context && content.toLowerCase() == context.name) {
|
||||
popContext();
|
||||
} else {
|
||||
markErr();
|
||||
}
|
||||
}
|
||||
cont();
|
||||
}
|
||||
|
||||
function notEndTag(style, content) {
|
||||
if (content == "/>" || content == ">") {
|
||||
pass();
|
||||
} else {
|
||||
cont(notEndTag);
|
||||
}
|
||||
}
|
||||
|
||||
function notHashEndTag(style, content) {
|
||||
if (content == "/]" || content == "]") {
|
||||
pass();
|
||||
} else {
|
||||
cont(notHashEndTag);
|
||||
}
|
||||
}
|
||||
|
||||
function endtag(closeTagPattern, endTagPattern, startOfLine) {
|
||||
return function(style, content) {
|
||||
if (content == closeTagPattern || (content == endTagPattern && autoSelfClosers.hasOwnProperty(currentTag))) {
|
||||
cont();
|
||||
} else if (content == endTagPattern) {
|
||||
pushContext(currentTag, startOfLine);
|
||||
cont();
|
||||
} else {
|
||||
markErr();
|
||||
cont(arguments.callee);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
indentation: function() { return indented; },
|
||||
|
||||
next: function() {
|
||||
token = tokens.next();
|
||||
if (token.style == "whitespace" && tokenNr == 0)
|
||||
indented = token.value.length;
|
||||
else
|
||||
tokenNr++;
|
||||
if (token.content == "\n") {
|
||||
indented = tokenNr = 0;
|
||||
token.indentation = computeIndentation(context);
|
||||
}
|
||||
|
||||
if (token.style == "whitespace" || token.type == "freemarker-comment")
|
||||
return token;
|
||||
|
||||
while(true) {
|
||||
consume = false;
|
||||
cc.pop()(token.style, token.content);
|
||||
if (consume) {
|
||||
return token;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
copy: function(){
|
||||
var _cc = cc.concat([]), _tokenState = tokens.state, _context = context;
|
||||
var parser = this;
|
||||
|
||||
return function(input){
|
||||
cc = _cc.concat([]);
|
||||
tokenNr = indented = 0;
|
||||
context = _context;
|
||||
tokens = tokenizeFreemarker(input, _tokenState);
|
||||
return parser;
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
make: parseFreemarker,
|
||||
electricChars: ">"
|
||||
};
|
||||
})();
|
||||
57
gulliver/js/codemirror/contrib/groovy/index.html
Executable file
57
gulliver/js/codemirror/contrib/groovy/index.html
Executable file
@@ -0,0 +1,57 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<script src="../../js/codemirror.js" type="text/javascript"></script>
|
||||
<title>CodeMirror: Groovy demonstration</title>
|
||||
<link rel="stylesheet" type="text/css" href="../../css/docs.css"/>
|
||||
</head>
|
||||
<body style="padding: 20px;">
|
||||
|
||||
<p>Demonstration of <a href="../../index.html">CodeMirror</a>'s Groovy highlighter.</p>
|
||||
|
||||
<p>Created by eXo Platform SAS (<a href="http://www.opensource.org/licenses/lgpl-2.1.php">license</a>).</p>
|
||||
|
||||
<p>Note that the files for this parser aren't included in the CodeMirror repository, but have to fetched from <a href="http://svn.exoplatform.org/">svn.exoplatform.org</a>:</p>
|
||||
|
||||
<ul>
|
||||
<li><a href="http://svn.exoplatform.org/projects/gwt/trunk/exo-gwtframework-editor/src/main/resources/org/exoplatform/gwtframework/editor/public/codemirror/js/tokenizegroovy.js">tokenizegroovy.js</a></li>
|
||||
<li><a href="http://svn.exoplatform.org/projects/gwt/trunk/exo-gwtframework-editor/src/main/resources/org/exoplatform/gwtframework/editor/public/codemirror/js/parsegroovy.js">parsegroovy.js</a></li>
|
||||
<li><a href="http://svn.exoplatform.org/projects/gwt/trunk/exo-gwtframework-editor/src/main/resources/org/exoplatform/gwtframework/editor/public/codemirror/css/groovycolors.css">groovy.colors.css</a></li>
|
||||
</ul>
|
||||
|
||||
<div style="border-top: 1px solid black; border-bottom: 1px solid black;">
|
||||
<textarea id="code" cols="120" rows="50">
|
||||
// simple groovy script
|
||||
import javax.ws.rs.Path
|
||||
import javax.ws.rs.GET
|
||||
import javax.ws.rs.PathParam
|
||||
import javax.ws.rs.POST
|
||||
|
||||
@Path("/")
|
||||
public class HelloWorld {
|
||||
@GET
|
||||
@Path("helloworld/{name}")
|
||||
public String hello(@PathParam("name") String name) {
|
||||
return "Hello " + name
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("helloworld/{name}")
|
||||
public String hello2(@PathParam("name") String name) {
|
||||
return "Hello " + name
|
||||
}
|
||||
}
|
||||
</textarea>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
var editor = CodeMirror.fromTextArea('code', {
|
||||
height: "450px",
|
||||
parserfile: ["http://svn.exoplatform.org/projects/gwt/trunk/exo-gwtframework-editor/src/main/resources/org/exoplatform/gwtframework/editor/public/codemirror/js/parsegroovy.js", "http://svn.exoplatform.org/projects/gwt/trunk/exo-gwtframework-editor/src/main/resources/org/exoplatform/gwtframework/editor/public/codemirror/js/tokenizegroovy.js"],
|
||||
stylesheet: "http://svn.exoplatform.org/projects/gwt/trunk/exo-gwtframework-editor/src/main/resources/org/exoplatform/gwtframework/editor/public/codemirror/css/groovycolors.css",
|
||||
path: "../../js/",
|
||||
textWrapping: false
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
20
gulliver/js/codemirror/contrib/java/LICENSE
Executable file
20
gulliver/js/codemirror/contrib/java/LICENSE
Executable file
@@ -0,0 +1,20 @@
|
||||
Copyright (c) 2010 Patrick Wied
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any
|
||||
damages arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any
|
||||
purpose, including commercial applications, and to alter it and
|
||||
redistribute it freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must
|
||||
not claim that you wrote the original software. If you use this
|
||||
software in a product, an acknowledgment in the product
|
||||
documentation would be appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must
|
||||
not be misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source
|
||||
distribution.
|
||||
64
gulliver/js/codemirror/contrib/java/css/javacolors.css
Executable file
64
gulliver/js/codemirror/contrib/java/css/javacolors.css
Executable file
@@ -0,0 +1,64 @@
|
||||
|
||||
html {
|
||||
cursor: text;
|
||||
}
|
||||
|
||||
.editbox {
|
||||
margin: .4em;
|
||||
padding: 0;
|
||||
font-family: monospace;
|
||||
font-size: 10pt;
|
||||
color: black;
|
||||
}
|
||||
|
||||
pre.code, .editbox {
|
||||
color: #666666;
|
||||
}
|
||||
|
||||
.editbox p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
span.java-punctuation {
|
||||
color: black;
|
||||
}
|
||||
|
||||
span.java-operator {
|
||||
color: purple;
|
||||
}
|
||||
|
||||
span.java-keyword {
|
||||
color: #7f0055;
|
||||
font-weight:bold;
|
||||
}
|
||||
|
||||
span.java-atom {
|
||||
color: brown;
|
||||
}
|
||||
|
||||
span.java-variable {
|
||||
color: black;
|
||||
}
|
||||
|
||||
|
||||
span.java-property {
|
||||
color: black;
|
||||
}
|
||||
|
||||
span.java-comment {
|
||||
color: green;
|
||||
}
|
||||
|
||||
span.javadoc-comment {
|
||||
color: #3e5797;
|
||||
font-weight:bold;
|
||||
}
|
||||
|
||||
span.java-string {
|
||||
color: blue;
|
||||
}
|
||||
|
||||
span.java-annotation{
|
||||
color: gray;
|
||||
}
|
||||
|
||||
66
gulliver/js/codemirror/contrib/java/index.html
Executable file
66
gulliver/js/codemirror/contrib/java/index.html
Executable file
@@ -0,0 +1,66 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<title>Demonstration of CodeMirrors Java highlighter written by Patrick Wied</title>
|
||||
<script src="../../js/codemirror.js" type="text/javascript"></script>
|
||||
<link rel="stylesheet" type="text/css" href="../../css/docs.css" />
|
||||
</head>
|
||||
<body>
|
||||
<p>Demonstration of <a href="http://www.codemirror.net">CodeMirror</a>'s Java highlighter.</p>
|
||||
|
||||
<p>Written by <a href="http://www.patrick-wied.at/">Patrick Wied</a>.</p>
|
||||
|
||||
<div style="border-top: 1px solid black; border-bottom: 1px solid black;">
|
||||
<textarea id="code">
|
||||
package example;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* This class subclasses DrawableRect and adds colors to the rectangle it draws
|
||||
**/
|
||||
public class ColoredRect extends DrawableRect {
|
||||
// These are new fields defined by this class.
|
||||
// x1, y1, x2, and y2 are inherited from our super-superclass, Rect.
|
||||
@AnnotationTest
|
||||
protected Color border, fill;
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* This constructor uses super() to invoke the superclass constructor, and
|
||||
* also does some initialization of its own.
|
||||
**/
|
||||
public ColoredRect(int x1, int y1, int x2, int y2, Color border, Color fill){
|
||||
super(x1, y1, x2, y2);
|
||||
/* This
|
||||
is a block comment */
|
||||
this.border = border;
|
||||
this.fill = fill;
|
||||
this.name = "This is a string";
|
||||
}
|
||||
|
||||
/**
|
||||
* This method overrides the draw() method of our superclass so that it
|
||||
* can make use of the colors that have been specified.
|
||||
**/
|
||||
public void draw(Graphics g) {
|
||||
g.setColor(fill);
|
||||
g.fillRect(x1, y1, x2, y2);
|
||||
g.setColor(border);
|
||||
g.drawRect(x1, y1, x2, y2);
|
||||
}
|
||||
}
|
||||
</textarea>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
var editor = CodeMirror.fromTextArea('code', {
|
||||
height: "650px",
|
||||
parserfile: ["../contrib/java/js/tokenizejava.js","../contrib/java/js/parsejava.js"],
|
||||
stylesheet: "css/javacolors.css",
|
||||
path: "../../js/",
|
||||
tabMode : "shift"
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
285
gulliver/js/codemirror/contrib/java/js/parsejava.js
Executable file
285
gulliver/js/codemirror/contrib/java/js/parsejava.js
Executable file
@@ -0,0 +1,285 @@
|
||||
/**
|
||||
* Java parser for codemirror
|
||||
*
|
||||
* @author Patrick Wied
|
||||
*/
|
||||
|
||||
var JavaParser = Editor.Parser = (function() {
|
||||
// Token types that can be considered to be atoms.
|
||||
var atomicTypes = {"atom": true, "number": true, "string": true, "regexp": true};
|
||||
// Setting that can be used to have JSON data indent properly.
|
||||
var json = false;
|
||||
// Constructor for the lexical context objects.
|
||||
function JavaLexical(indented, column, type, align, prev, info) {
|
||||
// indentation at start of this line
|
||||
this.indented = indented;
|
||||
// column at which this scope was opened
|
||||
this.column = column;
|
||||
// type of scope ( 'stat' (statement), 'form' (special form), '[', '{', or '(')
|
||||
this.type = type;
|
||||
// '[', '{', or '(' blocks that have any text after their opening
|
||||
// character are said to be 'aligned' -- any lines below are
|
||||
// indented all the way to the opening character.
|
||||
if (align != null)
|
||||
this.align = align;
|
||||
// Parent scope, if any.
|
||||
this.prev = prev;
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
// java indentation rules.
|
||||
function indentJava(lexical) {
|
||||
return function(firstChars) {
|
||||
var firstChar = firstChars && firstChars.charAt(0), type = lexical.type;
|
||||
var closing = firstChar == type;
|
||||
if (type == "form" && firstChar == "{")
|
||||
return lexical.indented;
|
||||
else if (type == "stat" || type == "form")
|
||||
return lexical.indented + indentUnit;
|
||||
else if (lexical.info == "switch" && !closing)
|
||||
return lexical.indented + (/^(?:case|default)\b/.test(firstChars) ? indentUnit : 2 * indentUnit);
|
||||
else if (lexical.align)
|
||||
return lexical.column - (closing ? 1 : 0);
|
||||
else
|
||||
return lexical.indented + (closing ? 0 : indentUnit);
|
||||
};
|
||||
}
|
||||
|
||||
// The parser-iterator-producing function itself.
|
||||
function parseJava(input, basecolumn) {
|
||||
// Wrap the input in a token stream
|
||||
var tokens = tokenizeJava(input);
|
||||
// The parser state. cc is a stack of actions that have to be
|
||||
// performed to finish the current statement. For example we might
|
||||
// know that we still need to find a closing parenthesis and a
|
||||
// semicolon. Actions at the end of the stack go first. It is
|
||||
// initialized with an infinitely looping action that consumes
|
||||
// whole statements.
|
||||
var cc = [statements];
|
||||
// The lexical scope, used mostly for indentation.
|
||||
var lexical = new JavaLexical(basecolumn || 0, 0, "block", false);
|
||||
// Current column, and the indentation at the start of the current
|
||||
// line. Used to create lexical scope objects.
|
||||
var column = 0;
|
||||
var indented = 0;
|
||||
// Variables which are used by the mark, cont, and pass functions
|
||||
// below to communicate with the driver loop in the 'next'
|
||||
// function.
|
||||
var consume, marked;
|
||||
|
||||
// The iterator object.
|
||||
var parser = {next: next, copy: copy};
|
||||
|
||||
function next(){
|
||||
// Start by performing any 'lexical' actions (adjusting the
|
||||
// lexical variable), or the operations below will be working
|
||||
// with the wrong lexical state.
|
||||
while(cc[cc.length - 1].lex)
|
||||
cc.pop()();
|
||||
|
||||
// Fetch a token.
|
||||
var token = tokens.next();
|
||||
|
||||
// Adjust column and indented.
|
||||
if (token.type == "whitespace" && column == 0)
|
||||
indented = token.value.length;
|
||||
column += token.value.length;
|
||||
if (token.content == "\n"){
|
||||
indented = column = 0;
|
||||
// If the lexical scope's align property is still undefined at
|
||||
// the end of the line, it is an un-aligned scope.
|
||||
if (!("align" in lexical))
|
||||
lexical.align = false;
|
||||
// Newline tokens get an indentation function associated with
|
||||
// them.
|
||||
token.indentation = indentJava(lexical);
|
||||
|
||||
}
|
||||
// No more processing for meaningless tokens.
|
||||
if (token.type == "whitespace" || token.type == "comment" || token.type == "javadoc" || token.type == "annotation")
|
||||
return token;
|
||||
|
||||
// When a meaningful token is found and the lexical scope's
|
||||
// align is undefined, it is an aligned scope.
|
||||
if (!("align" in lexical))
|
||||
lexical.align = true;
|
||||
|
||||
// Execute actions until one 'consumes' the token and we can
|
||||
// return it.
|
||||
while(true) {
|
||||
consume = marked = false;
|
||||
// Take and execute the topmost action.
|
||||
cc.pop()(token.type, token.content);
|
||||
if (consume){
|
||||
// Marked is used to change the style of the current token.
|
||||
if (marked)
|
||||
token.style = marked;
|
||||
return token;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This makes a copy of the parser state. It stores all the
|
||||
// stateful variables in a closure, and returns a function that
|
||||
// will restore them when called with a new input stream. Note
|
||||
// that the cc array has to be copied, because it is contantly
|
||||
// being modified. Lexical objects are not mutated, and context
|
||||
// objects are not mutated in a harmful way, so they can be shared
|
||||
// between runs of the parser.
|
||||
function copy(){
|
||||
var _lexical = lexical, _cc = cc.concat([]), _tokenState = tokens.state;
|
||||
|
||||
return function copyParser(input){
|
||||
lexical = _lexical;
|
||||
cc = _cc.concat([]); // copies the array
|
||||
column = indented = 0;
|
||||
tokens = tokenizeJava(input, _tokenState);
|
||||
return parser;
|
||||
};
|
||||
}
|
||||
|
||||
// Helper function for pushing a number of actions onto the cc
|
||||
// stack in reverse order.
|
||||
function push(fs){
|
||||
for (var i = fs.length - 1; i >= 0; i--)
|
||||
cc.push(fs[i]);
|
||||
}
|
||||
// cont and pass are used by the action functions to add other
|
||||
// actions to the stack. cont will cause the current token to be
|
||||
// consumed, pass will leave it for the next action.
|
||||
function cont(){
|
||||
push(arguments);
|
||||
consume = true;
|
||||
}
|
||||
function pass(){
|
||||
push(arguments);
|
||||
consume = false;
|
||||
}
|
||||
// Used to change the style of the current token.
|
||||
function mark(style){
|
||||
marked = style;
|
||||
}
|
||||
|
||||
// Push a new lexical context of the given type.
|
||||
function pushlex(type, info) {
|
||||
var result = function(){
|
||||
lexical = new JavaLexical(indented, column, type, null, lexical, info)
|
||||
};
|
||||
result.lex = true;
|
||||
return result;
|
||||
}
|
||||
// Pop off the current lexical context.
|
||||
function poplex(){
|
||||
lexical = lexical.prev;
|
||||
}
|
||||
poplex.lex = true;
|
||||
// The 'lex' flag on these actions is used by the 'next' function
|
||||
// to know they can (and have to) be ran before moving on to the
|
||||
// next token.
|
||||
|
||||
// Creates an action that discards tokens until it finds one of
|
||||
// the given type.
|
||||
function expect(wanted){
|
||||
return function expecting(type){
|
||||
if (type == wanted) cont();
|
||||
else cont(arguments.callee);
|
||||
};
|
||||
}
|
||||
|
||||
// Looks for a statement, and then calls itself.
|
||||
function statements(type){
|
||||
return pass(statement, statements);
|
||||
}
|
||||
// Dispatches various types of statements based on the type of the
|
||||
// current token.
|
||||
function statement(type){
|
||||
if (type == "keyword a") cont(pushlex("form"), expression, statement, poplex);
|
||||
else if (type == "keyword b") cont(pushlex("form"), statement, poplex);
|
||||
else if (type == "{") cont(pushlex("}"), block, poplex);
|
||||
else if (type == "for") cont(pushlex("form"), expect("("), pushlex(")"), forspec1, expect(")"), poplex, statement, poplex);
|
||||
else if (type == "variable") cont(pushlex("stat"), maybelabel);
|
||||
else if (type == "switch") cont(pushlex("form"), expression, pushlex("}", "switch"), expect("{"), block, poplex, poplex);
|
||||
else if (type == "case") cont(expression, expect(":"));
|
||||
else if (type == "default") cont(expect(":"));
|
||||
else if (type == "catch") cont(pushlex("form"), expect("("), function(){}, expect(")"), statement, poplex);
|
||||
else if (type == "class") cont();
|
||||
else if (type == "interface") cont();
|
||||
else if (type == "keyword c") cont(statement);
|
||||
else pass(pushlex("stat"), expression, expect(";"), poplex);
|
||||
}
|
||||
// Dispatch expression types.
|
||||
function expression(type){
|
||||
if (atomicTypes.hasOwnProperty(type)) cont(maybeoperator);
|
||||
//else if (type == "function") cont(functiondef);
|
||||
else if (type == "keyword c") cont(expression);
|
||||
else if (type == "(") cont(pushlex(")"), expression, expect(")"), poplex, maybeoperator);
|
||||
else if (type == "operator") cont(expression);
|
||||
else if (type == "[") cont(pushlex("]"), commasep(expression, "]"), poplex, maybeoperator);
|
||||
}
|
||||
// Called for places where operators, function calls, or
|
||||
// subscripts are valid. Will skip on to the next action if none
|
||||
// is found.
|
||||
function maybeoperator(type){
|
||||
if (type == "operator") cont(expression);
|
||||
else if (type == "(") cont(pushlex(")"), expression, commasep(expression, ")"), poplex, maybeoperator);
|
||||
else if (type == "[") cont(pushlex("]"), expression, expect("]"), poplex, maybeoperator);
|
||||
}
|
||||
// When a statement starts with a variable name, it might be a
|
||||
// label. If no colon follows, it's a regular statement.
|
||||
|
||||
function maybelabel(type){
|
||||
if (type == "(") cont(commasep(function(){}, ")"), poplex, statement); // method definition
|
||||
else if (type == "{") cont(poplex, pushlex("}"), block, poplex); // property definition
|
||||
else pass(maybeoperator, expect(";"), poplex);
|
||||
}
|
||||
|
||||
// Parses a comma-separated list of the things that are recognized
|
||||
// by the 'what' argument.
|
||||
function commasep(what, end){
|
||||
function proceed(type) {
|
||||
if (type == ",") cont(what, proceed);
|
||||
else if (type == end) cont();
|
||||
else cont(expect(end));
|
||||
};
|
||||
return function commaSeparated(type) {
|
||||
if (type == end) cont();
|
||||
else pass(what, proceed);
|
||||
};
|
||||
}
|
||||
// Look for statements until a closing brace is found.
|
||||
function block(type){
|
||||
if (type == "}") cont();
|
||||
else pass(statement, block);
|
||||
}
|
||||
|
||||
// For loops.
|
||||
|
||||
function forspec1(type){
|
||||
if (type == ";") pass(forspec2);
|
||||
else pass(forspec2);
|
||||
}
|
||||
function formaybein(type, value){
|
||||
if (value == "in") cont(expression);
|
||||
else cont(maybeoperator, forspec2);
|
||||
}
|
||||
function forspec2(type, value){
|
||||
if (type == ";") cont(forspec3);
|
||||
else if (value == "in") cont(expression);
|
||||
else cont(expression, expect(";"), forspec3);
|
||||
}
|
||||
function forspec3(type) {
|
||||
if (type == ")") pass();
|
||||
else cont(expression);
|
||||
}
|
||||
|
||||
return parser;
|
||||
}
|
||||
|
||||
return {
|
||||
make: parseJava,
|
||||
electricChars: "{}:",
|
||||
configure: function(obj) {
|
||||
if (obj.json != null) json = obj.json;
|
||||
}
|
||||
};
|
||||
})();
|
||||
222
gulliver/js/codemirror/contrib/java/js/tokenizejava.js
Executable file
222
gulliver/js/codemirror/contrib/java/js/tokenizejava.js
Executable file
@@ -0,0 +1,222 @@
|
||||
/**
|
||||
* Java tokenizer for codemirror
|
||||
*
|
||||
* @author Patrick Wied
|
||||
* @version 2010-10-07
|
||||
*/
|
||||
var tokenizeJava = (function() {
|
||||
// Advance the stream until the given character (not preceded by a
|
||||
// backslash) is encountered, or the end of the line is reached.
|
||||
function nextUntilUnescaped(source, end) {
|
||||
var escaped = false;
|
||||
var next;
|
||||
while (!source.endOfLine()) {
|
||||
var next = source.next();
|
||||
if (next == end && !escaped)
|
||||
return false;
|
||||
escaped = !escaped && next == "\\";
|
||||
}
|
||||
return escaped;
|
||||
}
|
||||
|
||||
// A map of Java's keywords. The a/b/c keyword distinction is
|
||||
// very rough, but it gives the parser enough information to parse
|
||||
// correct code correctly (we don't care that much how we parse
|
||||
// incorrect code). The style information included in these objects
|
||||
// is used by the highlighter to pick the correct CSS style for a
|
||||
// token.
|
||||
var keywords = function(){
|
||||
function result(type, style){
|
||||
return {type: type, style: "java-" + style};
|
||||
}
|
||||
// keywords that take a parenthised expression, and then a
|
||||
// statement (if)
|
||||
var keywordA = result("keyword a", "keyword");
|
||||
// keywords that take just a statement (else)
|
||||
var keywordB = result("keyword b", "keyword");
|
||||
// keywords that optionally take an expression, and form a
|
||||
// statement (return)
|
||||
var keywordC = result("keyword c", "keyword");
|
||||
var operator = result("operator", "keyword");
|
||||
var atom = result("atom", "atom");
|
||||
|
||||
return {
|
||||
"if": keywordA, "while": keywordA, "with": keywordA,
|
||||
"else": keywordB, "do": keywordB, "try": keywordB, "finally": keywordB,
|
||||
"return": keywordC, "break": keywordC, "continue": keywordC, "new": keywordC, "throw": keywordC, "throws": keywordB,
|
||||
"in": operator, "typeof": operator, "instanceof": operator,
|
||||
"catch": result("catch", "keyword"), "for": result("for", "keyword"), "switch": result("switch", "keyword"),
|
||||
"case": result("case", "keyword"), "default": result("default", "keyword"),
|
||||
"true": atom, "false": atom, "null": atom,
|
||||
|
||||
"class": result("class", "keyword"), "interface": result("interface", "keyword"), "package": keywordC, "import": keywordC,
|
||||
"implements": keywordC, "extends": keywordC, "super": keywordC,
|
||||
|
||||
"public": keywordC, "private": keywordC, "protected": keywordC, "transient": keywordC, "this": keywordC,
|
||||
"static": keywordC, "final": keywordC, "const": keywordC, "abstract": keywordC, "static": keywordC,
|
||||
|
||||
"int": keywordC, "double": keywordC, "long": keywordC, "boolean": keywordC, "char": keywordC,
|
||||
"void": keywordC, "byte": keywordC, "float": keywordC, "short": keywordC
|
||||
};
|
||||
}();
|
||||
|
||||
// Some helper regexps
|
||||
var isOperatorChar = /[+\-*&%=<>!?|]/;
|
||||
var isHexDigit = /[0-9A-Fa-f]/;
|
||||
var isWordChar = /[\w\$_]/;
|
||||
// Wrapper around javaToken that helps maintain parser state (whether
|
||||
// we are inside of a multi-line comment and whether the next token
|
||||
// could be a regular expression).
|
||||
function javaTokenState(inside, regexp) {
|
||||
return function(source, setState) {
|
||||
var newInside = inside;
|
||||
var type = javaToken(inside, regexp, source, function(c) {newInside = c;});
|
||||
var newRegexp = type.type == "operator" || type.type == "keyword c" || type.type.match(/^[\[{}\(,;:]$/);
|
||||
if (newRegexp != regexp || newInside != inside)
|
||||
setState(javaTokenState(newInside, newRegexp));
|
||||
return type;
|
||||
};
|
||||
}
|
||||
|
||||
// The token reader, inteded to be used by the tokenizer from
|
||||
// tokenize.js (through jsTokenState). Advances the source stream
|
||||
// over a token, and returns an object containing the type and style
|
||||
// of that token.
|
||||
function javaToken(inside, regexp, source, setInside) {
|
||||
function readHexNumber(){
|
||||
source.next(); // skip the 'x'
|
||||
source.nextWhileMatches(isHexDigit);
|
||||
return {type: "number", style: "java-atom"};
|
||||
}
|
||||
|
||||
function readNumber() {
|
||||
source.nextWhileMatches(/[0-9]/);
|
||||
if (source.equals(".")){
|
||||
source.next();
|
||||
source.nextWhileMatches(/[0-9]/);
|
||||
}
|
||||
if (source.equals("e") || source.equals("E")){
|
||||
source.next();
|
||||
if (source.equals("-"))
|
||||
source.next();
|
||||
source.nextWhileMatches(/[0-9]/);
|
||||
}
|
||||
return {type: "number", style: "java-atom"};
|
||||
}
|
||||
// Read a word, look it up in keywords. If not found, it is a
|
||||
// variable, otherwise it is a keyword of the type found.
|
||||
function readWord() {
|
||||
source.nextWhileMatches(isWordChar);
|
||||
var word = source.get();
|
||||
var known = keywords.hasOwnProperty(word) && keywords.propertyIsEnumerable(word) && keywords[word];
|
||||
return known ? {type: known.type, style: known.style, content: word} :
|
||||
{type: "variable", style: "java-variable", content: word};
|
||||
}
|
||||
function readRegexp() {
|
||||
nextUntilUnescaped(source, "/");
|
||||
source.nextWhileMatches(/[gi]/);
|
||||
return {type: "regexp", style: "java-string"};
|
||||
}
|
||||
// Mutli-line comments are tricky. We want to return the newlines
|
||||
// embedded in them as regular newline tokens, and then continue
|
||||
// returning a comment token for every line of the comment. So
|
||||
// some state has to be saved (inside) to indicate whether we are
|
||||
// inside a /* */ sequence.
|
||||
function readMultilineComment(start){
|
||||
var newInside = "/*";
|
||||
var maybeEnd = (start == "*");
|
||||
while (true) {
|
||||
if (source.endOfLine())
|
||||
break;
|
||||
var next = source.next();
|
||||
if (next == "/" && maybeEnd){
|
||||
newInside = null;
|
||||
break;
|
||||
}
|
||||
maybeEnd = (next == "*");
|
||||
}
|
||||
setInside(newInside);
|
||||
return {type: "comment", style: "java-comment"};
|
||||
}
|
||||
|
||||
// for reading javadoc
|
||||
function readJavaDocComment(start){
|
||||
var newInside = "/**";
|
||||
var maybeEnd = (start == "*");
|
||||
while (true) {
|
||||
if (source.endOfLine())
|
||||
break;
|
||||
var next = source.next();
|
||||
if (next == "/" && maybeEnd){
|
||||
newInside = null;
|
||||
break;
|
||||
}
|
||||
maybeEnd = (next == "*");
|
||||
}
|
||||
setInside(newInside);
|
||||
return {type: "javadoc", style: "javadoc-comment"};
|
||||
}
|
||||
// for reading annotations (word based)
|
||||
function readAnnotation(){
|
||||
source.nextWhileMatches(isWordChar);
|
||||
var word = source.get();
|
||||
return {type: "annotation", style: "java-annotation", content:word};
|
||||
}
|
||||
|
||||
function readOperator() {
|
||||
source.nextWhileMatches(isOperatorChar);
|
||||
return {type: "operator", style: "java-operator"};
|
||||
}
|
||||
function readString(quote) {
|
||||
var endBackSlash = nextUntilUnescaped(source, quote);
|
||||
setInside(endBackSlash ? quote : null);
|
||||
return {type: "string", style: "java-string"};
|
||||
}
|
||||
|
||||
// Fetch the next token. Dispatches on first character in the
|
||||
// stream, or first two characters when the first is a slash.
|
||||
if (inside == "\"" || inside == "'")
|
||||
return readString(inside);
|
||||
var ch = source.next();
|
||||
if (inside == "/*")
|
||||
return readMultilineComment(ch);
|
||||
else if(inside == "/**")
|
||||
return readJavaDocComment(ch);
|
||||
else if (ch == "\"" || ch == "'")
|
||||
return readString(ch);
|
||||
// with punctuation, the type of the token is the symbol itself
|
||||
else if (/[\[\]{}\(\),;\:\.]/.test(ch))
|
||||
return {type: ch, style: "java-punctuation"};
|
||||
else if (ch == "0" && (source.equals("x") || source.equals("X")))
|
||||
return readHexNumber();
|
||||
else if (/[0-9]/.test(ch))
|
||||
return readNumber();
|
||||
else if (ch == "@"){
|
||||
return readAnnotation();
|
||||
}else if (ch == "/"){
|
||||
if (source.equals("*")){
|
||||
source.next();
|
||||
|
||||
if(source.equals("*"))
|
||||
return readJavaDocComment(ch);
|
||||
|
||||
return readMultilineComment(ch);
|
||||
}
|
||||
else if (source.equals("/"))
|
||||
{ nextUntilUnescaped(source, null); return {type: "comment", style: "java-comment"};}
|
||||
else if (regexp)
|
||||
return readRegexp();
|
||||
else
|
||||
return readOperator();
|
||||
}
|
||||
else if (isOperatorChar.test(ch))
|
||||
return readOperator();
|
||||
else
|
||||
return readWord();
|
||||
}
|
||||
|
||||
// The external interface to the tokenizer.
|
||||
return function(source, startState) {
|
||||
return tokenizer(source, startState || javaTokenState(false, true));
|
||||
};
|
||||
})();
|
||||
32
gulliver/js/codemirror/contrib/lua/LICENSE
Executable file
32
gulliver/js/codemirror/contrib/lua/LICENSE
Executable file
@@ -0,0 +1,32 @@
|
||||
Copyright (c) 2009, Franciszek Wawrzak
|
||||
All rights reserved.
|
||||
|
||||
This software is provided for use in connection with the
|
||||
CodeMirror suite of modules and utilities, hosted and maintained
|
||||
at http://codemirror.net/.
|
||||
|
||||
Redistribution and use of this software in source and binary forms,
|
||||
with or without modification, are permitted provided that the
|
||||
following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
63
gulliver/js/codemirror/contrib/lua/css/luacolors.css
Executable file
63
gulliver/js/codemirror/contrib/lua/css/luacolors.css
Executable file
@@ -0,0 +1,63 @@
|
||||
html {
|
||||
cursor: text;
|
||||
}
|
||||
|
||||
.editbox {
|
||||
margin: .4em;
|
||||
padding: 0;
|
||||
font-family: monospace;
|
||||
font-size: 10pt;
|
||||
color: black;
|
||||
}
|
||||
|
||||
pre.code, .editbox {
|
||||
color: #666666;
|
||||
}
|
||||
|
||||
.editbox p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
span.lua-comment {
|
||||
color: #BB9977;
|
||||
}
|
||||
|
||||
span.lua-keyword {
|
||||
font-weight: bold;
|
||||
color: blue;
|
||||
}
|
||||
|
||||
span.lua-string {
|
||||
color: #AA2222;
|
||||
}
|
||||
|
||||
span.lua-stdfunc {
|
||||
font-weight: bold;
|
||||
color: #077;
|
||||
}
|
||||
span.lua-customfunc {
|
||||
font-weight: bold;
|
||||
color: #0AA;
|
||||
}
|
||||
|
||||
|
||||
span.lua-identifier {
|
||||
color: black;
|
||||
}
|
||||
|
||||
span.lua-number {
|
||||
color: #3A3;
|
||||
}
|
||||
|
||||
span.lua-token {
|
||||
color: #151;
|
||||
}
|
||||
|
||||
span.lua-error {
|
||||
color: #FFF;
|
||||
background-color: #F00;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
68
gulliver/js/codemirror/contrib/lua/index.html
Executable file
68
gulliver/js/codemirror/contrib/lua/index.html
Executable file
@@ -0,0 +1,68 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<script src="../../js/codemirror.js" type="text/javascript"></script>
|
||||
<title>CodeMirror: Lua demonstration</title>
|
||||
</head>
|
||||
<body style="padding: 20px;">
|
||||
|
||||
<p>This page demonstrates <a href="../../index.html">CodeMirror</a>'s
|
||||
Lua parser. Written by <a href="http://francio.pl/">Franciszek
|
||||
Wawrzak</a>, released under a BSD-style <a
|
||||
href="LICENSE">license</a>.</p>
|
||||
|
||||
<div style="border: 1px solid black; padding: 0px;">
|
||||
<textarea id="code" cols="120" rows="30">
|
||||
--[[
|
||||
example useless code to show lua syntax highlighting
|
||||
this is multiline comment
|
||||
]]
|
||||
|
||||
function blahblahblah(x)
|
||||
|
||||
local table = {
|
||||
"asd" = 123,
|
||||
"x" = 0.34,
|
||||
}
|
||||
if x ~= 3 then
|
||||
print( x )
|
||||
elseif x == "string"
|
||||
my_custom_function( 0x34 )
|
||||
else
|
||||
unknown_function( "some string" )
|
||||
end
|
||||
|
||||
--single line comment
|
||||
|
||||
end
|
||||
|
||||
function blablabla3()
|
||||
|
||||
for k,v in ipairs( table ) do
|
||||
--abcde..
|
||||
y=[=[
|
||||
x=[[
|
||||
x is a multi line string
|
||||
]]
|
||||
but its definition is iside a highest level string!
|
||||
]=]
|
||||
print(" \"\" ")
|
||||
--this marks a parser error:
|
||||
s = [== asdasdasd]]
|
||||
|
||||
s = math.sin( x )
|
||||
end
|
||||
|
||||
end
|
||||
</textarea>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
var editor = CodeMirror.fromTextArea('code', {
|
||||
height: "350px",
|
||||
parserfile: "../contrib/lua/js/parselua.js",
|
||||
stylesheet: "css/luacolors.css",
|
||||
path: "../../js/"
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
254
gulliver/js/codemirror/contrib/lua/js/parselua.js
Executable file
254
gulliver/js/codemirror/contrib/lua/js/parselua.js
Executable file
@@ -0,0 +1,254 @@
|
||||
/*
|
||||
Simple parser for LUA
|
||||
Written for Lua 5.1, based on parsecss and other parsers.
|
||||
features: highlights keywords, strings, comments (no leveling supported! ("[==[")),tokens, basic indenting
|
||||
|
||||
to make this parser highlight your special functions pass table with this functions names to parserConfig argument of creator,
|
||||
|
||||
parserConfig: ["myfunction1","myfunction2"],
|
||||
*/
|
||||
|
||||
|
||||
function findFirstRegexp(words) {
|
||||
return new RegExp("^(?:" + words.join("|") + ")", "i");
|
||||
}
|
||||
|
||||
function matchRegexp(words) {
|
||||
return new RegExp("^(?:" + words.join("|") + ")$", "i");
|
||||
}
|
||||
|
||||
|
||||
|
||||
var luaCustomFunctions= matchRegexp([]);
|
||||
|
||||
function configureLUA(parserConfig){
|
||||
if(parserConfig)
|
||||
luaCustomFunctions= matchRegexp(parserConfig);
|
||||
}
|
||||
|
||||
|
||||
//long list of standard functions from lua manual
|
||||
var luaStdFunctions = matchRegexp([
|
||||
"_G","_VERSION","assert","collectgarbage","dofile","error","getfenv","getmetatable","ipairs","load","loadfile","loadstring","module","next","pairs","pcall","print","rawequal","rawget","rawset","require","select","setfenv","setmetatable","tonumber","tostring","type","unpack","xpcall",
|
||||
|
||||
"coroutine.create","coroutine.resume","coroutine.running","coroutine.status","coroutine.wrap","coroutine.yield",
|
||||
|
||||
"debug.debug","debug.getfenv","debug.gethook","debug.getinfo","debug.getlocal","debug.getmetatable","debug.getregistry","debug.getupvalue","debug.setfenv","debug.sethook","debug.setlocal","debug.setmetatable","debug.setupvalue","debug.traceback",
|
||||
|
||||
"close","flush","lines","read","seek","setvbuf","write",
|
||||
|
||||
"io.close","io.flush","io.input","io.lines","io.open","io.output","io.popen","io.read","io.stderr","io.stdin","io.stdout","io.tmpfile","io.type","io.write",
|
||||
|
||||
"math.abs","math.acos","math.asin","math.atan","math.atan2","math.ceil","math.cos","math.cosh","math.deg","math.exp","math.floor","math.fmod","math.frexp","math.huge","math.ldexp","math.log","math.log10","math.max","math.min","math.modf","math.pi","math.pow","math.rad","math.random","math.randomseed","math.sin","math.sinh","math.sqrt","math.tan","math.tanh",
|
||||
|
||||
"os.clock","os.date","os.difftime","os.execute","os.exit","os.getenv","os.remove","os.rename","os.setlocale","os.time","os.tmpname",
|
||||
|
||||
"package.cpath","package.loaded","package.loaders","package.loadlib","package.path","package.preload","package.seeall",
|
||||
|
||||
"string.byte","string.char","string.dump","string.find","string.format","string.gmatch","string.gsub","string.len","string.lower","string.match","string.rep","string.reverse","string.sub","string.upper",
|
||||
|
||||
"table.concat","table.insert","table.maxn","table.remove","table.sort"
|
||||
]);
|
||||
|
||||
|
||||
|
||||
var luaKeywords = matchRegexp(["and","break","elseif","false","nil","not","or","return",
|
||||
"true","function", "end", "if", "then", "else", "do",
|
||||
"while", "repeat", "until", "for", "in", "local" ]);
|
||||
|
||||
var luaIndentKeys = matchRegexp(["function", "if","repeat","for","while", "[\(]", "{"]);
|
||||
var luaUnindentKeys = matchRegexp(["end", "until", "[\)]", "}"]);
|
||||
|
||||
var luaUnindentKeys2 = findFirstRegexp(["end", "until", "[\)]", "}"]);
|
||||
var luaMiddleKeys = findFirstRegexp(["else","elseif"]);
|
||||
|
||||
|
||||
|
||||
var LUAParser = Editor.Parser = (function() {
|
||||
var tokenizeLUA = (function() {
|
||||
function normal(source, setState) {
|
||||
var ch = source.next();
|
||||
|
||||
if (ch == "-" && source.equals("-")) {
|
||||
source.next();
|
||||
setState(inSLComment);
|
||||
return null;
|
||||
}
|
||||
else if (ch == "\"" || ch == "'") {
|
||||
setState(inString(ch));
|
||||
return null;
|
||||
}
|
||||
if (ch == "[" && (source.equals("[") || source.equals("="))) {
|
||||
var level = 0;
|
||||
while(source.equals("=")){
|
||||
level ++;
|
||||
source.next();
|
||||
}
|
||||
if(! source.equals("[") )
|
||||
return "lua-error";
|
||||
setState(inMLSomething(level,"lua-string"));
|
||||
return null;
|
||||
}
|
||||
|
||||
else if (ch == "=") {
|
||||
if (source.equals("="))
|
||||
source.next();
|
||||
return "lua-token";
|
||||
}
|
||||
|
||||
else if (ch == ".") {
|
||||
if (source.equals("."))
|
||||
source.next();
|
||||
if (source.equals("."))
|
||||
source.next();
|
||||
return "lua-token";
|
||||
}
|
||||
|
||||
else if (ch == "+" || ch == "-" || ch == "*" || ch == "/" || ch == "%" || ch == "^" || ch == "#" ) {
|
||||
return "lua-token";
|
||||
}
|
||||
else if (ch == ">" || ch == "<" || ch == "(" || ch == ")" || ch == "{" || ch == "}" || ch == "[" ) {
|
||||
return "lua-token";
|
||||
}
|
||||
else if (ch == "]" || ch == ";" || ch == ":" || ch == ",") {
|
||||
return "lua-token";
|
||||
}
|
||||
else if (source.equals("=") && (ch == "~" || ch == "<" || ch == ">")) {
|
||||
source.next();
|
||||
return "lua-token";
|
||||
}
|
||||
|
||||
else if (/\d/.test(ch)) {
|
||||
source.nextWhileMatches(/[\w.%]/);
|
||||
return "lua-number";
|
||||
}
|
||||
else {
|
||||
source.nextWhileMatches(/[\w\\\-_.]/);
|
||||
return "lua-identifier";
|
||||
}
|
||||
}
|
||||
|
||||
function inSLComment(source, setState) {
|
||||
var start = true;
|
||||
var count=0;
|
||||
while (!source.endOfLine()) {
|
||||
var ch = source.next();
|
||||
var level = 0;
|
||||
if ((ch =="[") && start){
|
||||
while(source.equals("=")){
|
||||
source.next();
|
||||
level++;
|
||||
}
|
||||
if (source.equals("[")){
|
||||
setState(inMLSomething(level,"lua-comment"));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
start = false;
|
||||
}
|
||||
setState(normal);
|
||||
return "lua-comment";
|
||||
|
||||
}
|
||||
|
||||
function inMLSomething(level,what) {
|
||||
//wat sholud be "lua-string" or "lua-comment", level is the number of "=" in opening mark.
|
||||
return function(source, setState){
|
||||
var dashes = 0;
|
||||
while (!source.endOfLine()) {
|
||||
var ch = source.next();
|
||||
if (dashes == level+1 && ch == "]" ) {
|
||||
setState(normal);
|
||||
break;
|
||||
}
|
||||
if (dashes == 0)
|
||||
dashes = (ch == "]") ? 1:0;
|
||||
else
|
||||
dashes = (ch == "=") ? dashes + 1 : 0;
|
||||
}
|
||||
return what;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function inString(quote) {
|
||||
return function(source, setState) {
|
||||
var escaped = false;
|
||||
while (!source.endOfLine()) {
|
||||
var ch = source.next();
|
||||
if (ch == quote && !escaped)
|
||||
break;
|
||||
escaped = !escaped && ch == "\\";
|
||||
}
|
||||
if (!escaped)
|
||||
setState(normal);
|
||||
return "lua-string";
|
||||
};
|
||||
}
|
||||
|
||||
return function(source, startState) {
|
||||
return tokenizer(source, startState || normal);
|
||||
};
|
||||
})();
|
||||
|
||||
function indentLUA(indentDepth, base) {
|
||||
return function(nextChars) {
|
||||
|
||||
var closing = (luaUnindentKeys2.test(nextChars) || luaMiddleKeys.test(nextChars));
|
||||
|
||||
|
||||
return base + ( indentUnit * (indentDepth - (closing?1:0)) );
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
function parseLUA(source,basecolumn) {
|
||||
basecolumn = basecolumn || 0;
|
||||
|
||||
var tokens = tokenizeLUA(source);
|
||||
var indentDepth = 0;
|
||||
|
||||
var iter = {
|
||||
next: function() {
|
||||
var token = tokens.next(), style = token.style, content = token.content;
|
||||
|
||||
|
||||
|
||||
if (style == "lua-identifier" && luaKeywords.test(content)){
|
||||
token.style = "lua-keyword";
|
||||
}
|
||||
if (style == "lua-identifier" && luaStdFunctions.test(content)){
|
||||
token.style = "lua-stdfunc";
|
||||
}
|
||||
if (style == "lua-identifier" && luaCustomFunctions.test(content)){
|
||||
token.style = "lua-customfunc";
|
||||
}
|
||||
|
||||
if (luaIndentKeys.test(content))
|
||||
indentDepth++;
|
||||
else if (luaUnindentKeys.test(content))
|
||||
indentDepth--;
|
||||
|
||||
|
||||
if (content == "\n")
|
||||
token.indentation = indentLUA( indentDepth, basecolumn);
|
||||
|
||||
return token;
|
||||
},
|
||||
|
||||
copy: function() {
|
||||
var _tokenState = tokens.state, _indentDepth = indentDepth;
|
||||
return function(source) {
|
||||
tokens = tokenizeLUA(source, _tokenState);
|
||||
|
||||
indentDepth = _indentDepth;
|
||||
return iter;
|
||||
};
|
||||
}
|
||||
};
|
||||
return iter;
|
||||
}
|
||||
|
||||
return {make: parseLUA, configure:configureLUA, electricChars: "delf})"}; //en[d] els[e] unti[l] elsei[f] // this should be taken from Keys keywords
|
||||
})();
|
||||
|
||||
23
gulliver/js/codemirror/contrib/ometa/LICENSE
Executable file
23
gulliver/js/codemirror/contrib/ometa/LICENSE
Executable file
@@ -0,0 +1,23 @@
|
||||
Copyright (c) 2007-2009 Marijn Haverbeke
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any
|
||||
damages arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any
|
||||
purpose, including commercial applications, and to alter it and
|
||||
redistribute it freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must
|
||||
not claim that you wrote the original software. If you use this
|
||||
software in a product, an acknowledgment in the product
|
||||
documentation would be appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must
|
||||
not be misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source
|
||||
distribution.
|
||||
|
||||
Marijn Haverbeke
|
||||
marijnh at gmail
|
||||
63
gulliver/js/codemirror/contrib/ometa/css/ometacolors.css
Executable file
63
gulliver/js/codemirror/contrib/ometa/css/ometacolors.css
Executable file
@@ -0,0 +1,63 @@
|
||||
html {
|
||||
cursor: text;
|
||||
}
|
||||
|
||||
.editbox {
|
||||
margin: .4em;
|
||||
padding: 0;
|
||||
font-family: monospace;
|
||||
font-size: 10pt;
|
||||
color: black;
|
||||
}
|
||||
|
||||
pre.code, .editbox {
|
||||
color: #666666;
|
||||
}
|
||||
|
||||
.editbox p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
span.js-punctuation {
|
||||
color: #666666;
|
||||
}
|
||||
|
||||
span.js-operator {
|
||||
color: #E1570F;
|
||||
}
|
||||
|
||||
span.js-keyword {
|
||||
color: #770088;
|
||||
}
|
||||
|
||||
span.js-atom {
|
||||
color: #228811;
|
||||
}
|
||||
|
||||
span.js-variable {
|
||||
color: black;
|
||||
}
|
||||
|
||||
span.js-variabledef {
|
||||
color: #0000FF;
|
||||
}
|
||||
|
||||
span.js-localvariable {
|
||||
color: #004499;
|
||||
}
|
||||
|
||||
span.js-property {
|
||||
color: black;
|
||||
}
|
||||
|
||||
span.js-comment {
|
||||
color: #AA7700;
|
||||
}
|
||||
|
||||
span.js-string {
|
||||
color: #AA2222;
|
||||
}
|
||||
|
||||
span.ometa-binding {
|
||||
color: #FF0000;
|
||||
}
|
||||
77
gulliver/js/codemirror/contrib/ometa/index.html
Executable file
77
gulliver/js/codemirror/contrib/ometa/index.html
Executable file
@@ -0,0 +1,77 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<script src="../../js/codemirror.js" type="text/javascript"></script>
|
||||
<title>CodeMirror: OmetaJS demonstration</title>
|
||||
<link rel="stylesheet" type="text/css" href="../../css/docs.css"/>
|
||||
</head>
|
||||
<body style="padding: 20px;">
|
||||
|
||||
<p>This page demonstrates <a href="../../index.html">CodeMirror</a>'s <a
|
||||
href="http://www.tinlizzie.org/ometa">OmetaJS</a> parser.</p>
|
||||
|
||||
<p>Adapted from the official Javascript parser by Eric KEDJI
|
||||
<<a href="mailto:eric.kedji@gmail.com">eric.kedji@gmail.com</a>>.</p>
|
||||
|
||||
<div style="border-top: 1px solid black; border-bottom: 1px solid black;">
|
||||
<textarea id="code" cols="120" rows="30">
|
||||
// Source: http://www.tinlizzie.org/ometa-js/#Lisp
|
||||
// Inspired by McCarthy's meta-circular lisp
|
||||
|
||||
ometa Lisp {
|
||||
ev = string:a -> self.env[a]
|
||||
| [#lambda :fs :body] -> [#lambda, fs, body]
|
||||
| [#quote :ans] -> ans
|
||||
| [#cond evCond:ans] -> ans
|
||||
| [ev:f ev*:xs] app(f, xs):ans -> ans,
|
||||
|
||||
evCond = condF* condT:ans anything* -> x,
|
||||
condT = [ev:x ?x ev:ans] -> ans,
|
||||
condF = ~condT anything,
|
||||
|
||||
app = #car [[:hd anything*]] -> hd
|
||||
| #cdr [[:hd anything*:tl]] -> tl
|
||||
| #cons [:hd :tl] -> [hd].concat(tl)
|
||||
| #atom [:x] -> (!(x instanceof Array))
|
||||
| #eq [:x :y] -> (x == y)
|
||||
| [#lambda :fs :body] :args
|
||||
enter bind(fs, args) ev(body):ans leave -> ans,
|
||||
enter = -> (self.env = self.env.delegated({_p: self.env})),
|
||||
bind = [] []
|
||||
| [:f anything*:fs] [:a anything*:as] bind(fs, as) -> (self.env[f] = a),
|
||||
leave = -> (self.env = self.env._p)
|
||||
}
|
||||
Lisp.initialize = function() { this.env = {car: "car", cdr: "cdr", cons: "cons", atom: "atom", eq: "eq", nil: null, T: "T"} }
|
||||
lispEval = function(x) { return Lisp.match(x, "ev") }
|
||||
|
||||
lispEval([`quote, [1, 2, 3]])
|
||||
lispEval([`car, [`quote, [1, 2, 3]]])
|
||||
lispEval([`cdr, [`quote, [1, 2, 3]]])
|
||||
lispEval([`cons, [`quote, `x], [`quote, `y]])
|
||||
lispEval([`eq, [`quote, `x], [`quote, `x]])
|
||||
lispEval([[`lambda, [`x], [`cons, `x, `x]], [`quote, `boo]])
|
||||
</textarea>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
/* var textarea = document.getElementById('code');
|
||||
var editor = new MirrorFrame(CodeMirror.replace(textarea), {
|
||||
height: "350px",
|
||||
content: textarea.value,
|
||||
parserfile: ["tokenizeometa.js", "parseometa.js"],
|
||||
stylesheet: "css/ometacolors.css",
|
||||
path: "js/",
|
||||
autoMatchParens: true
|
||||
});
|
||||
*/
|
||||
var editor = CodeMirror.fromTextArea('code', {
|
||||
height: "450px",
|
||||
parserfile: ["../contrib/ometa/js/tokenizeometa.js",
|
||||
"../contrib/ometa/js/parseometa.js"],
|
||||
stylesheet: "css/ometacolors.css",
|
||||
path: "../../js/",
|
||||
textWrapping: false
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
364
gulliver/js/codemirror/contrib/ometa/js/parseometa.js
Executable file
364
gulliver/js/codemirror/contrib/ometa/js/parseometa.js
Executable file
@@ -0,0 +1,364 @@
|
||||
/* Parse function for JavaScript. Makes use of the tokenizer from
|
||||
* tokenizejavascript.js. Note that your parsers do not have to be
|
||||
* this complicated -- if you don't want to recognize local variables,
|
||||
* in many languages it is enough to just look for braces, semicolons,
|
||||
* parentheses, etc, and know when you are inside a string or comment.
|
||||
*
|
||||
* See manual.html for more info about the parser interface.
|
||||
*/
|
||||
|
||||
var JSParser = Editor.Parser = (function() {
|
||||
// Token types that can be considered to be atoms.
|
||||
var atomicTypes = {"atom": true, "number": true, "variable": true, "string": true, "regexp": true};
|
||||
// Setting that can be used to have JSON data indent properly.
|
||||
var json = false;
|
||||
// Constructor for the lexical context objects.
|
||||
function JSLexical(indented, column, type, align, prev, info) {
|
||||
// indentation at start of this line
|
||||
this.indented = indented;
|
||||
// column at which this scope was opened
|
||||
this.column = column;
|
||||
// type of scope ('vardef', 'stat' (statement), 'form' (special form), '[', '{', or '(')
|
||||
this.type = type;
|
||||
// '[', '{', or '(' blocks that have any text after their opening
|
||||
// character are said to be 'aligned' -- any lines below are
|
||||
// indented all the way to the opening character.
|
||||
if (align != null)
|
||||
this.align = align;
|
||||
// Parent scope, if any.
|
||||
this.prev = prev;
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
// My favourite JavaScript indentation rules.
|
||||
function indentJS(lexical) {
|
||||
return function(firstChars) {
|
||||
var firstChar = firstChars && firstChars.charAt(0), type = lexical.type;
|
||||
var closing = firstChar == type;
|
||||
if (type == "vardef")
|
||||
return lexical.indented + 4;
|
||||
else if (type == "form" && firstChar == "{")
|
||||
return lexical.indented;
|
||||
else if (type == "stat" || type == "form")
|
||||
return lexical.indented + indentUnit;
|
||||
else if (lexical.info == "switch" && !closing)
|
||||
return lexical.indented + (/^(?:case|default)\b/.test(firstChars) ? indentUnit : 2 * indentUnit);
|
||||
else if (lexical.align)
|
||||
return lexical.column - (closing ? 1 : 0);
|
||||
else
|
||||
return lexical.indented + (closing ? 0 : indentUnit);
|
||||
};
|
||||
}
|
||||
|
||||
// The parser-iterator-producing function itself.
|
||||
function parseJS(input, basecolumn) {
|
||||
// Wrap the input in a token stream
|
||||
var tokens = tokenizeJavaScript(input);
|
||||
// The parser state. cc is a stack of actions that have to be
|
||||
// performed to finish the current statement. For example we might
|
||||
// know that we still need to find a closing parenthesis and a
|
||||
// semicolon. Actions at the end of the stack go first. It is
|
||||
// initialized with an infinitely looping action that consumes
|
||||
// whole statements.
|
||||
var cc = [json ? expressions : statements];
|
||||
// Context contains information about the current local scope, the
|
||||
// variables defined in that, and the scopes above it.
|
||||
var context = null;
|
||||
// The lexical scope, used mostly for indentation.
|
||||
var lexical = new JSLexical((basecolumn || 0) - indentUnit, 0, "block", false);
|
||||
// Current column, and the indentation at the start of the current
|
||||
// line. Used to create lexical scope objects.
|
||||
var column = 0;
|
||||
var indented = 0;
|
||||
// Variables which are used by the mark, cont, and pass functions
|
||||
// below to communicate with the driver loop in the 'next'
|
||||
// function.
|
||||
var consume, marked;
|
||||
|
||||
// The iterator object.
|
||||
var parser = {next: next, copy: copy};
|
||||
|
||||
function next(){
|
||||
// Start by performing any 'lexical' actions (adjusting the
|
||||
// lexical variable), or the operations below will be working
|
||||
// with the wrong lexical state.
|
||||
while(cc[cc.length - 1].lex)
|
||||
cc.pop()();
|
||||
|
||||
// Fetch a token.
|
||||
var token = tokens.next();
|
||||
|
||||
// Adjust column and indented.
|
||||
if (token.type == "whitespace" && column == 0)
|
||||
indented = token.value.length;
|
||||
column += token.value.length;
|
||||
if (token.content == "\n"){
|
||||
indented = column = 0;
|
||||
// If the lexical scope's align property is still undefined at
|
||||
// the end of the line, it is an un-aligned scope.
|
||||
if (!("align" in lexical))
|
||||
lexical.align = false;
|
||||
// Newline tokens get an indentation function associated with
|
||||
// them.
|
||||
token.indentation = indentJS(lexical);
|
||||
// special handling for multiline strings: keep everything in the first
|
||||
// column, as spaces at the start of a multiline string are significant
|
||||
if (lexical.info == "multilineString") {
|
||||
lexical.align = false;
|
||||
token.indentation = function () { return 0; };
|
||||
}
|
||||
}
|
||||
// No more processing for meaningless tokens.
|
||||
if (token.type == "whitespace" || token.type == "comment")
|
||||
return token;
|
||||
// Take note when a multiline string is found, so as to
|
||||
// correctly handle indentation at the end of the line
|
||||
// (see above, line 95)
|
||||
if (token.type == "multilineString")
|
||||
lexical.info = 'multilineString';
|
||||
// When a meaningful token is found and the lexical scope's
|
||||
// align is undefined, it is an aligned scope.
|
||||
if (!("align" in lexical))
|
||||
lexical.align = true;
|
||||
|
||||
// Execute actions until one 'consumes' the token and we can
|
||||
// return it.
|
||||
while(true) {
|
||||
consume = marked = false;
|
||||
// Take and execute the topmost action.
|
||||
cc.pop()(token.type, token.content);
|
||||
if (consume){
|
||||
// Marked is used to change the style of the current token.
|
||||
if (marked)
|
||||
token.style = marked;
|
||||
// Here we differentiate between local and global variables.
|
||||
else if (token.type == "variable" && inScope(token.content))
|
||||
token.style = "js-localvariable";
|
||||
return token;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This makes a copy of the parser state. It stores all the
|
||||
// stateful variables in a closure, and returns a function that
|
||||
// will restore them when called with a new input stream. Note
|
||||
// that the cc array has to be copied, because it is contantly
|
||||
// being modified. Lexical objects are not mutated, and context
|
||||
// objects are not mutated in a harmful way, so they can be shared
|
||||
// between runs of the parser.
|
||||
function copy(){
|
||||
var _context = context, _lexical = lexical, _cc = cc.concat([]), _tokenState = tokens.state;
|
||||
|
||||
return function copyParser(input){
|
||||
context = _context;
|
||||
lexical = _lexical;
|
||||
cc = _cc.concat([]); // copies the array
|
||||
column = indented = 0;
|
||||
tokens = tokenizeJavaScript(input, _tokenState);
|
||||
return parser;
|
||||
};
|
||||
}
|
||||
|
||||
// Helper function for pushing a number of actions onto the cc
|
||||
// stack in reverse order.
|
||||
function push(fs){
|
||||
for (var i = fs.length - 1; i >= 0; i--)
|
||||
cc.push(fs[i]);
|
||||
}
|
||||
// cont and pass are used by the action functions to add other
|
||||
// actions to the stack. cont will cause the current token to be
|
||||
// consumed, pass will leave it for the next action.
|
||||
function cont(){
|
||||
push(arguments);
|
||||
consume = true;
|
||||
}
|
||||
function pass(){
|
||||
push(arguments);
|
||||
consume = false;
|
||||
}
|
||||
// Used to change the style of the current token.
|
||||
function mark(style){
|
||||
marked = style;
|
||||
}
|
||||
|
||||
// Push a new scope. Will automatically link the current scope.
|
||||
function pushcontext(){
|
||||
context = {prev: context, vars: {"this": true, "arguments": true}};
|
||||
}
|
||||
// Pop off the current scope.
|
||||
function popcontext(){
|
||||
context = context.prev;
|
||||
}
|
||||
// Register a variable in the current scope.
|
||||
function register(varname){
|
||||
if (context){
|
||||
mark("js-variabledef");
|
||||
context.vars[varname] = true;
|
||||
}
|
||||
}
|
||||
// Check whether a variable is defined in the current scope.
|
||||
function inScope(varname){
|
||||
var cursor = context;
|
||||
while (cursor) {
|
||||
if (cursor.vars[varname])
|
||||
return true;
|
||||
cursor = cursor.prev;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Push a new lexical context of the given type.
|
||||
function pushlex(type, info) {
|
||||
var result = function(){
|
||||
lexical = new JSLexical(indented, column, type, null, lexical, info)
|
||||
};
|
||||
result.lex = true;
|
||||
return result;
|
||||
}
|
||||
// Pop off the current lexical context.
|
||||
function poplex(){
|
||||
lexical = lexical.prev;
|
||||
}
|
||||
poplex.lex = true;
|
||||
// The 'lex' flag on these actions is used by the 'next' function
|
||||
// to know they can (and have to) be ran before moving on to the
|
||||
// next token.
|
||||
|
||||
// Creates an action that discards tokens until it finds one of
|
||||
// the given type.
|
||||
function expect(wanted){
|
||||
return function expecting(type){
|
||||
if (type == wanted) cont();
|
||||
else cont(arguments.callee);
|
||||
};
|
||||
}
|
||||
|
||||
// Looks for a statement, and then calls itself.
|
||||
function statements(type){
|
||||
return pass(statement, statements);
|
||||
}
|
||||
function expressions(type){
|
||||
return pass(expression, expressions);
|
||||
}
|
||||
// Dispatches various types of statements based on the type of the
|
||||
// current token.
|
||||
function statement(type){
|
||||
if (type == "var") cont(pushlex("vardef"), vardef1, expect(";"), poplex);
|
||||
else if (type == "keyword a") cont(pushlex("form"), expression, statement, poplex);
|
||||
else if (type == "keyword b") cont(pushlex("form"), statement, poplex);
|
||||
else if (type == "{") cont(pushlex("}"), block, poplex);
|
||||
else if (type == "function") cont(functiondef);
|
||||
else if (type == "for") cont(pushlex("form"), expect("("), pushlex(")"), forspec1, expect(")"), poplex, statement, poplex);
|
||||
else if (type == "variable") cont(pushlex("stat"), maybelabel);
|
||||
else if (type == "switch") cont(pushlex("form"), expression, pushlex("}", "switch"), expect("{"), block, poplex, poplex);
|
||||
else if (type == "case") cont(expression, expect(":"));
|
||||
else if (type == "default") cont(expect(":"));
|
||||
else if (type == "catch") cont(pushlex("form"), pushcontext, expect("("), funarg, expect(")"), statement, poplex, popcontext);
|
||||
else pass(pushlex("stat"), expression, expect(";"), poplex);
|
||||
}
|
||||
// Dispatch expression types.
|
||||
function expression(type){
|
||||
if (atomicTypes.hasOwnProperty(type)) cont(maybeoperator);
|
||||
else if (type == "function") cont(functiondef);
|
||||
else if (type == "keyword c") cont(expression);
|
||||
else if (type == "(") cont(pushlex(")"), expression, expect(")"), poplex, maybeoperator);
|
||||
else if (type == "operator") cont(expression);
|
||||
else if (type == "[") cont(pushlex("]"), commasep(expression, "]"), poplex, maybeoperator);
|
||||
else if (type == "{") cont(pushlex("}"), commasep(objprop, "}"), poplex, maybeoperator);
|
||||
else cont();
|
||||
}
|
||||
// Called for places where operators, function calls, or
|
||||
// subscripts are valid. Will skip on to the next action if none
|
||||
// is found.
|
||||
function maybeoperator(type){
|
||||
if (type == "operator") cont(expression);
|
||||
else if (type == "(") cont(pushlex(")"), commasep(expression, ")"), poplex, maybeoperator);
|
||||
else if (type == ".") cont(property, maybeoperator);
|
||||
else if (type == "[") cont(pushlex("]"), expression, expect("]"), poplex, maybeoperator);
|
||||
}
|
||||
// When a statement starts with a variable name, it might be a
|
||||
// label. If no colon follows, it's a regular statement.
|
||||
function maybelabel(type){
|
||||
if (type == ":") cont(poplex, statement);
|
||||
else pass(maybeoperator, expect(";"), poplex);
|
||||
}
|
||||
// Property names need to have their style adjusted -- the
|
||||
// tokenizer thinks they are variables.
|
||||
function property(type){
|
||||
if (type == "variable") {mark("js-property"); cont();}
|
||||
}
|
||||
// This parses a property and its value in an object literal.
|
||||
function objprop(type){
|
||||
if (type == "variable") mark("js-property");
|
||||
if (atomicTypes.hasOwnProperty(type)) cont(expect(":"), expression);
|
||||
}
|
||||
// Parses a comma-separated list of the things that are recognized
|
||||
// by the 'what' argument.
|
||||
function commasep(what, end){
|
||||
function proceed(type) {
|
||||
if (type == ",") cont(what, proceed);
|
||||
else if (type == end) cont();
|
||||
else cont(expect(end));
|
||||
}
|
||||
return function commaSeparated(type) {
|
||||
if (type == end) cont();
|
||||
else pass(what, proceed);
|
||||
};
|
||||
}
|
||||
// Look for statements until a closing brace is found.
|
||||
function block(type){
|
||||
if (type == "}") cont();
|
||||
else pass(statement, block);
|
||||
}
|
||||
// Variable definitions are split into two actions -- 1 looks for
|
||||
// a name or the end of the definition, 2 looks for an '=' sign or
|
||||
// a comma.
|
||||
function vardef1(type, value){
|
||||
if (type == "variable"){register(value); cont(vardef2);}
|
||||
else cont();
|
||||
}
|
||||
function vardef2(type, value){
|
||||
if (value == "=") cont(expression, vardef2);
|
||||
else if (type == ",") cont(vardef1);
|
||||
}
|
||||
// For loops.
|
||||
function forspec1(type){
|
||||
if (type == "var") cont(vardef1, forspec2);
|
||||
else if (type == ";") pass(forspec2);
|
||||
else if (type == "variable") cont(formaybein);
|
||||
else pass(forspec2);
|
||||
}
|
||||
function formaybein(type, value){
|
||||
if (value == "in") cont(expression);
|
||||
else cont(maybeoperator, forspec2);
|
||||
}
|
||||
function forspec2(type, value){
|
||||
if (type == ";") cont(forspec3);
|
||||
else if (value == "in") cont(expression);
|
||||
else cont(expression, expect(";"), forspec3);
|
||||
}
|
||||
function forspec3(type) {
|
||||
if (type == ")") pass();
|
||||
else cont(expression);
|
||||
}
|
||||
// A function definition creates a new context, and the variables
|
||||
// in its argument list have to be added to this context.
|
||||
function functiondef(type, value){
|
||||
if (type == "variable"){register(value); cont(functiondef);}
|
||||
else if (type == "(") cont(pushcontext, commasep(funarg, ")"), statement, popcontext);
|
||||
}
|
||||
function funarg(type, value){
|
||||
if (type == "variable"){register(value); cont();}
|
||||
}
|
||||
|
||||
return parser;
|
||||
}
|
||||
|
||||
return {
|
||||
make: parseJS,
|
||||
electricChars: "{}:",
|
||||
configure: function(obj) {
|
||||
if (obj.json != null) json = obj.json;
|
||||
}
|
||||
};
|
||||
})();
|
||||
209
gulliver/js/codemirror/contrib/ometa/js/tokenizeometa.js
Executable file
209
gulliver/js/codemirror/contrib/ometa/js/tokenizeometa.js
Executable file
@@ -0,0 +1,209 @@
|
||||
/* Tokenizer for JavaScript code */
|
||||
|
||||
var tokenizeJavaScript = (function() {
|
||||
// Advance the stream until the given character (not preceded by a
|
||||
// backslash) is encountered, or the end of the line is reached.
|
||||
function nextUntilUnescaped(source, end) {
|
||||
var escaped = false;
|
||||
while (!source.endOfLine()) {
|
||||
var next = source.next();
|
||||
if (next == end && !escaped)
|
||||
return false;
|
||||
escaped = !escaped && next == "\\";
|
||||
}
|
||||
return escaped;
|
||||
}
|
||||
|
||||
// A map of JavaScript's keywords. The a/b/c keyword distinction is
|
||||
// very rough, but it gives the parser enough information to parse
|
||||
// correct code correctly (we don't care that much how we parse
|
||||
// incorrect code). The style information included in these objects
|
||||
// is used by the highlighter to pick the correct CSS style for a
|
||||
// token.
|
||||
var keywords = function(){
|
||||
function result(type, style){
|
||||
return {type: type, style: "js-" + style};
|
||||
}
|
||||
// keywords that take a parenthised expression, and then a
|
||||
// statement (if)
|
||||
var keywordA = result("keyword a", "keyword");
|
||||
// keywords that take just a statement (else)
|
||||
var keywordB = result("keyword b", "keyword");
|
||||
// keywords that optionally take an expression, and form a
|
||||
// statement (return)
|
||||
var keywordC = result("keyword c", "keyword");
|
||||
var operator = result("operator", "keyword");
|
||||
var atom = result("atom", "atom");
|
||||
return {
|
||||
"if": keywordA, "while": keywordA, "with": keywordA,
|
||||
"else": keywordB, "do": keywordB, "try": keywordB, "finally": keywordB,
|
||||
"return": keywordC, "break": keywordC, "continue": keywordC, "new": keywordC, "delete": keywordC, "throw": keywordC,
|
||||
"in": operator, "typeof": operator, "instanceof": operator,
|
||||
"var": result("var", "keyword"), "function": result("function", "keyword"), "catch": result("catch", "keyword"),
|
||||
"for": result("for", "keyword"), "switch": result("switch", "keyword"),
|
||||
"case": result("case", "keyword"), "default": result("default", "keyword"),
|
||||
"true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom,
|
||||
"ometa": keywordB
|
||||
};
|
||||
}();
|
||||
|
||||
// Some helper regexps
|
||||
var isOperatorChar = /[+\-*&%=<>!?|~]/;
|
||||
var isHexDigit = /[0-9A-Fa-f]/;
|
||||
var isWordChar = /[\w\$_]/;
|
||||
|
||||
// Wrapper around jsToken that helps maintain parser state (whether
|
||||
// we are inside of a multi-line comment and whether the next token
|
||||
// could be a regular expression).
|
||||
function jsTokenState(inside, regexp) {
|
||||
return function(source, setState) {
|
||||
var newInside = inside;
|
||||
var type = jsToken(inside, regexp, source, function(c) {newInside = c;});
|
||||
var newRegexp = type.type == "operator" || type.type == "keyword c" || type.type.match(/^[\[{}\(,;:]$/);
|
||||
if (newRegexp != regexp || newInside != inside)
|
||||
setState(jsTokenState(newInside, newRegexp));
|
||||
return type;
|
||||
};
|
||||
}
|
||||
|
||||
// The token reader, intended to be used by the tokenizer from
|
||||
// tokenize.js (through jsTokenState). Advances the source stream
|
||||
// over a token, and returns an object containing the type and style
|
||||
// of that token.
|
||||
function jsToken(inside, regexp, source, setInside) {
|
||||
function readHexNumber(){
|
||||
source.next(); // skip the 'x'
|
||||
source.nextWhileMatches(isHexDigit);
|
||||
return {type: "number", style: "js-atom"};
|
||||
}
|
||||
|
||||
function readNumber() {
|
||||
source.nextWhileMatches(/[0-9]/);
|
||||
if (source.equals(".")){
|
||||
source.next();
|
||||
source.nextWhileMatches(/[0-9]/);
|
||||
}
|
||||
if (source.equals("e") || source.equals("E")){
|
||||
source.next();
|
||||
if (source.equals("-"))
|
||||
source.next();
|
||||
source.nextWhileMatches(/[0-9]/);
|
||||
}
|
||||
return {type: "number", style: "js-atom"};
|
||||
}
|
||||
// Read a word, look it up in keywords. If not found, it is a
|
||||
// variable, otherwise it is a keyword of the type found.
|
||||
function readWord() {
|
||||
source.nextWhileMatches(isWordChar);
|
||||
var word = source.get();
|
||||
var known = keywords.hasOwnProperty(word) && keywords.propertyIsEnumerable(word) && keywords[word];
|
||||
return known ? {type: known.type, style: known.style, content: word} :
|
||||
{type: "variable", style: "js-variable", content: word};
|
||||
}
|
||||
function readRegexp() {
|
||||
nextUntilUnescaped(source, "/");
|
||||
source.nextWhileMatches(/[gi]/);
|
||||
return {type: "regexp", style: "js-string"};
|
||||
}
|
||||
// Mutli-line comments are tricky. We want to return the newlines
|
||||
// embedded in them as regular newline tokens, and then continue
|
||||
// returning a comment token for every line of the comment. So
|
||||
// some state has to be saved (inside) to indicate whether we are
|
||||
// inside a /* */ sequence.
|
||||
function readMultilineComment(start){
|
||||
var newInside = "/*";
|
||||
var maybeEnd = (start == "*");
|
||||
while (true) {
|
||||
if (source.endOfLine())
|
||||
break;
|
||||
var next = source.next();
|
||||
if (next == "/" && maybeEnd){
|
||||
newInside = null;
|
||||
break;
|
||||
}
|
||||
maybeEnd = (next == "*");
|
||||
}
|
||||
setInside(newInside);
|
||||
return {type: "comment", style: "js-comment"};
|
||||
}
|
||||
function readMultilineString(start, quotes) {
|
||||
var newInside = quotes;
|
||||
var quote = quotes.charAt(0);
|
||||
var maybeEnd = (start == quote);
|
||||
while (true) {
|
||||
if (source.endOfLine())
|
||||
break;
|
||||
var next = source.next();
|
||||
if (next == quote && source.peek() == quote && maybeEnd) {
|
||||
source.next();
|
||||
newInside = null;
|
||||
break;
|
||||
}
|
||||
maybeEnd = (next == quote);
|
||||
}
|
||||
setInside(newInside);
|
||||
return {type: "multilineString", style: "js-string"};
|
||||
}
|
||||
function readOperator() {
|
||||
source.nextWhileMatches(isOperatorChar);
|
||||
return {type: "operator", style: "js-operator"};
|
||||
}
|
||||
function readString(quote) {
|
||||
var endBackSlash = nextUntilUnescaped(source, quote);
|
||||
setInside(endBackSlash ? quote : null);
|
||||
return {type: "string", style: "js-string"};
|
||||
}
|
||||
function readOmetaIdentifierString() {
|
||||
source.nextWhileMatches(isWordChar);
|
||||
return {type: "string", style: "js-string"};
|
||||
}
|
||||
function readOmetaBinding() {
|
||||
source.nextWhileMatches(isWordChar);
|
||||
return {type: "variable", style: "ometa-binding"};
|
||||
}
|
||||
|
||||
// Fetch the next token. Dispatches on first character in the
|
||||
// stream, or first two characters when the first is a slash.
|
||||
if (inside == "\"" || inside == "'")
|
||||
return readString(inside);
|
||||
var ch = source.next();
|
||||
if (inside == "/*")
|
||||
return readMultilineComment(ch);
|
||||
if (inside == '"""' || inside == "'''")
|
||||
return readMultilineString(ch, inside);
|
||||
if (ch == '"' && source.lookAhead('""', true) || ch == "'" && source.lookAhead("''", true))
|
||||
return readMultilineString('-', ch+ch+ch); // work as far as '-' is not '"' nor "'"
|
||||
else if (ch == "\"" || ch == "'")
|
||||
return readString(ch);
|
||||
else if (ch == "`" || ch == "#" )
|
||||
return readOmetaIdentifierString();
|
||||
else if (ch == ':' && isWordChar.test(source.peek()))
|
||||
return readOmetaBinding();
|
||||
// with punctuation, the type of the token is the symbol itself
|
||||
else if (/[\[\]{}\(\),;\:\.]/.test(ch))
|
||||
return {type: ch, style: "js-punctuation"};
|
||||
else if (ch == "0" && (source.equals("x") || source.equals("X")))
|
||||
return readHexNumber();
|
||||
else if (/[0-9]/.test(ch))
|
||||
return readNumber();
|
||||
else if (ch == "/"){
|
||||
if (source.equals("*"))
|
||||
{ source.next(); return readMultilineComment(ch); }
|
||||
else if (source.equals("/"))
|
||||
{ nextUntilUnescaped(source, null); return {type: "comment", style: "js-comment"};}
|
||||
else if (regexp)
|
||||
return readRegexp();
|
||||
else
|
||||
return readOperator();
|
||||
}
|
||||
else if (isOperatorChar.test(ch))
|
||||
return readOperator();
|
||||
else
|
||||
return readWord();
|
||||
}
|
||||
|
||||
// The external interface to the tokenizer.
|
||||
return function(source, startState) {
|
||||
return tokenizer(source, startState || jsTokenState(false, true));
|
||||
};
|
||||
})();
|
||||
37
gulliver/js/codemirror/contrib/php/LICENSE
Executable file
37
gulliver/js/codemirror/contrib/php/LICENSE
Executable file
@@ -0,0 +1,37 @@
|
||||
Copyright (c) 2008-2009, Yahoo! Inc.
|
||||
All rights reserved.
|
||||
|
||||
This software is provided for use in connection with the
|
||||
CodeMirror suite of modules and utilities, hosted and maintained
|
||||
at http://codemirror.net/.
|
||||
|
||||
Redistribution and use of this software in source and binary forms,
|
||||
with or without modification, are permitted provided that the
|
||||
following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
* Neither the name of Yahoo! Inc. nor the names of its
|
||||
contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior
|
||||
written permission of Yahoo! Inc.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
114
gulliver/js/codemirror/contrib/php/css/phpcolors.css
Executable file
114
gulliver/js/codemirror/contrib/php/css/phpcolors.css
Executable file
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
Copyright (c) 2008-2009 Yahoo! Inc. All rights reserved.
|
||||
The copyrights embodied in the content of this file are licensed by
|
||||
Yahoo! Inc. under the BSD (revised) open source license
|
||||
|
||||
@author Dan Vlad Dascalescu <dandv@yahoo-inc.com>
|
||||
*/
|
||||
|
||||
html {
|
||||
cursor: text;
|
||||
}
|
||||
|
||||
.editbox {
|
||||
margin: .4em;
|
||||
padding: 0;
|
||||
font-family: monospace;
|
||||
font-size: 10pt;
|
||||
}
|
||||
|
||||
/*We should define specific styles for every element of the syntax.
|
||||
the setting below will cause some annoying color to show through if we missed
|
||||
defining a style for a token. This is also the "color" of the whitespace and
|
||||
of the cursor.
|
||||
*/
|
||||
pre.code, .editbox {
|
||||
color: red;
|
||||
}
|
||||
|
||||
.editbox p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
span.php-punctuation {
|
||||
color: blue;
|
||||
}
|
||||
|
||||
span.php-keyword {
|
||||
color: #770088;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
span.php-operator {
|
||||
color: blue;
|
||||
}
|
||||
|
||||
/* __FILE__ etc.; http://php.net/manual/en/reserved.php */
|
||||
span.php-compile-time-constant {
|
||||
color: #776088;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/* output of get_defined_constants(). Differs from http://php.net/manual/en/reserved.constants.php */
|
||||
span.php-predefined-constant {
|
||||
color: darkgreen;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/* PHP reserved "language constructs"... echo() etc.; http://php.net/manual/en/reserved.php */
|
||||
span.php-reserved-language-construct {
|
||||
color: green;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/* PHP built-in functions: glob(), chr() etc.; output of get_defined_functions()["internal"] */
|
||||
span.php-predefined-function {
|
||||
color: green;
|
||||
}
|
||||
|
||||
/* PHP predefined classes: PDO, Exception etc.; output of get_declared_classes() and different from http://php.net/manual/en/reserved.classes.php */
|
||||
span.php-predefined-class {
|
||||
color: green;
|
||||
}
|
||||
|
||||
span.php-atom {
|
||||
color: #228811;
|
||||
}
|
||||
|
||||
/* class, interface, namespace or function names, but not $variables */
|
||||
span.php-t_string {
|
||||
color: black;
|
||||
}
|
||||
|
||||
span.php-variable {
|
||||
color: black;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
|
||||
span.js-localvariable {
|
||||
color: #004499;
|
||||
}
|
||||
|
||||
span.php-comment {
|
||||
color: #AA7700;
|
||||
font-stretch: condensed;
|
||||
/* font-style: italic; This causes line height to slightly change, getting line numbers out of sync */
|
||||
}
|
||||
|
||||
span.php-string-single-quoted {
|
||||
color: #AA2222;
|
||||
}
|
||||
/* double quoted strings allow interpolation */
|
||||
span.php-string-double-quoted {
|
||||
color: #AA2222;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
span.syntax-error {
|
||||
background-color: red;
|
||||
}
|
||||
|
||||
span.deprecated {
|
||||
font-size: smaller;
|
||||
}
|
||||
310
gulliver/js/codemirror/contrib/php/index.html
Executable file
310
gulliver/js/codemirror/contrib/php/index.html
Executable file
@@ -0,0 +1,310 @@
|
||||
<!--
|
||||
Copyright (c) 2008-2009 Yahoo! Inc. All rights reserved.
|
||||
The copyrights embodied in the content of this file are licensed by
|
||||
Yahoo! Inc. under the BSD (revised) open source license
|
||||
|
||||
@author Dan Vlad Dascalescu <dandv@yahoo-inc.com>
|
||||
|
||||
-->
|
||||
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<script src="../../js/codemirror.js" type="text/javascript"></script>
|
||||
<title>CodeMirror: PHP+HTML+JavaScript+CSS mixed-mode demonstration</title>
|
||||
<link rel="stylesheet" type="text/css" href="../../css/docs.css"/>
|
||||
</head>
|
||||
<body style="padding: 20px;">
|
||||
|
||||
<p>This is a complex demonstration of the <b>PHP+HTML+JavaScript+CSS mixed-mode
|
||||
syntax highlight</b> capabilities of <a href="../../index.html">CodeMirror</a>.
|
||||
<?php ... ?> tags use the PHP parser, <script> tags use the JavaScript
|
||||
parser, and <style> tags use the CSS parser. The rest of the content is
|
||||
parsed using the XML parser in HTML mode.</p>
|
||||
|
||||
<p>Features of the PHP parser:
|
||||
<ul>
|
||||
<li>special "deprecated" style for PHP4 keywords like 'var'
|
||||
<li>support for PHP 5.3 keywords: 'namespace', 'use'
|
||||
<li>911 predefined constants, 1301 predefined functions, 105 predeclared classes
|
||||
from a typical PHP installation in a LAMP environment
|
||||
<li>new feature: syntax error flagging, thus enabling strict parsing of:
|
||||
<ol>
|
||||
<li>function definitions with explicitly or implicitly typed arguments and default values
|
||||
<li>modifiers (public, static etc.) applied to method and member definitions
|
||||
<li>foreach(array_expression as $key [=> $value]) loops
|
||||
</ol>
|
||||
<li>differentiation between single-quoted strings and double-quoted interpolating strings
|
||||
</ul>
|
||||
|
||||
<div style="border: 1px solid black; padding: 3px; background-color: #F8F8F8">
|
||||
<textarea id="code" cols="120" rows="30">
|
||||
The "root" parser is XML in HTML mode.
|
||||
Next, we can switch into PHP mode, for example. This is
|
||||
<?php echo 'text output by';
|
||||
?>
|
||||
PHP. </b>
|
||||
On the line above, we just had an XML syntax error due to the </b> tag not being opened.
|
||||
|
||||
<?xml version='1.0' encoding='UTF-8' standalone='yes'?> HTML text will follow
|
||||
<html>
|
||||
<head>
|
||||
<title>Similarly, the 'script' tag will switch to the JavaScript parser:</title>
|
||||
<script type="text/javascript">
|
||||
// Press enter inside the object and your new line will be suitably
|
||||
// indented.
|
||||
var keyBindings = {
|
||||
enter: "newline-and-indent",
|
||||
tab: "reindent-selection",
|
||||
ctrl_enter: "reparse-buffer",
|
||||
ctrl_z: "undo",
|
||||
ctrl_y: "redo",
|
||||
ctrl_backspace: "undo-for-safari-which-stupidly-enough-blocks-ctrl-z"
|
||||
};
|
||||
|
||||
// Press tab on the next line and the wrong indentation will be fixed.
|
||||
var regex = /foo|bar/i;
|
||||
|
||||
function example(x) {
|
||||
// Local variables get a different colour than global ones.
|
||||
var y = 44.4;
|
||||
return x + y - z;
|
||||
}
|
||||
</script>
|
||||
<style>
|
||||
/* Some example CSS */
|
||||
|
||||
@import url("something.css");
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 3em 6em;
|
||||
font-family: tahoma, arial, sans-serif;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
#navigation a {
|
||||
font-weight: bold;
|
||||
text-decoration: none !important;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 2.5em;
|
||||
}
|
||||
|
||||
h1:before, h2:before {
|
||||
content: "::";
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: courier, monospace;
|
||||
font-size: 80%;
|
||||
color: #418A8A;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
The PHP code below contains some deliberate errors. Play with the editor by fixing them
|
||||
and observing how the highlight changes.
|
||||
|
||||
<?php
|
||||
namespace A;
|
||||
namespace A::B::C;
|
||||
namespace A::::B;
|
||||
namespace A::B::C::;
|
||||
namespace A::B::C::D x;
|
||||
self::range($row['lft'], $row['rgt'])); // error: extra ')'
|
||||
$a = (b() + 4) 5 foo; // error: missing operators
|
||||
self::$var;
|
||||
$parent = self::range($max + 1, $max + 1);
|
||||
$row[attributes][$attribute_name] = $attribute_value;
|
||||
$row[attributes()][$attribute_name] = $attribute_value;
|
||||
$row[attributes(5)][$attribute_name] = $attribute_value;
|
||||
$row[$attributes()][$attribute_name] = $attribute_value;
|
||||
abstract class 5 extends foo implements echo {
|
||||
private function domainObjectBuilder() {
|
||||
return $this->use_domain_object_builder
|
||||
? $this->domain()->objectBuilder()
|
||||
: null;
|
||||
}
|
||||
|
||||
const $myconst = 'some string';
|
||||
$array[myconst] = 4;
|
||||
// this is a single-line C++-style comment
|
||||
# this is a single-line shell-style comment
|
||||
private var $a = __FILE__;
|
||||
protected static $b = timezone_transitions_get('some parameter here');
|
||||
global $g = isset("string");
|
||||
static $s = hash_update_file; // warning: predefined function non-call
|
||||
function mike ($var) $foo;
|
||||
mike(A::func(param));
|
||||
func($b $c); // error: function parameters must be comma-separated
|
||||
foo bar; // error: no operator
|
||||
$baz $quux; // error: no operator
|
||||
public abstract function loadPageXML(util_FilePath $filename, $merge=0+$foo, $x, $y=3) {
|
||||
$newrow[$key] = $val;
|
||||
$newresult[] = $row;
|
||||
$state = $row['c'] == 1;
|
||||
$attribute_values[$attribute_name] = null;
|
||||
$row['attributes'][$attribute_name] = $attribute_value;
|
||||
$result[$row['element']][$row['attribute']] = $row['value'];
|
||||
$sql = "multiline string
|
||||
line2 is special - it'll interpolate variables like $state and method calls
|
||||
{$this->cache->add($key, 5)} and maybe \"more\"
|
||||
|
||||
line5";
|
||||
$sql = 'multiline string
|
||||
single quoting means no \'interpolation\' like "$start" or method call
|
||||
{$this->cache->add($key, 5)} will happen
|
||||
|
||||
line5';
|
||||
$bitpattern = 1 << 2;
|
||||
$bitpattern <<= 3;
|
||||
$incorrect = <<< 5 EOSTRING // FIXME: CodeMirror update bug: add a letter before 5 and notice that syntax is not updated until EOF, even with continuousScanning: 500
|
||||
error: the identifier must conform to the identifier rules
|
||||
EOSTRING;
|
||||
$sql = <<< EOSQL
|
||||
SELECT attribute, element, value
|
||||
FROM attribute_values
|
||||
WHERE dimension = ?
|
||||
EOSQL;
|
||||
$this->lr_cache->add($key, self::range($row['lft'], $row['rgt']));
|
||||
$composite_string = <<<EOSTRING
|
||||
some lines here
|
||||
EOSTRING
|
||||
. 'something extra';
|
||||
$page_lft = ($domain->name() == 'page') ? $start + 1 : $page_start + 1;
|
||||
echo "This is class foo";
|
||||
echo "a = ".$this ->a[2+3*$array["foo"]]."";
|
||||
echo "b = {$this->b}"; // FIXME: highlight interpolation in strings
|
||||
}
|
||||
final function makecoffee error($types = array("cappuccino"), $coffeeMaker = NULL) {
|
||||
$out_of_way_amount = $max - $child->left() + 1;
|
||||
$absolute_pos = $child->left() - $move->width();
|
||||
$varfunc(1, 'x');
|
||||
$varfunc(1, 'x') + foo() - 5;
|
||||
$funcarray[$i]('param1', $param2);
|
||||
$lr[$domain_name] = $this->get_left_and_right($domain,
|
||||
$dimension_name,
|
||||
$element_name);
|
||||
$domain_list = is_null($domain) ?
|
||||
r3_Domain::names() :
|
||||
array($domain->name());
|
||||
foreach (r3_Domain::names() as $domain_name) {
|
||||
$placeholders = 'distance LIKE '
|
||||
. implode(array_fill(1, $num_distances, '?'),
|
||||
' OR distance LIKE ');
|
||||
|
||||
}
|
||||
return $this->target*$this->trans+myfunc(__METHOD__);
|
||||
/*
|
||||
echo 'This is a test'; /* This comment will cause a problem */
|
||||
*/
|
||||
}
|
||||
switch( $type ) {
|
||||
case "r3core_AddTemplateToTargetEvent":
|
||||
$this->notifyAddTemplateToTarget( $genevent );
|
||||
break;
|
||||
case "r3core_GenerateTargetEvent" $this:
|
||||
for($i=0; $i<=this->method(); $i++) {
|
||||
echo 'Syntax "highlighting"';
|
||||
}
|
||||
try {
|
||||
foreach($array xor $loader->parse_fn($filename) as $key => value) {
|
||||
namespace r3;
|
||||
}
|
||||
} catch( Exception $e ) {
|
||||
/** restore the backup
|
||||
*/
|
||||
$this->loadAll($tmp, $event, true);
|
||||
// `php -l` doesn't complain at all at this (it assumes string constants):
|
||||
this + makes * no - sense;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default moo:
|
||||
throw new r3_util_Exception( get_class( $genevent ) . " does not map" );
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
if($something==true):
|
||||
$test = 'something';
|
||||
endif;
|
||||
|
||||
for($i=0;$i<2000;$i++):
|
||||
echo $i;
|
||||
$k = $k + 1;
|
||||
endfor;
|
||||
|
||||
foreach(array('one','two') as $key => $value):
|
||||
echo $number . ' = '. $key;
|
||||
endforeach;
|
||||
|
||||
/* fails if nested */
|
||||
if($nested < 0):
|
||||
if($fail > 1):
|
||||
echo 'This fails....';
|
||||
endif;
|
||||
endif;
|
||||
?>
|
||||
|
||||
<r3:cphp>
|
||||
php("works", $here, 2);
|
||||
</r3:cphp>
|
||||
|
||||
<r4:cphp>
|
||||
class foo {
|
||||
// a comment
|
||||
var $a;
|
||||
var $b;
|
||||
};
|
||||
</r4:cphp>
|
||||
|
||||
<h1>This is an <?php # echo 'simple';?> example.</h1>
|
||||
<p>The header above will say 'This is an example'.</p>
|
||||
<h1>This is an <?php // echo 'simple';?> example.</h1>
|
||||
|
||||
<?php echo; ?>
|
||||
<body>
|
||||
|
||||
<?php echo "<html>
|
||||
<head>
|
||||
<script>
|
||||
var foo = 'bar';
|
||||
</script>
|
||||
<style>
|
||||
span.test {font-family: arial, 'lucida console', sans-serif}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<!-- comment -->
|
||||
</body>
|
||||
</html>"; ?>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
</textarea>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
var editor = CodeMirror.fromTextArea('code', {
|
||||
height: "350px",
|
||||
parserfile: ["parsexml.js", "parsecss.js", "tokenizejavascript.js", "parsejavascript.js",
|
||||
"../contrib/php/js/tokenizephp.js", "../contrib/php/js/parsephp.js",
|
||||
"../contrib/php/js/parsephphtmlmixed.js"],
|
||||
stylesheet: ["../../css/xmlcolors.css", "../../css/jscolors.css", "../../css/csscolors.css", "css/phpcolors.css"],
|
||||
path: "../../js/",
|
||||
continuousScanning: 500
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
419
gulliver/js/codemirror/contrib/php/js/parsephp.js
Executable file
419
gulliver/js/codemirror/contrib/php/js/parsephp.js
Executable file
@@ -0,0 +1,419 @@
|
||||
/*
|
||||
Copyright (c) 2008-2009 Yahoo! Inc. All rights reserved.
|
||||
The copyrights embodied in the content of this file are licensed by
|
||||
Yahoo! Inc. under the BSD (revised) open source license
|
||||
|
||||
@author Dan Vlad Dascalescu <dandv@yahoo-inc.com>
|
||||
|
||||
|
||||
Parse function for PHP. Makes use of the tokenizer from tokenizephp.js.
|
||||
Based on parsejavascript.js by Marijn Haverbeke.
|
||||
|
||||
|
||||
Features:
|
||||
+ special "deprecated" style for PHP4 keywords like 'var'
|
||||
+ support for PHP 5.3 keywords: 'namespace', 'use'
|
||||
+ 911 predefined constants, 1301 predefined functions, 105 predeclared classes
|
||||
from a typical PHP installation in a LAMP environment
|
||||
+ new feature: syntax error flagging, thus enabling strict parsing of:
|
||||
+ function definitions with explicitly or implicitly typed arguments and default values
|
||||
+ modifiers (public, static etc.) applied to method and member definitions
|
||||
+ foreach(array_expression as $key [=> $value]) loops
|
||||
+ differentiation between single-quoted strings and double-quoted interpolating strings
|
||||
|
||||
*/
|
||||
|
||||
|
||||
// add the Array.indexOf method for JS engines that don't support it (e.g. IE)
|
||||
// code from https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Global_Objects/Array/IndexOf
|
||||
if (!Array.prototype.indexOf)
|
||||
{
|
||||
Array.prototype.indexOf = function(elt /*, from*/)
|
||||
{
|
||||
var len = this.length;
|
||||
|
||||
var from = Number(arguments[1]) || 0;
|
||||
from = (from < 0)
|
||||
? Math.ceil(from)
|
||||
: Math.floor(from);
|
||||
if (from < 0)
|
||||
from += len;
|
||||
|
||||
for (; from < len; from++)
|
||||
{
|
||||
if (from in this &&
|
||||
this[from] === elt)
|
||||
return from;
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
var PHPParser = Editor.Parser = (function() {
|
||||
// Token types that can be considered to be atoms, part of operator expressions
|
||||
var atomicTypes = {
|
||||
"atom": true, "number": true, "variable": true, "string": true
|
||||
};
|
||||
// Constructor for the lexical context objects.
|
||||
function PHPLexical(indented, column, type, align, prev, info) {
|
||||
// indentation at start of this line
|
||||
this.indented = indented;
|
||||
// column at which this scope was opened
|
||||
this.column = column;
|
||||
// type of scope ('stat' (statement), 'form' (special form), '[', '{', or '(')
|
||||
this.type = type;
|
||||
// '[', '{', or '(' blocks that have any text after their opening
|
||||
// character are said to be 'aligned' -- any lines below are
|
||||
// indented all the way to the opening character.
|
||||
if (align != null)
|
||||
this.align = align;
|
||||
// Parent scope, if any.
|
||||
this.prev = prev;
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
// PHP indentation rules
|
||||
function indentPHP(lexical) {
|
||||
return function(firstChars) {
|
||||
var firstChar = firstChars && firstChars.charAt(0), type = lexical.type;
|
||||
var closing = firstChar == type;
|
||||
if (type == "form" && firstChar == "{")
|
||||
return lexical.indented;
|
||||
else if (type == "stat" || type == "form")
|
||||
return lexical.indented + indentUnit;
|
||||
else if (lexical.info == "switch" && !closing)
|
||||
return lexical.indented + (/^(?:case|default)\b/.test(firstChars) ? indentUnit : 2 * indentUnit);
|
||||
else if (lexical.align)
|
||||
return lexical.column - (closing ? 1 : 0);
|
||||
else
|
||||
return lexical.indented + (closing ? 0 : indentUnit);
|
||||
};
|
||||
}
|
||||
|
||||
// The parser-iterator-producing function itself.
|
||||
function parsePHP(input, basecolumn) {
|
||||
// Wrap the input in a token stream
|
||||
var tokens = tokenizePHP(input);
|
||||
// The parser state. cc is a stack of actions that have to be
|
||||
// performed to finish the current statement. For example we might
|
||||
// know that we still need to find a closing parenthesis and a
|
||||
// semicolon. Actions at the end of the stack go first. It is
|
||||
// initialized with an infinitely looping action that consumes
|
||||
// whole statements.
|
||||
var cc = [statements];
|
||||
// The lexical scope, used mostly for indentation.
|
||||
var lexical = new PHPLexical((basecolumn || 0) - indentUnit, 0, "block", false);
|
||||
// Current column, and the indentation at the start of the current
|
||||
// line. Used to create lexical scope objects.
|
||||
var column = 0;
|
||||
var indented = 0;
|
||||
// Variables which are used by the mark, cont, and pass functions
|
||||
// below to communicate with the driver loop in the 'next' function.
|
||||
var consume, marked;
|
||||
|
||||
// The iterator object.
|
||||
var parser = {next: next, copy: copy};
|
||||
|
||||
// parsing is accomplished by calling next() repeatedly
|
||||
function next(){
|
||||
// Start by performing any 'lexical' actions (adjusting the
|
||||
// lexical variable), or the operations below will be working
|
||||
// with the wrong lexical state.
|
||||
while(cc[cc.length - 1].lex)
|
||||
cc.pop()();
|
||||
|
||||
// Fetch the next token.
|
||||
var token = tokens.next();
|
||||
|
||||
// Adjust column and indented.
|
||||
if (token.type == "whitespace" && column == 0)
|
||||
indented = token.value.length;
|
||||
column += token.value.length;
|
||||
if (token.content == "\n"){
|
||||
indented = column = 0;
|
||||
// If the lexical scope's align property is still undefined at
|
||||
// the end of the line, it is an un-aligned scope.
|
||||
if (!("align" in lexical))
|
||||
lexical.align = false;
|
||||
// Newline tokens get an indentation function associated with
|
||||
// them.
|
||||
token.indentation = indentPHP(lexical);
|
||||
}
|
||||
// No more processing for meaningless tokens.
|
||||
if (token.type == "whitespace" || token.type == "comment"
|
||||
|| token.type == "string_not_terminated" )
|
||||
return token;
|
||||
// When a meaningful token is found and the lexical scope's
|
||||
// align is undefined, it is an aligned scope.
|
||||
if (!("align" in lexical))
|
||||
lexical.align = true;
|
||||
|
||||
// Execute actions until one 'consumes' the token and we can
|
||||
// return it. 'marked' is used to change the style of the current token.
|
||||
while(true) {
|
||||
consume = marked = false;
|
||||
// Take and execute the topmost action.
|
||||
var action = cc.pop();
|
||||
action(token);
|
||||
|
||||
if (consume){
|
||||
if (marked)
|
||||
token.style = marked;
|
||||
// Here we differentiate between local and global variables.
|
||||
return token;
|
||||
}
|
||||
}
|
||||
return 1; // Firebug workaround for http://code.google.com/p/fbug/issues/detail?id=1239#c1
|
||||
}
|
||||
|
||||
// This makes a copy of the parser state. It stores all the
|
||||
// stateful variables in a closure, and returns a function that
|
||||
// will restore them when called with a new input stream. Note
|
||||
// that the cc array has to be copied, because it is contantly
|
||||
// being modified. Lexical objects are not mutated, so they can
|
||||
// be shared between runs of the parser.
|
||||
function copy(){
|
||||
var _lexical = lexical, _cc = cc.concat([]), _tokenState = tokens.state;
|
||||
|
||||
return function copyParser(input){
|
||||
lexical = _lexical;
|
||||
cc = _cc.concat([]); // copies the array
|
||||
column = indented = 0;
|
||||
tokens = tokenizePHP(input, _tokenState);
|
||||
return parser;
|
||||
};
|
||||
}
|
||||
|
||||
// Helper function for pushing a number of actions onto the cc
|
||||
// stack in reverse order.
|
||||
function push(fs){
|
||||
for (var i = fs.length - 1; i >= 0; i--)
|
||||
cc.push(fs[i]);
|
||||
}
|
||||
// cont and pass are used by the action functions to add other
|
||||
// actions to the stack. cont will cause the current token to be
|
||||
// consumed, pass will leave it for the next action.
|
||||
function cont(){
|
||||
push(arguments);
|
||||
consume = true;
|
||||
}
|
||||
function pass(){
|
||||
push(arguments);
|
||||
consume = false;
|
||||
}
|
||||
// Used to change the style of the current token.
|
||||
function mark(style){
|
||||
marked = style;
|
||||
}
|
||||
// Add a lyer of style to the current token, for example syntax-error
|
||||
function mark_add(style){
|
||||
marked = marked + ' ' + style;
|
||||
}
|
||||
|
||||
// Push a new lexical context of the given type.
|
||||
function pushlex(type, info) {
|
||||
var result = function pushlexing() {
|
||||
lexical = new PHPLexical(indented, column, type, null, lexical, info)
|
||||
};
|
||||
result.lex = true;
|
||||
return result;
|
||||
}
|
||||
// Pop off the current lexical context.
|
||||
function poplex(){
|
||||
if (lexical.prev)
|
||||
lexical = lexical.prev;
|
||||
}
|
||||
poplex.lex = true;
|
||||
// The 'lex' flag on these actions is used by the 'next' function
|
||||
// to know they can (and have to) be ran before moving on to the
|
||||
// next token.
|
||||
|
||||
// Creates an action that discards tokens until it finds one of
|
||||
// the given type. This will ignore (and recover from) syntax errors.
|
||||
function expect(wanted){
|
||||
return function expecting(token){
|
||||
if (token.type == wanted) cont(); // consume the token
|
||||
else {
|
||||
cont(arguments.callee); // continue expecting() - call itself
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Require a specific token type, or one of the tokens passed in the 'wanted' array
|
||||
// Used to detect blatant syntax errors. 'execute' is used to pass extra code
|
||||
// to be executed if the token is matched. For example, a '(' match could
|
||||
// 'execute' a cont( compasep(funcarg), require(")") )
|
||||
function require(wanted, execute){
|
||||
return function requiring(token){
|
||||
var ok;
|
||||
var type = token.type;
|
||||
if (typeof(wanted) == "string")
|
||||
ok = (type == wanted) -1;
|
||||
else
|
||||
ok = wanted.indexOf(type);
|
||||
if (ok >= 0) {
|
||||
if (execute && typeof(execute[ok]) == "function") pass(execute[ok]);
|
||||
else cont();
|
||||
}
|
||||
else {
|
||||
if (!marked) mark(token.style);
|
||||
mark_add("syntax-error");
|
||||
cont(arguments.callee);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Looks for a statement, and then calls itself.
|
||||
function statements(token){
|
||||
return pass(statement, statements);
|
||||
}
|
||||
// Dispatches various types of statements based on the type of the current token.
|
||||
function statement(token){
|
||||
var type = token.type;
|
||||
if (type == "keyword a") cont(pushlex("form"), expression, altsyntax, statement, poplex);
|
||||
else if (type == "keyword b") cont(pushlex("form"), altsyntax, statement, poplex);
|
||||
else if (type == "{") cont(pushlex("}"), block, poplex);
|
||||
else if (type == "function") funcdef();
|
||||
// technically, "class implode {...}" is correct, but we'll flag that as an error because it overrides a predefined function
|
||||
else if (type == "class") classdef();
|
||||
else if (type == "foreach") cont(pushlex("form"), require("("), pushlex(")"), expression, require("as"), require("variable"), /* => $value */ expect(")"), altsyntax, poplex, statement, poplex);
|
||||
else if (type == "for") cont(pushlex("form"), require("("), pushlex(")"), expression, require(";"), expression, require(";"), expression, require(")"), altsyntax, poplex, statement, poplex);
|
||||
// public final function foo(), protected static $bar;
|
||||
else if (type == "modifier") cont(require(["modifier", "variable", "function", "abstract"],
|
||||
[null, commasep(require("variable")), funcdef, absfun]));
|
||||
else if (type == "abstract") abs();
|
||||
else if (type == "switch") cont(pushlex("form"), require("("), expression, require(")"), pushlex("}", "switch"), require([":", "{"]), block, poplex, poplex);
|
||||
else if (type == "case") cont(expression, require(":"));
|
||||
else if (type == "default") cont(require(":"));
|
||||
else if (type == "catch") cont(pushlex("form"), require("("), require("t_string"), require("variable"), require(")"), statement, poplex);
|
||||
else if (type == "const") cont(require("t_string")); // 'const static x=5' is a syntax error
|
||||
// technically, "namespace implode {...}" is correct, but we'll flag that as an error because it overrides a predefined function
|
||||
else if (type == "namespace") cont(namespacedef, require(";"));
|
||||
// $variables may be followed by operators, () for variable function calls, or [] subscripts
|
||||
else pass(pushlex("stat"), expression, require(";"), poplex);
|
||||
}
|
||||
// Dispatch expression types.
|
||||
function expression(token){
|
||||
var type = token.type;
|
||||
if (atomicTypes.hasOwnProperty(type)) cont(maybeoperator);
|
||||
else if (type == "<<<") cont(require("string"), maybeoperator); // heredoc/nowdoc
|
||||
else if (type == "t_string") cont(maybe_double_colon, maybeoperator);
|
||||
else if (type == "keyword c" || type == "operator") cont(expression);
|
||||
// lambda
|
||||
else if (type == "function") lambdadef();
|
||||
// function call or parenthesized expression: $a = ($b + 1) * 2;
|
||||
else if (type == "(") cont(pushlex(")"), commasep(expression), require(")"), poplex, maybeoperator);
|
||||
}
|
||||
// Called for places where operators, function calls, or subscripts are
|
||||
// valid. Will skip on to the next action if none is found.
|
||||
function maybeoperator(token){
|
||||
var type = token.type;
|
||||
if (type == "operator") {
|
||||
if (token.content == "?") cont(expression, require(":"), expression); // ternary operator
|
||||
else cont(expression);
|
||||
}
|
||||
else if (type == "(") cont(pushlex(")"), expression, commasep(expression), require(")"), poplex, maybeoperator /* $varfunc() + 3 */);
|
||||
else if (type == "[") cont(pushlex("]"), expression, require("]"), maybeoperator /* for multidimensional arrays, or $func[$i]() */, poplex);
|
||||
}
|
||||
// A regular use of the double colon to specify a class, as in self::func() or myclass::$var;
|
||||
// Differs from `namespace` or `use` in that only one class can be the parent; chains (A::B::$var) are a syntax error.
|
||||
function maybe_double_colon(token) {
|
||||
if (token.type == "t_double_colon")
|
||||
// A::$var, A::func(), A::const
|
||||
cont(require(["t_string", "variable"]), maybeoperator);
|
||||
else {
|
||||
// a t_string wasn't followed by ::, such as in a function call: foo()
|
||||
pass(expression)
|
||||
}
|
||||
}
|
||||
// the declaration or definition of a function
|
||||
function funcdef() {
|
||||
cont(require("t_string"), require("("), pushlex(")"), commasep(funcarg), require(")"), poplex, block);
|
||||
}
|
||||
// the declaration or definition of a lambda
|
||||
function lambdadef() {
|
||||
cont(require("("), pushlex(")"), commasep(funcarg), require(")"), maybe_lambda_use, poplex, require("{"), pushlex("}"), block, poplex);
|
||||
}
|
||||
// optional lambda 'use' statement
|
||||
function maybe_lambda_use(token) {
|
||||
if(token.type == "namespace") {
|
||||
cont(require('('), commasep(funcarg), require(')'));
|
||||
}
|
||||
else {
|
||||
pass(expression);
|
||||
}
|
||||
}
|
||||
// the definition of a class
|
||||
function classdef() {
|
||||
cont(require("t_string"), expect("{"), pushlex("}"), block, poplex);
|
||||
}
|
||||
// either funcdef if the current token is "function", or the keyword "function" + funcdef
|
||||
function absfun(token) {
|
||||
if(token.type == "function") funcdef();
|
||||
else cont(require(["function"], [funcdef]));
|
||||
}
|
||||
// the abstract class or function (with optional modifier)
|
||||
function abs(token) {
|
||||
cont(require(["modifier", "function", "class"], [absfun, funcdef, classdef]));
|
||||
}
|
||||
// Parses a comma-separated list of the things that are recognized
|
||||
// by the 'what' argument.
|
||||
function commasep(what){
|
||||
function proceed(token) {
|
||||
if (token.type == ",") cont(what, proceed);
|
||||
}
|
||||
return function commaSeparated() {
|
||||
pass(what, proceed);
|
||||
};
|
||||
}
|
||||
// Look for statements until a closing brace is found.
|
||||
function block(token) {
|
||||
if (token.type == "}") cont();
|
||||
else pass(statement, block);
|
||||
}
|
||||
function empty_parens_if_array(token) {
|
||||
if(token.content == "array")
|
||||
cont(require("("), require(")"));
|
||||
}
|
||||
function maybedefaultparameter(token){
|
||||
if (token.content == "=") cont(require(["t_string", "string", "number", "atom"], [empty_parens_if_array, null, null]));
|
||||
}
|
||||
function var_or_reference(token) {
|
||||
if(token.type == "variable") cont(maybedefaultparameter);
|
||||
else if(token.content == "&") cont(require("variable"), maybedefaultparameter);
|
||||
}
|
||||
// support for default arguments: http://us.php.net/manual/en/functions.arguments.php#functions.arguments.default
|
||||
function funcarg(token){
|
||||
// function foo(myclass $obj) {...} or function foo(myclass &objref) {...}
|
||||
if (token.type == "t_string") cont(var_or_reference);
|
||||
// function foo($var) {...} or function foo(&$ref) {...}
|
||||
else var_or_reference(token);
|
||||
}
|
||||
|
||||
// A namespace definition or use
|
||||
function maybe_double_colon_def(token) {
|
||||
if (token.type == "t_double_colon")
|
||||
cont(namespacedef);
|
||||
}
|
||||
function namespacedef(token) {
|
||||
pass(require("t_string"), maybe_double_colon_def);
|
||||
}
|
||||
|
||||
function altsyntax(token){
|
||||
if(token.content==':')
|
||||
cont(altsyntaxBlock,poplex);
|
||||
}
|
||||
|
||||
function altsyntaxBlock(token){
|
||||
if (token.type == "altsyntaxend") cont(require(';'));
|
||||
else pass(statement, altsyntaxBlock);
|
||||
}
|
||||
|
||||
|
||||
return parser;
|
||||
}
|
||||
|
||||
return {make: parsePHP, electricChars: "{}:"};
|
||||
|
||||
})();
|
||||
116
gulliver/js/codemirror/contrib/php/js/parsephphtmlmixed.js
Executable file
116
gulliver/js/codemirror/contrib/php/js/parsephphtmlmixed.js
Executable file
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
Copyright (c) 2008-2009 Yahoo! Inc. All rights reserved.
|
||||
The copyrights embodied in the content of this file are licensed by
|
||||
Yahoo! Inc. under the BSD (revised) open source license
|
||||
|
||||
@author Dan Vlad Dascalescu <dandv@yahoo-inc.com>
|
||||
|
||||
Based on parsehtmlmixed.js by Marijn Haverbeke.
|
||||
*/
|
||||
|
||||
var PHPHTMLMixedParser = Editor.Parser = (function() {
|
||||
var processingInstructions = ["<?php"];
|
||||
|
||||
if (!(PHPParser && CSSParser && JSParser && XMLParser))
|
||||
throw new Error("PHP, CSS, JS, and XML parsers must be loaded for PHP+HTML mixed mode to work.");
|
||||
XMLParser.configure({useHTMLKludges: true});
|
||||
|
||||
function parseMixed(stream) {
|
||||
var htmlParser = XMLParser.make(stream), localParser = null,
|
||||
inTag = false, lastAtt = null, phpParserState = null;
|
||||
var iter = {next: top, copy: copy};
|
||||
|
||||
function top() {
|
||||
var token = htmlParser.next();
|
||||
if (token.content == "<")
|
||||
inTag = true;
|
||||
else if (token.style == "xml-tagname" && inTag === true)
|
||||
inTag = token.content.toLowerCase();
|
||||
else if (token.style == "xml-attname")
|
||||
lastAtt = token.content;
|
||||
else if (token.type == "xml-processing") {
|
||||
// see if this opens a PHP block
|
||||
for (var i = 0; i < processingInstructions.length; i++)
|
||||
if (processingInstructions[i] == token.content) {
|
||||
iter.next = local(PHPParser, "?>");
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (token.style == "xml-attribute" && token.content == "\"php\"" && inTag == "script" && lastAtt == "language")
|
||||
inTag = "script/php";
|
||||
// "xml-processing" tokens are ignored, because they should be handled by a specific local parser
|
||||
else if (token.content == ">") {
|
||||
if (inTag == "script/php")
|
||||
iter.next = local(PHPParser, "</script>");
|
||||
else if (inTag == "script")
|
||||
iter.next = local(JSParser, "</script");
|
||||
else if (inTag == "style")
|
||||
iter.next = local(CSSParser, "</style");
|
||||
lastAtt = null;
|
||||
inTag = false;
|
||||
}
|
||||
return token;
|
||||
}
|
||||
function local(parser, tag) {
|
||||
var baseIndent = htmlParser.indentation();
|
||||
if (parser == PHPParser && phpParserState)
|
||||
localParser = phpParserState(stream);
|
||||
else
|
||||
localParser = parser.make(stream, baseIndent + indentUnit);
|
||||
|
||||
return function() {
|
||||
if (stream.lookAhead(tag, false, false, true)) {
|
||||
if (parser == PHPParser) phpParserState = localParser.copy();
|
||||
localParser = null;
|
||||
iter.next = top;
|
||||
return top(); // pass the ending tag to the enclosing parser
|
||||
}
|
||||
|
||||
var token = localParser.next();
|
||||
var lt = token.value.lastIndexOf("<"), sz = Math.min(token.value.length - lt, tag.length);
|
||||
if (lt != -1 && token.value.slice(lt, lt + sz).toLowerCase() == tag.slice(0, sz) &&
|
||||
stream.lookAhead(tag.slice(sz), false, false, true)) {
|
||||
stream.push(token.value.slice(lt));
|
||||
token.value = token.value.slice(0, lt);
|
||||
}
|
||||
|
||||
if (token.indentation) {
|
||||
var oldIndent = token.indentation;
|
||||
token.indentation = function(chars) {
|
||||
if (chars == "</")
|
||||
return baseIndent;
|
||||
else
|
||||
return oldIndent(chars);
|
||||
}
|
||||
}
|
||||
|
||||
return token;
|
||||
};
|
||||
}
|
||||
|
||||
function copy() {
|
||||
var _html = htmlParser.copy(), _local = localParser && localParser.copy(),
|
||||
_next = iter.next, _inTag = inTag, _lastAtt = lastAtt, _php = phpParserState;
|
||||
return function(_stream) {
|
||||
stream = _stream;
|
||||
htmlParser = _html(_stream);
|
||||
localParser = _local && _local(_stream);
|
||||
phpParserState = _php;
|
||||
iter.next = _next;
|
||||
inTag = _inTag;
|
||||
lastAtt = _lastAtt;
|
||||
return iter;
|
||||
};
|
||||
}
|
||||
return iter;
|
||||
}
|
||||
|
||||
return {
|
||||
make: parseMixed,
|
||||
electricChars: "{}/:",
|
||||
configure: function(conf) {
|
||||
if (conf.opening != null) processingInstructions = conf.opening;
|
||||
}
|
||||
};
|
||||
|
||||
})();
|
||||
1208
gulliver/js/codemirror/contrib/php/js/tokenizephp.js
Executable file
1208
gulliver/js/codemirror/contrib/php/js/tokenizephp.js
Executable file
File diff suppressed because it is too large
Load Diff
22
gulliver/js/codemirror/contrib/plsql/LICENSE
Executable file
22
gulliver/js/codemirror/contrib/plsql/LICENSE
Executable file
@@ -0,0 +1,22 @@
|
||||
Copyright (c) 2010 Peter Raganitsch
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any
|
||||
damages arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any
|
||||
purpose, including commercial applications, and to alter it and
|
||||
redistribute it freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must
|
||||
not claim that you wrote the original software. If you use this
|
||||
software in a product, an acknowledgment in the product
|
||||
documentation would be appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must
|
||||
not be misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source
|
||||
distribution.
|
||||
|
||||
Peter Raganitsch
|
||||
57
gulliver/js/codemirror/contrib/plsql/css/plsqlcolors.css
Executable file
57
gulliver/js/codemirror/contrib/plsql/css/plsqlcolors.css
Executable file
@@ -0,0 +1,57 @@
|
||||
html {
|
||||
cursor: text;
|
||||
}
|
||||
|
||||
.editbox {
|
||||
margin: .4em;
|
||||
padding: 0;
|
||||
font-family: monospace;
|
||||
font-size: 10pt;
|
||||
color: black;
|
||||
}
|
||||
|
||||
.editbox p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
span.plsql-keyword {
|
||||
color: blue;
|
||||
}
|
||||
|
||||
span.plsql-var {
|
||||
color: red;
|
||||
}
|
||||
|
||||
span.plsql-comment {
|
||||
color: #AA7700;
|
||||
}
|
||||
|
||||
span.plsql-literal {
|
||||
color: green;
|
||||
}
|
||||
|
||||
span.plsql-operator {
|
||||
color: blue;
|
||||
}
|
||||
|
||||
span.plsql-word {
|
||||
color: black;
|
||||
}
|
||||
|
||||
span.plsql-function {
|
||||
color: darkorange;
|
||||
}
|
||||
|
||||
span.plsql-type {
|
||||
color: purple;
|
||||
}
|
||||
|
||||
span.plsql-separator {
|
||||
color: #666666;
|
||||
}
|
||||
|
||||
span.plsql-number {
|
||||
color: darkcyan;
|
||||
}
|
||||
|
||||
|
||||
67
gulliver/js/codemirror/contrib/plsql/index.html
Executable file
67
gulliver/js/codemirror/contrib/plsql/index.html
Executable file
@@ -0,0 +1,67 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<script src="../../js/codemirror.js" type="text/javascript"></script>
|
||||
<title>CodeMirror: PLSQL demonstration</title>
|
||||
<link rel="stylesheet" type="text/css" href="../../css/docs.css"/>
|
||||
</head>
|
||||
<body style="padding: 20px;">
|
||||
|
||||
<p>Demonstration of <a href="../../index.html">CodeMirror</a>'s PLSQL
|
||||
highlighter.</p>
|
||||
|
||||
<p>Written by Peter Raganitsch (<a href="LICENSE">license</a>), based
|
||||
on John Benediktsson <a href="../sql/index.html">SQL parser</a>.</p>
|
||||
|
||||
<div style="border-top: 1px solid black; border-bottom: 1px solid black;">
|
||||
<textarea id="code" cols="120" rows="50">
|
||||
PROCEDURE generateResult
|
||||
( pRoutineType IN VARCHAR2
|
||||
, pReferenceType IN VARCHAR2
|
||||
, pReferenceId IN NUMBER
|
||||
)
|
||||
IS
|
||||
ROUTINE_NAME CONSTANT VARCHAR2(30) := 'generateResult';
|
||||
--
|
||||
vDisplayAs APEXLIB_V_PAGE_ITEM.DISPLAY_AS %TYPE;
|
||||
vLovQuery APEXLIB_V_PAGE_ITEM.LOV_QUERY %TYPE;
|
||||
vDisplayNullValue APEXLIB_V_PAGE_ITEM.LOV_DISPLAY_NULL%TYPE;
|
||||
vLovNullText APEXLIB_V_PAGE_ITEM.LOV_NULL_TEXT %TYPE;
|
||||
vLovNullValue APEXLIB_V_PAGE_ITEM.LOV_NULL_VALUE %TYPE;
|
||||
vApplicationId APEXLIB_V_PAGE_ITEM.APPLICATION_ID %TYPE;
|
||||
vPageId APEXLIB_V_PAGE_ITEM.PAGE_ID %TYPE;
|
||||
BEGIN
|
||||
----------------------------------------------------------------------------
|
||||
-- Determine which routine to call and pass parameters
|
||||
----------------------------------------------------------------------------
|
||||
CASE pRoutineType
|
||||
WHEN 'LOV'
|
||||
THEN
|
||||
ApexLib_Lov.generateLovResult( pReferenceType, pReferenceId );
|
||||
--
|
||||
WHEN 'COMPUTATION'
|
||||
THEN
|
||||
ApexLib_Computation.generateComputationResult( pReferenceType, pReferenceId );
|
||||
--
|
||||
ELSE
|
||||
Apexlib_Error.raiseImplError('Unsupported routine type "'||pRoutineType||'"!');
|
||||
END CASE;
|
||||
--
|
||||
EXCEPTION WHEN OTHERS THEN
|
||||
HTP.prn('Error: '||SQLERRM);
|
||||
-- RAISE; no raise, because APEX doesn't care anyway.
|
||||
END generateResult;
|
||||
</textarea>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
var editor = CodeMirror.fromTextArea('code', {
|
||||
height: "450px",
|
||||
parserfile: "../contrib/plsql/js/parseplsql.js",
|
||||
stylesheet: "css/plsqlcolors.css",
|
||||
path: "../../js/",
|
||||
textWrapping: false
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
233
gulliver/js/codemirror/contrib/plsql/js/parseplsql.js
Executable file
233
gulliver/js/codemirror/contrib/plsql/js/parseplsql.js
Executable file
@@ -0,0 +1,233 @@
|
||||
var PlsqlParser = Editor.Parser = (function() {
|
||||
|
||||
function wordRegexp(words) {
|
||||
return new RegExp("^(?:" + words.join("|") + ")$", "i");
|
||||
}
|
||||
|
||||
var functions = wordRegexp([
|
||||
"abs","acos","add_months","ascii","asin","atan","atan2","average",
|
||||
"bfilename",
|
||||
"ceil","chartorowid","chr","concat","convert","cos","cosh","count",
|
||||
"decode","deref","dual","dump","dup_val_on_index",
|
||||
"empty","error","exp",
|
||||
"false","floor","found",
|
||||
"glb","greatest",
|
||||
"hextoraw",
|
||||
"initcap","instr","instrb","isopen",
|
||||
"last_day","least","lenght","lenghtb","ln","lower","lpad","ltrim","lub",
|
||||
"make_ref","max","min","mod","months_between",
|
||||
"new_time","next_day","nextval","nls_charset_decl_len","nls_charset_id","nls_charset_name","nls_initcap","nls_lower",
|
||||
"nls_sort","nls_upper","nlssort","no_data_found","notfound","null","nvl",
|
||||
"others",
|
||||
"power",
|
||||
"rawtohex","reftohex","round","rowcount","rowidtochar","rpad","rtrim",
|
||||
"sign","sin","sinh","soundex","sqlcode","sqlerrm","sqrt","stddev","substr","substrb","sum","sysdate",
|
||||
"tan","tanh","to_char","to_date","to_label","to_multi_byte","to_number","to_single_byte","translate","true","trunc",
|
||||
"uid","upper","user","userenv",
|
||||
"variance","vsize"
|
||||
|
||||
]);
|
||||
|
||||
var keywords = wordRegexp([
|
||||
"abort","accept","access","add","all","alter","and","any","array","arraylen","as","asc","assert","assign","at","attributes","audit",
|
||||
"authorization","avg",
|
||||
"base_table","begin","between","binary_integer","body","boolean","by",
|
||||
"case","cast","char","char_base","check","close","cluster","clusters","colauth","column","comment","commit","compress","connect",
|
||||
"connected","constant","constraint","crash","create","current","currval","cursor",
|
||||
"data_base","database","date","dba","deallocate","debugoff","debugon","decimal","declare","default","definition","delay","delete",
|
||||
"desc","digits","dispose","distinct","do","drop",
|
||||
"else","elsif","enable","end","entry","escape","exception","exception_init","exchange","exclusive","exists","exit","external",
|
||||
"fast","fetch","file","for","force","form","from","function",
|
||||
"generic","goto","grant","group",
|
||||
"having",
|
||||
"identified","if","immediate","in","increment","index","indexes","indicator","initial","initrans","insert","interface","intersect",
|
||||
"into","is",
|
||||
"key",
|
||||
"level","library","like","limited","local","lock","log","logging","long","loop",
|
||||
"master","maxextents","maxtrans","member","minextents","minus","mislabel","mode","modify","multiset",
|
||||
"new","next","no","noaudit","nocompress","nologging","noparallel","not","nowait","number_base",
|
||||
"object","of","off","offline","on","online","only","open","option","or","order","out",
|
||||
"package","parallel","partition","pctfree","pctincrease","pctused","pls_integer","positive","positiven","pragma","primary","prior",
|
||||
"private","privileges","procedure","public",
|
||||
"raise","range","raw","read","rebuild","record","ref","references","refresh","release","rename","replace","resource","restrict","return",
|
||||
"returning","reverse","revoke","rollback","row","rowid","rowlabel","rownum","rows","run",
|
||||
"savepoint","schema","segment","select","separate","session","set","share","snapshot","some","space","split","sql","start","statement",
|
||||
"storage","subtype","successful","synonym",
|
||||
"tabauth","table","tables","tablespace","task","terminate","then","to","trigger","truncate","type",
|
||||
"union","unique","unlimited","unrecoverable","unusable","update","use","using",
|
||||
"validate","value","values","variable","view","views",
|
||||
"when","whenever","where","while","with","work"
|
||||
]);
|
||||
|
||||
var types = wordRegexp([
|
||||
"bfile","blob",
|
||||
"character","clob",
|
||||
"dec",
|
||||
"float",
|
||||
"int","integer",
|
||||
"mlslabel",
|
||||
"natural","naturaln","nchar","nclob","number","numeric","nvarchar2",
|
||||
"real","rowtype",
|
||||
"signtype","smallint","string",
|
||||
"varchar","varchar2"
|
||||
]);
|
||||
|
||||
var operators = wordRegexp([
|
||||
":=", "<", "<=", "==", "!=", "<>", ">", ">=", "like", "rlike", "in", "xor", "between"
|
||||
]);
|
||||
|
||||
var operatorChars = /[*+\-<>=&|:\/]/;
|
||||
|
||||
var tokenizeSql = (function() {
|
||||
function normal(source, setState) {
|
||||
var ch = source.next();
|
||||
if (ch == "@" || ch == "$") {
|
||||
source.nextWhileMatches(/[\w\d]/);
|
||||
return "plsql-var";
|
||||
}
|
||||
else if (ch == "\"" || ch == "'" || ch == "`") {
|
||||
setState(inLiteral(ch));
|
||||
return null;
|
||||
}
|
||||
else if (ch == "," || ch == ";") {
|
||||
return "plsql-separator"
|
||||
}
|
||||
else if (ch == '-') {
|
||||
if (source.peek() == "-") {
|
||||
while (!source.endOfLine()) source.next();
|
||||
return "plsql-comment";
|
||||
}
|
||||
else if (/\d/.test(source.peek())) {
|
||||
source.nextWhileMatches(/\d/);
|
||||
if (source.peek() == '.') {
|
||||
source.next();
|
||||
source.nextWhileMatches(/\d/);
|
||||
}
|
||||
return "plsql-number";
|
||||
}
|
||||
else
|
||||
return "plsql-operator";
|
||||
}
|
||||
else if (operatorChars.test(ch)) {
|
||||
source.nextWhileMatches(operatorChars);
|
||||
return "plsql-operator";
|
||||
}
|
||||
else if (/\d/.test(ch)) {
|
||||
source.nextWhileMatches(/\d/);
|
||||
if (source.peek() == '.') {
|
||||
source.next();
|
||||
source.nextWhileMatches(/\d/);
|
||||
}
|
||||
return "plsql-number";
|
||||
}
|
||||
else if (/[()]/.test(ch)) {
|
||||
return "plsql-punctuation";
|
||||
}
|
||||
else {
|
||||
source.nextWhileMatches(/[_\w\d]/);
|
||||
var word = source.get(), type;
|
||||
if (operators.test(word))
|
||||
type = "plsql-operator";
|
||||
else if (keywords.test(word))
|
||||
type = "plsql-keyword";
|
||||
else if (functions.test(word))
|
||||
type = "plsql-function";
|
||||
else if (types.test(word))
|
||||
type = "plsql-type";
|
||||
else
|
||||
type = "plsql-word";
|
||||
return {style: type, content: word};
|
||||
}
|
||||
}
|
||||
|
||||
function inLiteral(quote) {
|
||||
return function(source, setState) {
|
||||
var escaped = false;
|
||||
while (!source.endOfLine()) {
|
||||
var ch = source.next();
|
||||
if (ch == quote && !escaped) {
|
||||
setState(normal);
|
||||
break;
|
||||
}
|
||||
escaped = !escaped && ch == "\\";
|
||||
}
|
||||
return quote == "`" ? "plsql-word" : "plsql-literal";
|
||||
};
|
||||
}
|
||||
|
||||
return function(source, startState) {
|
||||
return tokenizer(source, startState || normal);
|
||||
};
|
||||
})();
|
||||
|
||||
function indentSql(context) {
|
||||
return function(nextChars) {
|
||||
var firstChar = nextChars && nextChars.charAt(0);
|
||||
var closing = context && firstChar == context.type;
|
||||
if (!context)
|
||||
return 0;
|
||||
else if (context.align)
|
||||
return context.col - (closing ? context.width : 0);
|
||||
else
|
||||
return context.indent + (closing ? 0 : indentUnit);
|
||||
}
|
||||
}
|
||||
|
||||
function parseSql(source) {
|
||||
var tokens = tokenizeSql(source);
|
||||
var context = null, indent = 0, col = 0;
|
||||
function pushContext(type, width, align) {
|
||||
context = {prev: context, indent: indent, col: col, type: type, width: width, align: align};
|
||||
}
|
||||
function popContext() {
|
||||
context = context.prev;
|
||||
}
|
||||
|
||||
var iter = {
|
||||
next: function() {
|
||||
var token = tokens.next();
|
||||
var type = token.style, content = token.content, width = token.value.length;
|
||||
|
||||
if (content == "\n") {
|
||||
token.indentation = indentSql(context);
|
||||
indent = col = 0;
|
||||
if (context && context.align == null) context.align = false;
|
||||
}
|
||||
else if (type == "whitespace" && col == 0) {
|
||||
indent = width;
|
||||
}
|
||||
else if (!context && type != "plsql-comment") {
|
||||
pushContext(";", 0, false);
|
||||
}
|
||||
|
||||
if (content != "\n") col += width;
|
||||
|
||||
if (type == "plsql-punctuation") {
|
||||
if (content == "(")
|
||||
pushContext(")", width);
|
||||
else if (content == ")")
|
||||
popContext();
|
||||
}
|
||||
else if (type == "plsql-separator" && content == ";" && context && !context.prev) {
|
||||
popContext();
|
||||
}
|
||||
|
||||
return token;
|
||||
},
|
||||
|
||||
copy: function() {
|
||||
var _context = context, _indent = indent, _col = col, _tokenState = tokens.state;
|
||||
return function(source) {
|
||||
tokens = tokenizeSql(source, _tokenState);
|
||||
context = _context;
|
||||
indent = _indent;
|
||||
col = _col;
|
||||
return iter;
|
||||
};
|
||||
}
|
||||
};
|
||||
return iter;
|
||||
}
|
||||
|
||||
return {make: parseSql, electricChars: ")"};
|
||||
})();
|
||||
32
gulliver/js/codemirror/contrib/python/LICENSE
Executable file
32
gulliver/js/codemirror/contrib/python/LICENSE
Executable file
@@ -0,0 +1,32 @@
|
||||
Copyright (c) 2009, Timothy Farrell
|
||||
All rights reserved.
|
||||
|
||||
This software is provided for use in connection with the
|
||||
CodeMirror suite of modules and utilities, hosted and maintained
|
||||
at http://codemirror.net/.
|
||||
|
||||
Redistribution and use of this software in source and binary forms,
|
||||
with or without modification, are permitted provided that the
|
||||
following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
58
gulliver/js/codemirror/contrib/python/css/pythoncolors.css
Executable file
58
gulliver/js/codemirror/contrib/python/css/pythoncolors.css
Executable file
@@ -0,0 +1,58 @@
|
||||
html {
|
||||
cursor: text;
|
||||
}
|
||||
|
||||
.editbox {
|
||||
padding: .4em;
|
||||
margin: 0;
|
||||
font-family: monospace;
|
||||
font-size: 10pt;
|
||||
line-height: 1.1em;
|
||||
color: black;
|
||||
}
|
||||
|
||||
pre.code, .editbox {
|
||||
color: #666666;
|
||||
}
|
||||
|
||||
.editbox p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
span.py-delimiter, span.py-special {
|
||||
color: #666666;
|
||||
}
|
||||
|
||||
span.py-operator {
|
||||
color: #666666;
|
||||
}
|
||||
|
||||
span.py-error {
|
||||
background-color: #660000;
|
||||
color: #FFFFFF;
|
||||
}
|
||||
|
||||
span.py-keyword {
|
||||
color: #770088;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
span.py-literal {
|
||||
color: #228811;
|
||||
}
|
||||
|
||||
span.py-identifier, span.py-func {
|
||||
color: black;
|
||||
}
|
||||
|
||||
span.py-type, span.py-decorator {
|
||||
color: #0000FF;
|
||||
}
|
||||
|
||||
span.py-comment {
|
||||
color: #AA7700;
|
||||
}
|
||||
|
||||
span.py-string, span.py-bytes, span.py-raw, span.py-unicode {
|
||||
color: #AA2222;
|
||||
}
|
||||
141
gulliver/js/codemirror/contrib/python/index.html
Executable file
141
gulliver/js/codemirror/contrib/python/index.html
Executable file
@@ -0,0 +1,141 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<script src="../../js/codemirror.js" type="text/javascript"></script>
|
||||
<title>CodeMirror: Python demonstration</title>
|
||||
<style type="text/css">
|
||||
.CodeMirror-line-numbers {
|
||||
width: 2.2em;
|
||||
color: #aaa;
|
||||
background-color: #eee;
|
||||
text-align: right;
|
||||
padding: .4em;
|
||||
margin: 0;
|
||||
font-family: monospace;
|
||||
font-size: 10pt;
|
||||
line-height: 1.1em;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body style="padding: 20px;">
|
||||
<p>
|
||||
This is a simple demonstration of the Python syntax highlighting module
|
||||
for <a href="index.html">CodeMirror</a>.
|
||||
</p>
|
||||
<p>
|
||||
Features of this parser include:
|
||||
</p>
|
||||
<ul>
|
||||
<li>Token-based syntax highlighting - currently very little lexical analysis happens. Few lexical errors will be detected.</li>
|
||||
<li>Use the normal indentation mode to enforce regular indentation, otherwise the "shift" indentation mode will give you more flexibility.</li>
|
||||
<li>Parser Options:
|
||||
<ul>
|
||||
<li>pythonVersion (Integer) - 2 or 3 to indicate which version of Python to parse. Default = 2</li>
|
||||
<li>strictErrors (Bool) - true to highlight errors that may not be Python errors but cause confusion for this parser. Default = true</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
<p>Written by Timothy Farrell (<a href="LICENSE">license</a>). Special
|
||||
thanks to Adam Brand and Marijn Haverbeke for their help in debugging
|
||||
and providing for this parser.</p>
|
||||
|
||||
<div style="border: 1px solid black; padding: 0px;">
|
||||
<textarea id="code" cols="100" rows="20" style="width:100%">
|
||||
# Literals
|
||||
1234
|
||||
0.0e101
|
||||
.123
|
||||
0b01010011100
|
||||
0o01234567
|
||||
0x0987654321abcdef
|
||||
# Error Literals
|
||||
.0b000
|
||||
0.0e
|
||||
0e
|
||||
|
||||
# String Literals
|
||||
'For\''
|
||||
"God\""
|
||||
"""so loved
|
||||
the world"""
|
||||
'''that he gave
|
||||
his only begotten\' '''
|
||||
'that whosoever believeth \
|
||||
in him'
|
||||
''
|
||||
|
||||
# Identifiers
|
||||
__a__
|
||||
a.b
|
||||
a.b.c
|
||||
# Error Identifiers
|
||||
a.
|
||||
|
||||
# Operators
|
||||
+ - * / % & | ^ ~ < >
|
||||
== != <= >= <> << >> // **
|
||||
and or not in is
|
||||
|
||||
# Delimiters
|
||||
() [] {} , : ` = ; @ . # At-signs and periods require context
|
||||
+= -= *= /= %= &= |= ^=
|
||||
//= >>= <<= **=
|
||||
|
||||
# Keywords
|
||||
as assert break class continue def del elif else except
|
||||
finally for from global if import lambda pass raise
|
||||
return try while with yield
|
||||
|
||||
# Python 2 Keywords (otherwise Identifiers)
|
||||
exec print
|
||||
|
||||
# Python 3 Keywords (otherwise Identifiers)
|
||||
nonlocal
|
||||
|
||||
# Types
|
||||
bool classmethod complex dict enumerate float frozenset int list object
|
||||
property reversed set slice staticmethod str super tuple type
|
||||
|
||||
# Python 2 Types (otherwise Identifiers)
|
||||
basestring buffer file long unicode xrange
|
||||
|
||||
# Python 3 Types (otherwise Identifiers)
|
||||
bytearray bytes filter map memoryview open range zip
|
||||
|
||||
# Example Strict Errors
|
||||
def doesNothing():
|
||||
pass # indentUnit is set to 4 but this line is indented 3
|
||||
|
||||
# Some Example code
|
||||
import os
|
||||
from package import ParentClass
|
||||
|
||||
@nonsenseDecorator
|
||||
def doesNothing():
|
||||
pass
|
||||
|
||||
class ExampleClass(ParentClass):
|
||||
@staticmethod
|
||||
def example(inputStr):
|
||||
a = list(inputStr)
|
||||
a.reverse()
|
||||
return ''.join(a)
|
||||
|
||||
def __init__(self, mixin = 'Hello'):
|
||||
self.mixin = mixin
|
||||
|
||||
</textarea>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
var editor = CodeMirror.fromTextArea('code', {
|
||||
parserfile: ["../contrib/python/js/parsepython.js"],
|
||||
stylesheet: "css/pythoncolors.css",
|
||||
path: "../../js/",
|
||||
lineNumbers: true,
|
||||
textWrapping: false,
|
||||
indentUnit: 4,
|
||||
parserConfig: {'pythonVersion': 2, 'strictErrors': true}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
541
gulliver/js/codemirror/contrib/python/js/parsepython.js
Executable file
541
gulliver/js/codemirror/contrib/python/js/parsepython.js
Executable file
@@ -0,0 +1,541 @@
|
||||
var PythonParser = Editor.Parser = (function() {
|
||||
function wordRegexp(words) {
|
||||
return new RegExp("^(?:" + words.join("|") + ")$");
|
||||
}
|
||||
var DELIMITERCLASS = 'py-delimiter';
|
||||
var LITERALCLASS = 'py-literal';
|
||||
var ERRORCLASS = 'py-error';
|
||||
var OPERATORCLASS = 'py-operator';
|
||||
var IDENTIFIERCLASS = 'py-identifier';
|
||||
var STRINGCLASS = 'py-string';
|
||||
var BYTESCLASS = 'py-bytes';
|
||||
var UNICODECLASS = 'py-unicode';
|
||||
var RAWCLASS = 'py-raw';
|
||||
var NORMALCONTEXT = 'normal';
|
||||
var STRINGCONTEXT = 'string';
|
||||
var singleOperators = '+-*/%&|^~<>';
|
||||
var doubleOperators = wordRegexp(['==', '!=', '\\<=', '\\>=', '\\<\\>',
|
||||
'\\<\\<', '\\>\\>', '\\/\\/', '\\*\\*']);
|
||||
var singleDelimiters = '()[]{}@,:`=;';
|
||||
var doubleDelimiters = ['\\+=', '\\-=', '\\*=', '/=', '%=', '&=', '\\|=',
|
||||
'\\^='];
|
||||
var tripleDelimiters = wordRegexp(['//=','\\>\\>=','\\<\\<=','\\*\\*=']);
|
||||
var singleStarters = singleOperators + singleDelimiters + '=!';
|
||||
var doubleStarters = '=<>*/';
|
||||
var identifierStarters = /[_A-Za-z]/;
|
||||
|
||||
var wordOperators = wordRegexp(['and', 'or', 'not', 'is', 'in']);
|
||||
var commonkeywords = ['as', 'assert', 'break', 'class', 'continue',
|
||||
'def', 'del', 'elif', 'else', 'except', 'finally',
|
||||
'for', 'from', 'global', 'if', 'import',
|
||||
'lambda', 'pass', 'raise', 'return',
|
||||
'try', 'while', 'with', 'yield'];
|
||||
var commontypes = ['bool', 'classmethod', 'complex', 'dict', 'enumerate',
|
||||
'float', 'frozenset', 'int', 'list', 'object',
|
||||
'property', 'reversed', 'set', 'slice', 'staticmethod',
|
||||
'str', 'super', 'tuple', 'type'];
|
||||
var py2 = {'types': ['basestring', 'buffer', 'file', 'long', 'unicode',
|
||||
'xrange'],
|
||||
'keywords': ['exec', 'print'],
|
||||
'version': 2 };
|
||||
var py3 = {'types': ['bytearray', 'bytes', 'filter', 'map', 'memoryview',
|
||||
'open', 'range', 'zip'],
|
||||
'keywords': ['nonlocal'],
|
||||
'version': 3};
|
||||
|
||||
var py, keywords, types, stringStarters, stringTypes, config;
|
||||
|
||||
function configure(conf) {
|
||||
if (!conf.hasOwnProperty('pythonVersion')) {
|
||||
conf.pythonVersion = 2;
|
||||
}
|
||||
if (!conf.hasOwnProperty('strictErrors')) {
|
||||
conf.strictErrors = true;
|
||||
}
|
||||
if (conf.pythonVersion != 2 && conf.pythonVersion != 3) {
|
||||
alert('CodeMirror: Unknown Python Version "' +
|
||||
conf.pythonVersion +
|
||||
'", defaulting to Python 2.x.');
|
||||
conf.pythonVersion = 2;
|
||||
}
|
||||
if (conf.pythonVersion == 3) {
|
||||
py = py3;
|
||||
stringStarters = /[\'\"rbRB]/;
|
||||
stringTypes = /[rb]/;
|
||||
doubleDelimiters.push('\\-\\>');
|
||||
} else {
|
||||
py = py2;
|
||||
stringStarters = /[\'\"RUru]/;
|
||||
stringTypes = /[ru]/;
|
||||
}
|
||||
config = conf;
|
||||
keywords = wordRegexp(commonkeywords.concat(py.keywords));
|
||||
types = wordRegexp(commontypes.concat(py.types));
|
||||
doubleDelimiters = wordRegexp(doubleDelimiters);
|
||||
}
|
||||
|
||||
var tokenizePython = (function() {
|
||||
function normal(source, setState) {
|
||||
var stringDelim, threeStr, temp, type, word, possible = {};
|
||||
var ch = source.next();
|
||||
|
||||
function filterPossible(token, styleIfPossible) {
|
||||
if (!possible.style && !possible.content) {
|
||||
return token;
|
||||
} else if (typeof(token) == STRINGCONTEXT) {
|
||||
token = {content: source.get(), style: token};
|
||||
}
|
||||
if (possible.style || styleIfPossible) {
|
||||
token.style = styleIfPossible ? styleIfPossible : possible.style;
|
||||
}
|
||||
if (possible.content) {
|
||||
token.content = possible.content + token.content;
|
||||
}
|
||||
possible = {};
|
||||
return token;
|
||||
}
|
||||
|
||||
// Handle comments
|
||||
if (ch == '#') {
|
||||
while (!source.endOfLine()) {
|
||||
source.next();
|
||||
}
|
||||
return 'py-comment';
|
||||
}
|
||||
// Handle special chars
|
||||
if (ch == '\\') {
|
||||
if (!source.endOfLine()) {
|
||||
var whitespace = true;
|
||||
while (!source.endOfLine()) {
|
||||
if(!(/[\s\u00a0]/.test(source.next()))) {
|
||||
whitespace = false;
|
||||
}
|
||||
}
|
||||
if (!whitespace) {
|
||||
return ERRORCLASS;
|
||||
}
|
||||
}
|
||||
return 'py-special';
|
||||
}
|
||||
// Handle operators and delimiters
|
||||
if (singleStarters.indexOf(ch) != -1 || (ch == "." && !source.matches(/\d/))) {
|
||||
if (doubleStarters.indexOf(source.peek()) != -1) {
|
||||
temp = ch + source.peek();
|
||||
// It must be a double delimiter or operator or triple delimiter
|
||||
if (doubleOperators.test(temp)) {
|
||||
source.next();
|
||||
var nextChar = source.peek();
|
||||
if (nextChar && tripleDelimiters.test(temp + nextChar)) {
|
||||
source.next();
|
||||
return DELIMITERCLASS;
|
||||
} else {
|
||||
return OPERATORCLASS;
|
||||
}
|
||||
} else if (doubleDelimiters.test(temp)) {
|
||||
source.next();
|
||||
return DELIMITERCLASS;
|
||||
}
|
||||
}
|
||||
// It must be a single delimiter or operator
|
||||
if (singleOperators.indexOf(ch) != -1 || ch == ".") {
|
||||
return OPERATORCLASS;
|
||||
} else if (singleDelimiters.indexOf(ch) != -1) {
|
||||
if (ch == '@' && source.matches(/\w/)) {
|
||||
source.nextWhileMatches(/[\w\d_]/);
|
||||
return {style:'py-decorator',
|
||||
content: source.get()};
|
||||
} else {
|
||||
return DELIMITERCLASS;
|
||||
}
|
||||
} else {
|
||||
return ERRORCLASS;
|
||||
}
|
||||
}
|
||||
// Handle number literals
|
||||
if (/\d/.test(ch) || (ch == "." && source.matches(/\d/))) {
|
||||
if (ch === '0' && !source.endOfLine()) {
|
||||
switch (source.peek()) {
|
||||
case 'o':
|
||||
case 'O':
|
||||
source.next();
|
||||
source.nextWhileMatches(/[0-7]/);
|
||||
return filterPossible(LITERALCLASS, ERRORCLASS);
|
||||
case 'x':
|
||||
case 'X':
|
||||
source.next();
|
||||
source.nextWhileMatches(/[0-9A-Fa-f]/);
|
||||
return filterPossible(LITERALCLASS, ERRORCLASS);
|
||||
case 'b':
|
||||
case 'B':
|
||||
source.next();
|
||||
source.nextWhileMatches(/[01]/);
|
||||
return filterPossible(LITERALCLASS, ERRORCLASS);
|
||||
}
|
||||
}
|
||||
source.nextWhileMatches(/\d/);
|
||||
if (ch != '.' && source.peek() == '.') {
|
||||
source.next();
|
||||
source.nextWhileMatches(/\d/);
|
||||
}
|
||||
// Grab an exponent
|
||||
if (source.matches(/e/i)) {
|
||||
source.next();
|
||||
if (source.peek() == '+' || source.peek() == '-') {
|
||||
source.next();
|
||||
}
|
||||
if (source.matches(/\d/)) {
|
||||
source.nextWhileMatches(/\d/);
|
||||
} else {
|
||||
return filterPossible(ERRORCLASS);
|
||||
}
|
||||
}
|
||||
// Grab a complex number
|
||||
if (source.matches(/j/i)) {
|
||||
source.next();
|
||||
}
|
||||
|
||||
return filterPossible(LITERALCLASS);
|
||||
}
|
||||
// Handle strings
|
||||
if (stringStarters.test(ch)) {
|
||||
var peek = source.peek();
|
||||
var stringType = STRINGCLASS;
|
||||
if ((stringTypes.test(ch)) && (peek == '"' || peek == "'")) {
|
||||
switch (ch.toLowerCase()) {
|
||||
case 'b':
|
||||
stringType = BYTESCLASS;
|
||||
break;
|
||||
case 'r':
|
||||
stringType = RAWCLASS;
|
||||
break;
|
||||
case 'u':
|
||||
stringType = UNICODECLASS;
|
||||
break;
|
||||
}
|
||||
ch = source.next();
|
||||
stringDelim = ch;
|
||||
if (source.peek() != stringDelim) {
|
||||
setState(inString(stringType, stringDelim));
|
||||
return null;
|
||||
} else {
|
||||
source.next();
|
||||
if (source.peek() == stringDelim) {
|
||||
source.next();
|
||||
threeStr = stringDelim + stringDelim + stringDelim;
|
||||
setState(inString(stringType, threeStr));
|
||||
return null;
|
||||
} else {
|
||||
return stringType;
|
||||
}
|
||||
}
|
||||
} else if (ch == "'" || ch == '"') {
|
||||
stringDelim = ch;
|
||||
if (source.peek() != stringDelim) {
|
||||
setState(inString(stringType, stringDelim));
|
||||
return null;
|
||||
} else {
|
||||
source.next();
|
||||
if (source.peek() == stringDelim) {
|
||||
source.next();
|
||||
threeStr = stringDelim + stringDelim + stringDelim;
|
||||
setState(inString(stringType, threeStr));
|
||||
return null;
|
||||
} else {
|
||||
return stringType;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Handle Identifier
|
||||
if (identifierStarters.test(ch)) {
|
||||
source.nextWhileMatches(/[\w\d_]/);
|
||||
word = source.get();
|
||||
if (wordOperators.test(word)) {
|
||||
type = OPERATORCLASS;
|
||||
} else if (keywords.test(word)) {
|
||||
type = 'py-keyword';
|
||||
} else if (types.test(word)) {
|
||||
type = 'py-type';
|
||||
} else {
|
||||
type = IDENTIFIERCLASS;
|
||||
while (source.peek() == '.') {
|
||||
source.next();
|
||||
if (source.matches(identifierStarters)) {
|
||||
source.nextWhileMatches(/[\w\d]/);
|
||||
} else {
|
||||
type = ERRORCLASS;
|
||||
break;
|
||||
}
|
||||
}
|
||||
word = word + source.get();
|
||||
}
|
||||
return filterPossible({style: type, content: word});
|
||||
}
|
||||
|
||||
// Register Dollar sign and Question mark as errors. Always!
|
||||
if (/\$\?/.test(ch)) {
|
||||
return filterPossible(ERRORCLASS);
|
||||
}
|
||||
|
||||
return filterPossible(ERRORCLASS);
|
||||
}
|
||||
|
||||
function inString(style, terminator) {
|
||||
return function(source, setState) {
|
||||
var matches = [];
|
||||
var found = false;
|
||||
while (!found && !source.endOfLine()) {
|
||||
var ch = source.next(), newMatches = [];
|
||||
// Skip escaped characters
|
||||
if (ch == '\\') {
|
||||
if (source.peek() == '\n') {
|
||||
break;
|
||||
}
|
||||
ch = source.next();
|
||||
}
|
||||
if (ch == terminator.charAt(0)) {
|
||||
matches.push(terminator);
|
||||
}
|
||||
for (var i = 0; i < matches.length; i++) {
|
||||
var match = matches[i];
|
||||
if (match.charAt(0) == ch) {
|
||||
if (match.length == 1) {
|
||||
setState(normal);
|
||||
found = true;
|
||||
break;
|
||||
} else {
|
||||
newMatches.push(match.slice(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
matches = newMatches;
|
||||
}
|
||||
return style;
|
||||
};
|
||||
}
|
||||
|
||||
return function(source, startState) {
|
||||
return tokenizer(source, startState || normal);
|
||||
};
|
||||
})();
|
||||
|
||||
function parsePython(source, basecolumn) {
|
||||
if (!keywords) {
|
||||
configure({});
|
||||
}
|
||||
basecolumn = basecolumn || 0;
|
||||
|
||||
var tokens = tokenizePython(source);
|
||||
var lastToken = null;
|
||||
var column = basecolumn;
|
||||
var context = {prev: null,
|
||||
endOfScope: false,
|
||||
startNewScope: false,
|
||||
level: basecolumn,
|
||||
next: null,
|
||||
type: NORMALCONTEXT
|
||||
};
|
||||
|
||||
function pushContext(level, type) {
|
||||
type = type ? type : NORMALCONTEXT;
|
||||
context = {prev: context,
|
||||
endOfScope: false,
|
||||
startNewScope: false,
|
||||
level: level,
|
||||
next: null,
|
||||
type: type
|
||||
};
|
||||
}
|
||||
|
||||
function popContext(remove) {
|
||||
remove = remove ? remove : false;
|
||||
if (context.prev) {
|
||||
if (remove) {
|
||||
context = context.prev;
|
||||
context.next = null;
|
||||
} else {
|
||||
context.prev.next = context;
|
||||
context = context.prev;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function indentPython(context) {
|
||||
var temp;
|
||||
return function(nextChars, currentLevel, direction) {
|
||||
if (direction === null || direction === undefined) {
|
||||
if (nextChars) {
|
||||
while (context.next) {
|
||||
context = context.next;
|
||||
}
|
||||
}
|
||||
return context.level;
|
||||
}
|
||||
else if (direction === true) {
|
||||
if (currentLevel == context.level) {
|
||||
if (context.next) {
|
||||
return context.next.level;
|
||||
} else {
|
||||
return context.level;
|
||||
}
|
||||
} else {
|
||||
temp = context;
|
||||
while (temp.prev && temp.prev.level > currentLevel) {
|
||||
temp = temp.prev;
|
||||
}
|
||||
return temp.level;
|
||||
}
|
||||
} else if (direction === false) {
|
||||
if (currentLevel > context.level) {
|
||||
return context.level;
|
||||
} else if (context.prev) {
|
||||
temp = context;
|
||||
while (temp.prev && temp.prev.level >= currentLevel) {
|
||||
temp = temp.prev;
|
||||
}
|
||||
if (temp.prev) {
|
||||
return temp.prev.level;
|
||||
} else {
|
||||
return temp.level;
|
||||
}
|
||||
}
|
||||
}
|
||||
return context.level;
|
||||
};
|
||||
}
|
||||
|
||||
var iter = {
|
||||
next: function() {
|
||||
var token = tokens.next();
|
||||
var type = token.style;
|
||||
var content = token.content;
|
||||
|
||||
if (lastToken) {
|
||||
if (lastToken.content == 'def' && type == IDENTIFIERCLASS) {
|
||||
token.style = 'py-func';
|
||||
}
|
||||
if (lastToken.content == '\n') {
|
||||
var tempCtx = context;
|
||||
// Check for a different scope
|
||||
if (type == 'whitespace' && context.type == NORMALCONTEXT) {
|
||||
if (token.value.length < context.level) {
|
||||
while (token.value.length < context.level) {
|
||||
popContext();
|
||||
}
|
||||
|
||||
if (token.value.length != context.level) {
|
||||
context = tempCtx;
|
||||
if (config.strictErrors) {
|
||||
token.style = ERRORCLASS;
|
||||
}
|
||||
} else {
|
||||
context.next = null;
|
||||
}
|
||||
}
|
||||
} else if (context.level !== basecolumn &&
|
||||
context.type == NORMALCONTEXT) {
|
||||
while (basecolumn !== context.level) {
|
||||
popContext();
|
||||
}
|
||||
|
||||
if (context.level !== basecolumn) {
|
||||
context = tempCtx;
|
||||
if (config.strictErrors) {
|
||||
token.style = ERRORCLASS;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle Scope Changes
|
||||
switch(type) {
|
||||
case STRINGCLASS:
|
||||
case BYTESCLASS:
|
||||
case RAWCLASS:
|
||||
case UNICODECLASS:
|
||||
if (context.type !== STRINGCONTEXT) {
|
||||
pushContext(context.level + 1, STRINGCONTEXT);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (context.type === STRINGCONTEXT) {
|
||||
popContext(true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
switch(content) {
|
||||
case '.':
|
||||
case '@':
|
||||
// These delimiters don't appear by themselves
|
||||
if (content !== token.value) {
|
||||
token.style = ERRORCLASS;
|
||||
}
|
||||
break;
|
||||
case ':':
|
||||
// Colons only delimit scope inside a normal scope
|
||||
if (context.type === NORMALCONTEXT) {
|
||||
context.startNewScope = context.level+indentUnit;
|
||||
}
|
||||
break;
|
||||
case '(':
|
||||
case '[':
|
||||
case '{':
|
||||
// These start a sequence scope
|
||||
pushContext(column + content.length, 'sequence');
|
||||
break;
|
||||
case ')':
|
||||
case ']':
|
||||
case '}':
|
||||
// These end a sequence scope
|
||||
popContext(true);
|
||||
break;
|
||||
case 'pass':
|
||||
case 'return':
|
||||
// These end a normal scope
|
||||
if (context.type === NORMALCONTEXT) {
|
||||
context.endOfScope = true;
|
||||
}
|
||||
break;
|
||||
case '\n':
|
||||
// Reset our column
|
||||
column = basecolumn;
|
||||
// Make any scope changes
|
||||
if (context.endOfScope) {
|
||||
context.endOfScope = false;
|
||||
popContext();
|
||||
} else if (context.startNewScope !== false) {
|
||||
var temp = context.startNewScope;
|
||||
context.startNewScope = false;
|
||||
pushContext(temp, NORMALCONTEXT);
|
||||
}
|
||||
// Newlines require an indentation function wrapped in a closure for proper context.
|
||||
token.indentation = indentPython(context);
|
||||
break;
|
||||
}
|
||||
|
||||
// Keep track of current column for certain scopes.
|
||||
if (content != '\n') {
|
||||
column += token.value.length;
|
||||
}
|
||||
|
||||
lastToken = token;
|
||||
return token;
|
||||
},
|
||||
|
||||
copy: function() {
|
||||
var _context = context, _tokenState = tokens.state;
|
||||
return function(source) {
|
||||
tokens = tokenizePython(source, _tokenState);
|
||||
context = _context;
|
||||
return iter;
|
||||
};
|
||||
}
|
||||
};
|
||||
return iter;
|
||||
}
|
||||
|
||||
return {make: parsePython,
|
||||
electricChars: "",
|
||||
configure: configure};
|
||||
})();
|
||||
214
gulliver/js/codemirror/contrib/regex/css/js-regexcolors.css
Executable file
214
gulliver/js/codemirror/contrib/regex/css/js-regexcolors.css
Executable file
@@ -0,0 +1,214 @@
|
||||
/*///////////////////////////////*/
|
||||
html {
|
||||
cursor: text;
|
||||
}
|
||||
.editbox {
|
||||
margin: .4em;
|
||||
padding: 0;
|
||||
font-family: monospace;
|
||||
font-size: 10pt;
|
||||
color: black;
|
||||
}
|
||||
.editbox p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
html, body {
|
||||
background: #cccccc !important;
|
||||
}
|
||||
|
||||
/*///////////////////////////////*/
|
||||
/* Inside character classes */
|
||||
span.regex-class-special-escape {
|
||||
color: Coral;
|
||||
}
|
||||
span.regex-class-begin, span.regex-class-end {
|
||||
color: YellowGreen;
|
||||
}
|
||||
span.regex-class-negator {
|
||||
color: Wheat;
|
||||
}
|
||||
span.regex-class-range-hyphen {
|
||||
color: Turquoise;
|
||||
}
|
||||
span.regex-class-final-hyphen {
|
||||
color: Violet;
|
||||
}
|
||||
|
||||
/*///////////////////////////////*/
|
||||
/* Inside character classes (suffixable by -begin-range or -end-range if beginning or ending a range) */
|
||||
span.regex-unicode-class-inside {
|
||||
color: Tomato;
|
||||
}
|
||||
span.regex-class-initial-hyphen {
|
||||
color: Teal;
|
||||
}
|
||||
span.regex-class-character {
|
||||
color: Tan;
|
||||
}
|
||||
span.regex-class-octal {
|
||||
color: SteelBlue;
|
||||
}
|
||||
span.regex-class-hex {
|
||||
color: SpringGreen;
|
||||
}
|
||||
span.regex-class-unicode-escape {
|
||||
color: SlateGray;
|
||||
}
|
||||
span.regex-class-ascii-control {
|
||||
color: SlateBlue;
|
||||
}
|
||||
span.regex-class-extra-escaped {
|
||||
color: SkyBlue;
|
||||
}
|
||||
span.regex-class-escaped-special {
|
||||
color: CornflowerBlue;
|
||||
}
|
||||
|
||||
/*///////////////////////////////*/
|
||||
span.class-special-escape-begin-range, span.class-special-escape-end-range {
|
||||
color: Brown;
|
||||
}
|
||||
span.regex-unicode-class-inside-begin-range, span.regex-unicode-class-inside-end-range {
|
||||
color: Silver;
|
||||
}
|
||||
span.regex-class-initial-hyphen-begin-range, span.regex-class-initial-hyphen-end-range {
|
||||
color: SeaGreen;
|
||||
}
|
||||
span.regex-class-character-begin-range, span.regex-class-character-end-range {
|
||||
color: SandyBrown;
|
||||
}
|
||||
span.regex-class-octal-begin-range, span.regex-class-octal-end-range {
|
||||
color: Salmon;
|
||||
}
|
||||
span.regex-class-hex-begin-range, span.regex-class-hex-end-range {
|
||||
color: SaddleBrown;
|
||||
}
|
||||
span.regex-class-unicode-escape-begin-range, span.regex-class-unicode-escape-end-range {
|
||||
color: RoyalBlue;
|
||||
}
|
||||
span.regex-class-ascii-control-begin-range, span.regex-class-ascii-control-end-range {
|
||||
color: RosyBrown;
|
||||
}
|
||||
span.regex-class-extra-escaped-begin-range, span.regex-class-extra-escaped-end-range {
|
||||
color: Orange;
|
||||
}
|
||||
span.regex-class-escaped-special-begin-range, span.regex-class-escaped-special-end-range {
|
||||
color: DarkKhaki;
|
||||
}
|
||||
|
||||
|
||||
/*///////////////////////////////*/
|
||||
/* Outside character classes */
|
||||
span.regex-special-escape {
|
||||
color: Chocolate;
|
||||
}
|
||||
span.regex-escaped-special {
|
||||
color: Orange;
|
||||
}
|
||||
span.regex-alternator {
|
||||
color: darkpink;
|
||||
}
|
||||
span.regex-unicode-class-outside {
|
||||
color: Green;
|
||||
}
|
||||
span.regex-octal {
|
||||
color: MediumVioletRed;
|
||||
}
|
||||
span.regex-ascii {
|
||||
color: MediumTurquoise;
|
||||
}
|
||||
span.regex-hex {
|
||||
color: MediumSpringGreen;
|
||||
}
|
||||
span.regex-unicode-escape {
|
||||
color:pink;
|
||||
}
|
||||
span.regex-ascii-control {
|
||||
color: MediumSlateBlue;
|
||||
}
|
||||
span.regex-extra-escaped {
|
||||
color: MediumSeaGreen;
|
||||
}
|
||||
span.regex-quantifier-escape {
|
||||
color: Azure;
|
||||
}
|
||||
span.regex-quantifiers {
|
||||
color: MediumPurple;
|
||||
}
|
||||
span.regex-repetition {
|
||||
color: MediumOrchid;
|
||||
}
|
||||
span.regex-literal-begin, span.regex-literal-end {
|
||||
color: MediumBlue;
|
||||
}
|
||||
span.regex-character {
|
||||
color: Navy;
|
||||
}
|
||||
|
||||
/*///////////////////////////////*/
|
||||
/* Literals/Surrounding characters */
|
||||
span.regex-flags {
|
||||
color: Green;
|
||||
}
|
||||
|
||||
/*///////////////////////////////*/
|
||||
/* Optional outside character class features*/
|
||||
span.regex-empty-class {
|
||||
color: Lime;
|
||||
}
|
||||
span.regex-named-backreference {
|
||||
color: LightSlateGray;
|
||||
}
|
||||
span.regex-free-spacing-mode {
|
||||
background-color: LightSeaGreen;
|
||||
}
|
||||
span.regex-mode-modifier {
|
||||
color: LightSalmon;
|
||||
}
|
||||
span.regex-comment-pattern {
|
||||
color: LightGreen;
|
||||
}
|
||||
span.regex-capturing-group, span.regex-ending-capturing-group {
|
||||
color: LightGray;
|
||||
}
|
||||
span.regex-named-capturing-group, span.regex-ending-named-capturing-group {
|
||||
color: LightCoral;
|
||||
}
|
||||
span.regex-group, span.regex-ending-group {
|
||||
color: LawnGreen;
|
||||
}
|
||||
|
||||
|
||||
span.regex-capturing-group1-1, span.regex-ending-capturing-group1-1 {
|
||||
background-color: red;
|
||||
}
|
||||
span.regex-capturing-group1-2, span.regex-ending-capturing-group1-2 {
|
||||
background-color: orange;
|
||||
}
|
||||
span.regex-capturing-group2-1, span.regex-ending-capturing-group2-1 {
|
||||
background-color: yellow;
|
||||
}
|
||||
span.regex-capturing-group2-2, span.regex-ending-capturing-group2-2 {
|
||||
background-color: green;
|
||||
}
|
||||
|
||||
/*///////////////////////////////*/
|
||||
/* Closing parentheses without opening, etc. */
|
||||
span.regex-bad-character, span.regex-bad-sequence {
|
||||
color: red;
|
||||
}
|
||||
|
||||
/* Used if "uniform" inner_group_mode is used */
|
||||
span.regex-group-1-1 {
|
||||
background-color: blue;
|
||||
}
|
||||
span.regex-group-1-2 {
|
||||
background-color: green;
|
||||
}
|
||||
span.regex-group-2-1 {
|
||||
background-color: pink;
|
||||
}
|
||||
span.regex-group-2-2 {
|
||||
background-color: yellow;
|
||||
}
|
||||
214
gulliver/js/codemirror/contrib/regex/css/regexcolors.css
Executable file
214
gulliver/js/codemirror/contrib/regex/css/regexcolors.css
Executable file
@@ -0,0 +1,214 @@
|
||||
/*///////////////////////////////*/
|
||||
html {
|
||||
cursor: text;
|
||||
}
|
||||
.editbox {
|
||||
margin: .4em;
|
||||
padding: 0;
|
||||
font-family: monospace;
|
||||
font-size: 10pt;
|
||||
color: black;
|
||||
}
|
||||
.editbox p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
html, body {
|
||||
background: #555555 !important;
|
||||
}
|
||||
|
||||
/*///////////////////////////////*/
|
||||
/* Inside character classes */
|
||||
span.regex-class-special-escape {
|
||||
color: Coral;
|
||||
}
|
||||
span.regex-class-begin, span.regex-class-end {
|
||||
color: YellowGreen;
|
||||
}
|
||||
span.regex-class-negator {
|
||||
color: Wheat;
|
||||
}
|
||||
span.regex-class-range-hyphen {
|
||||
color: Turquoise;
|
||||
}
|
||||
span.regex-class-final-hyphen {
|
||||
color: Violet;
|
||||
}
|
||||
|
||||
/*///////////////////////////////*/
|
||||
/* Inside character classes (suffixable by -begin-range or -end-range if beginning or ending a range) */
|
||||
span.regex-unicode-class-inside {
|
||||
color: Tomato;
|
||||
}
|
||||
span.regex-class-initial-hyphen {
|
||||
color: Teal;
|
||||
}
|
||||
span.regex-class-character {
|
||||
color: Tan;
|
||||
}
|
||||
span.regex-class-octal {
|
||||
color: SteelBlue;
|
||||
}
|
||||
span.regex-class-hex {
|
||||
color: SpringGreen;
|
||||
}
|
||||
span.regex-class-unicode-escape {
|
||||
color: LightGray;
|
||||
}
|
||||
span.regex-class-ascii-control {
|
||||
color: SlateBlue;
|
||||
}
|
||||
span.regex-class-extra-escaped {
|
||||
color: SkyBlue;
|
||||
}
|
||||
span.regex-class-escaped-special {
|
||||
color: CornflowerBlue;
|
||||
}
|
||||
|
||||
/*///////////////////////////////*/
|
||||
span.class-special-escape-begin-range, span.class-special-escape-end-range {
|
||||
color: Brown;
|
||||
}
|
||||
span.regex-unicode-class-inside-begin-range, span.regex-unicode-class-inside-end-range {
|
||||
color: Silver;
|
||||
}
|
||||
span.regex-class-initial-hyphen-begin-range, span.regex-class-initial-hyphen-end-range {
|
||||
color: SeaGreen;
|
||||
}
|
||||
span.regex-class-character-begin-range, span.regex-class-character-end-range {
|
||||
color: SandyBrown;
|
||||
}
|
||||
span.regex-class-octal-begin-range, span.regex-class-octal-end-range {
|
||||
color: Salmon;
|
||||
}
|
||||
span.regex-class-hex-begin-range, span.regex-class-hex-end-range {
|
||||
color: Tan;
|
||||
}
|
||||
span.regex-class-unicode-escape-begin-range, span.regex-class-unicode-escape-end-range {
|
||||
color: LightBlue;
|
||||
}
|
||||
span.regex-class-ascii-control-begin-range, span.regex-class-ascii-control-end-range {
|
||||
color: RosyBrown;
|
||||
}
|
||||
span.regex-class-extra-escaped-begin-range, span.regex-class-extra-escaped-end-range {
|
||||
color: Orange;
|
||||
}
|
||||
span.regex-class-escaped-special-begin-range, span.regex-class-escaped-special-end-range {
|
||||
color: DarkKhaki;
|
||||
}
|
||||
|
||||
|
||||
/*///////////////////////////////*/
|
||||
/* Outside character classes */
|
||||
span.regex-special-escape {
|
||||
color: Chocolate;
|
||||
}
|
||||
span.regex-escaped-special {
|
||||
color: Orange;
|
||||
}
|
||||
span.regex-alternator {
|
||||
color: BurlyWood;
|
||||
}
|
||||
span.regex-unicode-class-outside {
|
||||
color: Gold;
|
||||
}
|
||||
span.regex-octal {
|
||||
color: MediumVioletRed;
|
||||
}
|
||||
span.regex-ascii {
|
||||
color: MediumTurquoise;
|
||||
}
|
||||
span.regex-hex {
|
||||
color: MediumSpringGreen;
|
||||
}
|
||||
span.regex-unicode-escape {
|
||||
color:pink;
|
||||
}
|
||||
span.regex-ascii-control {
|
||||
color: MediumSlateBlue;
|
||||
}
|
||||
span.regex-extra-escaped {
|
||||
color: MediumSeaGreen;
|
||||
}
|
||||
span.regex-quantifier-escape {
|
||||
color: Azure;
|
||||
}
|
||||
span.regex-quantifiers {
|
||||
color: MediumPurple;
|
||||
}
|
||||
span.regex-repetition {
|
||||
color: MediumOrchid;
|
||||
}
|
||||
span.regex-literal-begin, span.regex-literal-end {
|
||||
color: MediumBlue;
|
||||
}
|
||||
span.regex-character {
|
||||
color: #FFFFAA;
|
||||
}
|
||||
|
||||
/*///////////////////////////////*/
|
||||
/* Literals/Surrounding characters */
|
||||
span.regex-flags {
|
||||
color: LimeGreen;
|
||||
}
|
||||
|
||||
/*///////////////////////////////*/
|
||||
/* Optional outside character class features*/
|
||||
span.regex-empty-class {
|
||||
color: Lime;
|
||||
}
|
||||
span.regex-named-backreference {
|
||||
color: LightSlateGray;
|
||||
}
|
||||
span.regex-free-spacing-mode {
|
||||
background-color: LightSeaGreen;
|
||||
}
|
||||
span.regex-mode-modifier {
|
||||
color: LightSalmon;
|
||||
}
|
||||
span.regex-comment-pattern {
|
||||
color: LightGreen;
|
||||
}
|
||||
span.regex-capturing-group, span.regex-ending-capturing-group {
|
||||
color: LightGray;
|
||||
}
|
||||
span.regex-named-capturing-group, span.regex-ending-named-capturing-group {
|
||||
color: LightCoral;
|
||||
}
|
||||
span.regex-group, span.regex-ending-group {
|
||||
color: LawnGreen;
|
||||
}
|
||||
|
||||
|
||||
span.regex-capturing-group1-1, span.regex-ending-capturing-group1-1 {
|
||||
background-color: red;
|
||||
}
|
||||
span.regex-capturing-group1-2, span.regex-ending-capturing-group1-2 {
|
||||
background-color: orange;
|
||||
}
|
||||
span.regex-capturing-group2-1, span.regex-ending-capturing-group2-1 {
|
||||
background-color: yellow;
|
||||
}
|
||||
span.regex-capturing-group2-2, span.regex-ending-capturing-group2-2 {
|
||||
background-color: green;
|
||||
}
|
||||
|
||||
/*///////////////////////////////*/
|
||||
/* Closing parentheses without opening, etc. */
|
||||
span.regex-bad-character, span.regex-bad-sequence {
|
||||
color: red;
|
||||
}
|
||||
|
||||
/* Used if "uniform" inner_group_mode is used */
|
||||
span.regex-group-1-1 {
|
||||
color: lightblue;
|
||||
}
|
||||
span.regex-group-1-2 {
|
||||
color: lightgreen;
|
||||
}
|
||||
span.regex-group-2-1 {
|
||||
color: pink;
|
||||
}
|
||||
span.regex-group-2-2 {
|
||||
color: yellow;
|
||||
}
|
||||
114
gulliver/js/codemirror/contrib/regex/index.html
Executable file
114
gulliver/js/codemirror/contrib/regex/index.html
Executable file
@@ -0,0 +1,114 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror Regex Highlighting</title>
|
||||
<script type="text/javascript" src="../../js/codemirror.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
window.onload = function () {
|
||||
var editor = CodeMirror.fromTextArea('regexp', {
|
||||
noScriptCaching: true,
|
||||
// continuousScanning: true, // Normally Debugging only, but useful with regex
|
||||
parserConfig: {
|
||||
// flags: 'x',
|
||||
//literal: true,
|
||||
flavor: 'all',
|
||||
regex_mode_modifier: true,
|
||||
regex_max_levels:2,
|
||||
regex_max_alternating:2,
|
||||
regex_unicode_mode: 'store',
|
||||
regex_inner_group_mode: 'uniform'
|
||||
},
|
||||
parserfile: ["../contrib/regex/js/parseregex.js", "../contrib/regex/js/parseregex-unicode.js"],
|
||||
stylesheet: ["css/regexcolors.css"],
|
||||
path: '../../js/',
|
||||
height: 'dynamic',
|
||||
minHeight: 20,
|
||||
|
||||
// Demonstrates Unicode tooltip features
|
||||
/**/
|
||||
activeTokens : (function () {
|
||||
var charLimit = 500;
|
||||
var lastEquivalent, rangeBegan, lastRangeHyphen;
|
||||
|
||||
function _buildTitle (beginChar, endChar) {
|
||||
var beginCode = beginChar.charCodeAt(0), endCode = endChar.charCodeAt(0);
|
||||
var title = '';
|
||||
if (endCode - beginCode <= charLimit) {
|
||||
for (var i = beginCode; i <= endCode; i++) {
|
||||
title += String.fromCharCode(i);
|
||||
}
|
||||
}
|
||||
return title;
|
||||
}
|
||||
|
||||
return function (spanNode, token, editor) {
|
||||
var content = token.content;
|
||||
if (lastEquivalent && token.style === 'regex-class-range-hyphen') {
|
||||
rangeBegan = true;
|
||||
lastRangeHyphen = spanNode;
|
||||
}
|
||||
else if (rangeBegan) {
|
||||
var beginChar = lastEquivalent;
|
||||
var endChar = (token.equivalent || content);
|
||||
lastRangeHyphen.title = _buildTitle(beginChar, endChar);
|
||||
rangeBegan = false;
|
||||
lastEquivalent = null;
|
||||
}
|
||||
else if (content === ']') {
|
||||
rangeBegan = false;
|
||||
}
|
||||
else {
|
||||
rangeBegan = false;
|
||||
// Fix: 'regex-unicode-class-inside' not supported and should not be since it wouldn't make sense as a starting range?
|
||||
lastEquivalent = token.equivalent || content;
|
||||
}
|
||||
|
||||
if (token.display) {
|
||||
spanNode.title = token.display;
|
||||
}
|
||||
else if (token.equivalent) {
|
||||
if (token.unicode) {
|
||||
var range = /(.)-(.)/g;
|
||||
spanNode.title = token.equivalent.replace(range,
|
||||
function (n0, n1, n2) {
|
||||
return _buildTitle(n1, n2);
|
||||
}
|
||||
);
|
||||
}
|
||||
else {
|
||||
spanNode.title = token.equivalent;
|
||||
}
|
||||
}
|
||||
};
|
||||
}())
|
||||
//*/
|
||||
});
|
||||
};
|
||||
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div>
|
||||
<h1>CodeMirror Regex Code Editor Demonstration</h1>
|
||||
<p>The Regex parser for CodeMirror allows syntax coloring on regular expressions with some beginning customizability by
|
||||
Regex flavor/language. For integrating styling of regular expression literals into JavaScript syntax highlighting, see this
|
||||
<a href="js-regex.html">JavaScript+Regex Demo</a>.</p>
|
||||
<p>Styling ability is fine-grained, so any token should be distinctly stylable if so desired. Parenthetical groups can
|
||||
be styled with the same styles for inner content, and the script also enables styling by nesting depth and sequence,
|
||||
including by imposing a limit such that styles will alternate.</p>
|
||||
<p>Information can also be passed on (especially when the parseregex-unicode.js file is included) for use in CodeMirror's
|
||||
activeTokens argument such as demonstrated below by tooltips which show which characters are present in a given
|
||||
range or Unicode class.</p>
|
||||
<p>Note that this editor does not support free-spacing mode, so it is not recommended to use multiple lines for input, but
|
||||
for demonstration purposes, multiple lines are shown.</p>
|
||||
<textarea id="regexp">(?ix)/some(group)and more(?:unnumbered)and(?=sth)but(?!not)
|
||||
(\k<named_$>b.ckref) (?#a comment) # some space
|
||||
fdd[^]aa[]ddf[\45-\55\67]sfa[\ca-\cb\cd]sdf\cdf\p{No}ddf[\a-\q]dffd[\u0033-\u0640\u0747]+?f*?df[\034-\038\u039]d
|
||||
[\xaf-\xbf]fdfe{1}dfsd{2,3}--fakj{3,}f[^ab]df\39d[^a-ze-]a076df[\u00a0-\u00f0][\u0010\49\077\xaf]ffa[--q]ds[*--]ad[-ad\qfw]fd\qad\p{^a}fdf\P{a}a[ab-cd]\x11\u0123\ca\34df/gi
|
||||
</textarea>
|
||||
<!--<textarea id="replacements" cols="30" rows="1">{$&}</textarea>-->
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
118
gulliver/js/codemirror/contrib/regex/js-regex.html
Executable file
118
gulliver/js/codemirror/contrib/regex/js-regex.html
Executable file
@@ -0,0 +1,118 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror Regex Highlighting</title>
|
||||
<script type="text/javascript" src="../../js/codemirror.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
window.onload = function () {
|
||||
|
||||
createEditor('js-regexp', 'uniform');
|
||||
createEditor('js-regexp-type', 'type');
|
||||
createEditor('js-regexp-none', false);
|
||||
|
||||
function createEditor (id, type) {
|
||||
var jseditor = CodeMirror.fromTextArea(id, {
|
||||
noScriptCaching: true,
|
||||
// continuousScanning: true, // Normally Debugging only, but useful with regex
|
||||
parserConfig: {
|
||||
// flags: 'x',
|
||||
//literal: true,
|
||||
flavor: 'ecma-262-ed3',
|
||||
regex_mode_modifier: true,
|
||||
regex_max_levels:2,
|
||||
regex_max_alternating:2,
|
||||
regex_inner_group_mode: type
|
||||
},
|
||||
parserfile: ["tokenizejavascript.js", "parsejavascript.js", "../contrib/regex/js/parseregex.js","../contrib/regex/js/parsejavascript_and_regex.js"],
|
||||
stylesheet: ["css/js-regexcolors.css", "../../css/jscolors.css"],
|
||||
path: '../../js/',
|
||||
height: 'dynamic',
|
||||
minHeight: 20,
|
||||
|
||||
// Demonstrates Unicode tooltip features
|
||||
activeTokens : (function () {
|
||||
var charLimit = 500;
|
||||
var lastEquivalent, rangeBegan, lastRangeHyphen;
|
||||
|
||||
function _buildTitle (beginChar, endChar) {
|
||||
var beginCode = beginChar.charCodeAt(0), endCode = endChar.charCodeAt(0);
|
||||
var title = '';
|
||||
if (endCode - beginCode <= charLimit) {
|
||||
for (var i = beginCode; i <= endCode; i++) {
|
||||
title += String.fromCharCode(i);
|
||||
}
|
||||
}
|
||||
return title;
|
||||
}
|
||||
|
||||
return function (spanNode, token, editor) {
|
||||
var content = token.content;
|
||||
if (lastEquivalent && token.style === 'regex-class-range-hyphen') {
|
||||
rangeBegan = true;
|
||||
lastRangeHyphen = spanNode;
|
||||
}
|
||||
else if (rangeBegan) {
|
||||
var beginChar = lastEquivalent;
|
||||
var endChar = (token.equivalent || content);
|
||||
lastRangeHyphen.title = _buildTitle(beginChar, endChar);
|
||||
rangeBegan = false;
|
||||
lastEquivalent = null;
|
||||
}
|
||||
else if (content === ']') {
|
||||
rangeBegan = false;
|
||||
}
|
||||
else {
|
||||
rangeBegan = false;
|
||||
// Fix: 'regex-unicode-class-inside' not supported and should not be since it wouldn't make sense as a starting range?
|
||||
lastEquivalent = token.equivalent || content;
|
||||
}
|
||||
|
||||
if (token.display) {
|
||||
spanNode.title = token.display;
|
||||
}
|
||||
else if (token.equivalent) {
|
||||
if (token.unicode) {
|
||||
var range = /(.)-(.)/g;
|
||||
spanNode.title = token.equivalent.replace(range,
|
||||
function (n0, n1, n2) {
|
||||
return _buildTitle(n1, n2);
|
||||
}
|
||||
);
|
||||
}
|
||||
else {
|
||||
spanNode.title = token.equivalent;
|
||||
}
|
||||
}
|
||||
};
|
||||
}())
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div>
|
||||
<h1>CodeMirror JavaScript-Integrated Regex Code Editor Demonstration</h1>
|
||||
<p>This demonstrates a parser in the regex folder which wraps the regular CodeMirror JavaScript editor and adds syntax coloring to
|
||||
regular expression literals in JavaScript.</p>
|
||||
<textarea id="js-regexp" cols="60" rows="1">
|
||||
var aVar = "aString" + 42 + aFunction(anArg, true);
|
||||
var myRgx = /test(group1|group2|(?:group3))and(group4)and(gr(ou)p5)/gi;
|
||||
</textarea>
|
||||
|
||||
<p>While the above styles by depth or sequence no matter the grouping type, this parser also allows styling distinctly by grouping type (capturing, named, non-capturing), while also still allowing alternating of colors within a type.</p>
|
||||
<textarea id="js-regexp-type" cols="60" rows="1">
|
||||
var aVar = "aString" + 42 + aFunction(anArg, true);
|
||||
var myRgx = /test(group1|group2|(?:group3))and(group4)and(gr(ou)p5)/gi;
|
||||
</textarea>
|
||||
<p>One may also simply turn off the styling of content inside groups, allowing only individual tokens to be styled per the stylesheet (though the parentheses tokens themselves can still indicate depth or sequence):</p>
|
||||
<textarea id="js-regexp-none" cols="60" rows="1">
|
||||
var aVar = "aString" + 42 + aFunction(anArg, true);
|
||||
var myRgx = /test(group1|group2|(?:group3))and(group4)and(gr(ou)p5)/gi;
|
||||
</textarea>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
91
gulliver/js/codemirror/contrib/regex/js/parsejavascript_and_regex.js
Executable file
91
gulliver/js/codemirror/contrib/regex/js/parsejavascript_and_regex.js
Executable file
@@ -0,0 +1,91 @@
|
||||
// See the dependencies parsejavascript.js and parseregex.js (optionally with parseregex-unicode.js) for options
|
||||
|
||||
var JSAndRegexParser = Editor.Parser = (function() {
|
||||
// Parser
|
||||
var run = function () {},
|
||||
regexParser, jsParser, lastRegexSrc,
|
||||
regexPG = {}, jsPG = {};
|
||||
|
||||
function simpleStream (s) {
|
||||
var str = s, pos = 0;
|
||||
return {
|
||||
next : function () {
|
||||
if (pos >= str.length) {
|
||||
throw StopIteration;
|
||||
}
|
||||
return str.charAt(pos++);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function regex () {
|
||||
var token;
|
||||
try {
|
||||
token = regexParser.next();
|
||||
}
|
||||
catch(e) {
|
||||
_setState(js);
|
||||
return js();
|
||||
}
|
||||
_setState(regex);
|
||||
return token;
|
||||
}
|
||||
function js () {
|
||||
var token = jsParser.next();
|
||||
if (token.type === 'regexp') {
|
||||
lastRegexSrc = stringStream(simpleStream(token.content));
|
||||
regexParser = RegexParser.make(lastRegexSrc);
|
||||
return regex();
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
function _setState (func) {
|
||||
run = func;
|
||||
}
|
||||
|
||||
function parseJSAndRegex (stream, basecolumn) {
|
||||
JSParser.configure(jsPG);
|
||||
RegexParser.configure(regexPG);
|
||||
jsParser = JSParser.make(stream, basecolumn);
|
||||
_setState(js);
|
||||
|
||||
var iter = {
|
||||
next: function() {
|
||||
return run(stream);
|
||||
},
|
||||
copy: function() {
|
||||
var _run = run, _lastRegexSrc = lastRegexSrc,
|
||||
_jsParser = jsParser.copy(),
|
||||
_regexParser = regexParser && regexParser.copy();
|
||||
|
||||
return function (_stream) {
|
||||
stream = _stream;
|
||||
jsParser = _jsParser(_stream);
|
||||
regexParser = _regexParser && _regexParser(_lastRegexSrc);
|
||||
run = _run;
|
||||
return iter;
|
||||
};
|
||||
}
|
||||
};
|
||||
return iter;
|
||||
}
|
||||
|
||||
// Parser object
|
||||
return {
|
||||
make: parseJSAndRegex,
|
||||
configure: function (parserConfig) {
|
||||
for (var opt in parserConfig) {
|
||||
if ((/^regex_/).test(opt)) {
|
||||
regexPG[opt.replace(/^regex_/, '')] = parserConfig[opt];
|
||||
}
|
||||
else { // Doesn't need a js- prefix, but we'll strip if it does
|
||||
jsPG[opt.replace(/^js_/, '')] = parserConfig[opt];
|
||||
}
|
||||
}
|
||||
regexPG.flavor = regexPG.flavor || 'ecma-262-ed3'; // Allow ed5, etc. if specified
|
||||
regexPG.literal = true; // This is only for literals, since can't easily detect whether will be used for RegExp
|
||||
regexPG.literal_initial = '/'; // Ensure it's always this for JavaScript regex literals
|
||||
}
|
||||
};
|
||||
})();
|
||||
284
gulliver/js/codemirror/contrib/regex/js/parseregex-unicode.js
Executable file
284
gulliver/js/codemirror/contrib/regex/js/parseregex-unicode.js
Executable file
@@ -0,0 +1,284 @@
|
||||
/*
|
||||
* Note: To include Unicode validation, you must include your CodeMirror parserfile option in this sequence:
|
||||
* parserfile: ["parseregex.js", "parseregex-unicode.js"]
|
||||
*/
|
||||
(function () {
|
||||
|
||||
|
||||
// Fix: Add non-BMP code points
|
||||
|
||||
var UnicodeCategories = {
|
||||
C: "0000-001F007F-009F00AD03780379037F-0383038B038D03A20526-05300557055805600588058B-059005C8-05CF05EB-05EF05F5-0605061C061D0620065F06DD070E070F074B074C07B2-07BF07FB-07FF082E082F083F-08FF093A093B094F095609570973-097809800984098D098E0991099209A909B109B3-09B509BA09BB09C509C609C909CA09CF-09D609D8-09DB09DE09E409E509FC-0A000A040A0B-0A0E0A110A120A290A310A340A370A3A0A3B0A3D0A43-0A460A490A4A0A4E-0A500A52-0A580A5D0A5F-0A650A76-0A800A840A8E0A920AA90AB10AB40ABA0ABB0AC60ACA0ACE0ACF0AD1-0ADF0AE40AE50AF00AF2-0B000B040B0D0B0E0B110B120B290B310B340B3A0B3B0B450B460B490B4A0B4E-0B550B58-0B5B0B5E0B640B650B72-0B810B840B8B-0B8D0B910B96-0B980B9B0B9D0BA0-0BA20BA5-0BA70BAB-0BAD0BBA-0BBD0BC3-0BC50BC90BCE0BCF0BD1-0BD60BD8-0BE50BFB-0C000C040C0D0C110C290C340C3A-0C3C0C450C490C4E-0C540C570C5A-0C5F0C640C650C70-0C770C800C810C840C8D0C910CA90CB40CBA0CBB0CC50CC90CCE-0CD40CD7-0CDD0CDF0CE40CE50CF00CF3-0D010D040D0D0D110D290D3A-0D3C0D450D490D4E-0D560D58-0D5F0D640D650D76-0D780D800D810D840D97-0D990DB20DBC0DBE0DBF0DC7-0DC90DCB-0DCE0DD50DD70DE0-0DF10DF5-0E000E3B-0E3E0E5C-0E800E830E850E860E890E8B0E8C0E8E-0E930E980EA00EA40EA60EA80EA90EAC0EBA0EBE0EBF0EC50EC70ECE0ECF0EDA0EDB0EDE-0EFF0F480F6D-0F700F8C-0F8F0F980FBD0FCD0FD9-0FFF10C6-10CF10FD-10FF1249124E124F12571259125E125F1289128E128F12B112B612B712BF12C112C612C712D7131113161317135B-135E137D-137F139A-139F13F5-13FF169D-169F16F1-16FF170D1715-171F1737-173F1754-175F176D17711774-177F17B417B517DE17DF17EA-17EF17FA-17FF180F181A-181F1878-187F18AB-18AF18F6-18FF191D-191F192C-192F193C-193F1941-1943196E196F1975-197F19AC-19AF19CA-19CF19DB-19DD1A1C1A1D1A5F1A7D1A7E1A8A-1A8F1A9A-1A9F1AAE-1AFF1B4C-1B4F1B7D-1B7F1BAB-1BAD1BBA-1BFF1C38-1C3A1C4A-1C4C1C80-1CCF1CF3-1CFF1DE7-1DFC1F161F171F1E1F1F1F461F471F4E1F4F1F581F5A1F5C1F5E1F7E1F7F1FB51FC51FD41FD51FDC1FF01FF11FF51FFF200B-200F202A-202E2060-206F20722073208F2095-209F20B9-20CF20F1-20FF218A-218F23E9-23FF2427-243F244B-245F26CE26E226E4-26E727002705270A270B2728274C274E2753-2755275F27602795-279727B027BF27CB27CD-27CF2B4D-2B4F2B5A-2BFF2C2F2C5F2CF2-2CF82D26-2D2F2D66-2D6E2D70-2D7F2D97-2D9F2DA72DAF2DB72DBF2DC72DCF2DD72DDF2E32-2E7F2E9A2EF4-2EFF2FD6-2FEF2FFC-2FFF3040309730983100-3104312E-3130318F31B8-31BF31E4-31EF321F32FF4DB6-4DBF9FCC-9FFFA48D-A48FA4C7-A4CFA62C-A63FA660A661A674-A67BA698-A69FA6F8-A6FFA78D-A7FAA82C-A82FA83A-A83FA878-A87FA8C5-A8CDA8DA-A8DFA8FC-A8FFA954-A95EA97D-A97FA9CEA9DA-A9DDA9E0-A9FFAA37-AA3FAA4EAA4FAA5AAA5BAA7C-AA7FAAC3-AADAAAE0-ABBFABEEABEFABFA-ABFFD7A4-D7AFD7C7-D7CAD7FC-F8FFFA2EFA2FFA6EFA6FFADA-FAFFFB07-FB12FB18-FB1CFB37FB3DFB3FFB42FB45FBB2-FBD2FD40-FD4FFD90FD91FDC8-FDEFFDFEFDFFFE1A-FE1FFE27-FE2FFE53FE67FE6C-FE6FFE75FEFD-FF00FFBF-FFC1FFC8FFC9FFD0FFD1FFD8FFD9FFDD-FFDFFFE7FFEF-FFFBFFFEFFFF",
|
||||
Cc: "0000-001F007F-009F",
|
||||
Cf: "00AD0600-060306DD070F17B417B5200B-200F202A-202E2060-2064206A-206FFEFFFFF9-FFFB",
|
||||
Co: "E000-F8FF",
|
||||
Cs: "D800-DFFF",
|
||||
Cn: "03780379037F-0383038B038D03A20526-05300557055805600588058B-059005C8-05CF05EB-05EF05F5-05FF06040605061C061D0620065F070E074B074C07B2-07BF07FB-07FF082E082F083F-08FF093A093B094F095609570973-097809800984098D098E0991099209A909B109B3-09B509BA09BB09C509C609C909CA09CF-09D609D8-09DB09DE09E409E509FC-0A000A040A0B-0A0E0A110A120A290A310A340A370A3A0A3B0A3D0A43-0A460A490A4A0A4E-0A500A52-0A580A5D0A5F-0A650A76-0A800A840A8E0A920AA90AB10AB40ABA0ABB0AC60ACA0ACE0ACF0AD1-0ADF0AE40AE50AF00AF2-0B000B040B0D0B0E0B110B120B290B310B340B3A0B3B0B450B460B490B4A0B4E-0B550B58-0B5B0B5E0B640B650B72-0B810B840B8B-0B8D0B910B96-0B980B9B0B9D0BA0-0BA20BA5-0BA70BAB-0BAD0BBA-0BBD0BC3-0BC50BC90BCE0BCF0BD1-0BD60BD8-0BE50BFB-0C000C040C0D0C110C290C340C3A-0C3C0C450C490C4E-0C540C570C5A-0C5F0C640C650C70-0C770C800C810C840C8D0C910CA90CB40CBA0CBB0CC50CC90CCE-0CD40CD7-0CDD0CDF0CE40CE50CF00CF3-0D010D040D0D0D110D290D3A-0D3C0D450D490D4E-0D560D58-0D5F0D640D650D76-0D780D800D810D840D97-0D990DB20DBC0DBE0DBF0DC7-0DC90DCB-0DCE0DD50DD70DE0-0DF10DF5-0E000E3B-0E3E0E5C-0E800E830E850E860E890E8B0E8C0E8E-0E930E980EA00EA40EA60EA80EA90EAC0EBA0EBE0EBF0EC50EC70ECE0ECF0EDA0EDB0EDE-0EFF0F480F6D-0F700F8C-0F8F0F980FBD0FCD0FD9-0FFF10C6-10CF10FD-10FF1249124E124F12571259125E125F1289128E128F12B112B612B712BF12C112C612C712D7131113161317135B-135E137D-137F139A-139F13F5-13FF169D-169F16F1-16FF170D1715-171F1737-173F1754-175F176D17711774-177F17DE17DF17EA-17EF17FA-17FF180F181A-181F1878-187F18AB-18AF18F6-18FF191D-191F192C-192F193C-193F1941-1943196E196F1975-197F19AC-19AF19CA-19CF19DB-19DD1A1C1A1D1A5F1A7D1A7E1A8A-1A8F1A9A-1A9F1AAE-1AFF1B4C-1B4F1B7D-1B7F1BAB-1BAD1BBA-1BFF1C38-1C3A1C4A-1C4C1C80-1CCF1CF3-1CFF1DE7-1DFC1F161F171F1E1F1F1F461F471F4E1F4F1F581F5A1F5C1F5E1F7E1F7F1FB51FC51FD41FD51FDC1FF01FF11FF51FFF2065-206920722073208F2095-209F20B9-20CF20F1-20FF218A-218F23E9-23FF2427-243F244B-245F26CE26E226E4-26E727002705270A270B2728274C274E2753-2755275F27602795-279727B027BF27CB27CD-27CF2B4D-2B4F2B5A-2BFF2C2F2C5F2CF2-2CF82D26-2D2F2D66-2D6E2D70-2D7F2D97-2D9F2DA72DAF2DB72DBF2DC72DCF2DD72DDF2E32-2E7F2E9A2EF4-2EFF2FD6-2FEF2FFC-2FFF3040309730983100-3104312E-3130318F31B8-31BF31E4-31EF321F32FF4DB6-4DBF9FCC-9FFFA48D-A48FA4C7-A4CFA62C-A63FA660A661A674-A67BA698-A69FA6F8-A6FFA78D-A7FAA82C-A82FA83A-A83FA878-A87FA8C5-A8CDA8DA-A8DFA8FC-A8FFA954-A95EA97D-A97FA9CEA9DA-A9DDA9E0-A9FFAA37-AA3FAA4EAA4FAA5AAA5BAA7C-AA7FAAC3-AADAAAE0-ABBFABEEABEFABFA-ABFFD7A4-D7AFD7C7-D7CAD7FC-D7FFFA2EFA2FFA6EFA6FFADA-FAFFFB07-FB12FB18-FB1CFB37FB3DFB3FFB42FB45FBB2-FBD2FD40-FD4FFD90FD91FDC8-FDEFFDFEFDFFFE1A-FE1FFE27-FE2FFE53FE67FE6C-FE6FFE75FEFDFEFEFF00FFBF-FFC1FFC8FFC9FFD0FFD1FFD8FFD9FFDD-FFDFFFE7FFEF-FFF8FFFEFFFF",
|
||||
L: "0041-005A0061-007A00AA00B500BA00C0-00D600D8-00F600F8-02C102C6-02D102E0-02E402EC02EE0370-037403760377037A-037D03860388-038A038C038E-03A103A3-03F503F7-0481048A-05250531-055605590561-058705D0-05EA05F0-05F20621-064A066E066F0671-06D306D506E506E606EE06EF06FA-06FC06FF07100712-072F074D-07A507B107CA-07EA07F407F507FA0800-0815081A082408280904-0939093D09500958-0961097109720979-097F0985-098C098F09900993-09A809AA-09B009B209B6-09B909BD09CE09DC09DD09DF-09E109F009F10A05-0A0A0A0F0A100A13-0A280A2A-0A300A320A330A350A360A380A390A59-0A5C0A5E0A72-0A740A85-0A8D0A8F-0A910A93-0AA80AAA-0AB00AB20AB30AB5-0AB90ABD0AD00AE00AE10B05-0B0C0B0F0B100B13-0B280B2A-0B300B320B330B35-0B390B3D0B5C0B5D0B5F-0B610B710B830B85-0B8A0B8E-0B900B92-0B950B990B9A0B9C0B9E0B9F0BA30BA40BA8-0BAA0BAE-0BB90BD00C05-0C0C0C0E-0C100C12-0C280C2A-0C330C35-0C390C3D0C580C590C600C610C85-0C8C0C8E-0C900C92-0CA80CAA-0CB30CB5-0CB90CBD0CDE0CE00CE10D05-0D0C0D0E-0D100D12-0D280D2A-0D390D3D0D600D610D7A-0D7F0D85-0D960D9A-0DB10DB3-0DBB0DBD0DC0-0DC60E01-0E300E320E330E40-0E460E810E820E840E870E880E8A0E8D0E94-0E970E99-0E9F0EA1-0EA30EA50EA70EAA0EAB0EAD-0EB00EB20EB30EBD0EC0-0EC40EC60EDC0EDD0F000F40-0F470F49-0F6C0F88-0F8B1000-102A103F1050-1055105A-105D106110651066106E-10701075-1081108E10A0-10C510D0-10FA10FC1100-1248124A-124D1250-12561258125A-125D1260-1288128A-128D1290-12B012B2-12B512B8-12BE12C012C2-12C512C8-12D612D8-13101312-13151318-135A1380-138F13A0-13F41401-166C166F-167F1681-169A16A0-16EA1700-170C170E-17111720-17311740-17511760-176C176E-17701780-17B317D717DC1820-18771880-18A818AA18B0-18F51900-191C1950-196D1970-19741980-19AB19C1-19C71A00-1A161A20-1A541AA71B05-1B331B45-1B4B1B83-1BA01BAE1BAF1C00-1C231C4D-1C4F1C5A-1C7D1CE9-1CEC1CEE-1CF11D00-1DBF1E00-1F151F18-1F1D1F20-1F451F48-1F4D1F50-1F571F591F5B1F5D1F5F-1F7D1F80-1FB41FB6-1FBC1FBE1FC2-1FC41FC6-1FCC1FD0-1FD31FD6-1FDB1FE0-1FEC1FF2-1FF41FF6-1FFC2071207F2090-209421022107210A-211321152119-211D212421262128212A-212D212F-2139213C-213F2145-2149214E218321842C00-2C2E2C30-2C5E2C60-2CE42CEB-2CEE2D00-2D252D30-2D652D6F2D80-2D962DA0-2DA62DA8-2DAE2DB0-2DB62DB8-2DBE2DC0-2DC62DC8-2DCE2DD0-2DD62DD8-2DDE2E2F300530063031-3035303B303C3041-3096309D-309F30A1-30FA30FC-30FF3105-312D3131-318E31A0-31B731F0-31FF3400-4DB54E00-9FCBA000-A48CA4D0-A4FDA500-A60CA610-A61FA62AA62BA640-A65FA662-A66EA67F-A697A6A0-A6E5A717-A71FA722-A788A78BA78CA7FB-A801A803-A805A807-A80AA80C-A822A840-A873A882-A8B3A8F2-A8F7A8FBA90A-A925A930-A946A960-A97CA984-A9B2A9CFAA00-AA28AA40-AA42AA44-AA4BAA60-AA76AA7AAA80-AAAFAAB1AAB5AAB6AAB9-AABDAAC0AAC2AADB-AADDABC0-ABE2AC00-D7A3D7B0-D7C6D7CB-D7FBF900-FA2DFA30-FA6DFA70-FAD9FB00-FB06FB13-FB17FB1DFB1F-FB28FB2A-FB36FB38-FB3CFB3EFB40FB41FB43FB44FB46-FBB1FBD3-FD3DFD50-FD8FFD92-FDC7FDF0-FDFBFE70-FE74FE76-FEFCFF21-FF3AFF41-FF5AFF66-FFBEFFC2-FFC7FFCA-FFCFFFD2-FFD7FFDA-FFDC",
|
||||
Ll: "0061-007A00AA00B500BA00DF-00F600F8-00FF01010103010501070109010B010D010F01110113011501170119011B011D011F01210123012501270129012B012D012F01310133013501370138013A013C013E014001420144014601480149014B014D014F01510153015501570159015B015D015F01610163016501670169016B016D016F0171017301750177017A017C017E-0180018301850188018C018D019201950199-019B019E01A101A301A501A801AA01AB01AD01B001B401B601B901BA01BD-01BF01C601C901CC01CE01D001D201D401D601D801DA01DC01DD01DF01E101E301E501E701E901EB01ED01EF01F001F301F501F901FB01FD01FF02010203020502070209020B020D020F02110213021502170219021B021D021F02210223022502270229022B022D022F02310233-0239023C023F0240024202470249024B024D024F-02930295-02AF037103730377037B-037D039003AC-03CE03D003D103D5-03D703D903DB03DD03DF03E103E303E503E703E903EB03ED03EF-03F303F503F803FB03FC0430-045F04610463046504670469046B046D046F04710473047504770479047B047D047F0481048B048D048F04910493049504970499049B049D049F04A104A304A504A704A904AB04AD04AF04B104B304B504B704B904BB04BD04BF04C204C404C604C804CA04CC04CE04CF04D104D304D504D704D904DB04DD04DF04E104E304E504E704E904EB04ED04EF04F104F304F504F704F904FB04FD04FF05010503050505070509050B050D050F05110513051505170519051B051D051F0521052305250561-05871D00-1D2B1D62-1D771D79-1D9A1E011E031E051E071E091E0B1E0D1E0F1E111E131E151E171E191E1B1E1D1E1F1E211E231E251E271E291E2B1E2D1E2F1E311E331E351E371E391E3B1E3D1E3F1E411E431E451E471E491E4B1E4D1E4F1E511E531E551E571E591E5B1E5D1E5F1E611E631E651E671E691E6B1E6D1E6F1E711E731E751E771E791E7B1E7D1E7F1E811E831E851E871E891E8B1E8D1E8F1E911E931E95-1E9D1E9F1EA11EA31EA51EA71EA91EAB1EAD1EAF1EB11EB31EB51EB71EB91EBB1EBD1EBF1EC11EC31EC51EC71EC91ECB1ECD1ECF1ED11ED31ED51ED71ED91EDB1EDD1EDF1EE11EE31EE51EE71EE91EEB1EED1EEF1EF11EF31EF51EF71EF91EFB1EFD1EFF-1F071F10-1F151F20-1F271F30-1F371F40-1F451F50-1F571F60-1F671F70-1F7D1F80-1F871F90-1F971FA0-1FA71FB0-1FB41FB61FB71FBE1FC2-1FC41FC61FC71FD0-1FD31FD61FD71FE0-1FE71FF2-1FF41FF61FF7210A210E210F2113212F21342139213C213D2146-2149214E21842C30-2C5E2C612C652C662C682C6A2C6C2C712C732C742C76-2C7C2C812C832C852C872C892C8B2C8D2C8F2C912C932C952C972C992C9B2C9D2C9F2CA12CA32CA52CA72CA92CAB2CAD2CAF2CB12CB32CB52CB72CB92CBB2CBD2CBF2CC12CC32CC52CC72CC92CCB2CCD2CCF2CD12CD32CD52CD72CD92CDB2CDD2CDF2CE12CE32CE42CEC2CEE2D00-2D25A641A643A645A647A649A64BA64DA64FA651A653A655A657A659A65BA65DA65FA663A665A667A669A66BA66DA681A683A685A687A689A68BA68DA68FA691A693A695A697A723A725A727A729A72BA72DA72F-A731A733A735A737A739A73BA73DA73FA741A743A745A747A749A74BA74DA74FA751A753A755A757A759A75BA75DA75FA761A763A765A767A769A76BA76DA76FA771-A778A77AA77CA77FA781A783A785A787A78CFB00-FB06FB13-FB17FF41-FF5A",
|
||||
Lu: "0041-005A00C0-00D600D8-00DE01000102010401060108010A010C010E01100112011401160118011A011C011E01200122012401260128012A012C012E01300132013401360139013B013D013F0141014301450147014A014C014E01500152015401560158015A015C015E01600162016401660168016A016C016E017001720174017601780179017B017D018101820184018601870189-018B018E-0191019301940196-0198019C019D019F01A001A201A401A601A701A901AC01AE01AF01B1-01B301B501B701B801BC01C401C701CA01CD01CF01D101D301D501D701D901DB01DE01E001E201E401E601E801EA01EC01EE01F101F401F6-01F801FA01FC01FE02000202020402060208020A020C020E02100212021402160218021A021C021E02200222022402260228022A022C022E02300232023A023B023D023E02410243-02460248024A024C024E03700372037603860388-038A038C038E038F0391-03A103A3-03AB03CF03D2-03D403D803DA03DC03DE03E003E203E403E603E803EA03EC03EE03F403F703F903FA03FD-042F04600462046404660468046A046C046E04700472047404760478047A047C047E0480048A048C048E04900492049404960498049A049C049E04A004A204A404A604A804AA04AC04AE04B004B204B404B604B804BA04BC04BE04C004C104C304C504C704C904CB04CD04D004D204D404D604D804DA04DC04DE04E004E204E404E604E804EA04EC04EE04F004F204F404F604F804FA04FC04FE05000502050405060508050A050C050E05100512051405160518051A051C051E0520052205240531-055610A0-10C51E001E021E041E061E081E0A1E0C1E0E1E101E121E141E161E181E1A1E1C1E1E1E201E221E241E261E281E2A1E2C1E2E1E301E321E341E361E381E3A1E3C1E3E1E401E421E441E461E481E4A1E4C1E4E1E501E521E541E561E581E5A1E5C1E5E1E601E621E641E661E681E6A1E6C1E6E1E701E721E741E761E781E7A1E7C1E7E1E801E821E841E861E881E8A1E8C1E8E1E901E921E941E9E1EA01EA21EA41EA61EA81EAA1EAC1EAE1EB01EB21EB41EB61EB81EBA1EBC1EBE1EC01EC21EC41EC61EC81ECA1ECC1ECE1ED01ED21ED41ED61ED81EDA1EDC1EDE1EE01EE21EE41EE61EE81EEA1EEC1EEE1EF01EF21EF41EF61EF81EFA1EFC1EFE1F08-1F0F1F18-1F1D1F28-1F2F1F38-1F3F1F48-1F4D1F591F5B1F5D1F5F1F68-1F6F1FB8-1FBB1FC8-1FCB1FD8-1FDB1FE8-1FEC1FF8-1FFB21022107210B-210D2110-211221152119-211D212421262128212A-212D2130-2133213E213F214521832C00-2C2E2C602C62-2C642C672C692C6B2C6D-2C702C722C752C7E-2C802C822C842C862C882C8A2C8C2C8E2C902C922C942C962C982C9A2C9C2C9E2CA02CA22CA42CA62CA82CAA2CAC2CAE2CB02CB22CB42CB62CB82CBA2CBC2CBE2CC02CC22CC42CC62CC82CCA2CCC2CCE2CD02CD22CD42CD62CD82CDA2CDC2CDE2CE02CE22CEB2CEDA640A642A644A646A648A64AA64CA64EA650A652A654A656A658A65AA65CA65EA662A664A666A668A66AA66CA680A682A684A686A688A68AA68CA68EA690A692A694A696A722A724A726A728A72AA72CA72EA732A734A736A738A73AA73CA73EA740A742A744A746A748A74AA74CA74EA750A752A754A756A758A75AA75CA75EA760A762A764A766A768A76AA76CA76EA779A77BA77DA77EA780A782A784A786A78BFF21-FF3A",
|
||||
Lt: "01C501C801CB01F21F88-1F8F1F98-1F9F1FA8-1FAF1FBC1FCC1FFC",
|
||||
Lm: "02B0-02C102C6-02D102E0-02E402EC02EE0374037A0559064006E506E607F407F507FA081A0824082809710E460EC610FC17D718431AA71C78-1C7D1D2C-1D611D781D9B-1DBF2071207F2090-20942C7D2D6F2E2F30053031-3035303B309D309E30FC-30FEA015A4F8-A4FDA60CA67FA717-A71FA770A788A9CFAA70AADDFF70FF9EFF9F",
|
||||
Lo: "01BB01C0-01C3029405D0-05EA05F0-05F20621-063F0641-064A066E066F0671-06D306D506EE06EF06FA-06FC06FF07100712-072F074D-07A507B107CA-07EA0800-08150904-0939093D09500958-096109720979-097F0985-098C098F09900993-09A809AA-09B009B209B6-09B909BD09CE09DC09DD09DF-09E109F009F10A05-0A0A0A0F0A100A13-0A280A2A-0A300A320A330A350A360A380A390A59-0A5C0A5E0A72-0A740A85-0A8D0A8F-0A910A93-0AA80AAA-0AB00AB20AB30AB5-0AB90ABD0AD00AE00AE10B05-0B0C0B0F0B100B13-0B280B2A-0B300B320B330B35-0B390B3D0B5C0B5D0B5F-0B610B710B830B85-0B8A0B8E-0B900B92-0B950B990B9A0B9C0B9E0B9F0BA30BA40BA8-0BAA0BAE-0BB90BD00C05-0C0C0C0E-0C100C12-0C280C2A-0C330C35-0C390C3D0C580C590C600C610C85-0C8C0C8E-0C900C92-0CA80CAA-0CB30CB5-0CB90CBD0CDE0CE00CE10D05-0D0C0D0E-0D100D12-0D280D2A-0D390D3D0D600D610D7A-0D7F0D85-0D960D9A-0DB10DB3-0DBB0DBD0DC0-0DC60E01-0E300E320E330E40-0E450E810E820E840E870E880E8A0E8D0E94-0E970E99-0E9F0EA1-0EA30EA50EA70EAA0EAB0EAD-0EB00EB20EB30EBD0EC0-0EC40EDC0EDD0F000F40-0F470F49-0F6C0F88-0F8B1000-102A103F1050-1055105A-105D106110651066106E-10701075-1081108E10D0-10FA1100-1248124A-124D1250-12561258125A-125D1260-1288128A-128D1290-12B012B2-12B512B8-12BE12C012C2-12C512C8-12D612D8-13101312-13151318-135A1380-138F13A0-13F41401-166C166F-167F1681-169A16A0-16EA1700-170C170E-17111720-17311740-17511760-176C176E-17701780-17B317DC1820-18421844-18771880-18A818AA18B0-18F51900-191C1950-196D1970-19741980-19AB19C1-19C71A00-1A161A20-1A541B05-1B331B45-1B4B1B83-1BA01BAE1BAF1C00-1C231C4D-1C4F1C5A-1C771CE9-1CEC1CEE-1CF12135-21382D30-2D652D80-2D962DA0-2DA62DA8-2DAE2DB0-2DB62DB8-2DBE2DC0-2DC62DC8-2DCE2DD0-2DD62DD8-2DDE3006303C3041-3096309F30A1-30FA30FF3105-312D3131-318E31A0-31B731F0-31FF3400-4DB54E00-9FCBA000-A014A016-A48CA4D0-A4F7A500-A60BA610-A61FA62AA62BA66EA6A0-A6E5A7FB-A801A803-A805A807-A80AA80C-A822A840-A873A882-A8B3A8F2-A8F7A8FBA90A-A925A930-A946A960-A97CA984-A9B2AA00-AA28AA40-AA42AA44-AA4BAA60-AA6FAA71-AA76AA7AAA80-AAAFAAB1AAB5AAB6AAB9-AABDAAC0AAC2AADBAADCABC0-ABE2AC00-D7A3D7B0-D7C6D7CB-D7FBF900-FA2DFA30-FA6DFA70-FAD9FB1DFB1F-FB28FB2A-FB36FB38-FB3CFB3EFB40FB41FB43FB44FB46-FBB1FBD3-FD3DFD50-FD8FFD92-FDC7FDF0-FDFBFE70-FE74FE76-FEFCFF66-FF6FFF71-FF9DFFA0-FFBEFFC2-FFC7FFCA-FFCFFFD2-FFD7FFDA-FFDC",
|
||||
M: "0300-036F0483-04890591-05BD05BF05C105C205C405C505C70610-061A064B-065E067006D6-06DC06DE-06E406E706E806EA-06ED07110730-074A07A6-07B007EB-07F30816-0819081B-08230825-08270829-082D0900-0903093C093E-094E0951-0955096209630981-098309BC09BE-09C409C709C809CB-09CD09D709E209E30A01-0A030A3C0A3E-0A420A470A480A4B-0A4D0A510A700A710A750A81-0A830ABC0ABE-0AC50AC7-0AC90ACB-0ACD0AE20AE30B01-0B030B3C0B3E-0B440B470B480B4B-0B4D0B560B570B620B630B820BBE-0BC20BC6-0BC80BCA-0BCD0BD70C01-0C030C3E-0C440C46-0C480C4A-0C4D0C550C560C620C630C820C830CBC0CBE-0CC40CC6-0CC80CCA-0CCD0CD50CD60CE20CE30D020D030D3E-0D440D46-0D480D4A-0D4D0D570D620D630D820D830DCA0DCF-0DD40DD60DD8-0DDF0DF20DF30E310E34-0E3A0E47-0E4E0EB10EB4-0EB90EBB0EBC0EC8-0ECD0F180F190F350F370F390F3E0F3F0F71-0F840F860F870F90-0F970F99-0FBC0FC6102B-103E1056-1059105E-10601062-10641067-106D1071-10741082-108D108F109A-109D135F1712-17141732-1734175217531772177317B6-17D317DD180B-180D18A91920-192B1930-193B19B0-19C019C819C91A17-1A1B1A55-1A5E1A60-1A7C1A7F1B00-1B041B34-1B441B6B-1B731B80-1B821BA1-1BAA1C24-1C371CD0-1CD21CD4-1CE81CED1CF21DC0-1DE61DFD-1DFF20D0-20F02CEF-2CF12DE0-2DFF302A-302F3099309AA66F-A672A67CA67DA6F0A6F1A802A806A80BA823-A827A880A881A8B4-A8C4A8E0-A8F1A926-A92DA947-A953A980-A983A9B3-A9C0AA29-AA36AA43AA4CAA4DAA7BAAB0AAB2-AAB4AAB7AAB8AABEAABFAAC1ABE3-ABEAABECABEDFB1EFE00-FE0FFE20-FE26",
|
||||
Mn: "0300-036F0483-04870591-05BD05BF05C105C205C405C505C70610-061A064B-065E067006D6-06DC06DF-06E406E706E806EA-06ED07110730-074A07A6-07B007EB-07F30816-0819081B-08230825-08270829-082D0900-0902093C0941-0948094D0951-095509620963098109BC09C1-09C409CD09E209E30A010A020A3C0A410A420A470A480A4B-0A4D0A510A700A710A750A810A820ABC0AC1-0AC50AC70AC80ACD0AE20AE30B010B3C0B3F0B41-0B440B4D0B560B620B630B820BC00BCD0C3E-0C400C46-0C480C4A-0C4D0C550C560C620C630CBC0CBF0CC60CCC0CCD0CE20CE30D41-0D440D4D0D620D630DCA0DD2-0DD40DD60E310E34-0E3A0E47-0E4E0EB10EB4-0EB90EBB0EBC0EC8-0ECD0F180F190F350F370F390F71-0F7E0F80-0F840F860F870F90-0F970F99-0FBC0FC6102D-10301032-10371039103A103D103E10581059105E-10601071-1074108210851086108D109D135F1712-17141732-1734175217531772177317B7-17BD17C617C9-17D317DD180B-180D18A91920-19221927192819321939-193B1A171A181A561A58-1A5E1A601A621A65-1A6C1A73-1A7C1A7F1B00-1B031B341B36-1B3A1B3C1B421B6B-1B731B801B811BA2-1BA51BA81BA91C2C-1C331C361C371CD0-1CD21CD4-1CE01CE2-1CE81CED1DC0-1DE61DFD-1DFF20D0-20DC20E120E5-20F02CEF-2CF12DE0-2DFF302A-302F3099309AA66FA67CA67DA6F0A6F1A802A806A80BA825A826A8C4A8E0-A8F1A926-A92DA947-A951A980-A982A9B3A9B6-A9B9A9BCAA29-AA2EAA31AA32AA35AA36AA43AA4CAAB0AAB2-AAB4AAB7AAB8AABEAABFAAC1ABE5ABE8ABEDFB1EFE00-FE0FFE20-FE26",
|
||||
Mc: "0903093E-09400949-094C094E0982098309BE-09C009C709C809CB09CC09D70A030A3E-0A400A830ABE-0AC00AC90ACB0ACC0B020B030B3E0B400B470B480B4B0B4C0B570BBE0BBF0BC10BC20BC6-0BC80BCA-0BCC0BD70C01-0C030C41-0C440C820C830CBE0CC0-0CC40CC70CC80CCA0CCB0CD50CD60D020D030D3E-0D400D46-0D480D4A-0D4C0D570D820D830DCF-0DD10DD8-0DDF0DF20DF30F3E0F3F0F7F102B102C10311038103B103C105610571062-10641067-106D108310841087-108C108F109A-109C17B617BE-17C517C717C81923-19261929-192B193019311933-193819B0-19C019C819C91A19-1A1B1A551A571A611A631A641A6D-1A721B041B351B3B1B3D-1B411B431B441B821BA11BA61BA71BAA1C24-1C2B1C341C351CE11CF2A823A824A827A880A881A8B4-A8C3A952A953A983A9B4A9B5A9BAA9BBA9BD-A9C0AA2FAA30AA33AA34AA4DAA7BABE3ABE4ABE6ABE7ABE9ABEAABEC",
|
||||
Me: "0488048906DE20DD-20E020E2-20E4A670-A672",
|
||||
N: "0030-003900B200B300B900BC-00BE0660-066906F0-06F907C0-07C90966-096F09E6-09EF09F4-09F90A66-0A6F0AE6-0AEF0B66-0B6F0BE6-0BF20C66-0C6F0C78-0C7E0CE6-0CEF0D66-0D750E50-0E590ED0-0ED90F20-0F331040-10491090-10991369-137C16EE-16F017E0-17E917F0-17F91810-18191946-194F19D0-19DA1A80-1A891A90-1A991B50-1B591BB0-1BB91C40-1C491C50-1C5920702074-20792080-20892150-21822185-21892460-249B24EA-24FF2776-27932CFD30073021-30293038-303A3192-31953220-32293251-325F3280-328932B1-32BFA620-A629A6E6-A6EFA830-A835A8D0-A8D9A900-A909A9D0-A9D9AA50-AA59ABF0-ABF9FF10-FF19",
|
||||
Nd: "0030-00390660-066906F0-06F907C0-07C90966-096F09E6-09EF0A66-0A6F0AE6-0AEF0B66-0B6F0BE6-0BEF0C66-0C6F0CE6-0CEF0D66-0D6F0E50-0E590ED0-0ED90F20-0F291040-10491090-109917E0-17E91810-18191946-194F19D0-19DA1A80-1A891A90-1A991B50-1B591BB0-1BB91C40-1C491C50-1C59A620-A629A8D0-A8D9A900-A909A9D0-A9D9AA50-AA59ABF0-ABF9FF10-FF19",
|
||||
Nl: "16EE-16F02160-21822185-218830073021-30293038-303AA6E6-A6EF",
|
||||
No: "00B200B300B900BC-00BE09F4-09F90BF0-0BF20C78-0C7E0D70-0D750F2A-0F331369-137C17F0-17F920702074-20792080-20892150-215F21892460-249B24EA-24FF2776-27932CFD3192-31953220-32293251-325F3280-328932B1-32BFA830-A835",
|
||||
P: "0021-00230025-002A002C-002F003A003B003F0040005B-005D005F007B007D00A100AB00B700BB00BF037E0387055A-055F0589058A05BE05C005C305C605F305F40609060A060C060D061B061E061F066A-066D06D40700-070D07F7-07F90830-083E0964096509700DF40E4F0E5A0E5B0F04-0F120F3A-0F3D0F850FD0-0FD4104A-104F10FB1361-13681400166D166E169B169C16EB-16ED1735173617D4-17D617D8-17DA1800-180A1944194519DE19DF1A1E1A1F1AA0-1AA61AA8-1AAD1B5A-1B601C3B-1C3F1C7E1C7F1CD32010-20272030-20432045-20512053-205E207D207E208D208E2329232A2768-277527C527C627E6-27EF2983-299829D8-29DB29FC29FD2CF9-2CFC2CFE2CFF2E00-2E2E2E302E313001-30033008-30113014-301F3030303D30A030FBA4FEA4FFA60D-A60FA673A67EA6F2-A6F7A874-A877A8CEA8CFA8F8-A8FAA92EA92FA95FA9C1-A9CDA9DEA9DFAA5C-AA5FAADEAADFABEBFD3EFD3FFE10-FE19FE30-FE52FE54-FE61FE63FE68FE6AFE6BFF01-FF03FF05-FF0AFF0C-FF0FFF1AFF1BFF1FFF20FF3B-FF3DFF3FFF5BFF5DFF5F-FF65",
|
||||
Pd: "002D058A05BE140018062010-20152E172E1A301C303030A0FE31FE32FE58FE63FF0D",
|
||||
Ps: "0028005B007B0F3A0F3C169B201A201E2045207D208D23292768276A276C276E27702772277427C527E627E827EA27EC27EE2983298529872989298B298D298F299129932995299729D829DA29FC2E222E242E262E283008300A300C300E3010301430163018301A301DFD3EFE17FE35FE37FE39FE3BFE3DFE3FFE41FE43FE47FE59FE5BFE5DFF08FF3BFF5BFF5FFF62",
|
||||
Pe: "0029005D007D0F3B0F3D169C2046207E208E232A2769276B276D276F27712773277527C627E727E927EB27ED27EF298429862988298A298C298E2990299229942996299829D929DB29FD2E232E252E272E293009300B300D300F3011301530173019301B301E301FFD3FFE18FE36FE38FE3AFE3CFE3EFE40FE42FE44FE48FE5AFE5CFE5EFF09FF3DFF5DFF60FF63",
|
||||
Pi: "00AB2018201B201C201F20392E022E042E092E0C2E1C2E20",
|
||||
Pf: "00BB2019201D203A2E032E052E0A2E0D2E1D2E21",
|
||||
Pc: "005F203F20402054FE33FE34FE4D-FE4FFF3F",
|
||||
Po: "0021-00230025-0027002A002C002E002F003A003B003F0040005C00A100B700BF037E0387055A-055F058905C005C305C605F305F40609060A060C060D061B061E061F066A-066D06D40700-070D07F7-07F90830-083E0964096509700DF40E4F0E5A0E5B0F04-0F120F850FD0-0FD4104A-104F10FB1361-1368166D166E16EB-16ED1735173617D4-17D617D8-17DA1800-18051807-180A1944194519DE19DF1A1E1A1F1AA0-1AA61AA8-1AAD1B5A-1B601C3B-1C3F1C7E1C7F1CD3201620172020-20272030-2038203B-203E2041-20432047-205120532055-205E2CF9-2CFC2CFE2CFF2E002E012E06-2E082E0B2E0E-2E162E182E192E1B2E1E2E1F2E2A-2E2E2E302E313001-3003303D30FBA4FEA4FFA60D-A60FA673A67EA6F2-A6F7A874-A877A8CEA8CFA8F8-A8FAA92EA92FA95FA9C1-A9CDA9DEA9DFAA5C-AA5FAADEAADFABEBFE10-FE16FE19FE30FE45FE46FE49-FE4CFE50-FE52FE54-FE57FE5F-FE61FE68FE6AFE6BFF01-FF03FF05-FF07FF0AFF0CFF0EFF0FFF1AFF1BFF1FFF20FF3CFF61FF64FF65",
|
||||
S: "0024002B003C-003E005E0060007C007E00A2-00A900AC00AE-00B100B400B600B800D700F702C2-02C502D2-02DF02E5-02EB02ED02EF-02FF03750384038503F604820606-0608060B060E060F06E906FD06FE07F609F209F309FA09FB0AF10B700BF3-0BFA0C7F0CF10CF20D790E3F0F01-0F030F13-0F170F1A-0F1F0F340F360F380FBE-0FC50FC7-0FCC0FCE0FCF0FD5-0FD8109E109F13601390-139917DB194019E0-19FF1B61-1B6A1B74-1B7C1FBD1FBF-1FC11FCD-1FCF1FDD-1FDF1FED-1FEF1FFD1FFE20442052207A-207C208A-208C20A0-20B8210021012103-21062108210921142116-2118211E-2123212521272129212E213A213B2140-2144214A-214D214F2190-2328232B-23E82400-24262440-244A249C-24E92500-26CD26CF-26E126E326E8-26FF2701-27042706-2709270C-27272729-274B274D274F-27522756-275E2761-276727942798-27AF27B1-27BE27C0-27C427C7-27CA27CC27D0-27E527F0-29822999-29D729DC-29FB29FE-2B4C2B50-2B592CE5-2CEA2E80-2E992E9B-2EF32F00-2FD52FF0-2FFB300430123013302030363037303E303F309B309C319031913196-319F31C0-31E33200-321E322A-32503260-327F328A-32B032C0-32FE3300-33FF4DC0-4DFFA490-A4C6A700-A716A720A721A789A78AA828-A82BA836-A839AA77-AA79FB29FDFCFDFDFE62FE64-FE66FE69FF04FF0BFF1C-FF1EFF3EFF40FF5CFF5EFFE0-FFE6FFE8-FFEEFFFCFFFD",
|
||||
Sm: "002B003C-003E007C007E00AC00B100D700F703F60606-060820442052207A-207C208A-208C2140-2144214B2190-2194219A219B21A021A321A621AE21CE21CF21D221D421F4-22FF2308-230B23202321237C239B-23B323DC-23E125B725C125F8-25FF266F27C0-27C427C7-27CA27CC27D0-27E527F0-27FF2900-29822999-29D729DC-29FB29FE-2AFF2B30-2B442B47-2B4CFB29FE62FE64-FE66FF0BFF1C-FF1EFF5CFF5EFFE2FFE9-FFEC",
|
||||
Sc: "002400A2-00A5060B09F209F309FB0AF10BF90E3F17DB20A0-20B8A838FDFCFE69FF04FFE0FFE1FFE5FFE6",
|
||||
Sk: "005E006000A800AF00B400B802C2-02C502D2-02DF02E5-02EB02ED02EF-02FF0375038403851FBD1FBF-1FC11FCD-1FCF1FDD-1FDF1FED-1FEF1FFD1FFE309B309CA700-A716A720A721A789A78AFF3EFF40FFE3",
|
||||
So: "00A600A700A900AE00B000B60482060E060F06E906FD06FE07F609FA0B700BF3-0BF80BFA0C7F0CF10CF20D790F01-0F030F13-0F170F1A-0F1F0F340F360F380FBE-0FC50FC7-0FCC0FCE0FCF0FD5-0FD8109E109F13601390-1399194019E0-19FF1B61-1B6A1B74-1B7C210021012103-21062108210921142116-2118211E-2123212521272129212E213A213B214A214C214D214F2195-2199219C-219F21A121A221A421A521A7-21AD21AF-21CD21D021D121D321D5-21F32300-2307230C-231F2322-2328232B-237B237D-239A23B4-23DB23E2-23E82400-24262440-244A249C-24E92500-25B625B8-25C025C2-25F72600-266E2670-26CD26CF-26E126E326E8-26FF2701-27042706-2709270C-27272729-274B274D274F-27522756-275E2761-276727942798-27AF27B1-27BE2800-28FF2B00-2B2F2B452B462B50-2B592CE5-2CEA2E80-2E992E9B-2EF32F00-2FD52FF0-2FFB300430123013302030363037303E303F319031913196-319F31C0-31E33200-321E322A-32503260-327F328A-32B032C0-32FE3300-33FF4DC0-4DFFA490-A4C6A828-A82BA836A837A839AA77-AA79FDFDFFE4FFE8FFEDFFEEFFFCFFFD",
|
||||
Z: "002000A01680180E2000-200A20282029202F205F3000",
|
||||
Zs: "002000A01680180E2000-200A202F205F3000",
|
||||
Zl: "2028",
|
||||
Zp: "2029"
|
||||
};
|
||||
|
||||
var UnicodeBlocks = {
|
||||
InBasic_Latin: "0000-007F",
|
||||
InLatin_1_Supplement: "0080-00FF",
|
||||
InLatin_Extended_A: "0100-017F",
|
||||
InLatin_Extended_B: "0180-024F",
|
||||
InIPA_Extensions: "0250-02AF",
|
||||
InSpacing_Modifier_Letters: "02B0-02FF",
|
||||
InCombining_Diacritical_Marks: "0300-036F",
|
||||
InGreek_and_Coptic: "0370-03FF",
|
||||
InCyrillic: "0400-04FF",
|
||||
InCyrillic_Supplement: "0500-052F",
|
||||
InArmenian: "0530-058F",
|
||||
InHebrew: "0590-05FF",
|
||||
InArabic: "0600-06FF",
|
||||
InSyriac: "0700-074F",
|
||||
InArabic_Supplement: "0750-077F",
|
||||
InThaana: "0780-07BF",
|
||||
InNKo: "07C0-07FF",
|
||||
InSamaritan: "0800-083F",
|
||||
InDevanagari: "0900-097F",
|
||||
InBengali: "0980-09FF",
|
||||
InGurmukhi: "0A00-0A7F",
|
||||
InGujarati: "0A80-0AFF",
|
||||
InOriya: "0B00-0B7F",
|
||||
InTamil: "0B80-0BFF",
|
||||
InTelugu: "0C00-0C7F",
|
||||
InKannada: "0C80-0CFF",
|
||||
InMalayalam: "0D00-0D7F",
|
||||
InSinhala: "0D80-0DFF",
|
||||
InThai: "0E00-0E7F",
|
||||
InLao: "0E80-0EFF",
|
||||
InTibetan: "0F00-0FFF",
|
||||
InMyanmar: "1000-109F",
|
||||
InGeorgian: "10A0-10FF",
|
||||
InHangul_Jamo: "1100-11FF",
|
||||
InEthiopic: "1200-137F",
|
||||
InEthiopic_Supplement: "1380-139F",
|
||||
InCherokee: "13A0-13FF",
|
||||
InUnified_Canadian_Aboriginal_Syllabics: "1400-167F",
|
||||
InOgham: "1680-169F",
|
||||
InRunic: "16A0-16FF",
|
||||
InTagalog: "1700-171F",
|
||||
InHanunoo: "1720-173F",
|
||||
InBuhid: "1740-175F",
|
||||
InTagbanwa: "1760-177F",
|
||||
InKhmer: "1780-17FF",
|
||||
InMongolian: "1800-18AF",
|
||||
InUnified_Canadian_Aboriginal_Syllabics_Extended: "18B0-18FF",
|
||||
InLimbu: "1900-194F",
|
||||
InTai_Le: "1950-197F",
|
||||
InNew_Tai_Lue: "1980-19DF",
|
||||
InKhmer_Symbols: "19E0-19FF",
|
||||
InBuginese: "1A00-1A1F",
|
||||
InTai_Tham: "1A20-1AAF",
|
||||
InBalinese: "1B00-1B7F",
|
||||
InSundanese: "1B80-1BBF",
|
||||
InLepcha: "1C00-1C4F",
|
||||
InOl_Chiki: "1C50-1C7F",
|
||||
InVedic_Extensions: "1CD0-1CFF",
|
||||
InPhonetic_Extensions: "1D00-1D7F",
|
||||
InPhonetic_Extensions_Supplement: "1D80-1DBF",
|
||||
InCombining_Diacritical_Marks_Supplement: "1DC0-1DFF",
|
||||
InLatin_Extended_Additional: "1E00-1EFF",
|
||||
InGreek_Extended: "1F00-1FFF",
|
||||
InGeneral_Punctuation: "2000-206F",
|
||||
InSuperscripts_and_Subscripts: "2070-209F",
|
||||
InCurrency_Symbols: "20A0-20CF",
|
||||
InCombining_Diacritical_Marks_for_Symbols: "20D0-20FF",
|
||||
InLetterlike_Symbols: "2100-214F",
|
||||
InNumber_Forms: "2150-218F",
|
||||
InArrows: "2190-21FF",
|
||||
InMathematical_Operators: "2200-22FF",
|
||||
InMiscellaneous_Technical: "2300-23FF",
|
||||
InControl_Pictures: "2400-243F",
|
||||
InOptical_Character_Recognition: "2440-245F",
|
||||
InEnclosed_Alphanumerics: "2460-24FF",
|
||||
InBox_Drawing: "2500-257F",
|
||||
InBlock_Elements: "2580-259F",
|
||||
InGeometric_Shapes: "25A0-25FF",
|
||||
InMiscellaneous_Symbols: "2600-26FF",
|
||||
InDingbats: "2700-27BF",
|
||||
InMiscellaneous_Mathematical_Symbols_A: "27C0-27EF",
|
||||
InSupplemental_Arrows_A: "27F0-27FF",
|
||||
InBraille_Patterns: "2800-28FF",
|
||||
InSupplemental_Arrows_B: "2900-297F",
|
||||
InMiscellaneous_Mathematical_Symbols_B: "2980-29FF",
|
||||
InSupplemental_Mathematical_Operators: "2A00-2AFF",
|
||||
InMiscellaneous_Symbols_and_Arrows: "2B00-2BFF",
|
||||
InGlagolitic: "2C00-2C5F",
|
||||
InLatin_Extended_C: "2C60-2C7F",
|
||||
InCoptic: "2C80-2CFF",
|
||||
InGeorgian_Supplement: "2D00-2D2F",
|
||||
InTifinagh: "2D30-2D7F",
|
||||
InEthiopic_Extended: "2D80-2DDF",
|
||||
InCyrillic_Extended_A: "2DE0-2DFF",
|
||||
InSupplemental_Punctuation: "2E00-2E7F",
|
||||
InCJK_Radicals_Supplement: "2E80-2EFF",
|
||||
InKangxi_Radicals: "2F00-2FDF",
|
||||
InIdeographic_Description_Characters: "2FF0-2FFF",
|
||||
InCJK_Symbols_and_Punctuation: "3000-303F",
|
||||
InHiragana: "3040-309F",
|
||||
InKatakana: "30A0-30FF",
|
||||
InBopomofo: "3100-312F",
|
||||
InHangul_Compatibility_Jamo: "3130-318F",
|
||||
InKanbun: "3190-319F",
|
||||
InBopomofo_Extended: "31A0-31BF",
|
||||
InCJK_Strokes: "31C0-31EF",
|
||||
InKatakana_Phonetic_Extensions: "31F0-31FF",
|
||||
InEnclosed_CJK_Letters_and_Months: "3200-32FF",
|
||||
InCJK_Compatibility: "3300-33FF",
|
||||
InCJK_Unified_Ideographs_Extension_A: "3400-4DBF",
|
||||
InYijing_Hexagram_Symbols: "4DC0-4DFF",
|
||||
InCJK_Unified_Ideographs: "4E00-9FFF",
|
||||
InYi_Syllables: "A000-A48F",
|
||||
InYi_Radicals: "A490-A4CF",
|
||||
InLisu: "A4D0-A4FF",
|
||||
InVai: "A500-A63F",
|
||||
InCyrillic_Extended_B: "A640-A69F",
|
||||
InBamum: "A6A0-A6FF",
|
||||
InModifier_Tone_Letters: "A700-A71F",
|
||||
InLatin_Extended_D: "A720-A7FF",
|
||||
InSyloti_Nagri: "A800-A82F",
|
||||
InCommon_Indic_Number_Forms: "A830-A83F",
|
||||
InPhags_pa: "A840-A87F",
|
||||
InSaurashtra: "A880-A8DF",
|
||||
InDevanagari_Extended: "A8E0-A8FF",
|
||||
InKayah_Li: "A900-A92F",
|
||||
InRejang: "A930-A95F",
|
||||
InHangul_Jamo_Extended_A: "A960-A97F",
|
||||
InJavanese: "A980-A9DF",
|
||||
InCham: "AA00-AA5F",
|
||||
InMyanmar_Extended_A: "AA60-AA7F",
|
||||
InTai_Viet: "AA80-AADF",
|
||||
InMeetei_Mayek: "ABC0-ABFF",
|
||||
InHangul_Syllables: "AC00-D7AF",
|
||||
InHangul_Jamo_Extended_B: "D7B0-D7FF",
|
||||
InHigh_Surrogates: "D800-DB7F",
|
||||
InHigh_Private_Use_Surrogates: "DB80-DBFF",
|
||||
InLow_Surrogates: "DC00-DFFF",
|
||||
InPrivate_Use_Area: "E000-F8FF",
|
||||
InCJK_Compatibility_Ideographs: "F900-FAFF",
|
||||
InAlphabetic_Presentation_Forms: "FB00-FB4F",
|
||||
InArabic_Presentation_Forms_A: "FB50-FDFF",
|
||||
InVariation_Selectors: "FE00-FE0F",
|
||||
InVertical_Forms: "FE10-FE1F",
|
||||
InCombining_Half_Marks: "FE20-FE2F",
|
||||
InCJK_Compatibility_Forms: "FE30-FE4F",
|
||||
InSmall_Form_Variants: "FE50-FE6F",
|
||||
InArabic_Presentation_Forms_B: "FE70-FEFF",
|
||||
InHalfwidth_and_Fullwidth_Forms: "FF00-FFEF",
|
||||
InSpecials: "FFF0-FFFF"
|
||||
};
|
||||
|
||||
var UnicodeScripts = {
|
||||
Common: "0000-0040005B-0060007B-00A900AB-00B900BB-00BF00D700F702B9-02DF02E5-02FF0374037E0385038705890600-0603060C061B061F06400660-066906DD0964096509700CF10CF20E3F0FD5-0FD810FB16EB-16ED173517361802180318051CD31CE11CE9-1CEC1CEE-1CF22000-200B200E-2064206A-20702074-207E2080-208E20A0-20B82100-21252127-2129212C-21312133-214D214F-215F21892190-23E82400-24262440-244A2460-26CD26CF-26E126E326E8-26FF2701-27042706-2709270C-27272729-274B274D274F-27522756-275E2761-27942798-27AF27B1-27BE27C0-27CA27CC27D0-27FF2900-2B4C2B50-2B592E00-2E312FF0-2FFB3000-300430063008-30203030-3037303C-303F309B309C30A030FB30FC3190-319F31C0-31E33220-325F327F-32CF3358-33FF4DC0-4DFFA700-A721A788-A78AA830-A839FD3EFD3FFDFDFE10-FE19FE30-FE52FE54-FE66FE68-FE6BFEFFFF01-FF20FF3B-FF40FF5B-FF65FF70FF9EFF9FFFE0-FFE6FFE8-FFEEFFF9-FFFD",
|
||||
Arabic: "0606-060B060D-061A061E0621-063F0641-064A0656-065E066A-066F0671-06DC06DE-06FF0750-077FFB50-FBB1FBD3-FD3DFD50-FD8FFD92-FDC7FDF0-FDFCFE70-FE74FE76-FEFC",
|
||||
Armenian: "0531-05560559-055F0561-0587058AFB13-FB17",
|
||||
Balinese: "1B00-1B4B1B50-1B7C",
|
||||
Bamum: "A6A0-A6F7",
|
||||
Bengali: "0981-09830985-098C098F09900993-09A809AA-09B009B209B6-09B909BC-09C409C709C809CB-09CE09D709DC09DD09DF-09E309E6-09FB",
|
||||
Bopomofo: "3105-312D31A0-31B7",
|
||||
Braille: "2800-28FF",
|
||||
Buginese: "1A00-1A1B1A1E1A1F",
|
||||
Buhid: "1740-1753",
|
||||
Canadian_Aboriginal: "1400-167F18B0-18F5",
|
||||
Cham: "AA00-AA36AA40-AA4DAA50-AA59AA5C-AA5F",
|
||||
Cherokee: "13A0-13F4",
|
||||
Coptic: "03E2-03EF2C80-2CF12CF9-2CFF",
|
||||
Cyrillic: "0400-04840487-05251D2B1D782DE0-2DFFA640-A65FA662-A673A67C-A697",
|
||||
Devanagari: "0900-0939093C-094E09500953-09550958-09630966-096F097109720979-097FA8E0-A8FB",
|
||||
Ethiopic: "1200-1248124A-124D1250-12561258125A-125D1260-1288128A-128D1290-12B012B2-12B512B8-12BE12C012C2-12C512C8-12D612D8-13101312-13151318-135A135F-137C1380-13992D80-2D962DA0-2DA62DA8-2DAE2DB0-2DB62DB8-2DBE2DC0-2DC62DC8-2DCE2DD0-2DD62DD8-2DDE",
|
||||
Georgian: "10A0-10C510D0-10FA10FC2D00-2D25",
|
||||
Glagolitic: "2C00-2C2E2C30-2C5E",
|
||||
Greek: "0370-03730375-0377037A-037D038403860388-038A038C038E-03A103A3-03E103F0-03FF1D26-1D2A1D5D-1D611D66-1D6A1DBF1F00-1F151F18-1F1D1F20-1F451F48-1F4D1F50-1F571F591F5B1F5D1F5F-1F7D1F80-1FB41FB6-1FC41FC6-1FD31FD6-1FDB1FDD-1FEF1FF2-1FF41FF6-1FFE2126",
|
||||
Gujarati: "0A81-0A830A85-0A8D0A8F-0A910A93-0AA80AAA-0AB00AB20AB30AB5-0AB90ABC-0AC50AC7-0AC90ACB-0ACD0AD00AE0-0AE30AE6-0AEF0AF1",
|
||||
Gurmukhi: "0A01-0A030A05-0A0A0A0F0A100A13-0A280A2A-0A300A320A330A350A360A380A390A3C0A3E-0A420A470A480A4B-0A4D0A510A59-0A5C0A5E0A66-0A75",
|
||||
Han: "2E80-2E992E9B-2EF32F00-2FD5300530073021-30293038-303B3400-4DB54E00-9FCBF900-FA2DFA30-FA6DFA70-FAD9",
|
||||
Hangul: "1100-11FF3131-318E3200-321E3260-327EA960-A97CAC00-D7A3D7B0-D7C6D7CB-D7FBFFA0-FFBEFFC2-FFC7FFCA-FFCFFFD2-FFD7FFDA-FFDC",
|
||||
Hanunoo: "1720-1734",
|
||||
Hebrew: "0591-05C705D0-05EA05F0-05F4FB1D-FB36FB38-FB3CFB3EFB40FB41FB43FB44FB46-FB4F",
|
||||
Hiragana: "3041-3096309D-309F",
|
||||
Inherited: "0300-036F04850486064B-06550670095109521CD0-1CD21CD4-1CE01CE2-1CE81CED1DC0-1DE61DFD-1DFF200C200D20D0-20F0302A-302F3099309AFE00-FE0FFE20-FE26",
|
||||
Javanese: "A980-A9CDA9CF-A9D9A9DEA9DF",
|
||||
Kannada: "0C820C830C85-0C8C0C8E-0C900C92-0CA80CAA-0CB30CB5-0CB90CBC-0CC40CC6-0CC80CCA-0CCD0CD50CD60CDE0CE0-0CE30CE6-0CEF",
|
||||
Katakana: "30A1-30FA30FD-30FF31F0-31FF32D0-32FE3300-3357FF66-FF6FFF71-FF9D",
|
||||
Kayah_Li: "A900-A92F",
|
||||
Khmer: "1780-17DD17E0-17E917F0-17F919E0-19FF",
|
||||
Lao: "0E810E820E840E870E880E8A0E8D0E94-0E970E99-0E9F0EA1-0EA30EA50EA70EAA0EAB0EAD-0EB90EBB-0EBD0EC0-0EC40EC60EC8-0ECD0ED0-0ED90EDC0EDD",
|
||||
Latin: "0041-005A0061-007A00AA00BA00C0-00D600D8-00F600F8-02B802E0-02E41D00-1D251D2C-1D5C1D62-1D651D6B-1D771D79-1DBE1E00-1EFF2071207F2090-2094212A212B2132214E2160-21882C60-2C7FA722-A787A78BA78CA7FB-A7FFFB00-FB06FF21-FF3AFF41-FF5A",
|
||||
Lepcha: "1C00-1C371C3B-1C491C4D-1C4F",
|
||||
Limbu: "1900-191C1920-192B1930-193B19401944-194F",
|
||||
Lisu: "A4D0-A4FF",
|
||||
Malayalam: "0D020D030D05-0D0C0D0E-0D100D12-0D280D2A-0D390D3D-0D440D46-0D480D4A-0D4D0D570D60-0D630D66-0D750D79-0D7F",
|
||||
Meetei_Mayek: "ABC0-ABEDABF0-ABF9",
|
||||
Mongolian: "1800180118041806-180E1810-18191820-18771880-18AA",
|
||||
Myanmar: "1000-109FAA60-AA7B",
|
||||
New_Tai_Lue: "1980-19AB19B0-19C919D0-19DA19DE19DF",
|
||||
NKo: "07C0-07FA",
|
||||
Ogham: "1680-169C",
|
||||
Ol_Chiki: "1C50-1C7F",
|
||||
Oriya: "0B01-0B030B05-0B0C0B0F0B100B13-0B280B2A-0B300B320B330B35-0B390B3C-0B440B470B480B4B-0B4D0B560B570B5C0B5D0B5F-0B630B66-0B71",
|
||||
Phags_Pa: "A840-A877",
|
||||
Rejang: "A930-A953A95F",
|
||||
Runic: "16A0-16EA16EE-16F0",
|
||||
Samaritan: "0800-082D0830-083E",
|
||||
Saurashtra: "A880-A8C4A8CE-A8D9",
|
||||
Sinhala: "0D820D830D85-0D960D9A-0DB10DB3-0DBB0DBD0DC0-0DC60DCA0DCF-0DD40DD60DD8-0DDF0DF2-0DF4",
|
||||
Sundanese: "1B80-1BAA1BAE-1BB9",
|
||||
Syloti_Nagri: "A800-A82B",
|
||||
Syriac: "0700-070D070F-074A074D-074F",
|
||||
Tagalog: "1700-170C170E-1714",
|
||||
Tagbanwa: "1760-176C176E-177017721773",
|
||||
Tai_Le: "1950-196D1970-1974",
|
||||
Tai_Tham: "1A20-1A5E1A60-1A7C1A7F-1A891A90-1A991AA0-1AAD",
|
||||
Tai_Viet: "AA80-AAC2AADB-AADF",
|
||||
Tamil: "0B820B830B85-0B8A0B8E-0B900B92-0B950B990B9A0B9C0B9E0B9F0BA30BA40BA8-0BAA0BAE-0BB90BBE-0BC20BC6-0BC80BCA-0BCD0BD00BD70BE6-0BFA",
|
||||
Telugu: "0C01-0C030C05-0C0C0C0E-0C100C12-0C280C2A-0C330C35-0C390C3D-0C440C46-0C480C4A-0C4D0C550C560C580C590C60-0C630C66-0C6F0C78-0C7F",
|
||||
Thaana: "0780-07B1",
|
||||
Thai: "0E01-0E3A0E40-0E5B",
|
||||
Tibetan: "0F00-0F470F49-0F6C0F71-0F8B0F90-0F970F99-0FBC0FBE-0FCC0FCE-0FD4",
|
||||
Tifinagh: "2D30-2D652D6F",
|
||||
Vai: "A500-A62B",
|
||||
Yi: "A000-A48CA490-A4C6"
|
||||
};
|
||||
|
||||
var unicode = {
|
||||
categories: UnicodeCategories,
|
||||
blocks: UnicodeBlocks,
|
||||
scripts: UnicodeScripts
|
||||
};
|
||||
|
||||
// EXPORTS
|
||||
RegexParser.unicode = unicode;
|
||||
|
||||
}());
|
||||
847
gulliver/js/codemirror/contrib/regex/js/parseregex.js
Executable file
847
gulliver/js/codemirror/contrib/regex/js/parseregex.js
Executable file
@@ -0,0 +1,847 @@
|
||||
/* Simple parser for Regular Expressions */
|
||||
/* Thanks to Marijn for patiently addressing some questions and to
|
||||
* Steven Levithan for XRegExp http://xregexp.com/ for pointing the way to the regexps for the regex (I
|
||||
* only discovered his own regex syntax editor RegexPal later on) */
|
||||
|
||||
/*
|
||||
// Possible future to-dos:
|
||||
0) Unicode plugin fix for astral and update for Unicode 6.0.0
|
||||
1) Allow parsing of string escaped regular expressions (e.g., \\ as \ and regular \n as an actual newline) and
|
||||
could potentially integrate into parsing for other languages where known (e.g., string inside RegExp constructor)
|
||||
2) If configured, allow parsing of replace strings (e.g., $1, \1)
|
||||
3) Shared classes
|
||||
a) As with ranges and unicode classes, could also try to supply equivalents which list all
|
||||
characters inside a whole character class
|
||||
b) Add common classes for ranges, inside char. classes, and allow for alternation of colors
|
||||
4) Groups
|
||||
a) detect max's (or even inner_group_mode) from CSS if specified as "max-available"
|
||||
_cssPropertyExists('span.regex-max-available') || _cssPropertyExists('.regex-max-available');
|
||||
b) Remove inner_group_mode and just always both uniform and type-based styles? (first improve
|
||||
inner_group_mode performance when on)
|
||||
5) Expand configuration for different flavors of regex or language implementations corresponding to config
|
||||
options
|
||||
6) Allow free-spacing mode to work with newlines?
|
||||
*/
|
||||
|
||||
/**
|
||||
* OPTIONS (SETUP):
|
||||
* "possible_flags": {String} All flags to support (as a string of joined characters); default is 'imgxs';
|
||||
* if 'literal' is on, this will check for validity against the literal flags, but
|
||||
* use the literal flags
|
||||
* "flags": {String} List of flags to use on this query; will be added to any literals; default is ''
|
||||
* "literal": {Boolean} Whether inside a literal or not
|
||||
* "literal_initial": {String} The initial character to surround regular expression (optionally followed by flags);
|
||||
* A forward slash ("/"), by default
|
||||
*
|
||||
* OPTIONS (STYLING)
|
||||
* "inner_group_mode": {'type'|'uniform'} Indicates how (if at all) to style content inside groups; if by "type",
|
||||
* the class will be assigned by type; if "uniform", a class named
|
||||
* "regex-group-<lev>-<seq>" where <lev> is the nesting level and
|
||||
* <seq> is the sequence number; the "uniform" option allows grouped
|
||||
* content to be styled consistently (but potentially differently from
|
||||
* the parentheses themselves) no matter the type of group
|
||||
* "max_levels": {Number|String} Maximum number of nesting levels before class numbers repeat
|
||||
* "max_alternating": {Number|String} Maximum number of alternating sequences at the same level before
|
||||
* class numbers repeat
|
||||
*
|
||||
* OPTIONS (PATTERNS)
|
||||
* "flavor": {'all'|'ecma-262-ed5'|'ecma-262-ed3'} Sets defaults for the following patterns according to the regex flavor
|
||||
*
|
||||
* "unicode_mode": {'simple'|'validate'|'store'} Mode for handling Unicode classes; unless 'simple' is chosen, may
|
||||
* affect performance given initial need to load and subsequent need
|
||||
* to parse and validate (i.e., selectively color), and, if 'store' is chosen,
|
||||
* also makes these (many) additional values on the token object, e.g.,
|
||||
* for use by activeTokens for adding tooltips; Default is 'simple' which
|
||||
* simply checks that the values are plausible;
|
||||
* Note: To include Unicode validation, you must include your
|
||||
* CodeMirror parserfile in this sequence:
|
||||
* parserfile: ["parseregex.js", "parseregex-unicode.js"]
|
||||
* "unicode_classes": {Boolean} Whether to accept all Unicode classes (unless overridden); default is true
|
||||
* "unicode_blocks": {Boolean} Whether to accept Unicode blocks (overrides unicode_classes default); e.g., \p{InArabic}
|
||||
* "unicode_scripts": {Boolean} Whether to accept Unicode scripts (overrides unicode_classes default); e.g., \p{Hebrew}
|
||||
* "unicode_categories": {Boolean} Whether to accept Unicode categories (overrides unicode_classes default); e.g., \p{Ll} (for lower-case letters)
|
||||
* "named_backreferences": {Boolean} Whether to accept named backreferences; default is true
|
||||
* "empty_char_class": {Boolean} Whether to allow [] or [^] as character classes; default is true
|
||||
* "mode_modifier": {Boolean} Whether to allow (?imsx) mode modifiers
|
||||
*
|
||||
* NOTE
|
||||
* You can add the following to your CodeMirror configuration object in order to get simple tooltips showing the
|
||||
* character equivalent of an escape sequence:
|
||||
activeTokens : function (spanNode, tokenObject, editor) {
|
||||
if (tokenObject.equivalent) {
|
||||
spanNode.title = tokenObject.equivalent;
|
||||
}
|
||||
},
|
||||
....or this more advanced one which adds ranges (though you may wish to change the character limit, being
|
||||
aware that browsers have a limitation on tooltip size, unless you were to also use a tooltip library which used
|
||||
this information to expand the visible content):
|
||||
activeTokens : (function () {
|
||||
var charLimit = 500;
|
||||
var lastEquivalent, rangeBegan, lastRangeHyphen;
|
||||
|
||||
function _buildTitle (beginChar, endChar) {
|
||||
var beginCode = beginChar.charCodeAt(0), endCode = endChar.charCodeAt(0);
|
||||
var title = '';
|
||||
if (endCode - beginCode <= charLimit) {
|
||||
for (var i = beginCode; i <= endCode; i++) {
|
||||
title += String.fromCharCode(i);
|
||||
}
|
||||
}
|
||||
return title;
|
||||
}
|
||||
|
||||
return function (spanNode, token, editor) {
|
||||
var content = token.content;
|
||||
if (lastEquivalent && token.style === 'regex-class-range-hyphen') {
|
||||
rangeBegan = true;
|
||||
lastRangeHyphen = spanNode;
|
||||
}
|
||||
else if (rangeBegan) {
|
||||
var beginChar = lastEquivalent;
|
||||
var endChar = (token.equivalent || content);
|
||||
lastRangeHyphen.title = _buildTitle(beginChar, endChar);
|
||||
rangeBegan = false;
|
||||
lastEquivalent = null;
|
||||
//editor.reparseBuffer(); // title must be redrawn since already added previously (do below instead as locking up on undo?); too intensive to call this, but keeping here for record
|
||||
}
|
||||
else if (content === ']') {
|
||||
rangeBegan = false;
|
||||
}
|
||||
else {
|
||||
rangeBegan = false;
|
||||
// Fix: 'regex-unicode-class-inside' not supported and should not be since it wouldn't make sense as a starting range?
|
||||
lastEquivalent = token.equivalent || content;
|
||||
}
|
||||
|
||||
if (token.display) {
|
||||
spanNode.title = token.display;
|
||||
}
|
||||
else if (token.equivalent) {
|
||||
if (token.unicode) {
|
||||
var range = /(.)-(.)/g;
|
||||
spanNode.title = token.equivalent.replace(range,
|
||||
function (n0, n1, n2) {
|
||||
return _buildTitle(n1, n2);
|
||||
}
|
||||
);
|
||||
// editor.reparseBuffer(); // too intensive to call this, but keeping here for record
|
||||
}
|
||||
else {
|
||||
spanNode.title = token.equivalent;
|
||||
// editor.reparseBuffer(); // too intensive to call this, but keeping here for record
|
||||
}
|
||||
}
|
||||
};
|
||||
}()),
|
||||
*/
|
||||
|
||||
|
||||
var RegexParser = Editor.Parser = (function() {
|
||||
|
||||
var regexConfigBooleanOptions = ['unicode_blocks', 'unicode_scripts', 'unicode_categories',
|
||||
'unicode_classes', 'named_backreferences', 'empty_char_class', 'mode_modifier'],
|
||||
regexConfigStringOptions = ['unicode_mode'], // Just for record-keeping
|
||||
possibleFlags = 'imgxs',
|
||||
config = {}, ucl;
|
||||
// Resettable
|
||||
var initialFound, endFound, charClassRangeBegun, negatedCharClass, mode_modifier_begun, flags = '',
|
||||
groupTypes, groupCounts;
|
||||
|
||||
config.literal_initial = '/';
|
||||
|
||||
// Adapted from tokenize.js (not distinctly treating whitespace except for newlines)
|
||||
function noWSTokenizer (source, state) {
|
||||
var tokenizer = {
|
||||
state: state,
|
||||
take: function(type) {
|
||||
if (typeof(type) == "string")
|
||||
type = {style: type, type: type};
|
||||
type.content = (type.content || "") + source.get();
|
||||
type.value = type.content + source.get();
|
||||
return type;
|
||||
},
|
||||
next: function () {
|
||||
if (!source.more()) throw StopIteration;
|
||||
var type;
|
||||
if (source.equals("\n")) {
|
||||
source.next();
|
||||
return this.take("whitespace");
|
||||
}
|
||||
while (!type)
|
||||
type = this.state(source, function(s) {tokenizer.state = s;});
|
||||
return this.take(type);
|
||||
}
|
||||
};
|
||||
return tokenizer;
|
||||
}
|
||||
|
||||
// Private static utilities
|
||||
function _expandRange (type, name) { // More efficient than unpack in targeting only which we need (though ideally would not need to convert at all)
|
||||
var codePt = /\w{4}/g,
|
||||
unicode = RegexParser.unicode, group = unicode[type];
|
||||
if (group.hasOwnProperty(name)) {
|
||||
// group[name] = group[name].replace(codePt, '\\u$&'); // We shouldn't need this unless we start validating against a matching string
|
||||
return group[name].replace(codePt,
|
||||
function (n0) {
|
||||
if (n0 === '002D') {
|
||||
return 'U+' + n0; // Leave genuine hyphens unresolved so they won't get confused with range hyphens
|
||||
}
|
||||
return String.fromCharCode(parseInt('0x' + n0, 16)); // Fix: Would be more efficient to store as Unicode characters like this from the start
|
||||
});
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function _copyObj (obj, deep) {
|
||||
var ret = {};
|
||||
for (var p in obj) {
|
||||
if (obj.hasOwnProperty(p)) {
|
||||
if (deep && typeof obj[p] === 'object' && obj[p] !== null) {
|
||||
ret[p] = _copyObj(obj[p], deep);
|
||||
}
|
||||
else {
|
||||
ret[p] = obj[p];
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
function _forEach (arr, h) {
|
||||
for (var i = 0, arrl = arr.length; i < arrl; i++) {
|
||||
h(arr[i], i);
|
||||
}
|
||||
}
|
||||
function _setOptions (arr, value) {
|
||||
arr = typeof arr === 'string' ? [arr] : arr;
|
||||
_forEach(arr, function (item) {
|
||||
config[item] = value;
|
||||
});
|
||||
}
|
||||
|
||||
function _cssPropertyExists (selectorText) {
|
||||
var i = 0, j = 0, dsl = 0, crl = 0, ss, d = document,
|
||||
_getPropertyFromStyleSheet =
|
||||
function (ss, selectorText) {
|
||||
var rules = ss.cssRules ? ss.cssRules : ss.rules; /* Mozilla or IE */
|
||||
for (j = 0, crl = rules.length; j < crl; j++) {
|
||||
var rule = rules[j];
|
||||
try {
|
||||
if (rule.type === CSSRule.STYLE_RULE && rule.selectorText === selectorText) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (err) { /* IE */
|
||||
if (rule.selectorText === selectorText) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
var value;
|
||||
for (i = 0, dsl = d.styleSheets.length; i < dsl; i++) {
|
||||
ss = d.styleSheets[i];
|
||||
value = _getPropertyFromStyleSheet(ss, selectorText);
|
||||
if (value) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function _addFlags (f) {
|
||||
if ((/[^a-z]/).test(f)) { // Could insist on particular flags
|
||||
throw 'Invalid flag supplied to the regular expression parser';
|
||||
}
|
||||
flags += f;
|
||||
}
|
||||
function _setPossibleFlags (f) {
|
||||
if ((/[^a-z]/).test(f)) { // Could insist on particular flags
|
||||
throw 'Invalid flag supplied to the regular expression parser';
|
||||
}
|
||||
possibleFlags = f;
|
||||
}
|
||||
function _esc (s) {
|
||||
return s.replace(/"[.\\+*?\[\^\]$(){}=!<>|:\-]/g, '\\$&');
|
||||
}
|
||||
|
||||
var tokenizeRegex = (function() {
|
||||
// Private utilities
|
||||
function _hasFlag (f) {
|
||||
return flags.indexOf(f) > -1;
|
||||
}
|
||||
function _lookAheadMatches (source, regex) {
|
||||
var matches = source.lookAheadRegex(regex, true);
|
||||
if (matches && matches.length > 1) { // Allow us to return the position of a match out of alternates
|
||||
for (var i = matches.length - 1; i >= 0; i--) {
|
||||
if (matches[i] != null) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
function validateUnicodeClass (negated, place, source) {
|
||||
var neg = ' regex-' + negated + 'unicode', ret = 'regex-unicode-class-' + place + neg,
|
||||
name, unicode = RegexParser.unicode;
|
||||
if (!unicode) {
|
||||
throw 'Unicode plugin of the regular expression parser not properly loaded';
|
||||
}
|
||||
if (config.unicode_categories) {
|
||||
var categories = source.lookAheadRegex(/^\\[pP]{\^?([A-Z][a-z]?)}/, true);
|
||||
if (categories) {
|
||||
name = categories[1];
|
||||
if (unicode.categories[name]) {
|
||||
return ret + '-category-' + place + neg + '-category-' + name + '-' + place;
|
||||
}
|
||||
return 'regex-bad-sequence';
|
||||
}
|
||||
}
|
||||
if (config.unicode_blocks) {
|
||||
var blocks = source.lookAheadRegex(/^\\[pP]{\^?(In[A-Z][^}]*)}/, true);
|
||||
if (blocks) {
|
||||
name = blocks[1];
|
||||
if (unicode.blocks[name]) {
|
||||
return ret + '-block-' + place + neg + '-block-' + name + '-' + place;
|
||||
}
|
||||
return 'regex-bad-sequence';
|
||||
}
|
||||
}
|
||||
if (config.unicode_scripts) {
|
||||
var scripts = source.lookAheadRegex(/^\\[pP]{\^?([^}]*)}/, true);
|
||||
if (scripts) {
|
||||
name = scripts[1];
|
||||
if (unicode.scripts[name]) {
|
||||
return ret + '-script-' + place + neg + '-script-' + name + '-' + place;
|
||||
}
|
||||
return 'regex-bad-sequence';
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function unicode_class (source, place) {
|
||||
var ret = 'regex-unicode-class-' + place + ' ', negated = '';
|
||||
if (source.lookAheadRegex(/^\\P/) || source.lookAheadRegex(/^\\p{\^/)) {
|
||||
negated = 'negated';
|
||||
}
|
||||
else if (source.lookAheadRegex(/^\\P{\^/)) { // Double-negative
|
||||
return false;
|
||||
}
|
||||
switch (config.unicode_mode) {
|
||||
case 'validate': case 'store':
|
||||
return validateUnicodeClass(negated, place, source);
|
||||
case 'simple': // Fall-through
|
||||
default:
|
||||
// generic: /^\\[pP]{\^?[^}]*}/
|
||||
if (config.unicode_categories && source.lookAheadRegex(/^\\[pP]{\^?[A-Z][a-z]?}/, true)) {
|
||||
return ret + 'regex-' + negated + 'unicode-category';
|
||||
}
|
||||
if (config.unicode_blocks && source.lookAheadRegex(/^\\[pP]{\^?In[A-Z][^}]*}/, true)) {
|
||||
return ret + 'regex-' + negated + 'unicode-block';
|
||||
}
|
||||
if (config.unicode_scripts && source.lookAheadRegex(/^\\[pP]{\^?[^}]*}/, true)) {
|
||||
return ret + 'regex-' + negated + 'unicode-script';
|
||||
}
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// State functions
|
||||
// Changed [\s\S] to [^\n] to avoid accidentally grabbing a terminating (auto-inserted place-holder?) newline
|
||||
var inside_class_meta = /^\\(?:([0-3][0-7]{0,2}|[4-7][0-7]?)|(x[\dA-Fa-f]{2})|(u[\dA-Fa-f]{4})|(c[A-Za-z])|(-\\]^)|([bBdDfnrsStvwW0])|([^\n]))/;
|
||||
function inside_class (source, setState) {
|
||||
var ret;
|
||||
if (source.lookAhead(']', true)) {
|
||||
// charClassRangeBegun = false; // Shouldn't be needed
|
||||
setState(customOutsideClass);
|
||||
return 'regex-class-end';
|
||||
}
|
||||
if (negatedCharClass && source.lookAhead('^', true)) {
|
||||
negatedCharClass = false;
|
||||
return 'regex-class-negator';
|
||||
}
|
||||
if (source.lookAhead('-', true)) {
|
||||
if (!charClassRangeBegun) {
|
||||
ret = 'regex-class-initial-hyphen';
|
||||
}
|
||||
else if (source.equals(']')) {
|
||||
ret = 'regex-class-final-hyphen';
|
||||
}
|
||||
else {
|
||||
return 'regex-class-range-hyphen';
|
||||
}
|
||||
}
|
||||
else if (!source.equals('\\')) {
|
||||
var ch = source.next();
|
||||
if (config.literal && ch === config.literal_initial) {
|
||||
return 'regex-bad-character';
|
||||
}
|
||||
ret = 'regex-class-character';
|
||||
}
|
||||
else if ((ucl = unicode_class(source, 'inside'))) {
|
||||
ret = ucl;
|
||||
}
|
||||
else if (source.lookAheadRegex(/^\\(\n|$)/)) { // Treat an ending backslash like a bad
|
||||
// character to avoid auto-adding of extra text
|
||||
source.next();
|
||||
ret = 'regex-bad-character';
|
||||
}
|
||||
else {
|
||||
switch (_lookAheadMatches(source, inside_class_meta)) {
|
||||
case 1:
|
||||
ret = 'regex-class-octal';
|
||||
break;
|
||||
case 2:
|
||||
ret = 'regex-class-hex';
|
||||
break;
|
||||
case 3:
|
||||
ret = 'regex-class-unicode-escape';
|
||||
break;
|
||||
case 4:
|
||||
ret = 'regex-class-ascii-control';
|
||||
break;
|
||||
case 5:
|
||||
ret = 'regex-class-escaped-special';
|
||||
break;
|
||||
case 6:
|
||||
ret = 'regex-class-special-escape';
|
||||
break;
|
||||
case 7:
|
||||
ret = 'regex-class-extra-escaped';
|
||||
break;
|
||||
default:
|
||||
throw 'Unexpected character inside class, beginning ' +
|
||||
source.lookAheadRegex(/^[\s\S]+$/)[0] + ' and of length '+
|
||||
source.lookAheadRegex(/^[\s\S]+$/)[0].length; // Shouldn't reach here
|
||||
}
|
||||
}
|
||||
// Fix: Add this as a token property in the parser instead?
|
||||
if (charClassRangeBegun) {
|
||||
charClassRangeBegun = false;
|
||||
ret += '-end-range';
|
||||
}
|
||||
else if (source.equals('-')) {
|
||||
charClassRangeBegun = true;
|
||||
ret += '-begin-range';
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Changed [\s\S] to [^\n] to avoid accidentally grabbing a terminating (auto-inserted place-holder?) newline
|
||||
var outside_class_meta = /^(?:\\(?:(0(?:[0-3][0-7]{0,2}|[4-7][0-7]?)?)|([1-9]\d*)|(x[\dA-Fa-f]{2})|(u[\dA-Fa-f]{4})|(c[A-Za-z])|([bBdDfnrsStvwW0])|([?*+])|([.\\[$|{])|([^\n]))|([?*+]\??)|({\d+(?:,\d*)?}\??))/;
|
||||
function outside_class (source, setState) {
|
||||
if ((ucl = unicode_class(source, 'outside'))) {
|
||||
return ucl;
|
||||
}
|
||||
switch (_lookAheadMatches(source, outside_class_meta)) {
|
||||
case 1:
|
||||
return 'regex-octal';
|
||||
case 2:
|
||||
return 'regex-ascii';
|
||||
case 3:
|
||||
return 'regex-hex';
|
||||
case 4:
|
||||
return 'regex-unicode-escape';
|
||||
case 5:
|
||||
return 'regex-ascii-control';
|
||||
case 6:
|
||||
return 'regex-special-escape';
|
||||
case 7:
|
||||
return 'regex-quantifier-escape'; // Fix: could probably just merge with escaped-special
|
||||
case 8:
|
||||
return 'regex-escaped-special';
|
||||
case 9:
|
||||
return 'regex-extra-escaped';
|
||||
case 10:
|
||||
return 'regex-quantifiers';
|
||||
case 11:
|
||||
return 'regex-repetition';
|
||||
default:
|
||||
if (config.literal && source.lookAhead(config.literal_initial, true)) {
|
||||
if (!initialFound) {
|
||||
initialFound = true;
|
||||
return 'regex-literal-begin';
|
||||
}
|
||||
endFound = true;
|
||||
setState(beginFlags);
|
||||
return 'regex-literal-end';
|
||||
}
|
||||
if (source.lookAhead('|', true)) {
|
||||
return 'regex-alternator';
|
||||
}
|
||||
if (source.lookAheadRegex(/^\\$/, true)) {
|
||||
return 'regex-bad-character';
|
||||
}
|
||||
source.next();
|
||||
return 'regex-character';
|
||||
}
|
||||
}
|
||||
function beginFlags (source, setState) {
|
||||
var endFlags = source.lookAheadRegex(new RegExp('^[' + possibleFlags + ']*', ''), true);
|
||||
if (endFlags == null) {
|
||||
// Unrecognized flag used in regular expression literal
|
||||
return 'regex-bad-character';
|
||||
}
|
||||
// Already confirmed validity earlier
|
||||
setState(finished);
|
||||
return 'regex-flags';
|
||||
}
|
||||
function finished () {
|
||||
throw StopIteration;
|
||||
}
|
||||
|
||||
function customOutsideClass (source, setState) {
|
||||
if (config.named_backreferences && source.lookAheadRegex(/^\\k<([\w$]+)>/, true)) {
|
||||
return 'regex-named-backreference';
|
||||
}
|
||||
if (_hasFlag('x') && source.lookAheadRegex(/^(?:#.*)+?/, true)) { // Fix: lookAheadRegex will avoid new lines; added extra '?' at end
|
||||
// Regex should be /^(?:\s+|#.*)+?/ but this was problematic
|
||||
return 'regex-free-spacing-mode';
|
||||
}
|
||||
|
||||
if (source.lookAhead('[', true)) {
|
||||
if (source.lookAheadRegex(/^\^?]/, true)) {
|
||||
return config.empty_char_class ? 'regex-empty-class' : 'regex-bad-character';
|
||||
}
|
||||
if (source.equals('^')) {
|
||||
negatedCharClass = true;
|
||||
}
|
||||
setState(inside_class);
|
||||
return 'regex-class-begin';
|
||||
}
|
||||
|
||||
// Unmatched ending parentheses
|
||||
if (source.lookAhead(')', true)) {
|
||||
return 'regex-ending-group';
|
||||
}
|
||||
if (source.lookAhead('(', true)) {
|
||||
if (config.mode_modifier && mode_modifier_begun) {
|
||||
var mode_modifier = source.lookAheadRegex(/^\?([imsx]+)\)/, true);
|
||||
if (mode_modifier) { // We know it should exist if we're here
|
||||
// addFlags(mode_modifier[1]); // Handle flags earlier
|
||||
mode_modifier_begun = false;
|
||||
return 'regex-mode-modifier';
|
||||
}
|
||||
}
|
||||
if (source.lookAheadRegex(/^\?#[^)]*\)/, true)) { // No apparent nesting of comments?
|
||||
return 'regex-comment-pattern';
|
||||
}
|
||||
|
||||
var ret;
|
||||
if (source.lookAheadRegex(/^(?!\?)/, true)) {
|
||||
ret = 'regex-capturing-group';
|
||||
}
|
||||
if (source.lookAheadRegex(/^\?<([$\w]+)>/, true)) {
|
||||
ret = 'regex-named-capturing-group';
|
||||
}
|
||||
if (source.lookAheadRegex(/^\?[:=!]/, true)) {
|
||||
ret = 'regex-grouping';
|
||||
}
|
||||
if (!ret) {
|
||||
return 'regex-bad-character'; // 'Uncaught parenthetical in tokenizing regular expression';
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
return outside_class(source, setState);
|
||||
}
|
||||
|
||||
return function(source, startState) {
|
||||
return noWSTokenizer(source, startState || customOutsideClass);
|
||||
};
|
||||
})();
|
||||
|
||||
|
||||
function resetStateVariables () {
|
||||
initialFound = false, endFound = false, charClassRangeBegun = false, negatedCharClass = false,
|
||||
mode_modifier_begun = false;
|
||||
flags = '';
|
||||
if (config.flags) { // Reset to configuration value
|
||||
_addFlags(config.flags);
|
||||
}
|
||||
groupTypes = [],
|
||||
groupCounts = {
|
||||
'capturing-group': {currentCount: 0},
|
||||
'named-capturing-group': {currentCount: 0},
|
||||
'grouping': {currentCount: 0}
|
||||
};
|
||||
}
|
||||
|
||||
// Parser
|
||||
function parseRegex (source) {
|
||||
resetStateVariables();
|
||||
|
||||
var tokens = tokenizeRegex(source);
|
||||
|
||||
if (config.literal && !source.equals(config.literal_initial)) {
|
||||
throw 'Regular expression literals must include a beginning "'+config.literal_initial+'"';
|
||||
}
|
||||
|
||||
if (config.literal) {
|
||||
var regex = new RegExp('^[\\s\\S]*' + _esc(config.literal_initial) + '([' + possibleFlags + ']*)$', '');
|
||||
var endFlags = source.lookAheadRegex(regex);
|
||||
if (endFlags == null) {
|
||||
// Unrecognized flag used in regular expression literal
|
||||
}
|
||||
else {
|
||||
_addFlags(endFlags[1]);
|
||||
}
|
||||
}
|
||||
else if (config.mode_modifier) { // Fix: We are not allowing both a mode modifier and
|
||||
// literal syntax (presumably redundant)
|
||||
var mode_modifier = source.lookAheadRegex(/^\(\?([imsx]+)\)/, true);
|
||||
if (mode_modifier) {
|
||||
mode_modifier_begun = true;
|
||||
_addFlags(mode_modifier[1]);
|
||||
}
|
||||
}
|
||||
var iter = {
|
||||
next: function() {
|
||||
try {
|
||||
var level_num,
|
||||
token = tokens.next(),
|
||||
style = token.style,
|
||||
content = token.content,
|
||||
lastChildren, currentChildren, currentCount, currentGroupStyle,
|
||||
type = style.replace(/^regex-/, '');
|
||||
|
||||
switch (type) {
|
||||
case 'ending-group':
|
||||
if (!groupTypes.length) {
|
||||
// Closing parenthesis without an opening one
|
||||
token.style = 'regex-bad-character';
|
||||
}
|
||||
else {
|
||||
level_num = config.max_levels ?
|
||||
((groupTypes.length % config.max_levels) || config.max_levels) : groupTypes.length;
|
||||
var popped = groupTypes.pop();
|
||||
// Allow numbered classes
|
||||
currentChildren = groupCounts[popped];
|
||||
while (currentChildren && currentChildren.currentChildren &&
|
||||
currentChildren.currentChildren.currentChildren) { // Find lowest level parent
|
||||
currentChildren = currentChildren.currentChildren;
|
||||
}
|
||||
delete currentChildren.currentChildren; // Use parent to delete children
|
||||
currentCount = currentChildren.currentCount; // Use parent as new child to get current count
|
||||
currentCount = config.max_alternating ?
|
||||
((currentCount % config.max_alternating) || config.max_alternating) : currentCount;
|
||||
|
||||
currentGroupStyle = level_num + '-' + currentCount;
|
||||
token.style = 'regex-ending-' + popped + ' regex-ending-' + popped + currentGroupStyle;
|
||||
if (config.inner_group_mode === 'uniform') { // 'type' is automatically processed for ending
|
||||
token.style += ' regex-group-' + currentGroupStyle;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'capturing-group':
|
||||
case 'named-capturing-group':
|
||||
case 'grouping':
|
||||
lastChildren = groupCounts[type],
|
||||
currentChildren = groupCounts[type].currentChildren;
|
||||
while (currentChildren) {
|
||||
lastChildren = currentChildren;
|
||||
currentChildren = currentChildren.currentChildren;
|
||||
}
|
||||
currentCount = ++lastChildren.currentCount;
|
||||
if (!lastChildren.currentChildren) {
|
||||
lastChildren.currentChildren = {currentCount: 0};
|
||||
}
|
||||
|
||||
groupTypes.push(type);
|
||||
level_num = config.max_levels ?
|
||||
((groupTypes.length % config.max_levels) || config.max_levels) : groupTypes.length;
|
||||
// Allow numbered classes
|
||||
currentCount = config.max_alternating ?
|
||||
((currentCount % config.max_alternating) || config.max_alternating) : currentCount;
|
||||
currentGroupStyle = level_num + '-' + currentCount;
|
||||
var currentStyle = ' ' + token.style;
|
||||
|
||||
|
||||
if (config.inner_group_mode) {
|
||||
token.style += config.inner_group_mode === 'type' ?
|
||||
currentStyle + currentGroupStyle :
|
||||
' regex-group-' + currentGroupStyle;
|
||||
token.style += ' ' + style + currentGroupStyle;
|
||||
}
|
||||
else {
|
||||
token.style += currentStyle + currentGroupStyle;
|
||||
}
|
||||
lastChildren.currentGroupStyle = currentGroupStyle;
|
||||
lastChildren.currentStyle = currentStyle;
|
||||
break;
|
||||
// Allow ability to extract information on character equivalence, e.g., for use on tooltips
|
||||
case 'class-octal': case 'octal': // Fall-through
|
||||
case 'class-octal-begin-range': case 'class-octal-end-range': // Fall-through
|
||||
case 'class-ascii-begin-range': case 'class-ascii-end-range': // Fall-through
|
||||
case 'class-ascii': case 'ascii': // Firefox apparently treats ascii here as octals
|
||||
token.equivalent = String.fromCharCode(parseInt(content.replace(/^\\/, ''), 8));
|
||||
break;
|
||||
case 'class-hex': case 'hex': // Fall-through
|
||||
case 'class-hex-begin-range': case 'class-hex-end-range': // Fall-through
|
||||
case 'class-unicode-escape': case 'class-unicode-escape-begin-range': // Fall-through
|
||||
case 'class-unicode-escape-end-range': case 'unicode-escape':
|
||||
token.equivalent = String.fromCharCode(parseInt('0x'+content.replace(/^\\(x|u)/, ''), 16));
|
||||
break;
|
||||
case 'class-ascii-control-begin-range': case 'class-ascii-control-end-range': // Fall-through
|
||||
case 'class-ascii-control': case 'ascii-control':
|
||||
token.equivalent = String.fromCharCode(content.replace(/^\\c/, '').charCodeAt(0) - 64);
|
||||
break;
|
||||
case 'class-special-escape': case 'class-special-escape-begin-range': // Fall-through
|
||||
case 'class-special-escape-end-range': case 'special-escape':
|
||||
// Others to ignore (though some (\d, \s, \w) could have theirs listed): bBdDsSwW
|
||||
var chr = content.replace(/^\\/, ''),
|
||||
pos = 'fnrtv'.indexOf(chr),
|
||||
specialEquivs = '\f\n\r\t\v';
|
||||
if (pos !== -1) { // May not be visible without conversion to codepoints
|
||||
var c = specialEquivs.charAt(pos);
|
||||
var hex = c.charCodeAt(0).toString(16).toUpperCase();
|
||||
token.display = 'U+' + Array(5 - hex.length).join('0') + hex;
|
||||
token.equivalent = c;
|
||||
}
|
||||
break;
|
||||
case 'regex-class-escaped-special': case 'regex-class-escaped-special-begin-range':
|
||||
case 'regex-class-escaped-special-end-range':
|
||||
case 'class-extra-escaped-begin-range': case 'class-extra-escaped-end-range':
|
||||
case 'class-extra-escaped': case 'extra-escaped':
|
||||
token.equivalent = content.replace(/^\\/, '');
|
||||
break;
|
||||
default:
|
||||
if (config.unicode_mode === 'store') {
|
||||
if (config.unicode_categories) {
|
||||
var cat = type.match(/regex-unicode-category-(\w+?)-(?:outside|inside)/);
|
||||
if (cat) {
|
||||
token.equivalent = _expandRange('categories', cat[1]) || '';
|
||||
token.unicode = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (config.unicode_blocks) {
|
||||
var block = type.match(/regex-unicode-block-(\w+)-(?:outside|inside)/);
|
||||
if (block) {
|
||||
token.equivalent = _expandRange('blocks', block[1]) || '';
|
||||
token.unicode = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (config.unicode_scripts) {
|
||||
var script = type.match(/regex-unicode-script-(\w+)-(?:outside|inside)/);
|
||||
if (script) {
|
||||
token.equivalent = _expandRange('scripts', script[1]) || '';
|
||||
token.unicode = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (config.inner_group_mode && type !== 'ending-group' && type !== 'capturing-group' && type !== 'named-capturing-group' &&
|
||||
type !== 'grouping') {
|
||||
level_num = config.max_levels ?
|
||||
((groupTypes.length % config.max_levels) || config.max_levels) : groupTypes.length;
|
||||
// Allow numbered classes
|
||||
var last = groupTypes[groupTypes.length - 1];
|
||||
if (last) {
|
||||
currentChildren = groupCounts[last];
|
||||
while (currentChildren && currentChildren.currentChildren &&
|
||||
currentChildren.currentChildren.currentChildren) { // Find lowest level parent
|
||||
currentChildren = currentChildren.currentChildren;
|
||||
}
|
||||
token.style += config.inner_group_mode === 'type' ?
|
||||
currentChildren.currentStyle + currentChildren.currentGroupStyle :
|
||||
' regex-group-' + currentChildren.currentGroupStyle;
|
||||
}
|
||||
}
|
||||
if (!source.more()) {
|
||||
if (groupTypes.length) { // Opening group without a closing parenthesis
|
||||
token.style = 'regex-bad-character';
|
||||
}
|
||||
else if (config.literal && !endFound) {
|
||||
//throw 'Regular expression literals must include a (non-escaped) ending "' +
|
||||
// config.literal_initial + '" (with optional flags).';
|
||||
token.style = 'regex-bad-character';
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
if (e != StopIteration) {
|
||||
alert(e + '::'+e.lineNumber);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
return token;
|
||||
},
|
||||
copy: function() {
|
||||
var _initialFound = initialFound, _charClassRangeBegun = charClassRangeBegun,
|
||||
_negatedCharClass = negatedCharClass, _flags = flags,
|
||||
_endFound = endFound, _groupTypes = groupTypes,
|
||||
_mode_modifier_begun = mode_modifier_begun,
|
||||
_tokenState = tokens.state,
|
||||
_groupCounts = _copyObj(groupCounts, true);
|
||||
return function(source) {
|
||||
initialFound = _initialFound;
|
||||
charClassRangeBegun = _charClassRangeBegun;
|
||||
negatedCharClass = _negatedCharClass;
|
||||
flags = _flags;
|
||||
endFound = _endFound;
|
||||
groupTypes = _groupTypes;
|
||||
mode_modifier_begun = _mode_modifier_begun;
|
||||
tokens = tokenizeRegex(source, _tokenState);
|
||||
groupCounts = _groupCounts;
|
||||
return iter;
|
||||
};
|
||||
}
|
||||
};
|
||||
return iter;
|
||||
}
|
||||
|
||||
// Parser object
|
||||
return {
|
||||
make: parseRegex,
|
||||
configure: function (parserConfig) {
|
||||
var unicode = this.unicode;
|
||||
|
||||
// Overridable
|
||||
_setOptions('unicode_mode', 'simple');
|
||||
_setOptions(regexConfigBooleanOptions, false);
|
||||
if (parserConfig.unicode_classes) {
|
||||
_setOptions(['unicode_blocks', 'unicode_scripts', 'unicode_categories'], true);
|
||||
}
|
||||
switch (parserConfig.flavor) {
|
||||
case 'ecma-262-ed5':
|
||||
_setOptions(['empty_char_class'], true);
|
||||
// Fall-through
|
||||
case 'ecma-262-ed3':
|
||||
config.possible_flags = 'gim'; // If wish for Firefox 'y', add it on parserConfig
|
||||
break;
|
||||
case 'all':
|
||||
default:
|
||||
_setOptions(regexConfigBooleanOptions, true);
|
||||
break;
|
||||
}
|
||||
|
||||
// Setting with possible overrides
|
||||
for (var opt in parserConfig) {
|
||||
if ((/^regex_/).test(opt)) { // Use for compatibility with JS+Regex
|
||||
config[opt.replace(/^regex_/, '')] = parserConfig[opt];
|
||||
continue;
|
||||
}
|
||||
config[opt] = parserConfig[opt];
|
||||
}
|
||||
|
||||
// Post-processing
|
||||
if (config.possible_flags) {
|
||||
_setPossibleFlags(config.possible_flags);
|
||||
}
|
||||
|
||||
if (config.unicode_mode !== 'simple') {
|
||||
if (!unicode) {
|
||||
throw 'You must include the parseregex-unicode.js file in order to use validate or storage mode Unicode';
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
})();
|
||||
23
gulliver/js/codemirror/contrib/scheme/LICENSE
Executable file
23
gulliver/js/codemirror/contrib/scheme/LICENSE
Executable file
@@ -0,0 +1,23 @@
|
||||
Copyright (c) 2010 Danny Yoo
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any
|
||||
damages arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any
|
||||
purpose, including commercial applications, and to alter it and
|
||||
redistribute it freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must
|
||||
not claim that you wrote the original software. If you use this
|
||||
software in a product, an acknowledgment in the product
|
||||
documentation would be appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must
|
||||
not be misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source
|
||||
distribution.
|
||||
|
||||
Danny Yoo
|
||||
dyoo@cs.wpi.edu
|
||||
45
gulliver/js/codemirror/contrib/scheme/css/schemecolors.css
Executable file
45
gulliver/js/codemirror/contrib/scheme/css/schemecolors.css
Executable file
@@ -0,0 +1,45 @@
|
||||
html {
|
||||
cursor: text;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
.editbox {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin: 0pt;
|
||||
padding: 0;
|
||||
font-family: monospace;
|
||||
font-size: 10pt;
|
||||
color: black;
|
||||
}
|
||||
|
||||
|
||||
|
||||
pre.code, .editbox {
|
||||
color: #666666;
|
||||
}
|
||||
|
||||
.editbox p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
span.scheme-string {color: green;}
|
||||
span.scheme-number {color: blue;}
|
||||
span.scheme-boolean {color: darkred;}
|
||||
span.scheme-character {color: orange;}
|
||||
span.scheme-symbol {color: steelblue;}
|
||||
span.scheme-punctuation {color: black;}
|
||||
span.scheme-lparen {color: black;}
|
||||
span.scheme-rparen {color: black;}
|
||||
span.scheme-comment { color: orange; }
|
||||
|
||||
span.good-matching-paren {
|
||||
font-weight: bold;
|
||||
color: #3399FF;
|
||||
}
|
||||
span.bad-matching-paren {
|
||||
font-weight: bold;
|
||||
color: red;
|
||||
}
|
||||
82
gulliver/js/codemirror/contrib/scheme/index.html
Executable file
82
gulliver/js/codemirror/contrib/scheme/index.html
Executable file
@@ -0,0 +1,82 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<script src="../../js/codemirror.js" type="text/javascript"></script>
|
||||
<script src="../../js/mirrorframe.js" type="text/javascript"></script>
|
||||
<title>CodeMirror: Scheme demonstration</title>
|
||||
<link rel="stylesheet" type="text/css" href="../../css/docs.css"/>
|
||||
|
||||
<style type="text/css">
|
||||
.CodeMirror-line-numbers {
|
||||
width: 2.2em;
|
||||
color: #aaa;
|
||||
background-color: #eee;
|
||||
text-align: right;
|
||||
padding-right: .3em;
|
||||
font-size: 10pt;
|
||||
font-family: monospace;
|
||||
padding-top: .4em;
|
||||
line-height: normal;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body style="padding: 20px;">
|
||||
|
||||
<p>This page demonstrates <a href="index.html">CodeMirror</a>'s
|
||||
Scheme parser. (<a href="LICENSE">license</a>)</p>
|
||||
|
||||
<div style="border-top: 1px solid black; border-bottom: 1px solid black;">
|
||||
<textarea id="code" cols="120" rows="30">
|
||||
(define (factorial x)
|
||||
(cond
|
||||
[(= x 0)
|
||||
1]
|
||||
[else
|
||||
(* x (factorial (sub1 x)))]))
|
||||
|
||||
(list "This is a string"
|
||||
'boolean
|
||||
true
|
||||
3.14)
|
||||
|
||||
(local [(define x 42)]
|
||||
(printf "ok~n"))
|
||||
</textarea>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
function addClass(element, className) {
|
||||
if (!editor.win.hasClass(element, className)) {
|
||||
element.className = ((element.className.split(" ")).concat([className])).join(" ");
|
||||
}
|
||||
}
|
||||
|
||||
function removeClass(element, className) {
|
||||
if (editor.win.hasClass(element, className)) {
|
||||
var classes = element.className.split(" ");
|
||||
for (var i = classes.length - 1 ; i >= 0; i--) {
|
||||
if (classes[i] === className) {
|
||||
classes.splice(i, 1);
|
||||
}
|
||||
}
|
||||
element.className = classes.join(" ");
|
||||
}
|
||||
}
|
||||
|
||||
var textarea = document.getElementById('code');
|
||||
var editor = new CodeMirror(CodeMirror.replace(textarea), {
|
||||
height: "350px",
|
||||
content: textarea.value,
|
||||
path: "../../js/",
|
||||
parserfile: ["../contrib/scheme/js/tokenizescheme.js",
|
||||
"../contrib/scheme/js/parsescheme.js"],
|
||||
stylesheet: "css/schemecolors.css",
|
||||
autoMatchParens: true,
|
||||
disableSpellcheck: true,
|
||||
lineNumbers: true,
|
||||
markParen: function(span, good) {addClass(span, good ? "good-matching-paren" : "bad-matching-paren");},
|
||||
unmarkParen: function(span) {removeClass(span, "good-matching-paren"); removeClass(span, "bad-matching-paren");}
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
428
gulliver/js/codemirror/contrib/scheme/js/parsescheme.js
Executable file
428
gulliver/js/codemirror/contrib/scheme/js/parsescheme.js
Executable file
@@ -0,0 +1,428 @@
|
||||
var SchemeParser = Editor.Parser = (function() {
|
||||
|
||||
|
||||
// isLparen: char -> boolean
|
||||
var isLparen = function(ch) {
|
||||
return ch === '(' || ch === '[' || ch === '{';
|
||||
};
|
||||
|
||||
// isRparen: char -> boolean
|
||||
var isRparen = function(ch) {
|
||||
return ch === ')' || ch === ']' || ch === '}';
|
||||
};
|
||||
|
||||
// isMatchingParens: char char -> boolean
|
||||
var isMatchingParens = function(lparen, rparen) {
|
||||
return ((lparen === '(' && rparen === ')') ||
|
||||
(lparen === '[' && rparen === ']') ||
|
||||
(lparen === '{' && rparen === '}'));
|
||||
};
|
||||
|
||||
|
||||
// Compute the indentation context enclosing the end of the token
|
||||
// sequence tokens.
|
||||
// The context is the token sequence of the enclosing s-expression,
|
||||
// augmented with column information.
|
||||
var getIndentationContext = function(tokenStack) {
|
||||
var EMPTY_CONTEXT = [];
|
||||
|
||||
var pendingParens = [], i = 0, j, line, column, context;
|
||||
var tokens = [];
|
||||
|
||||
// Scan for the start of the indentation context, accumulating tokens.
|
||||
while (! isEmptyPair(tokenStack)) {
|
||||
i++;
|
||||
tokens.push(pairFirst(tokenStack));
|
||||
if (isLparen(pairFirst(tokenStack).type)) {
|
||||
if (pendingParens.length === 0) {
|
||||
break;
|
||||
} else {
|
||||
if (isMatchingParens(pairFirst(tokenStack).value,
|
||||
pendingParens[pendingParens.length - 1])) {
|
||||
pendingParens.pop();
|
||||
} else {
|
||||
// Error condition: we see mismatching parens,
|
||||
// so we exit with no known indentation context.
|
||||
return EMPTY_CONTEXT;
|
||||
}
|
||||
}
|
||||
} else if (isRparen(pairFirst(tokenStack).type)) {
|
||||
pendingParens.push(pairFirst(tokenStack).type);
|
||||
}
|
||||
tokenStack = pairRest(tokenStack);
|
||||
}
|
||||
|
||||
// If we scanned backward too far, we couldn't find a context. Just
|
||||
// return the empty context.
|
||||
if (isEmptyPair(tokenStack)) {
|
||||
return EMPTY_CONTEXT;
|
||||
}
|
||||
|
||||
// Position tokenStack to the next token beyond.
|
||||
tokenStack = pairRest(tokenStack);
|
||||
|
||||
// We now scan backwards to closest newline to figure out the column
|
||||
// number:
|
||||
while (! isEmptyPair(tokenStack)) {
|
||||
if(pairFirst(tokenStack).type === 'whitespace' &&
|
||||
pairFirst(tokenStack).value === '\n') {
|
||||
break;
|
||||
}
|
||||
tokens.push(pairFirst(tokenStack));
|
||||
tokenStack = pairRest(tokenStack);
|
||||
}
|
||||
|
||||
line = 0;
|
||||
column = 0;
|
||||
context = [];
|
||||
// Start generating the context, walking forward.
|
||||
for (j = tokens.length-1; j >= 0; j--) {
|
||||
if (j < i) {
|
||||
context.push({ type: tokens[j].type,
|
||||
value: tokens[j].value,
|
||||
line: line,
|
||||
column: column });
|
||||
}
|
||||
|
||||
if (tokens[j].type === 'whitespace' &&
|
||||
tokens[j].value === '\n') {
|
||||
column = 0;
|
||||
line++;
|
||||
} else {
|
||||
column += tokens[j].value.length;
|
||||
}
|
||||
}
|
||||
return context;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// calculateIndentationFromContext: indentation-context number -> number
|
||||
var calculateIndentationFromContext = function(context, currentIndentation) {
|
||||
if (context.length === 0) {
|
||||
return 0;
|
||||
}
|
||||
if (isBeginLikeContext(context)) {
|
||||
return beginLikeIndentation(context);
|
||||
}
|
||||
if (isDefineLikeContext(context)) {
|
||||
return defineLikeIndentation(context);
|
||||
}
|
||||
if (isLambdaLikeContext(context)) {
|
||||
return lambdaLikeIndentation(context);
|
||||
}
|
||||
return beginLikeIndentation(context, 0);
|
||||
};
|
||||
|
||||
|
||||
|
||||
// findContextElement: indentation-context number -> index or -1
|
||||
var findContextElement = function(context, index) {
|
||||
var depth = 0;
|
||||
for(var i = 0; i < context.length; i++) {
|
||||
if (context[i].type !== 'whitespace' && depth === 1) {
|
||||
if (index === 0)
|
||||
return i;
|
||||
else
|
||||
index--;
|
||||
}
|
||||
|
||||
if (isLparen(context[i].type)) {
|
||||
depth++;
|
||||
}
|
||||
if (isRparen(context[i].type)) {
|
||||
depth = Math.max(depth - 1, 0);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
|
||||
// contextElement: context -> (arrayof index)
|
||||
var contextElements = function(context) {
|
||||
var i = 0, index, results = [];
|
||||
|
||||
while ((index = findContextElement(context, i++)) != -1) {
|
||||
results.push(index);
|
||||
}
|
||||
return results;
|
||||
};
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
var BEGIN_LIKE_KEYWORDS = ["case-lambda",
|
||||
"compound-unit",
|
||||
"compound-unit/sig",
|
||||
"cond",
|
||||
"delay",
|
||||
"inherit",
|
||||
"match-lambda",
|
||||
"match-lambda*",
|
||||
"override",
|
||||
"private",
|
||||
"public",
|
||||
"sequence",
|
||||
"unit"];
|
||||
|
||||
var isBeginLikeContext = function(context) {
|
||||
var j = findContextElement(context, 0);
|
||||
if (j === -1) { return false; }
|
||||
return (/^begin/.test(context[j].value) ||
|
||||
isMember(context[j].value, BEGIN_LIKE_KEYWORDS));
|
||||
};
|
||||
|
||||
|
||||
// Begin: if there's no elements within the begin context,
|
||||
// the indentation is that of the begin keyword's column + offset.
|
||||
// Otherwise, find the leading element on the last line.
|
||||
// Also used for default indentation.
|
||||
var beginLikeIndentation = function(context, offset) {
|
||||
if (typeof(offset) === 'undefined') { offset = 1; }
|
||||
|
||||
var indices = contextElements(context), j;
|
||||
if (indices.length === 0) {
|
||||
return context[0].column + 1;
|
||||
} else if (indices.length === 1) {
|
||||
// if we only see the begin keyword, indentation is based
|
||||
// off the keyword.
|
||||
return context[indices[0]].column + offset;
|
||||
} else {
|
||||
// Otherwise, we scan for the contextElement of the last line
|
||||
for (j = indices.length -1; j > 1; j--) {
|
||||
if (context[indices[j]].line !==
|
||||
context[indices[j-1]].line) {
|
||||
return context[indices[j]].column;
|
||||
}
|
||||
}
|
||||
return context[indices[j]].column;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
var DEFINE_LIKE_KEYWORDS = ["local"];
|
||||
|
||||
var isDefineLikeContext = function(context) {
|
||||
var j = findContextElement(context, 0);
|
||||
if (j === -1) { return false; }
|
||||
return (/^def/.test(context[j].value) ||
|
||||
isMember(context[j].value, DEFINE_LIKE_KEYWORDS));
|
||||
};
|
||||
|
||||
|
||||
var defineLikeIndentation = function(context) {
|
||||
var i = findContextElement(context, 0);
|
||||
if (i === -1) { return 0; }
|
||||
return context[i].column +1;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
var LAMBDA_LIKE_KEYWORDS = ["cases",
|
||||
"instantiate",
|
||||
"super-instantiate",
|
||||
"syntax/loc",
|
||||
"quasisyntax/loc",
|
||||
"lambda",
|
||||
"let",
|
||||
"let*",
|
||||
"letrec",
|
||||
"recur",
|
||||
"lambda/kw",
|
||||
"letrec-values",
|
||||
"with-syntax",
|
||||
"with-continuation-mark",
|
||||
"module",
|
||||
"match",
|
||||
"match-let",
|
||||
"match-let*",
|
||||
"match-letrec",
|
||||
"let/cc",
|
||||
"let/ec",
|
||||
"letcc",
|
||||
"catch",
|
||||
"let-syntax",
|
||||
"letrec-syntax",
|
||||
"fluid-let-syntax",
|
||||
"letrec-syntaxes+values",
|
||||
"for",
|
||||
"for/list",
|
||||
"for/hash",
|
||||
"for/hasheq",
|
||||
"for/and",
|
||||
"for/or",
|
||||
"for/lists",
|
||||
"for/first",
|
||||
"for/last",
|
||||
"for/fold",
|
||||
"for*",
|
||||
"for*/list",
|
||||
"for*/hash",
|
||||
"for*/hasheq",
|
||||
"for*/and",
|
||||
"for*/or",
|
||||
"for*/lists",
|
||||
"for*/first",
|
||||
"for*/last",
|
||||
"for*/fold",
|
||||
"kernel-syntax-case",
|
||||
"syntax-case",
|
||||
"syntax-case*",
|
||||
"syntax-rules",
|
||||
"syntax-id-rules",
|
||||
"let-signature",
|
||||
"fluid-let",
|
||||
"let-struct",
|
||||
"let-macro",
|
||||
"let-values",
|
||||
"let*-values",
|
||||
"case",
|
||||
"when",
|
||||
"unless",
|
||||
"let-enumerate",
|
||||
"class",
|
||||
"class*",
|
||||
"class-asi",
|
||||
"class-asi*",
|
||||
"class*/names",
|
||||
"class100",
|
||||
"class100*",
|
||||
"class100-asi",
|
||||
"class100-asi*",
|
||||
"class100*/names",
|
||||
"rec",
|
||||
"make-object",
|
||||
"mixin",
|
||||
"define-some",
|
||||
"do",
|
||||
"opt-lambda",
|
||||
"send*",
|
||||
"with-method",
|
||||
"define-record",
|
||||
"catch",
|
||||
"shared",
|
||||
"unit/sig",
|
||||
"unit/lang",
|
||||
"with-handlers",
|
||||
"interface",
|
||||
"parameterize",
|
||||
"call-with-input-file",
|
||||
"call-with-input-file*",
|
||||
"with-input-from-file",
|
||||
"with-input-from-port",
|
||||
"call-with-output-file",
|
||||
"with-output-to-file",
|
||||
"with-output-to-port",
|
||||
"for-all"];
|
||||
|
||||
|
||||
var isLambdaLikeContext = function(context) {
|
||||
var j = findContextElement(context, 0);
|
||||
if (j === -1) { return false; }
|
||||
return (isMember(context[j].value, LAMBDA_LIKE_KEYWORDS));
|
||||
};
|
||||
|
||||
|
||||
var lambdaLikeIndentation = function(context) {
|
||||
var i = findContextElement(context, 0);
|
||||
if (i === -1) { return 0; }
|
||||
var j = findContextElement(context, 1);
|
||||
if (j === -1) {
|
||||
return context[i].column + 4;
|
||||
} else {
|
||||
return context[i].column + 1;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Helpers
|
||||
var isMember = function(x, l) {
|
||||
for (var i = 0; i < l.length; i++) {
|
||||
if (x === l[i]) { return true; }
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
var pair = function(x, y) {
|
||||
return [x,y];
|
||||
};
|
||||
var EMPTY_PAIR = [];
|
||||
var pairFirst = function(p) { return p[0]; }
|
||||
var pairRest = function(p) { return p[1]; }
|
||||
var isEmptyPair = function(p) { return p === EMPTY_PAIR; }
|
||||
var pairLength = function(p) {
|
||||
var l = 0;
|
||||
while (! isEmptyPair(p)) {
|
||||
p = pairRest(p);
|
||||
}
|
||||
return l;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
|
||||
var indentTo = function(tokenStack) {
|
||||
return function(tokenText, currentIndentation, direction) {
|
||||
|
||||
// If we're in the middle of an unclosed token,
|
||||
// do not change indentation.
|
||||
if ((! isEmptyPair(tokenStack)) &&
|
||||
(! isEmptyPair(pairRest(tokenStack))) &&
|
||||
(pairFirst(pairRest(tokenStack)).isUnclosed)) {
|
||||
return currentIndentation;
|
||||
}
|
||||
|
||||
var indentationContext =
|
||||
getIndentationContext(tokenStack);
|
||||
return calculateIndentationFromContext(indentationContext,
|
||||
currentIndentation);
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
var startParse = function(source) {
|
||||
source = tokenizeScheme(source);
|
||||
var tokenStack = EMPTY_PAIR;
|
||||
var iter = {
|
||||
next: function() {
|
||||
var tok = source.next();
|
||||
tokenStack = pair(tok, tokenStack);
|
||||
if (tok.type === "whitespace") {
|
||||
if (tok.value === "\n") {
|
||||
tok.indentation = indentTo(tokenStack);
|
||||
}
|
||||
}
|
||||
return tok;
|
||||
},
|
||||
|
||||
copy: function() {
|
||||
var _tokenStack = tokenStack;
|
||||
var _tokenState = source.state;
|
||||
return function(_source) {
|
||||
tokenStack = _tokenStack;
|
||||
source = tokenizeScheme(_source, _tokenState);
|
||||
return iter;
|
||||
};
|
||||
}
|
||||
};
|
||||
return iter;
|
||||
};
|
||||
return { make: startParse };
|
||||
})();
|
||||
241
gulliver/js/codemirror/contrib/scheme/js/tokenizescheme.js
Executable file
241
gulliver/js/codemirror/contrib/scheme/js/tokenizescheme.js
Executable file
@@ -0,0 +1,241 @@
|
||||
/* Tokenizer for Scheme code */
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
TODO: follow the definitions in:
|
||||
|
||||
http://docs.racket-lang.org/reference/reader.html
|
||||
|
||||
to the letter; at the moment, we've just done something quick-and-dirty.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
var tokenizeScheme = (function() {
|
||||
var isWhiteSpace = function(ch) {
|
||||
// The messy regexp is because IE's regexp matcher is of the
|
||||
// opinion that non-breaking spaces are no whitespace.
|
||||
return ch != "\n" && /^[\s\u00a0]*$/.test(ch);
|
||||
};
|
||||
|
||||
|
||||
// scanUntilUnescaped: string-stream char -> boolean
|
||||
// Advances the stream until the given character (not preceded by a
|
||||
// backslash) is encountered.
|
||||
// Returns true if we hit end of line without closing.
|
||||
// Returns false otherwise.
|
||||
var scanUntilUnescaped = function(source, end) {
|
||||
var escaped = false;
|
||||
while (true) {
|
||||
if (source.endOfLine()) {
|
||||
return true;
|
||||
}
|
||||
var next = source.next();
|
||||
if (next == end && !escaped)
|
||||
return false;
|
||||
escaped = !escaped && next == "\\";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Advance the stream until endline.
|
||||
var scanUntilEndline = function(source, end) {
|
||||
while (!source.endOfLine()) {
|
||||
source.next();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Some helper regexps
|
||||
var isHexDigit = /[0-9A-Fa-f]/;
|
||||
|
||||
|
||||
var whitespaceChar = new RegExp("[\\s\\u00a0]");
|
||||
|
||||
var isDelimiterChar =
|
||||
new RegExp("[\\s\\\(\\\)\\\[\\\]\\\{\\\}\\\"\\\,\\\'\\\`\\\;]");
|
||||
|
||||
var isNotDelimiterChar =
|
||||
new RegExp("[^\\s\\\(\\\)\\\[\\\]\\\{\\\}\\\"\\\,\\\'\\\`\\\;]");
|
||||
|
||||
|
||||
var numberHeader = ("(?:(?:\\d+\\/\\d+)|"+
|
||||
( "(?:(?:\\d+\\.\\d+|\\d+\\.|\\.\\d+)(?:[eE][+\\-]?\\d+)?)|")+
|
||||
( "(?:\\d+(?:[eE][+\\-]?\\d+)?))"));
|
||||
var numberPatterns = [
|
||||
// complex numbers
|
||||
new RegExp("^((?:(?:\\#[ei])?[+\\-]?" + numberHeader +")?"
|
||||
+ "(?:[+\\-]" + numberHeader + ")i$)"),
|
||||
/^((?:\#[ei])?[+-]inf.0)$/,
|
||||
/^((?:\#[ei])?[+-]nan.0)$/,
|
||||
new RegExp("^((?:\\#[ei])?[+\\-]?" + numberHeader + "$)"),
|
||||
new RegExp("^0[xX][0-9A-Fa-f]+$")];
|
||||
|
||||
|
||||
// looksLikeNumber: string -> boolean
|
||||
// Returns true if string s looks like a number.
|
||||
var looksLikeNumber = function(s) {
|
||||
for (var i = 0; i < numberPatterns.length; i++) {
|
||||
if (numberPatterns[i].test(s)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
|
||||
var UNCLOSED_STRING = function(source, setState) {
|
||||
var readNewline = function() {
|
||||
var content = source.get();
|
||||
return { type:'whitespace', style:'whitespace', content: content };
|
||||
};
|
||||
|
||||
var ch = source.peek();
|
||||
if (ch === '\n') {
|
||||
source.next();
|
||||
return readNewline();
|
||||
} else {
|
||||
var isUnclosedString = scanUntilUnescaped(source, '"');
|
||||
if (isUnclosedString) {
|
||||
setState(UNCLOSED_STRING);
|
||||
} else {
|
||||
setState(START);
|
||||
}
|
||||
var content = source.get();
|
||||
return {type: "string", style: "scheme-string", content: content,
|
||||
isUnclosed: isUnclosedString};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
var START = function(source, setState) {
|
||||
// Read a word, look it up in keywords. If not found, it is a
|
||||
// variable, otherwise it is a keyword of the type found.
|
||||
var readWordOrNumber = function() {
|
||||
source.nextWhileMatches(isNotDelimiterChar);
|
||||
var word = source.get();
|
||||
if (looksLikeNumber(word)) {
|
||||
return {type: "number", style: "scheme-number", content: word};
|
||||
} else {
|
||||
return {type: "variable", style: "scheme-symbol", content: word};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
var readString = function(quote) {
|
||||
var isUnclosedString = scanUntilUnescaped(source, quote);
|
||||
if (isUnclosedString) {
|
||||
setState(UNCLOSED_STRING);
|
||||
}
|
||||
var word = source.get();
|
||||
return {type: "string", style: "scheme-string", content: word,
|
||||
isUnclosed: isUnclosedString};
|
||||
};
|
||||
|
||||
|
||||
var readPound = function() {
|
||||
var text;
|
||||
// FIXME: handle special things here
|
||||
if (source.equals(";")) {
|
||||
source.next();
|
||||
text = source.get();
|
||||
return {type: text,
|
||||
style:"scheme-symbol",
|
||||
content: text};
|
||||
} else {
|
||||
text = source.get();
|
||||
|
||||
return {type : "symbol",
|
||||
style: "scheme-symbol",
|
||||
content: text};
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
var readLineComment = function() {
|
||||
scanUntilEndline(source);
|
||||
var text = source.get();
|
||||
return { type: "comment", style: "scheme-comment", content: text};
|
||||
};
|
||||
|
||||
|
||||
var readWhitespace = function() {
|
||||
source.nextWhile(isWhiteSpace);
|
||||
var content = source.get();
|
||||
return { type: 'whitespace', style:'whitespace', content: content };
|
||||
};
|
||||
|
||||
var readNewline = function() {
|
||||
var content = source.get();
|
||||
return { type:'whitespace', style:'whitespace', content: content };
|
||||
};
|
||||
|
||||
|
||||
// Fetch the next token. Dispatches on first character in the
|
||||
// stream, or first two characters when the first is a slash.
|
||||
var ch = source.next();
|
||||
if (ch === '\n') {
|
||||
return readNewline();
|
||||
} else if (whitespaceChar.test(ch)) {
|
||||
return readWhitespace();
|
||||
} else if (ch === "#") {
|
||||
return readPound();
|
||||
} else if (ch ===';') {
|
||||
return readLineComment();
|
||||
} else if (ch === "\"") {
|
||||
return readString(ch);
|
||||
} else if (isDelimiterChar.test(ch)) {
|
||||
return {type: ch, style: "scheme-punctuation"};
|
||||
} else {
|
||||
return readWordOrNumber();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var makeTokenizer = function(source, state) {
|
||||
// Newlines are always a separate token.
|
||||
|
||||
var tokenizer = {
|
||||
state: state,
|
||||
|
||||
take: function(type) {
|
||||
if (typeof(type) == "string")
|
||||
type = {style: type, type: type};
|
||||
|
||||
type.content = (type.content || "") + source.get();
|
||||
type.value = type.content;
|
||||
return type;
|
||||
},
|
||||
|
||||
next: function () {
|
||||
if (!source.more()) throw StopIteration;
|
||||
|
||||
var type;
|
||||
while (!type) {
|
||||
type = tokenizer.state(source, function(s) {
|
||||
tokenizer.state = s;
|
||||
});
|
||||
}
|
||||
var result = this.take(type);
|
||||
return result;
|
||||
}
|
||||
};
|
||||
return tokenizer;
|
||||
};
|
||||
|
||||
|
||||
// The external interface to the tokenizer.
|
||||
return function(source, startState) {
|
||||
return makeTokenizer(source, startState || START);
|
||||
};
|
||||
})();
|
||||
22
gulliver/js/codemirror/contrib/sql/LICENSE
Executable file
22
gulliver/js/codemirror/contrib/sql/LICENSE
Executable file
@@ -0,0 +1,22 @@
|
||||
Copyright (c) 2009 John Benediktsson
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any
|
||||
damages arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any
|
||||
purpose, including commercial applications, and to alter it and
|
||||
redistribute it freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must
|
||||
not claim that you wrote the original software. If you use this
|
||||
software in a product, an acknowledgment in the product
|
||||
documentation would be appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must
|
||||
not be misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source
|
||||
distribution.
|
||||
|
||||
John Benediktsson
|
||||
59
gulliver/js/codemirror/contrib/sql/css/sqlcolors.css
Executable file
59
gulliver/js/codemirror/contrib/sql/css/sqlcolors.css
Executable file
@@ -0,0 +1,59 @@
|
||||
html {
|
||||
cursor: text;
|
||||
}
|
||||
|
||||
.editbox {
|
||||
margin: .4em;
|
||||
padding: 0;
|
||||
font-family: monospace;
|
||||
font-size: 10pt;
|
||||
color: black;
|
||||
}
|
||||
|
||||
.editbox p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
span.sql-keyword {
|
||||
color: blue;
|
||||
}
|
||||
|
||||
span.sql-var {
|
||||
color: red;
|
||||
}
|
||||
|
||||
span.sql-comment {
|
||||
color: #AA7700;
|
||||
}
|
||||
|
||||
span.sql-literal {
|
||||
color: green;
|
||||
}
|
||||
|
||||
span.sql-operator {
|
||||
color: blue;
|
||||
}
|
||||
|
||||
span.sql-word {
|
||||
color: black;
|
||||
}
|
||||
|
||||
span.sql-quoted-word {
|
||||
color: #680;
|
||||
}
|
||||
|
||||
span.sql-function {
|
||||
color: darkorange;
|
||||
}
|
||||
|
||||
span.sql-type {
|
||||
color: purple;
|
||||
}
|
||||
|
||||
span.sql-separator {
|
||||
color: #666666;
|
||||
}
|
||||
|
||||
span.sql-number {
|
||||
color: darkcyan;
|
||||
}
|
||||
56
gulliver/js/codemirror/contrib/sql/index.html
Executable file
56
gulliver/js/codemirror/contrib/sql/index.html
Executable file
@@ -0,0 +1,56 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<script src="../../js/codemirror.js" type="text/javascript"></script>
|
||||
<title>CodeMirror: SQL demonstration</title>
|
||||
<link rel="stylesheet" type="text/css" href="../../css/docs.css"/>
|
||||
</head>
|
||||
<body style="padding: 20px;">
|
||||
|
||||
<p>Demonstration of <a href="../../index.html">CodeMirror</a>'s SQL
|
||||
highlighter.</p>
|
||||
|
||||
<p>Written by John Benediktsson (<a href="LICENSE">license</a>).</p>
|
||||
|
||||
<div style="border-top: 1px solid black; border-bottom: 1px solid black;">
|
||||
<textarea id="code" cols="120" rows="50">
|
||||
create table if not exists table1(
|
||||
a bigint(13) not null primary key,
|
||||
b char(4) not null,
|
||||
c char(50) not null,
|
||||
d int(9) not null,
|
||||
);
|
||||
|
||||
insert into table1 values (1234567890123, "b", "c", 0);
|
||||
|
||||
select from_unixtime(a/1000), b, c, min(d) as `using`
|
||||
from table1 t1
|
||||
left join table2 t2 using (a)
|
||||
-- inner join table3 t3 on t3._a = t1.a
|
||||
join (
|
||||
select a, b, c
|
||||
from data
|
||||
) as foo on foo.a = t1.a
|
||||
|
||||
where a > 10
|
||||
and b like '%foo'
|
||||
or c = 3.14159
|
||||
and d < -15.7
|
||||
order by 1 desc
|
||||
;
|
||||
|
||||
select @total := sum(d) from data;
|
||||
</textarea>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
var editor = CodeMirror.fromTextArea('code', {
|
||||
height: "450px",
|
||||
parserfile: "../contrib/sql/js/parsesql.js",
|
||||
stylesheet: "css/sqlcolors.css",
|
||||
path: "../../js/",
|
||||
textWrapping: false
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
267
gulliver/js/codemirror/contrib/sql/js/parsesql.js
Executable file
267
gulliver/js/codemirror/contrib/sql/js/parsesql.js
Executable file
@@ -0,0 +1,267 @@
|
||||
var SqlParser = Editor.Parser = (function() {
|
||||
|
||||
function wordRegexp(words) {
|
||||
return new RegExp("^(?:" + words.join("|") + ")$", "i");
|
||||
}
|
||||
|
||||
var functions = wordRegexp([
|
||||
"abs", "acos", "adddate", "aes_encrypt", "aes_decrypt", "ascii",
|
||||
"asin", "atan", "atan2", "avg", "benchmark", "bin", "bit_and",
|
||||
"bit_count", "bit_length", "bit_or", "cast", "ceil", "ceiling",
|
||||
"char_length", "character_length", "coalesce", "concat", "concat_ws",
|
||||
"connection_id", "conv", "convert", "cos", "cot", "count", "curdate",
|
||||
"current_date", "current_time", "current_timestamp", "current_user",
|
||||
"curtime", "database", "date_add", "date_format", "date_sub",
|
||||
"dayname", "dayofmonth", "dayofweek", "dayofyear", "decode", "degrees",
|
||||
"des_encrypt", "des_decrypt", "elt", "encode", "encrypt", "exp",
|
||||
"export_set", "extract", "field", "find_in_set", "floor", "format",
|
||||
"found_rows", "from_days", "from_unixtime", "get_lock", "greatest",
|
||||
"group_unique_users", "hex", "ifnull", "inet_aton", "inet_ntoa", "instr",
|
||||
"interval", "is_free_lock", "isnull", "last_insert_id", "lcase", "least",
|
||||
"left", "length", "ln", "load_file", "locate", "log", "log2", "log10",
|
||||
"lower", "lpad", "ltrim", "make_set", "master_pos_wait", "max", "md5",
|
||||
"mid", "min", "mod", "monthname", "now", "nullif", "oct", "octet_length",
|
||||
"ord", "password", "period_add", "period_diff", "pi", "position",
|
||||
"pow", "power", "quarter", "quote", "radians", "rand", "release_lock",
|
||||
"repeat", "reverse", "right", "round", "rpad", "rtrim", "sec_to_time",
|
||||
"session_user", "sha", "sha1", "sign", "sin", "soundex", "space", "sqrt",
|
||||
"std", "stddev", "strcmp", "subdate", "substring", "substring_index",
|
||||
"sum", "sysdate", "system_user", "tan", "time_format", "time_to_sec",
|
||||
"to_days", "trim", "ucase", "unique_users", "unix_timestamp", "upper",
|
||||
"user", "version", "week", "weekday", "yearweek"
|
||||
]);
|
||||
|
||||
var keywords = wordRegexp([
|
||||
"alter", "grant", "revoke", "primary", "key", "table", "start", "top",
|
||||
"transaction", "select", "update", "insert", "delete", "create", "describe",
|
||||
"from", "into", "values", "where", "join", "inner", "left", "natural", "and",
|
||||
"or", "in", "not", "xor", "like", "using", "on", "order", "group", "by",
|
||||
"asc", "desc", "limit", "offset", "union", "all", "as", "distinct", "set",
|
||||
"commit", "rollback", "replace", "view", "database", "separator", "if",
|
||||
"exists", "null", "truncate", "status", "show", "lock", "unique", "having",
|
||||
"drop", "procedure", "begin", "end", "delimiter", "call", "else", "leave",
|
||||
"declare", "temporary", "then"
|
||||
]);
|
||||
|
||||
var types = wordRegexp([
|
||||
"bigint", "binary", "bit", "blob", "bool", "char", "character", "date",
|
||||
"datetime", "dec", "decimal", "double", "enum", "float", "float4", "float8",
|
||||
"int", "int1", "int2", "int3", "int4", "int8", "integer", "long", "longblob",
|
||||
"longtext", "mediumblob", "mediumint", "mediumtext", "middleint", "nchar",
|
||||
"numeric", "real", "set", "smallint", "text", "time", "timestamp", "tinyblob",
|
||||
"tinyint", "tinytext", "varbinary", "varchar", "year"
|
||||
]);
|
||||
|
||||
var operators = wordRegexp([
|
||||
":=", "<", "<=", "==", "<>", ">", ">=", "like", "rlike", "in", "xor", "between"
|
||||
]);
|
||||
|
||||
var operatorChars = /[*+\-<>=&|:\/]/;
|
||||
|
||||
var CFG = {};
|
||||
|
||||
var tokenizeSql = (function() {
|
||||
function normal(source, setState) {
|
||||
var ch = source.next();
|
||||
if (ch == "@" || ch == "$") {
|
||||
source.nextWhileMatches(/[\w\d]/);
|
||||
return "sql-var";
|
||||
}
|
||||
else if (ch == "["){
|
||||
setState(inAlias(ch))
|
||||
return null;
|
||||
}
|
||||
else if (ch == "\"" || ch == "'" || ch == "`") {
|
||||
setState(inLiteral(ch));
|
||||
return null;
|
||||
}
|
||||
else if (ch == "," || ch == ";") {
|
||||
return "sql-separator"
|
||||
}
|
||||
else if (ch == '#') {
|
||||
while (!source.endOfLine()) source.next();
|
||||
return "sql-comment";
|
||||
}
|
||||
else if (ch == '-') {
|
||||
if (source.peek() == "-") {
|
||||
while (!source.endOfLine()) source.next();
|
||||
return "sql-comment";
|
||||
}
|
||||
else if (/\d/.test(source.peek())) {
|
||||
source.nextWhileMatches(/\d/);
|
||||
if (source.peek() == '.') {
|
||||
source.next();
|
||||
source.nextWhileMatches(/\d/);
|
||||
}
|
||||
return "sql-number";
|
||||
}
|
||||
else
|
||||
return "sql-operator";
|
||||
}
|
||||
else if (operatorChars.test(ch)) {
|
||||
|
||||
if(ch == "/" && source.peek() == "*"){
|
||||
setState(inBlock("sql-comment", "*/"));
|
||||
return null;
|
||||
}
|
||||
else{
|
||||
source.nextWhileMatches(operatorChars);
|
||||
return "sql-operator";
|
||||
}
|
||||
|
||||
}
|
||||
else if (/\d/.test(ch)) {
|
||||
source.nextWhileMatches(/\d/);
|
||||
if (source.peek() == '.') {
|
||||
source.next();
|
||||
source.nextWhileMatches(/\d/);
|
||||
}
|
||||
return "sql-number";
|
||||
}
|
||||
else if (/[()]/.test(ch)) {
|
||||
return "sql-punctuation";
|
||||
}
|
||||
else {
|
||||
source.nextWhileMatches(/[_\w\d]/);
|
||||
var word = source.get(), type;
|
||||
if (operators.test(word))
|
||||
type = "sql-operator";
|
||||
else if (keywords.test(word))
|
||||
type = "sql-keyword";
|
||||
else if (functions.test(word))
|
||||
type = "sql-function";
|
||||
else if (types.test(word))
|
||||
type = "sql-type";
|
||||
else
|
||||
type = "sql-word";
|
||||
return {style: type, content: word};
|
||||
}
|
||||
}
|
||||
|
||||
function inAlias(quote) {
|
||||
return function(source, setState) {
|
||||
while (!source.endOfLine()) {
|
||||
var ch = source.next();
|
||||
if (ch == ']') {
|
||||
setState(normal);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return "sql-word";
|
||||
}
|
||||
}
|
||||
|
||||
function inLiteral(quote) {
|
||||
return function(source, setState) {
|
||||
var escaped = false;
|
||||
while (!source.endOfLine()) {
|
||||
var ch = source.next();
|
||||
if (ch == quote && !escaped) {
|
||||
setState(normal);
|
||||
break;
|
||||
}
|
||||
escaped = CFG.extension == 'T-SQL' ?
|
||||
!escaped && quote == ch && source.equals(quote) :
|
||||
!escaped && ch == "\\";
|
||||
}
|
||||
return quote == "`" ? "sql-quoted-word" : "sql-literal";
|
||||
};
|
||||
}
|
||||
|
||||
function inBlock(style, terminator) {
|
||||
return function(source, setState) {
|
||||
while (!source.endOfLine()) {
|
||||
if (source.lookAhead(terminator, true)) {
|
||||
setState(normal);
|
||||
break;
|
||||
}
|
||||
source.next();
|
||||
}
|
||||
return style;
|
||||
};
|
||||
}
|
||||
|
||||
return function(source, startState) {
|
||||
return tokenizer(source, startState || normal);
|
||||
};
|
||||
})();
|
||||
|
||||
function indentSql(context) {
|
||||
return function(nextChars) {
|
||||
var firstChar = nextChars && nextChars.charAt(0);
|
||||
var closing = context && firstChar == context.type;
|
||||
if (!context)
|
||||
return 0;
|
||||
else if (context.align)
|
||||
return context.col - (closing ? context.width : 0);
|
||||
else
|
||||
return context.indent + (closing ? 0 : indentUnit);
|
||||
}
|
||||
}
|
||||
|
||||
function parseSql(source) {
|
||||
var tokens = tokenizeSql(source);
|
||||
var context = null, indent = 0, col = 0;
|
||||
function pushContext(type, width, align) {
|
||||
context = {prev: context, indent: indent, col: col, type: type, width: width, align: align};
|
||||
}
|
||||
function popContext() {
|
||||
context = context.prev;
|
||||
}
|
||||
|
||||
var iter = {
|
||||
next: function() {
|
||||
var token = tokens.next();
|
||||
var type = token.style, content = token.content, width = token.value.length;
|
||||
|
||||
if (content == "\n") {
|
||||
token.indentation = indentSql(context);
|
||||
indent = col = 0;
|
||||
if (context && context.align == null) context.align = false;
|
||||
}
|
||||
else if (type == "whitespace" && col == 0) {
|
||||
indent = width;
|
||||
}
|
||||
else if (!context && type != "sql-comment") {
|
||||
pushContext(";", 0, false);
|
||||
}
|
||||
|
||||
if (content != "\n") col += width;
|
||||
|
||||
if (type == "sql-punctuation") {
|
||||
if (content == "(")
|
||||
pushContext(")", width);
|
||||
else if (content == ")")
|
||||
popContext();
|
||||
}
|
||||
else if (type == "sql-separator" && content == ";" && context && !context.prev) {
|
||||
popContext();
|
||||
}
|
||||
|
||||
return token;
|
||||
},
|
||||
|
||||
copy: function() {
|
||||
var _context = context, _indent = indent, _col = col, _tokenState = tokens.state;
|
||||
return function(source) {
|
||||
tokens = tokenizeSql(source, _tokenState);
|
||||
context = _context;
|
||||
indent = _indent;
|
||||
col = _col;
|
||||
return iter;
|
||||
};
|
||||
}
|
||||
};
|
||||
return iter;
|
||||
}
|
||||
|
||||
function configure (parserConfig) {
|
||||
for (var p in parserConfig) {
|
||||
if (parserConfig.hasOwnProperty(p)) {
|
||||
CFG[p] = parserConfig[p];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {make: parseSql, electricChars: ")", configure: configure};
|
||||
})();
|
||||
13
gulliver/js/codemirror/contrib/xquery/LICENSE
Executable file
13
gulliver/js/codemirror/contrib/xquery/LICENSE
Executable file
@@ -0,0 +1,13 @@
|
||||
Copyright 2010 Mike Brevoort
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
93
gulliver/js/codemirror/contrib/xquery/css/xqcolors-dark.css
Executable file
93
gulliver/js/codemirror/contrib/xquery/css/xqcolors-dark.css
Executable file
@@ -0,0 +1,93 @@
|
||||
|
||||
.editbox {
|
||||
margin: .4em;
|
||||
padding: 0;
|
||||
font-family: monospace;
|
||||
font-size: 10pt;
|
||||
color: white;
|
||||
background-color: black;
|
||||
line-height: 16px;
|
||||
}
|
||||
|
||||
span.word {
|
||||
color:white;
|
||||
}
|
||||
|
||||
span.xqueryKeyword {
|
||||
color: #ffbd40;
|
||||
/* font-weight: bold; */
|
||||
}
|
||||
|
||||
span.xqueryComment {
|
||||
color: #CDCDCD;
|
||||
font-style:italic;
|
||||
}
|
||||
|
||||
span.xqueryModifier {
|
||||
color:#6c8cd5;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
span.xqueryType {
|
||||
color:#6c8cd5;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
span.xqueryAtom {
|
||||
color:#6c8cd5;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
span.xqueryString {
|
||||
color: #9fee00;
|
||||
}
|
||||
|
||||
span.xqueryRegexp {
|
||||
color: rgb(128,0,64);
|
||||
}
|
||||
|
||||
span.xqueryNumber {
|
||||
color: rgb(255,0,0);
|
||||
}
|
||||
|
||||
span.xqueryVariable {
|
||||
|
||||
}
|
||||
|
||||
span.xqueryFunction {
|
||||
color:#FFF700;
|
||||
}
|
||||
|
||||
span.xqueryLocalvariable {
|
||||
color: white;
|
||||
}
|
||||
|
||||
span.xqueryProperty
|
||||
{
|
||||
color: white;
|
||||
}
|
||||
|
||||
span.xqueryOperator {
|
||||
color: orange;
|
||||
}
|
||||
|
||||
span.xqueryPunctuation {
|
||||
color: white;
|
||||
}
|
||||
|
||||
span.xquery-doc-directive {
|
||||
color: white;
|
||||
}
|
||||
|
||||
span.xml-tagname {
|
||||
color: #ffbd40; ;
|
||||
}
|
||||
|
||||
span.xml-attribute {
|
||||
color: #FFF700;
|
||||
}
|
||||
|
||||
span.xml-attribute-value {
|
||||
color: #FFF700;
|
||||
font-style:italic;
|
||||
}
|
||||
99
gulliver/js/codemirror/contrib/xquery/css/xqcolors.css
Executable file
99
gulliver/js/codemirror/contrib/xquery/css/xqcolors.css
Executable file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
Copyright 2010 Mike Brevoort http://mike.brevoort.com (twitter:@mbrevoort)
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
This is an indirect collective derivative of the other parses in this package
|
||||
|
||||
*/
|
||||
.editbox {
|
||||
margin: .4em;
|
||||
padding: 0;
|
||||
font-family: monospace;
|
||||
font-size: 10pt;
|
||||
color: black;
|
||||
background-color: white;
|
||||
line-height: 16px;
|
||||
}
|
||||
|
||||
span.word {
|
||||
}
|
||||
|
||||
span.xqueryKeyword {
|
||||
color: red; /* #1240AB; */
|
||||
/* font-weight: bold; */
|
||||
}
|
||||
|
||||
span.xqueryComment {
|
||||
color: gray;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
span.xqueryModifier {
|
||||
color: rgb(0,102,153);
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
span.xqueryType {
|
||||
color: purple;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
span.xqueryAtom {
|
||||
color: rgb(0,102,153);
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
span.xqueryString {
|
||||
color: green;
|
||||
}
|
||||
|
||||
span.xqueryRegexp {
|
||||
color: rgb(128,0,64);
|
||||
}
|
||||
|
||||
span.xqueryNumber {
|
||||
color: #1240AB;
|
||||
}
|
||||
|
||||
span.xqueryVariable {
|
||||
/* color: red; */
|
||||
}
|
||||
|
||||
span.xqueryFunction {
|
||||
color: #1240AB;
|
||||
/* font-weight:bold; */
|
||||
}
|
||||
|
||||
|
||||
span.xqueryOperator {
|
||||
color: red;
|
||||
}
|
||||
|
||||
span.xqueryPunctuation {
|
||||
color: DIMGray;
|
||||
}
|
||||
|
||||
span.xml-tagname {
|
||||
color: purple;
|
||||
}
|
||||
|
||||
span.xml-attribute {
|
||||
color: purple;
|
||||
font-style:italic;
|
||||
}
|
||||
|
||||
span.xml-attribute-value {
|
||||
color: purple;
|
||||
font-style:italic;
|
||||
}
|
||||
96
gulliver/js/codemirror/contrib/xquery/css/xqcolors2.css
Executable file
96
gulliver/js/codemirror/contrib/xquery/css/xqcolors2.css
Executable file
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
Copyright 2010 Mike Brevoort http://mike.brevoort.com (twitter:@mbrevoort)
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
This is an indirect collective derivative of the other parses in this package
|
||||
|
||||
*/
|
||||
.editbox {
|
||||
margin: .4em;
|
||||
padding: 0;
|
||||
font-family: monospace;
|
||||
font-size: 10pt;
|
||||
color: black;
|
||||
background-color: white;
|
||||
line-height: 16px;
|
||||
}
|
||||
|
||||
span.word {
|
||||
}
|
||||
|
||||
span.xqueryKeyword {
|
||||
color: blue;
|
||||
/* font-weight: bold; */
|
||||
}
|
||||
|
||||
span.xqueryComment {
|
||||
color: gray;
|
||||
}
|
||||
|
||||
span.xqueryModifier {
|
||||
color: rgb(0,102,153);
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
span.xqueryType {
|
||||
color: rgb(0,135,255);
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
span.xqueryAtom {
|
||||
color: rgb(0,102,153);
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
span.xqueryString {
|
||||
color: green;
|
||||
}
|
||||
|
||||
span.xqueryRegexp {
|
||||
color: rgb(128,0,64);
|
||||
}
|
||||
|
||||
span.xqueryNumber {
|
||||
color: rgb(255,0,0);
|
||||
}
|
||||
|
||||
span.xqueryVariable {
|
||||
color: red;
|
||||
}
|
||||
|
||||
span.xqueryFunction {
|
||||
text-decoration:underline
|
||||
}
|
||||
|
||||
|
||||
span.xqueryOperator {
|
||||
color: DimGray;
|
||||
}
|
||||
|
||||
span.xqueryPunctuation {
|
||||
}
|
||||
|
||||
span.xml-tagname {
|
||||
color: purple;
|
||||
}
|
||||
|
||||
span.xml-attribute {
|
||||
color: purple;
|
||||
font-style:italic;
|
||||
}
|
||||
|
||||
span.xml-attribute-value {
|
||||
color: purple;
|
||||
font-style:italic;
|
||||
}
|
||||
552
gulliver/js/codemirror/contrib/xquery/index.html
Executable file
552
gulliver/js/codemirror/contrib/xquery/index.html
Executable file
@@ -0,0 +1,552 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<script src="../../js/codemirror.js" type="text/javascript"></script>
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
|
||||
<title>CodeMirror: XQuery highlighting demonstration</title>
|
||||
<style type="text/css">
|
||||
.CodeMirror-line-numbers {
|
||||
width: 2.2em;
|
||||
color: #aaa;
|
||||
background-color: #eee;
|
||||
text-align: right;
|
||||
padding-right: .3em;
|
||||
font-size: 10pt;
|
||||
font-family: monospace;
|
||||
padding-top: .4em;
|
||||
line-height: normal;
|
||||
}
|
||||
body {
|
||||
font-family: helvetica;
|
||||
font-weight:bold;
|
||||
max-width:4000px;
|
||||
}
|
||||
a {
|
||||
color: #EB1D1D;
|
||||
text-decoration: none;
|
||||
}
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
div.border {
|
||||
border: 1px solid black;
|
||||
}
|
||||
.css-switch {
|
||||
margin-right:15px;
|
||||
padding-bottom:5px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body style="padding: 20px;">
|
||||
|
||||
<div style="margin:auto; width:920px; border-width:1px;">
|
||||
<h2>XQuery Syntax Support for CodeMirror</h2>
|
||||
<p style="text-align: justify; word-spacing: 3px;">This is a demonstration of the XQuery highlighting module
|
||||
for <a href="index.html">CodeMirror</a>. The formatting is CSS driven and very easy to customize to your liking.
|
||||
There are three sample styles sets below.
|
||||
You can edit or paste in any code below to give it a test run.
|
||||
</p>
|
||||
|
||||
<a href="#" rel="xqcolors.css" class="css-switch">Light 1</a> <a href="#" rel="xqcolors2.css" class="css-switch">Light 2</a> <a href="#" rel="xqcolors-dark.css" class="css-switch">Dark</a>
|
||||
|
||||
<div class="border">
|
||||
<textarea id="code" cols="120" rows="50">
|
||||
xquery version "1.0-ml";
|
||||
(: this is
|
||||
: a
|
||||
"comment" :)
|
||||
let $let := <x attr="value">"test"</x>
|
||||
let $joe:=1
|
||||
return element element {
|
||||
attribute attribute { 1 },
|
||||
element test { 'a' },
|
||||
attribute foo { "bar" },
|
||||
fn:doc()[ foo/@bar eq $let ],
|
||||
//x }
|
||||
|
||||
|
||||
module namespace comoms-dls = "http://marklogic.com/comoms-dls";
|
||||
import module namespace dls = "http://marklogic.com/xdmp/dls" at "/MarkLogic/dls.xqy";
|
||||
import module namespace comoms-util = "http://marklogic.com/comoms-util" at "/lib/comoms-util.xqy";
|
||||
import module namespace comoms-user = "http://marklogic.com/comoms-user" at "/lib/comoms-user.xqy";
|
||||
|
||||
|
||||
|
||||
|
||||
(:~
|
||||
: Make a call to insert and Manage. This IS NOT DONE WITHIN AN EVAL becuase
|
||||
: haven't figured out how to pass the permissions variable through to be bound
|
||||
:)
|
||||
declare function comoms-dls:insert($uri as xs:string, $doc as node(), $note as xs:string){
|
||||
let $log := xdmp:log("in comoms-dls:insert.")
|
||||
let $collection := "DRAFTS"
|
||||
let $permissions := (xdmp:permission('mkp-admin', 'update'), xdmp:permission('mkp-admin', 'read'))
|
||||
return dls:document-insert-and-manage($uri, fn:false(), $doc, $note, $permissions, $collection)
|
||||
|
||||
(:
|
||||
let $collection := "DRAFTS"
|
||||
return
|
||||
xdmp:eval(
|
||||
fn:concat(
|
||||
comoms-dls:_import(),
|
||||
"
|
||||
declare variable $uri as xs:string external;
|
||||
declare variable $doc as node() external;
|
||||
declare variable $collection as xs:string external;
|
||||
declare variable $note as xs:string external;
|
||||
dls:document-insert-and-manage($uri, fn:true(), $doc, $note,
|
||||
(xdmp:permission('mkp-anon', 'read'), xdmp:permission('mkp-admin', 'update')) , $collection)
|
||||
"
|
||||
),
|
||||
(xs:QName("uri"), $uri, xs:QName("doc"), $doc, xs:QName("note"), $note, xs:QName("collection"), $collection)
|
||||
)
|
||||
:)
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
declare function comoms-dls:manage($uri, $manageNote){
|
||||
let $log := xdmp:log("in comoms-dls:manage with note.")
|
||||
return (
|
||||
xdmp:eval(
|
||||
fn:concat(
|
||||
comoms-dls:_import(),
|
||||
"
|
||||
declare variable $uri as xs:string external;
|
||||
declare variable $manageNote as xs:string external;
|
||||
dls:document-manage($uri, fn:false(), $manageNote)
|
||||
"
|
||||
),
|
||||
(xs:QName("uri"), $uri, xs:QName("manageNote"), $manageNote)
|
||||
)
|
||||
)
|
||||
};
|
||||
|
||||
declare function comoms-dls:update($uri as xs:string, $doc as node(), $note as xs:string){
|
||||
|
||||
xdmp:eval(
|
||||
fn:concat(
|
||||
comoms-dls:_import(),
|
||||
"
|
||||
declare variable $uri as xs:string external;
|
||||
declare variable $doc as node() external;
|
||||
declare variable $note as xs:string external;
|
||||
dls:document-update($uri, $doc, $note, fn:true(), (xdmp:permission('mkp-admin', 'update'), xdmp:permission('mkp-admin', 'read')) )
|
||||
"
|
||||
),
|
||||
(xs:QName("uri"), $uri, xs:QName("doc"), $doc, xs:QName("note"), $note)
|
||||
)
|
||||
|
||||
};
|
||||
|
||||
|
||||
declare function comoms-dls:manage($uri){
|
||||
let $log := xdmp:log("in comoms-dls:manage without note.")
|
||||
return (xdmp:eval(
|
||||
fn:concat(comoms-dls:_import(), "dls:document-manage('", $uri, "', fn:false())"))
|
||||
)
|
||||
};
|
||||
|
||||
declare function comoms-dls:unmanageAndDelete($uris){
|
||||
for $uri in $uris
|
||||
let $unpublish := (xdmp:eval(
|
||||
fn:concat(comoms-dls:_import(),
|
||||
"import module namespace comoms-dls = 'http://marklogic.com/comoms-dls' at '/lib/comoms-dls.xqy'; comoms-dls:unpublish('",
|
||||
$uri, "')")))
|
||||
let $unmanage := (xdmp:eval(
|
||||
fn:concat(comoms-dls:_import(), "dls:document-unmanage('", $uri, "', fn:false(), fn:true())"))
|
||||
)
|
||||
return
|
||||
xdmp:document-delete($uri)
|
||||
};
|
||||
|
||||
|
||||
declare function comoms-dls:checkout($uri) {
|
||||
xdmp:eval(
|
||||
fn:concat(comoms-dls:_import(), "dls:document-checkout('", $uri, "', fn:false())"))
|
||||
};
|
||||
|
||||
declare function comoms-dls:checkin($uri) {
|
||||
xdmp:eval(
|
||||
fn:concat(comoms-dls:_import(), "dls:document-checkin('", $uri, "', fn:false())"))
|
||||
};
|
||||
|
||||
|
||||
declare function comoms-dls:add($uri) {
|
||||
xdmp:eval(
|
||||
fn:concat(comoms-dls:_import(), "dls:document-manage('", $uri, "', fn:false())")
|
||||
)
|
||||
};
|
||||
|
||||
|
||||
declare function comoms-dls:documentHistory($uri) {
|
||||
xdmp:eval(
|
||||
fn:concat(comoms-dls:_import(), "dls:document-history('", $uri, "')")
|
||||
)
|
||||
};
|
||||
|
||||
declare function comoms-dls:checkoutStatus($uri) {
|
||||
xdmp:eval(
|
||||
fn:concat(comoms-dls:_import(), "dls:document-checkout-status('", $uri, "')")
|
||||
)
|
||||
};
|
||||
|
||||
(:~
|
||||
: call fn:doc but wrapped in an eval
|
||||
:)
|
||||
declare function comoms-dls:docInEval($uri) {
|
||||
xdmp:eval(
|
||||
fn:concat(comoms-dls:_import(), "fn:doc('", $uri, "')")
|
||||
)
|
||||
};
|
||||
|
||||
(: ########################################################################### :)
|
||||
(: PUBLISHING FUNCTIONS :)
|
||||
(: ########################################################################### :)
|
||||
|
||||
(:~
|
||||
: Given a sequence of version URIs, publish all of these versions of each document
|
||||
: If there is a version of the same document already published, unpublish it 1st
|
||||
:
|
||||
: When "publish" is referred to, we mean that it is put into the PUBLISHED collection
|
||||
: unpublish removes content from this collection
|
||||
: @param $version_uris - sequence of uris of versions of managed documents to publish
|
||||
:)
|
||||
declare function comoms-dls:publish($version_uris as item()*) {
|
||||
for $uri in $version_uris
|
||||
let $doc := fn:doc($uri)
|
||||
let $managed_base_uri := $doc/node()/property::dls:version/dls:document-uri/text()
|
||||
let $existing := comoms-dls:publishedDoc($managed_base_uri)
|
||||
let $unpublishExisting := if($existing) then comoms-dls:unpublishVersion((xdmp:node-uri($existing))) else ()
|
||||
let $addPermissions := dls:document-add-permissions($uri, (xdmp:permission('mkp-anon', 'read')))
|
||||
return
|
||||
dls:document-add-collections($uri, ("PUBLISHED"))
|
||||
};
|
||||
|
||||
declare function comoms-dls:publishLatest($uri) {
|
||||
(: TODO check if it's in the draft collection probably :)
|
||||
|
||||
let $latest_version_uri := comoms-dls:latestVersionUri($uri)
|
||||
let $log:= xdmp:log(fn:concat("latest: ", $latest_version_uri))
|
||||
let $log:= xdmp:log(fn:concat("uri: ", $uri))
|
||||
return comoms-dls:publish($latest_version_uri)
|
||||
|
||||
};
|
||||
|
||||
declare function comoms-dls:latestVersionUri($uri) {
|
||||
let $latest_version_num :=
|
||||
(
|
||||
for $version in dls:document-history($uri)/dls:version
|
||||
order by fn:number($version//dls:version-id/text()) descending
|
||||
return $version//dls:version-id/text()
|
||||
)[1]
|
||||
|
||||
|
||||
return dls:document-version-uri($uri, $latest_version_num)
|
||||
};
|
||||
|
||||
declare function comoms-dls:unpublish($uris as item()*) {
|
||||
for $uri in $uris
|
||||
return
|
||||
let $published_doc := comoms-dls:publishedDoc($uri)
|
||||
return
|
||||
if($published_doc) then
|
||||
let $published_version_uri := xdmp:node-uri($published_doc)
|
||||
return comoms-dls:unpublishVersion($published_version_uri)
|
||||
else
|
||||
()
|
||||
};
|
||||
|
||||
declare function comoms-dls:latestPublishedDocAuthor($uri) {
|
||||
let $author_id := doc($uri)/property::dls:version/dls:author/text()
|
||||
return
|
||||
if($author_id) then
|
||||
comoms-user:getUsername($author_id)
|
||||
else
|
||||
()
|
||||
|
||||
};
|
||||
|
||||
(:~
|
||||
: Given a sequence of version URIs, unpublish all of these versions of each document
|
||||
:)
|
||||
declare function comoms-dls:unpublishVersion($version_uris as item()*) {
|
||||
for $uri in $version_uris
|
||||
return
|
||||
let $removePermissions := dls:document-remove-permissions($uri, (xdmp:permission('mkp-anon', 'read')))
|
||||
return dls:document-remove-collections($uri, ("PUBLISHED"))
|
||||
};
|
||||
|
||||
(:~
|
||||
: Given the base URI of a managed piece of content, return the document of the node
|
||||
: of the version that is published
|
||||
:)
|
||||
declare function comoms-dls:publishedDoc($uri) {
|
||||
fn:collection("PUBLISHED")[property::dls:version/dls:document-uri = $uri]
|
||||
};
|
||||
|
||||
|
||||
(:~
|
||||
: Test if any version of the managed document is published
|
||||
:)
|
||||
declare function comoms-dls:isPublished($uri) {
|
||||
if( comoms-dls:publishedDoc($uri)) then
|
||||
fn:true()
|
||||
else
|
||||
fn:false()
|
||||
};
|
||||
|
||||
|
||||
declare function comoms-dls:publishedState($uri) {
|
||||
let $doc := comoms-dls:publishedDoc($uri)
|
||||
let $published_uri := if($doc) then xdmp:node-uri($doc) else ()
|
||||
let $latest := comoms-dls:latestVersionUri($uri)
|
||||
return
|
||||
if($doc) then
|
||||
if($latest ne $published_uri) then
|
||||
"stale"
|
||||
else
|
||||
"published"
|
||||
else
|
||||
"unpublished"
|
||||
};
|
||||
|
||||
|
||||
declare function comoms-dls:getManagedDocUri($uri) {
|
||||
let $doc := fn:doc($uri)
|
||||
let $managed_uri := $doc/property::dls:version/dls:document-uri/text()
|
||||
let $managed_uri := if($managed_uri) then $managed_uri else $uri
|
||||
return $managed_uri
|
||||
};
|
||||
|
||||
(:~
|
||||
: Given a manage content url (e.g. /content/123456.xml) return the appropriate
|
||||
: version of the document based on what stage collection is being viewed and
|
||||
: what's published
|
||||
:
|
||||
: @param $uri a manage content url (e.g. /content/123456.xml) - NOT A VERSIONED URI
|
||||
:)
|
||||
declare function comoms-dls:doc($uri) {
|
||||
let $doc := fn:root(comoms-dls:collection()[property::dls:version/dls:document-uri = $uri][1])
|
||||
return
|
||||
if($doc) then
|
||||
$doc
|
||||
else
|
||||
let $managedDocInCollection := comoms-dls:collection-name() = xdmp:document-get-collections($uri)
|
||||
return
|
||||
if($managedDocInCollection) then
|
||||
fn:doc($uri)
|
||||
else
|
||||
()
|
||||
};
|
||||
|
||||
(:~
|
||||
: Get the collection to be used when querying for content
|
||||
: THIS or comoms-dls:collection-name() SHOULD BE USED WHEN BUILDING ANY QUERY FOR MANAGED CONTENT
|
||||
:)
|
||||
declare function comoms-dls:collection() {
|
||||
fn:collection( comoms-dls:collection-name() )
|
||||
};
|
||||
|
||||
(:~
|
||||
: Get the collection nameto be used when querying for content
|
||||
: THIS or comoms-dls:collection() SHOULD BE USED WHEN BUILDING ANY QUERY FOR MANAGED CONTENT
|
||||
:)
|
||||
declare function comoms-dls:collection-name() as xs:string {
|
||||
let $default_collection := "PUBLISHED"
|
||||
return
|
||||
if(comoms-user:isAdmin()) then
|
||||
let $pub_stage_collection_cookie := comoms-util:getCookie("COMOMS_COLLECTION")
|
||||
return
|
||||
if($pub_stage_collection_cookie) then
|
||||
$pub_stage_collection_cookie
|
||||
else
|
||||
$default_collection
|
||||
else
|
||||
$default_collection
|
||||
};
|
||||
|
||||
(:~
|
||||
: Check if the published collection is being viewed
|
||||
:)
|
||||
declare function comoms-dls:isViewingPublished() {
|
||||
if(comoms-dls:collection-name() = "PUBLISHED") then
|
||||
fn:true()
|
||||
else
|
||||
fn:false()
|
||||
};
|
||||
|
||||
(:~
|
||||
: Get the best URL for the content URI.
|
||||
: This is either the default URI based on detail type or should also take
|
||||
: into account friendly urls and navigation structures to figure out the
|
||||
: best choice
|
||||
:)
|
||||
declare function comoms-dls:contentUrl($uri) {
|
||||
|
||||
(: TODO: add friendly URL and nav structure logic 1st :)
|
||||
|
||||
let $doc := fn:doc($uri)
|
||||
let $managedDocUri := $doc/property::dls:version/dls:document-uri
|
||||
let $uri := if($managedDocUri) then $managedDocUri else $uri
|
||||
let $type := $doc/node()/fn:name()
|
||||
let $content_id := fn:tokenize( fn:tokenize($uri, "/")[3], "\.")[1]
|
||||
return
|
||||
fn:concat("/", $type, "/", $content_id)
|
||||
};
|
||||
|
||||
(:
|
||||
:
|
||||
: gets list of doc versions and uri.
|
||||
:
|
||||
:)
|
||||
declare function comoms-dls:versionHistory($uri) {
|
||||
let $published_doc := comoms-dls:publishedDoc($uri)
|
||||
let $published_uri := if($published_doc) then xdmp:node-uri($published_doc) else ()
|
||||
return
|
||||
<versions>
|
||||
{
|
||||
for $version in dls:document-history($uri)/dls:version
|
||||
let $version_num := $version/dls:version-id/text()
|
||||
let $created := $version/dls:created/text()
|
||||
let $author_id := $version/dls:author/text()
|
||||
let $author := comoms-user:getUsername($author_id)
|
||||
|
||||
|
||||
let $note := $version/dls:annotation/text()
|
||||
let $version_uri := xdmp:node-uri(dls:document-version($uri, $version_num))
|
||||
let $published := $published_uri eq $version_uri
|
||||
return
|
||||
<version>
|
||||
<version-number>{$version_num}</version-number>
|
||||
<created>{$created}</created>
|
||||
<author>{$author}</author>
|
||||
<published>{$published}</published>
|
||||
<version-uri>{$version_uri}</version-uri>
|
||||
</version>
|
||||
}
|
||||
</versions>
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
(: ########################################################################### :)
|
||||
(: PRIVATE FUNCTIONS :)
|
||||
(: ########################################################################### :)
|
||||
|
||||
declare function comoms-dls:_import() {
|
||||
"xquery version '1.0-ml';
|
||||
import module namespace dls = 'http://marklogic.com/xdmp/dls' at '/MarkLogic/dls.xqy'; "
|
||||
};
|
||||
|
||||
(: CODE SAMPLE BELOW BORROWED FROM PARTICK WIED :)
|
||||
declare function local:document-move-forest($uri as xs:string, $forest-ids as xs:unsignedLong*)
|
||||
{
|
||||
xdmp:document-insert(
|
||||
$uri,
|
||||
fn:doc($uri),
|
||||
xdmp:document-get-permissions($uri),
|
||||
xdmp:document-get-collections($uri),
|
||||
xdmp:document-get-quality($uri),
|
||||
$forest-ids
|
||||
)
|
||||
};
|
||||
|
||||
let $xml :=
|
||||
<xml att="blah" att2="blah">
|
||||
sdasd<b>asdasd</b>
|
||||
</xml>
|
||||
(: -------- :)
|
||||
for $d in fn:doc("depts.xml")/depts/deptno
|
||||
let $e := fn:doc("emps.xml")/emps/emp[deptno = $d]
|
||||
where fn:count($e) >= 10
|
||||
order by fn:avg($e/salary) descending
|
||||
return
|
||||
<big-dept>
|
||||
{
|
||||
$d,
|
||||
<headcount>{fn:count($e)}</headcount>,
|
||||
<avgsal>{fn:avg($e/salary)}</avgsal>
|
||||
}
|
||||
</big-dept>
|
||||
(: -------- :)
|
||||
declare function local:depth($e as node()) as xs:integer
|
||||
{
|
||||
(: A node with no children has depth 1 :)
|
||||
(: Otherwise, add 1 to max depth of children :)
|
||||
if (fn:empty($e/*)) then 1
|
||||
else fn:max(for $c in $e/* return local:depth($c)) + 1
|
||||
};
|
||||
|
||||
local:depth(fn:doc("partlist.xml"))
|
||||
|
||||
(: -------- :)
|
||||
<html><head/><body>
|
||||
{
|
||||
for $act in doc("hamlet.xml")//ACT
|
||||
let $speakers := distinct-values($act//SPEAKER)
|
||||
return
|
||||
<div>{ string($act/TITLE) }</h1>
|
||||
<ul>
|
||||
{
|
||||
for $speaker in $speakers
|
||||
return <li>{ $speaker }</li>
|
||||
}
|
||||
</ul>
|
||||
</div>
|
||||
}
|
||||
</body></html>
|
||||
(: -------- :)
|
||||
{
|
||||
for $book in doc("books.xml")//book
|
||||
return
|
||||
if (contains($book/author/text(),"Herbert") or contains($book/author/text(),"Asimov"))
|
||||
then $book
|
||||
else $book/text()
|
||||
|
||||
let $let := <x>"test"</x>
|
||||
return element element {
|
||||
attribute attribute { 1 },
|
||||
element test { 'a' },
|
||||
attribute foo { "bar" },
|
||||
fn:doc()[ foo/@bar eq $let ],
|
||||
//x }
|
||||
}
|
||||
(: -------- :)
|
||||
<bib>
|
||||
{
|
||||
for $b in doc("http://bstore1.example.com/bib.xml")/bib/book
|
||||
where $b/publisher = "Addison-Wesley" and $b/@year > 1991
|
||||
return
|
||||
<book year="{ $b/@year }">
|
||||
{ $b/title }
|
||||
</book>
|
||||
}
|
||||
</bib>
|
||||
(: -------- :)
|
||||
</textarea>
|
||||
</div>
|
||||
<div style="width:100%;text-align:center;padding-top:15px;">
|
||||
Developed by <a href="http://mike.brevoort.com">Mike Brevoort</a> (<a href="http://twitter.com">@mbrevoort</a>)
|
||||
<br/><small><a href="http://www.apache.org/licenses/LICENSE-2.0.html">Apache License, Version 2.0</a></small></div>
|
||||
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
var editor = CodeMirror.fromTextArea('code', {
|
||||
height: "550px",
|
||||
parserfile: ["../contrib/xquery/js/tokenizexquery.js", "../contrib/xquery/js/parsexquery.js" ],
|
||||
stylesheet: ["css/xqcolors.css"],
|
||||
path: "../../js/",
|
||||
continuousScanning: false, //500,
|
||||
lineNumbers: true
|
||||
});
|
||||
|
||||
$(document).ready(function() {
|
||||
$(".css-switch").click(function() {
|
||||
editor.setStylesheet("css/" + $(this).attr("rel"));
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
234
gulliver/js/codemirror/contrib/xquery/js/parsexquery.js
Executable file
234
gulliver/js/codemirror/contrib/xquery/js/parsexquery.js
Executable file
@@ -0,0 +1,234 @@
|
||||
/*
|
||||
Copyright 2010 Mike Brevoort http://mike.brevoort.com (twitter:@mbrevoort)
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
This is an indirect collective derivative of the other parses in this package
|
||||
|
||||
*/
|
||||
|
||||
// The XQuery parser uses the xquery tokenizer in tokenizexquery.js. Given the
|
||||
// stream of tokens, it makes decisions to override the tokens styles by evaluating
|
||||
// it's context with respect to the other tokens.
|
||||
|
||||
var XqueryParser = Editor.Parser = (function() {
|
||||
function xqueryLexical(startColumn, currentToken, align, previousToken, encloseLevel) {
|
||||
this.startColumn = startColumn;
|
||||
this.currentToken = currentToken;
|
||||
if (align != null)
|
||||
this.align = align;
|
||||
this.previousToken = previousToken;
|
||||
this.encloseLevel = encloseLevel;
|
||||
}
|
||||
|
||||
// Xquery indentation rules.
|
||||
function indentXquery(lexical) {
|
||||
return function(firstChars, curIndent, direction) {
|
||||
// test if this is next row after the open brace
|
||||
if (lexical.encloseLevel !== 0 && firstChars === "}") {
|
||||
return lexical.startColumn - indentUnit;
|
||||
}
|
||||
|
||||
return lexical.startColumn;
|
||||
};
|
||||
}
|
||||
|
||||
function parseXquery(source) {
|
||||
var tokens = tokenizeXquery(source);
|
||||
|
||||
var column = 0;
|
||||
// tells the first non-whitespace symbol from the
|
||||
// start of row.
|
||||
var previousToken = null;
|
||||
var previousTokens = [];
|
||||
//mb
|
||||
var align = false;
|
||||
// tells if the text after the open brace
|
||||
var encloseLevel = 0;
|
||||
// tells curent opened braces quantity
|
||||
var cc = [statements];
|
||||
var consume,
|
||||
marked;
|
||||
|
||||
var iter = {
|
||||
next: function() {
|
||||
var token = tokens.next();
|
||||
// since attribute and elements can be named the same, assume the
|
||||
// following word of each is a variable
|
||||
if (previousToken && (previousToken.content == "attribute" || previousToken.content == "element") && previousToken.type == "xqueryKeywordC") {
|
||||
token.type = "variable";
|
||||
token.style = "xqueryVariable";
|
||||
}
|
||||
|
||||
else if (previousToken && previousToken.content == "xquery" && token.content == "version") {
|
||||
//token.type="variable";
|
||||
token.style = "xqueryModifier";
|
||||
}
|
||||
|
||||
else if (token.type == "word" && (getPrevious(3).style == "xml-attribute" || (previousToken && previousToken.type == "xml-tag-open")) &&
|
||||
previousToken.content.substring(previousToken.content.length - 1) != ">") {
|
||||
token.style = "xml-attribute";
|
||||
}
|
||||
else if (previousToken && previousToken.content == "=" && previousTokens.length > 2
|
||||
&& getPrevious(2).style == "xml-attribute") {
|
||||
token.style = "xml-attribute-value";
|
||||
}
|
||||
else if(token.type == "string" && previousToken && previousToken.type == "}") {
|
||||
// looking for expressions within a string and detecting if the expression is within an attribute
|
||||
var i=0;
|
||||
while(i++ < previousTokens.length-1) {
|
||||
if(getPrevious(i).style == "xml-attribute-value" ) {
|
||||
token.style = "xml-attribute-value";
|
||||
break;
|
||||
}
|
||||
else if(getPrevious(i).type == "string") {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(token.type == "string") {
|
||||
// brute force check for strings inside XML TODO... something else
|
||||
var i=0;
|
||||
var closeCount = 0;
|
||||
while(i++ < previousTokens.length-1) {
|
||||
var prev = getPrevious(i);
|
||||
if(prev.type == "xml-tag-open") {
|
||||
if(closeCount == 0) {
|
||||
token.style = "word";
|
||||
break;
|
||||
} else {
|
||||
closeCount--;
|
||||
}
|
||||
}
|
||||
else if(prev.type == "xml-tag-close") {
|
||||
closeCount++;
|
||||
}
|
||||
else if(prev.content == ":=" || prev.content == "return" || prev.content == "{")
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if(getPrevious(2).content == "module" && getPrevious(1).content == "namespace")
|
||||
token.style="xqueryFunction";
|
||||
else if(token.content == "=" && getPrevious(1).style == "xml-attribute")
|
||||
token.style="xml-attribute"
|
||||
|
||||
if (token.type == "whitespace") {
|
||||
if (token.value == "\n") {
|
||||
// test if this is end of line
|
||||
if (previousToken !== null) {
|
||||
if (previousToken.type === "{") {
|
||||
// test if there is open brace at the end of line
|
||||
align = true;
|
||||
column += indentUnit;
|
||||
encloseLevel++;
|
||||
}
|
||||
else
|
||||
if (previousToken.type === "}") {
|
||||
// test if there is close brace at the end of line
|
||||
align = false;
|
||||
if (encloseLevel > 0) {
|
||||
encloseLevel--;
|
||||
}
|
||||
else {
|
||||
encloseLevel = 0;
|
||||
}
|
||||
}
|
||||
var lexical = new xqueryLexical(column, token, align, previousToken, encloseLevel);
|
||||
token.indentation = indentXquery(lexical);
|
||||
}
|
||||
}
|
||||
else
|
||||
column = token.value.length;
|
||||
}
|
||||
|
||||
// maintain the previous tokens array so that it doesn't continue to leak
|
||||
// keep only the last 5000
|
||||
if(previousTokens.length > 5000) previousTokens.shift();
|
||||
|
||||
while (true) {
|
||||
consume = marked = false;
|
||||
// Take and execute the topmost action.
|
||||
cc.pop()(token.type, token.content);
|
||||
if (consume) {
|
||||
// Marked is used to change the style of the current token.
|
||||
if (marked)
|
||||
token.style = marked;
|
||||
// Here we differentiate between local and global variables.
|
||||
previousToken = token;
|
||||
previousTokens[previousTokens.length] = token;
|
||||
return token;
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
copy: function() {
|
||||
var _cc = cc.concat([]),
|
||||
_tokenState = tokens.state,
|
||||
_column = column;
|
||||
|
||||
return function copyParser(_source) {
|
||||
cc = _cc.concat([]);
|
||||
column = indented = _column;
|
||||
tokens = tokenizeXquery(_source, _tokenState);
|
||||
return iter;
|
||||
};
|
||||
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
function statements(type) {
|
||||
return pass(statement, statements);
|
||||
}
|
||||
|
||||
function statement(type) {
|
||||
cont();
|
||||
}
|
||||
|
||||
function push(fs) {
|
||||
for (var i = fs.length - 1; i >= 0; i--)
|
||||
cc.push(fs[i]);
|
||||
}
|
||||
|
||||
function cont() {
|
||||
push(arguments);
|
||||
consume = true;
|
||||
}
|
||||
|
||||
function pass() {
|
||||
push(arguments);
|
||||
consume = false;
|
||||
}
|
||||
|
||||
|
||||
function getPrevious(numberFromCurrent) {
|
||||
var l = previousTokens.length;
|
||||
if (l - numberFromCurrent >= 0)
|
||||
return previousTokens[l - numberFromCurrent];
|
||||
else
|
||||
return {
|
||||
type: "",
|
||||
style: "",
|
||||
content: ""
|
||||
};
|
||||
}
|
||||
|
||||
return iter;
|
||||
|
||||
|
||||
}
|
||||
return {
|
||||
make: parseXquery
|
||||
};
|
||||
})();
|
||||
457
gulliver/js/codemirror/contrib/xquery/js/tokenizexquery.js
Executable file
457
gulliver/js/codemirror/contrib/xquery/js/tokenizexquery.js
Executable file
@@ -0,0 +1,457 @@
|
||||
/*
|
||||
Copyright 2010 Mike Brevoort http://mike.brevoort.com (twitter:@mbrevoort)
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
This is an indirect collective derivative of the other parses in this package
|
||||
|
||||
*/
|
||||
|
||||
// A tokenizer for xQuery, looks at the source stream and tokenizes, applying
|
||||
// metadata to be able to apply the proper CSS classes in the parser.
|
||||
|
||||
var tokenizeXquery = (function() {
|
||||
// Advance the stream until the given character (not preceded by a
|
||||
// backslash) is encountered, or the end of the line is reached.
|
||||
function nextUntilUnescaped(source, end) {
|
||||
var escaped = false;
|
||||
while (!source.endOfLine()) {
|
||||
var next = source.next();
|
||||
if (next == end && !escaped)
|
||||
return false;
|
||||
escaped = !escaped && next == "\\";
|
||||
}
|
||||
return escaped;
|
||||
}
|
||||
|
||||
// A map of Xquery's keywords. The a/b/c keyword distinction is
|
||||
// very rough, but it gives the parser enough information to parse
|
||||
// correct code correctly (we don't care that much how we parse
|
||||
// incorrect code). The style information included in these objects
|
||||
// is used by the highlighter to pick the correct CSS style for a
|
||||
// token.
|
||||
var keywords = function() {
|
||||
function result(type, style) {
|
||||
return {
|
||||
type: type,
|
||||
style: style
|
||||
};
|
||||
}
|
||||
|
||||
var allKeywords = {};
|
||||
var keywordsList = {};
|
||||
|
||||
// an array of all of the keywords that will be used by default, otherwise keywords will be more specifically specified and overridden below
|
||||
var allKeywordsArray = new Array('after','ancestor','ancestor-or-self','and','as','ascending','assert','attribute','before','by','case','cast','child','comment','comment','declare','default','define','descendant','descendant-or-self','descending','document-node','element','element','else','eq','every','except','external','following','following-sibling','follows','for','function','if','import','in','instance','intersect','item','let','module','namespace','node','node','of','only','or','order','parent','precedes','preceding','preceding-sibling','processing-instruction','ref','return','returns','satisfies','schema','schema-element','self','some','sortby','stable','text','then','to','treat','typeswitch','union','variable','version','where','xquery');
|
||||
|
||||
for(var i in allKeywordsArray) {
|
||||
allKeywords[allKeywordsArray[i]] = result("keyword", "xqueryKeyword");
|
||||
}
|
||||
|
||||
/* This next bit is broken down this was for future indentation support */
|
||||
// keywords that take a parenthised expression, and then a statement (if)
|
||||
keywordsList['xqueryKeywordA'] = new Array('if', 'switch', 'while', 'for');
|
||||
|
||||
// keywords that take just a statement (else)
|
||||
keywordsList['xqueryKeywordB'] = new Array('else', 'then', 'try', 'finally');
|
||||
|
||||
// keywords that optionally take an expression, and form a statement (return)
|
||||
keywordsList['xqueryKeywordC'] = new Array('element', 'attribute', 'let', 'implements', 'import', 'module', 'namespace', 'return', 'super', 'this', 'throws', 'where');
|
||||
|
||||
keywordsList['xqueryOperator'] = new Array('eq', 'ne', 'lt', 'le', 'gt', 'ge');
|
||||
|
||||
for (var keywordType in keywordsList) {
|
||||
for (var i = 0; i < keywordsList[keywordType].length; i++) {
|
||||
allKeywords[keywordsList[keywordType][i]] = result(keywordType, "xqueryKeyword");
|
||||
}
|
||||
}
|
||||
|
||||
keywordsList = {};
|
||||
|
||||
keywordsList['xqueryAtom'] = new Array('null', 'fn:false()', 'fn:true()');
|
||||
for (var keywordType in keywordsList) {
|
||||
for (var i = 0; i < keywordsList[keywordType].length; i++) {
|
||||
allKeywords[keywordsList[keywordType][i]] = result(keywordType, keywordType);
|
||||
}
|
||||
}
|
||||
|
||||
keywordsList = {};
|
||||
keywordsList['xqueryModifier'] = new Array('xquery', 'ascending', 'descending');
|
||||
keywordsList['xqueryType'] = new Array('xs:string', 'xs:float', 'xs:decimal', 'xs:double', 'xs:integer', 'xs:boolean', 'xs:date', 'xs:dateTime', 'xs:time', 'xs:duration', 'xs:dayTimeDuration', 'xs:time', 'xs:yearMonthDuration', 'numeric', 'xs:hexBinary', 'xs:base64Binary', 'xs:anyURI', 'xs:QName', 'xs:byte','xs:boolean','xs:anyURI','xf:yearMonthDuration');
|
||||
for (var keywordType in keywordsList) {
|
||||
for (var i = 0; i < keywordsList[keywordType].length; i++) {
|
||||
allKeywords[keywordsList[keywordType][i]] = result('function', keywordType);
|
||||
}
|
||||
}
|
||||
|
||||
allKeywords = objectConcat(allKeywords, {
|
||||
"catch": result("catch", "xqueryKeyword"),
|
||||
"for": result("for", "xqueryKeyword"),
|
||||
"case": result("case", "xqueryKeyword"),
|
||||
"default": result("default", "xqueryKeyword"),
|
||||
"instanceof": result("operator", "xqueryKeyword")
|
||||
});
|
||||
|
||||
// ------------------- xquery keywords
|
||||
var keywordsList = {};
|
||||
|
||||
// keywords that optionally take an expression, and form a statement (return)
|
||||
keywordsList['xqueryKeywordC'] = new Array('assert', 'property');
|
||||
for (var i = 0; i < keywordsList['xqueryKeywordC'].length; i++) {
|
||||
allKeywords[keywordsList['xqueryKeywordC'][i]] = result("xqueryKeywordC", "xqueryKeyword");
|
||||
}
|
||||
|
||||
// other xquery keywords
|
||||
allKeywords = objectConcat(allKeywords, {
|
||||
"as": result("operator", "xqueryKeyword"),
|
||||
"in": result("operator", "xqueryKeyword"),
|
||||
"at": result("operator", "xqueryKeyword"),
|
||||
"declare": result("function", "xqueryKeyword"),
|
||||
"function": result("function", "xqueryKeyword")
|
||||
});
|
||||
return allKeywords;
|
||||
} ();
|
||||
|
||||
// there are some special cases where ordinarily text like xs:string() would
|
||||
// look like a function call when it is really a type, etc.
|
||||
function specialCases(source, word) {
|
||||
if (word in {
|
||||
"fn:true": "",
|
||||
"fn:false": ""
|
||||
} && source.lookAhead("()", false)) {
|
||||
source.next();
|
||||
source.next();
|
||||
source.get();
|
||||
return {
|
||||
type: "function",
|
||||
style: "xqueryAtom",
|
||||
content: word + "()"
|
||||
};
|
||||
}
|
||||
else if (word in {
|
||||
"node": "",
|
||||
"item": "",
|
||||
"text": ""
|
||||
} && source.lookAhead("()", false)) {
|
||||
source.next();
|
||||
source.next();
|
||||
source.get();
|
||||
return {
|
||||
type: "function",
|
||||
style: "xqueryType",
|
||||
content: word + "()"
|
||||
};
|
||||
}
|
||||
else if (source.lookAhead("(")) {
|
||||
return {
|
||||
type: "function",
|
||||
style: "xqueryFunction",
|
||||
content: word
|
||||
};
|
||||
}
|
||||
else return null;
|
||||
}
|
||||
|
||||
// Some helper regexp matchers.
|
||||
var isOperatorChar = /[=+\-*&%!?@\/]/;
|
||||
var isDigit = /[0-9]/;
|
||||
var isHexDigit = /^[0-9A-Fa-f]$/;
|
||||
var isWordChar = /[\w\:\-\$_]/;
|
||||
var isVariableChar = /[\w\$_-]/;
|
||||
var isXqueryVariableChar = /[\w\.()\[\]{}]/;
|
||||
var isPunctuation = /[\[\]{}\(\),;\.]/;
|
||||
var isStringDelimeter = /^[\/'"]$/;
|
||||
var isRegexpDelimeter = /^[\/'$]/;
|
||||
var tagnameChar = /[<\w\:\-\/_]/;
|
||||
|
||||
// Wrapper around xqueryToken that helps maintain parser state (whether
|
||||
// we are inside of a multi-line comment and whether the next token
|
||||
// could be a regular expression).
|
||||
function xqueryTokenState(inside, regexp) {
|
||||
return function(source, setState) {
|
||||
var newInside = inside;
|
||||
var type = xqueryToken(inside, regexp, source,
|
||||
function(c) {
|
||||
newInside = c;
|
||||
});
|
||||
var newRegexp = type.type == "operator" || type.type == "xqueryKeywordC" || type.type == "xqueryKeywordC" || type.type.match(/^[\[{}\(,;:]$/);
|
||||
if (newRegexp != regexp || newInside != inside)
|
||||
setState(xqueryTokenState(newInside, newRegexp));
|
||||
return type;
|
||||
};
|
||||
}
|
||||
|
||||
// The token reader, inteded to be used by the tokenizer from
|
||||
// tokenize.js (through xqueryTokenState). Advances the source stream
|
||||
// over a token, and returns an object containing the type and style
|
||||
// of that token.
|
||||
function xqueryToken(inside, regexp, source, setInside) {
|
||||
function readHexNumber() {
|
||||
setInside(null);
|
||||
source.next();
|
||||
// skip the 'x'
|
||||
source.nextWhileMatches(isHexDigit);
|
||||
return {
|
||||
type: "number",
|
||||
style: "xqueryNumber"
|
||||
};
|
||||
}
|
||||
|
||||
function readNumber() {
|
||||
setInside(null);
|
||||
source.nextWhileMatches(isDigit);
|
||||
if (source.equals(".")) {
|
||||
source.next();
|
||||
|
||||
// read ranges
|
||||
if (source.equals("."))
|
||||
source.next();
|
||||
|
||||
source.nextWhileMatches(isDigit);
|
||||
}
|
||||
if (source.equals("e") || source.equals("E")) {
|
||||
source.next();
|
||||
if (source.equals("-"))
|
||||
source.next();
|
||||
source.nextWhileMatches(isDigit);
|
||||
}
|
||||
return {
|
||||
type: "number",
|
||||
style: "xqueryNumber"
|
||||
};
|
||||
}
|
||||
// Read a word, look it up in keywords. If not found, it is a
|
||||
// variable, otherwise it is a keyword of the type found.
|
||||
function readWord() {
|
||||
//setInside(null);
|
||||
source.nextWhileMatches(isWordChar);
|
||||
var word = source.get();
|
||||
var specialCase = specialCases(source, word);
|
||||
if (specialCase) return specialCase;
|
||||
var known = keywords.hasOwnProperty(word) && keywords.propertyIsEnumerable(word) && keywords[word];
|
||||
if (known) return {
|
||||
type: known.type,
|
||||
style: known.style,
|
||||
content: word
|
||||
}
|
||||
return {
|
||||
type: "word",
|
||||
style: "word",
|
||||
content: word
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// read regexp like /\w{1}:\\.+\\.+/
|
||||
function readRegexp() {
|
||||
// go to the end / not \/
|
||||
nextUntilUnescaped(source, "/");
|
||||
|
||||
return {
|
||||
type: "regexp",
|
||||
style: "xqueryRegexp"
|
||||
};
|
||||
}
|
||||
|
||||
// Mutli-line comments are tricky. We want to return the newlines
|
||||
// embedded in them as regular newline tokens, and then continue
|
||||
// returning a comment token for every line of the comment. So
|
||||
// some state has to be saved (inside) to indicate whether we are
|
||||
// inside a (: :) sequence.
|
||||
function readMultilineComment(start) {
|
||||
var newInside = "(:";
|
||||
var maybeEnd = (start == ":");
|
||||
while (true) {
|
||||
if (source.endOfLine())
|
||||
break;
|
||||
var next = source.next();
|
||||
if (next == ")" && maybeEnd) {
|
||||
newInside = null;
|
||||
break;
|
||||
}
|
||||
maybeEnd = (next == ":");
|
||||
}
|
||||
setInside(newInside);
|
||||
return {
|
||||
type: "comment",
|
||||
style: "xqueryComment"
|
||||
};
|
||||
}
|
||||
|
||||
function readOperator() {
|
||||
if (ch == "=")
|
||||
setInside("=")
|
||||
else if (ch == "~")
|
||||
setInside("~")
|
||||
else if (ch == ":" && source.equals("=")) {
|
||||
setInside(null);
|
||||
source.nextWhileMatches(/[:=]/);
|
||||
var word = source.get();
|
||||
return {
|
||||
type: "operator",
|
||||
style: "xqueryOperator",
|
||||
content: word
|
||||
};
|
||||
}
|
||||
else setInside(null);
|
||||
|
||||
return {
|
||||
type: "operator",
|
||||
style: "xqueryOperator"
|
||||
};
|
||||
}
|
||||
|
||||
// read a string, but look for embedded expressions wrapped in curly
|
||||
// brackets.
|
||||
function readString(quote) {
|
||||
var newInside = quote;
|
||||
var previous = "";
|
||||
while (true) {
|
||||
if (source.endOfLine())
|
||||
break;
|
||||
if(source.lookAhead("{", false)) {
|
||||
newInside = quote + "{";
|
||||
break;
|
||||
}
|
||||
var next = source.next();
|
||||
if (next == quote && previous != "\\") {
|
||||
newInside = null;
|
||||
break;
|
||||
}
|
||||
previous = next;
|
||||
}
|
||||
setInside(newInside);
|
||||
return {
|
||||
type: "string",
|
||||
style: "xqueryString"
|
||||
};
|
||||
}
|
||||
|
||||
// Given an expression end by a closing curly bracket, mark the } as
|
||||
// punctuation an resume the string processing by setting "inside" to
|
||||
// the type of string it's embedded in.
|
||||
// This is known because the readString() function sets inside to the
|
||||
// quote type then an open curly bracket like "{ or '{
|
||||
function readExpressionEndInString(inside) {
|
||||
var quote = inside.substr(0,1);
|
||||
setInside(quote);
|
||||
return { type: ch, style: "xqueryPunctuation"};
|
||||
}
|
||||
|
||||
function readVariable() {
|
||||
//setInside(null);
|
||||
source.nextWhileMatches(isVariableChar);
|
||||
var word = source.get();
|
||||
return {
|
||||
type: "variable",
|
||||
style: "xqueryVariable",
|
||||
content: word
|
||||
};
|
||||
}
|
||||
|
||||
// read an XML Tagname, both closing and opening
|
||||
function readTagname(lt) {
|
||||
var tagtype = (source.lookAhead("/", false)) ? "xml-tag-close": "xml-tag-open";
|
||||
source.nextWhileMatches(tagnameChar);
|
||||
var word = source.get();
|
||||
if (source.lookAhead(">", false)) {
|
||||
source.next();
|
||||
}
|
||||
return {
|
||||
type: tagtype,
|
||||
style: "xml-tagname",
|
||||
content: word
|
||||
};
|
||||
}
|
||||
|
||||
// Fetch the next token. Dispatches on first character in the stream
|
||||
// what follows is a big if statement that makes decisions based on the
|
||||
// character, the following character and the inside variable
|
||||
|
||||
if (inside == "\"" || inside == "'")
|
||||
return readString(inside);
|
||||
|
||||
var ch = source.next();
|
||||
if (inside && inside.indexOf("{") == 1 && ch == "}") {
|
||||
return readExpressionEndInString(inside);
|
||||
}
|
||||
if (inside == "(:")
|
||||
return readMultilineComment(ch);
|
||||
else if (ch == "\"" || ch == "'")
|
||||
return readString(ch);
|
||||
|
||||
|
||||
// test if this is range
|
||||
else if (ch == "." && source.equals(".")) {
|
||||
source.next();
|
||||
return {
|
||||
type: "..",
|
||||
style: "xqueryOperator"
|
||||
};
|
||||
}
|
||||
|
||||
else if (ch == "(" && source.equals(":")) {
|
||||
source.next();
|
||||
return readMultilineComment(ch);
|
||||
}
|
||||
else if (ch == "$")
|
||||
return readVariable();
|
||||
else if (ch == ":" && source.equals("="))
|
||||
return readOperator();
|
||||
|
||||
// with punctuation, the type of the token is the symbol itself
|
||||
else if (isPunctuation.test(ch))
|
||||
return {
|
||||
type: ch,
|
||||
style: "xqueryPunctuation"
|
||||
};
|
||||
else if (ch == "0" && (source.equals("x") || source.equals("X")))
|
||||
return readHexNumber();
|
||||
else if (isDigit.test(ch))
|
||||
return readNumber();
|
||||
|
||||
else if (ch == "~") {
|
||||
setInside("~");
|
||||
// prepare to read slashy string like ~ /\w{1}:\\.+\\.+/
|
||||
return readOperator(ch);
|
||||
}
|
||||
else if (isOperatorChar.test(ch)) {
|
||||
return readOperator(ch);
|
||||
}
|
||||
// some xml handling stuff
|
||||
else if (ch == "<")
|
||||
return readTagname(ch);
|
||||
else if (ch == ">")
|
||||
return {
|
||||
type: "xml-tag",
|
||||
style: "xml-tagname"
|
||||
};
|
||||
else
|
||||
return readWord();
|
||||
}
|
||||
|
||||
// returns new object = object1 + object2
|
||||
function objectConcat(object1, object2) {
|
||||
for (var name in object2) {
|
||||
if (!object2.hasOwnProperty(name)) continue;
|
||||
if (object1.hasOwnProperty(name)) continue;
|
||||
object1[name] = object2[name];
|
||||
}
|
||||
return object1;
|
||||
}
|
||||
|
||||
// The external interface to the tokenizer.
|
||||
return function(source, startState) {
|
||||
return tokenizer(source, startState || xqueryTokenState(false, true));
|
||||
};
|
||||
})();
|
||||
BIN
gulliver/js/codemirror/css/baboon.png
Executable file
BIN
gulliver/js/codemirror/css/baboon.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 21 KiB |
962
gulliver/js/codemirror/css/baboon_vector.ai
Executable file
962
gulliver/js/codemirror/css/baboon_vector.ai
Executable file
File diff suppressed because one or more lines are too long
55
gulliver/js/codemirror/css/csscolors.css
Executable file
55
gulliver/js/codemirror/css/csscolors.css
Executable file
@@ -0,0 +1,55 @@
|
||||
html {
|
||||
cursor: text;
|
||||
}
|
||||
|
||||
.editbox {
|
||||
margin: .4em;
|
||||
padding: 0;
|
||||
font-family: monospace;
|
||||
font-size: 10pt;
|
||||
color: black;
|
||||
}
|
||||
|
||||
pre.code, .editbox {
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.editbox p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
span.css-at {
|
||||
color: #708;
|
||||
}
|
||||
|
||||
span.css-unit {
|
||||
color: #281;
|
||||
}
|
||||
|
||||
span.css-value {
|
||||
color: #708;
|
||||
}
|
||||
|
||||
span.css-identifier {
|
||||
color: black;
|
||||
}
|
||||
|
||||
span.css-selector {
|
||||
color: #11B;
|
||||
}
|
||||
|
||||
span.css-important {
|
||||
color: #00F;
|
||||
}
|
||||
|
||||
span.css-colorcode {
|
||||
color: #299;
|
||||
}
|
||||
|
||||
span.css-comment {
|
||||
color: #A70;
|
||||
}
|
||||
|
||||
span.css-string {
|
||||
color: #A22;
|
||||
}
|
||||
158
gulliver/js/codemirror/css/docs.css
Executable file
158
gulliver/js/codemirror/css/docs.css
Executable file
@@ -0,0 +1,158 @@
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
line-height: 1.5;
|
||||
max-width: 64.3em;
|
||||
margin: 3em auto;
|
||||
padding: 0 1em;
|
||||
}
|
||||
body.droid {
|
||||
font-family: Droid Sans, Arial, sans-serif;
|
||||
}
|
||||
|
||||
h1 {
|
||||
letter-spacing: -3px;
|
||||
font-size: 3.23em;
|
||||
font-weight: bold;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 1.23em;
|
||||
font-weight: bold;
|
||||
margin: .5em 0;
|
||||
letter-spacing: -1px;
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-size: 1em;
|
||||
font-weight: bold;
|
||||
margin: .4em 0;
|
||||
}
|
||||
|
||||
pre {
|
||||
font-family: Courier New, monospaced;
|
||||
background-color: #eee;
|
||||
-moz-border-radius: 6px;
|
||||
-webkit-border-radius: 6px;
|
||||
border-radius: 6px;
|
||||
padding: 1em;
|
||||
}
|
||||
|
||||
pre.code {
|
||||
margin: 0 1em;
|
||||
}
|
||||
|
||||
.grey {
|
||||
font-size: 2em;
|
||||
padding: .5em 1em;
|
||||
line-height: 1.2em;
|
||||
margin-top: .5em;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
img.logo {
|
||||
position: absolute;
|
||||
right: -25px;
|
||||
bottom: 4px;
|
||||
}
|
||||
|
||||
a:link, a:visited, .quasilink {
|
||||
color: #df0019;
|
||||
cursor: pointer;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:hover, .quasilink:hover {
|
||||
color: #800004;
|
||||
}
|
||||
|
||||
h1 a:link, h1 a:visited, h1 a:hover {
|
||||
color: black;
|
||||
}
|
||||
|
||||
ul {
|
||||
margin: 0;
|
||||
padding-left: 1.2em;
|
||||
}
|
||||
|
||||
a.download {
|
||||
color: white;
|
||||
background-color: #df0019;
|
||||
width: 100%;
|
||||
display: block;
|
||||
text-align: center;
|
||||
font-size: 1.23em;
|
||||
font-weight: bold;
|
||||
text-decoration: none;
|
||||
-moz-border-radius: 6px;
|
||||
-webkit-border-radius: 6px;
|
||||
border-radius: 6px;
|
||||
padding: .5em 0;
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
|
||||
a.download:hover {
|
||||
background-color: #bb0010;
|
||||
}
|
||||
|
||||
.rel {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.rel-note {
|
||||
color: #777;
|
||||
font-size: .9em;
|
||||
margin-top: .1em;
|
||||
}
|
||||
|
||||
.logo-braces {
|
||||
color: #df0019;
|
||||
position: relative;
|
||||
top: -4px;
|
||||
}
|
||||
|
||||
.blk {
|
||||
float: left;
|
||||
}
|
||||
|
||||
.left {
|
||||
width: 37em;
|
||||
padding-right: 6.53em;
|
||||
padding-bottom: 1em;
|
||||
}
|
||||
|
||||
.left1 {
|
||||
width: 15.24em;
|
||||
padding-right: 6.45em;
|
||||
}
|
||||
|
||||
.left2 {
|
||||
width: 15.24em;
|
||||
}
|
||||
|
||||
.right {
|
||||
width: 20.68em;
|
||||
}
|
||||
|
||||
.leftbig {
|
||||
width: 42.44em;
|
||||
padding-right: 6.53em;
|
||||
}
|
||||
|
||||
.rightsmall {
|
||||
width: 15.24em;
|
||||
}
|
||||
|
||||
.clear:after {
|
||||
visibility: hidden;
|
||||
display: block;
|
||||
font-size: 0;
|
||||
content: " ";
|
||||
clear: both;
|
||||
height: 0;
|
||||
}
|
||||
.clear { display: inline-block; }
|
||||
/* start commented backslash hack \*/
|
||||
* html .clear { height: 1%; }
|
||||
.clear { display: block; }
|
||||
/* close commented backslash hack */
|
||||
15
gulliver/js/codemirror/css/font.js
Executable file
15
gulliver/js/codemirror/css/font.js
Executable file
@@ -0,0 +1,15 @@
|
||||
function waitForStyles() {
|
||||
for (var i = 0; i < document.styleSheets.length; i++)
|
||||
if (/googleapis/.test(document.styleSheets[i].href))
|
||||
return document.body.className += " droid";
|
||||
setTimeout(waitForStyles, 100);
|
||||
}
|
||||
setTimeout(function() {
|
||||
if (/AppleWebKit/.test(navigator.userAgent) && /iP[oa]d|iPhone/.test(navigator.userAgent)) return;
|
||||
var link = document.createElement("LINK");
|
||||
link.type = "text/css";
|
||||
link.rel = "stylesheet";
|
||||
link.href = "http://fonts.googleapis.com/css?family=Droid+Sans|Droid+Sans:bold";
|
||||
document.documentElement.getElementsByTagName("HEAD")[0].appendChild(link);
|
||||
waitForStyles();
|
||||
}, 20);
|
||||
59
gulliver/js/codemirror/css/jscolors.css
Executable file
59
gulliver/js/codemirror/css/jscolors.css
Executable file
@@ -0,0 +1,59 @@
|
||||
html {
|
||||
cursor: text;
|
||||
}
|
||||
|
||||
.editbox {
|
||||
margin: .4em;
|
||||
padding: 0;
|
||||
font-family: monospace;
|
||||
font-size: 10pt;
|
||||
color: black;
|
||||
}
|
||||
|
||||
pre.code, .editbox {
|
||||
color: #666666;
|
||||
}
|
||||
|
||||
.editbox p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
span.js-punctuation {
|
||||
color: #666666;
|
||||
}
|
||||
|
||||
span.js-operator {
|
||||
color: #666666;
|
||||
}
|
||||
|
||||
span.js-keyword {
|
||||
color: #770088;
|
||||
}
|
||||
|
||||
span.js-atom {
|
||||
color: #228811;
|
||||
}
|
||||
|
||||
span.js-variable {
|
||||
color: black;
|
||||
}
|
||||
|
||||
span.js-variabledef {
|
||||
color: #0000FF;
|
||||
}
|
||||
|
||||
span.js-localvariable {
|
||||
color: #004499;
|
||||
}
|
||||
|
||||
span.js-property {
|
||||
color: black;
|
||||
}
|
||||
|
||||
span.js-comment {
|
||||
color: #AA7700;
|
||||
}
|
||||
|
||||
span.js-string {
|
||||
color: #AA2222;
|
||||
}
|
||||
BIN
gulliver/js/codemirror/css/people.jpg
Executable file
BIN
gulliver/js/codemirror/css/people.jpg
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
43
gulliver/js/codemirror/css/sparqlcolors.css
Executable file
43
gulliver/js/codemirror/css/sparqlcolors.css
Executable file
@@ -0,0 +1,43 @@
|
||||
html {
|
||||
cursor: text;
|
||||
}
|
||||
|
||||
.editbox {
|
||||
margin: .4em;
|
||||
padding: 0;
|
||||
font-family: monospace;
|
||||
font-size: 10pt;
|
||||
color: black;
|
||||
}
|
||||
|
||||
.editbox p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
span.sp-keyword {
|
||||
color: #708;
|
||||
}
|
||||
|
||||
span.sp-prefixed {
|
||||
color: #5d1;
|
||||
}
|
||||
|
||||
span.sp-var {
|
||||
color: #00c;
|
||||
}
|
||||
|
||||
span.sp-comment {
|
||||
color: #a70;
|
||||
}
|
||||
|
||||
span.sp-literal {
|
||||
color: #a22;
|
||||
}
|
||||
|
||||
span.sp-uri {
|
||||
color: #292;
|
||||
}
|
||||
|
||||
span.sp-operator {
|
||||
color: #088;
|
||||
}
|
||||
55
gulliver/js/codemirror/css/xmlcolors.css
Executable file
55
gulliver/js/codemirror/css/xmlcolors.css
Executable file
@@ -0,0 +1,55 @@
|
||||
html {
|
||||
cursor: text;
|
||||
}
|
||||
|
||||
.editbox {
|
||||
margin: .4em;
|
||||
padding: 0;
|
||||
font-family: monospace;
|
||||
font-size: 10pt;
|
||||
color: black;
|
||||
}
|
||||
|
||||
.editbox p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
span.xml-tagname {
|
||||
color: #A0B;
|
||||
}
|
||||
|
||||
span.xml-attribute {
|
||||
color: #281;
|
||||
}
|
||||
|
||||
span.xml-punctuation {
|
||||
color: black;
|
||||
}
|
||||
|
||||
span.xml-attname {
|
||||
color: #00F;
|
||||
}
|
||||
|
||||
span.xml-comment {
|
||||
color: #A70;
|
||||
}
|
||||
|
||||
span.xml-cdata {
|
||||
color: #48A;
|
||||
}
|
||||
|
||||
span.xml-processing {
|
||||
color: #999;
|
||||
}
|
||||
|
||||
span.xml-entity {
|
||||
color: #A22;
|
||||
}
|
||||
|
||||
span.xml-error {
|
||||
color: #F00 !important;
|
||||
}
|
||||
|
||||
span.xml-text {
|
||||
color: black;
|
||||
}
|
||||
582
gulliver/js/codemirror/js/codemirror.js
Executable file
582
gulliver/js/codemirror/js/codemirror.js
Executable file
@@ -0,0 +1,582 @@
|
||||
/* CodeMirror main module (http://codemirror.net/)
|
||||
*
|
||||
* Implements the CodeMirror constructor and prototype, which take care
|
||||
* of initializing the editor frame, and providing the outside interface.
|
||||
*/
|
||||
|
||||
// The CodeMirrorConfig object is used to specify a default
|
||||
// configuration. If you specify such an object before loading this
|
||||
// file, the values you put into it will override the defaults given
|
||||
// below. You can also assign to it after loading.
|
||||
var CodeMirrorConfig = window.CodeMirrorConfig || {};
|
||||
|
||||
var CodeMirror = (function(){
|
||||
function setDefaults(object, defaults) {
|
||||
for (var option in defaults) {
|
||||
if (!object.hasOwnProperty(option))
|
||||
object[option] = defaults[option];
|
||||
}
|
||||
}
|
||||
function forEach(array, action) {
|
||||
for (var i = 0; i < array.length; i++)
|
||||
action(array[i]);
|
||||
}
|
||||
function createHTMLElement(el) {
|
||||
if (document.createElementNS && document.documentElement.namespaceURI !== null)
|
||||
return document.createElementNS("http://www.w3.org/1999/xhtml", el)
|
||||
else
|
||||
return document.createElement(el)
|
||||
}
|
||||
|
||||
// These default options can be overridden by passing a set of
|
||||
// options to a specific CodeMirror constructor. See manual.html for
|
||||
// their meaning.
|
||||
setDefaults(CodeMirrorConfig, {
|
||||
stylesheet: [],
|
||||
path: "",
|
||||
parserfile: [],
|
||||
basefiles: ["util.js", "stringstream.js", "select.js", "undo.js", "editor.js", "tokenize.js"],
|
||||
iframeClass: null,
|
||||
passDelay: 200,
|
||||
passTime: 50,
|
||||
lineNumberDelay: 200,
|
||||
lineNumberTime: 50,
|
||||
continuousScanning: false,
|
||||
saveFunction: null,
|
||||
onLoad: null,
|
||||
onChange: null,
|
||||
undoDepth: 50,
|
||||
undoDelay: 800,
|
||||
disableSpellcheck: true,
|
||||
textWrapping: true,
|
||||
readOnly: false,
|
||||
width: "",
|
||||
height: "300px",
|
||||
minHeight: 100,
|
||||
autoMatchParens: false,
|
||||
markParen: null,
|
||||
unmarkParen: null,
|
||||
parserConfig: null,
|
||||
tabMode: "indent", // or "spaces", "default", "shift"
|
||||
enterMode: "indent", // or "keep", "flat"
|
||||
electricChars: true,
|
||||
reindentOnLoad: false,
|
||||
activeTokens: null,
|
||||
onCursorActivity: null,
|
||||
lineNumbers: false,
|
||||
firstLineNumber: 1,
|
||||
onLineNumberClick: null,
|
||||
indentUnit: 2,
|
||||
domain: null,
|
||||
noScriptCaching: false,
|
||||
incrementalLoading: false
|
||||
});
|
||||
|
||||
function addLineNumberDiv(container, firstNum) {
|
||||
var nums = createHTMLElement("div"),
|
||||
scroller = createHTMLElement("div");
|
||||
nums.style.position = "absolute";
|
||||
nums.style.height = "100%";
|
||||
if (nums.style.setExpression) {
|
||||
try {nums.style.setExpression("height", "this.previousSibling.offsetHeight + 'px'");}
|
||||
catch(e) {} // Seems to throw 'Not Implemented' on some IE8 versions
|
||||
}
|
||||
nums.style.top = "0px";
|
||||
nums.style.left = "0px";
|
||||
nums.style.overflow = "hidden";
|
||||
container.appendChild(nums);
|
||||
scroller.className = "CodeMirror-line-numbers";
|
||||
nums.appendChild(scroller);
|
||||
scroller.innerHTML = "<div>" + firstNum + "</div>";
|
||||
return nums;
|
||||
}
|
||||
|
||||
function frameHTML(options) {
|
||||
if (typeof options.parserfile == "string")
|
||||
options.parserfile = [options.parserfile];
|
||||
if (typeof options.basefiles == "string")
|
||||
options.basefiles = [options.basefiles];
|
||||
if (typeof options.stylesheet == "string")
|
||||
options.stylesheet = [options.stylesheet];
|
||||
|
||||
var html = ["<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"><html><head>"];
|
||||
// Hack to work around a bunch of IE8-specific problems.
|
||||
html.push("<meta http-equiv=\"X-UA-Compatible\" content=\"IE=EmulateIE7\"/>");
|
||||
var queryStr = options.noScriptCaching ? "?nocache=" + new Date().getTime().toString(16) : "";
|
||||
forEach(options.stylesheet, function(file) {
|
||||
html.push("<link rel=\"stylesheet\" type=\"text/css\" href=\"/js/codemirror/" + file + queryStr + "\"/>");
|
||||
});
|
||||
forEach(options.basefiles.concat(options.parserfile), function(file) {
|
||||
if (!/^https?:/.test(file)) file = options.path + file;
|
||||
html.push("<script type=\"text/javascript\" src=\"/js/codemirror/" + file + queryStr + "\"><" + "/script>");
|
||||
});
|
||||
html.push("</head><body style=\"border-width: 0;\" class=\"editbox\" spellcheck=\"" +
|
||||
(options.disableSpellcheck ? "false" : "true") + "\"></body></html>");
|
||||
return html.join("");
|
||||
}
|
||||
|
||||
var internetExplorer = document.selection && window.ActiveXObject && /MSIE/.test(navigator.userAgent);
|
||||
|
||||
function CodeMirror(place, options) {
|
||||
// Use passed options, if any, to override defaults.
|
||||
this.options = options = options || {};
|
||||
setDefaults(options, CodeMirrorConfig);
|
||||
|
||||
// Backward compatibility for deprecated options.
|
||||
if (options.dumbTabs) options.tabMode = "spaces";
|
||||
else if (options.normalTab) options.tabMode = "default";
|
||||
if (options.cursorActivity) options.onCursorActivity = options.cursorActivity;
|
||||
|
||||
var frame = this.frame = createHTMLElement("iframe");
|
||||
if (options.iframeClass) frame.className = options.iframeClass;
|
||||
frame.frameBorder = 0;
|
||||
frame.style.border = "0";
|
||||
frame.style.width = '100%';
|
||||
frame.style.height = '100%';
|
||||
// display: block occasionally suppresses some Firefox bugs, so we
|
||||
// always add it, redundant as it sounds.
|
||||
frame.style.display = "block";
|
||||
|
||||
var div = this.wrapping = createHTMLElement("div");
|
||||
div.style.position = "relative";
|
||||
div.className = "CodeMirror-wrapping";
|
||||
div.style.width = options.width;
|
||||
div.style.height = (options.height == "dynamic") ? options.minHeight + "px" : options.height;
|
||||
// This is used by Editor.reroutePasteEvent
|
||||
var teHack = this.textareaHack = createHTMLElement("textarea");
|
||||
div.appendChild(teHack);
|
||||
teHack.style.position = "absolute";
|
||||
teHack.style.left = "-10000px";
|
||||
teHack.style.width = "10px";
|
||||
teHack.tabIndex = 100000;
|
||||
|
||||
// Link back to this object, so that the editor can fetch options
|
||||
// and add a reference to itself.
|
||||
frame.CodeMirror = this;
|
||||
if (options.domain && internetExplorer) {
|
||||
this.html = frameHTML(options);
|
||||
frame.src = "javascript:(function(){document.open();" +
|
||||
(options.domain ? "document.domain=\"" + options.domain + "\";" : "") +
|
||||
"document.write(window.frameElement.CodeMirror.html);document.close();})()";
|
||||
}
|
||||
else {
|
||||
frame.src = "javascript:;";
|
||||
}
|
||||
|
||||
if (place.appendChild) place.appendChild(div);
|
||||
else place(div);
|
||||
div.appendChild(frame);
|
||||
if (options.lineNumbers) this.lineNumbers = addLineNumberDiv(div, options.firstLineNumber);
|
||||
|
||||
this.win = frame.contentWindow;
|
||||
if (!options.domain || !internetExplorer) {
|
||||
this.win.document.open();
|
||||
this.win.document.write(frameHTML(options));
|
||||
this.win.document.close();
|
||||
}
|
||||
}
|
||||
|
||||
CodeMirror.prototype = {
|
||||
init: function() {
|
||||
// Deprecated, but still supported.
|
||||
if (this.options.initCallback) this.options.initCallback(this);
|
||||
if (this.options.onLoad) this.options.onLoad(this);
|
||||
if (this.options.lineNumbers) this.activateLineNumbers();
|
||||
if (this.options.reindentOnLoad) this.reindent();
|
||||
if (this.options.height == "dynamic") this.setDynamicHeight();
|
||||
},
|
||||
|
||||
getCode: function() {return this.editor.getCode();},
|
||||
setCode: function(code) {this.editor.importCode(code);},
|
||||
selection: function() {this.focusIfIE(); return this.editor.selectedText();},
|
||||
reindent: function() {this.editor.reindent();},
|
||||
reindentSelection: function() {this.focusIfIE(); this.editor.reindentSelection(null);},
|
||||
|
||||
focusIfIE: function() {
|
||||
// in IE, a lot of selection-related functionality only works when the frame is focused
|
||||
if (this.win.select.ie_selection && document.activeElement != this.frame)
|
||||
this.focus();
|
||||
},
|
||||
focus: function() {
|
||||
this.win.focus();
|
||||
if (this.editor.selectionSnapshot) // IE hack
|
||||
this.win.select.setBookmark(this.win.document.body, this.editor.selectionSnapshot);
|
||||
},
|
||||
replaceSelection: function(text) {
|
||||
this.focus();
|
||||
this.editor.replaceSelection(text);
|
||||
return true;
|
||||
},
|
||||
replaceChars: function(text, start, end) {
|
||||
this.editor.replaceChars(text, start, end);
|
||||
},
|
||||
getSearchCursor: function(string, fromCursor, caseFold) {
|
||||
return this.editor.getSearchCursor(string, fromCursor, caseFold);
|
||||
},
|
||||
|
||||
undo: function() {this.editor.history.undo();},
|
||||
redo: function() {this.editor.history.redo();},
|
||||
historySize: function() {return this.editor.history.historySize();},
|
||||
clearHistory: function() {this.editor.history.clear();},
|
||||
|
||||
grabKeys: function(callback, filter) {this.editor.grabKeys(callback, filter);},
|
||||
ungrabKeys: function() {this.editor.ungrabKeys();},
|
||||
|
||||
setParser: function(name, parserConfig) {this.editor.setParser(name, parserConfig);},
|
||||
setSpellcheck: function(on) {this.win.document.body.spellcheck = on;},
|
||||
setStylesheet: function(names) {
|
||||
if (typeof names === "string") names = [names];
|
||||
var activeStylesheets = {};
|
||||
var matchedNames = {};
|
||||
var links = this.win.document.getElementsByTagName("link");
|
||||
// Create hashes of active stylesheets and matched names.
|
||||
// This is O(n^2) but n is expected to be very small.
|
||||
for (var x = 0, link; link = links[x]; x++) {
|
||||
if (link.rel.indexOf("stylesheet") !== -1) {
|
||||
for (var y = 0; y < names.length; y++) {
|
||||
var name = names[y];
|
||||
if (link.href.substring(link.href.length - name.length) === name) {
|
||||
activeStylesheets[link.href] = true;
|
||||
matchedNames[name] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Activate the selected stylesheets and disable the rest.
|
||||
for (var x = 0, link; link = links[x]; x++) {
|
||||
if (link.rel.indexOf("stylesheet") !== -1) {
|
||||
link.disabled = !(link.href in activeStylesheets);
|
||||
}
|
||||
}
|
||||
// Create any new stylesheets.
|
||||
for (var y = 0; y < names.length; y++) {
|
||||
var name = names[y];
|
||||
if (!(name in matchedNames)) {
|
||||
var link = this.win.document.createElement("link");
|
||||
link.rel = "stylesheet";
|
||||
link.type = "text/css";
|
||||
link.href = name;
|
||||
this.win.document.getElementsByTagName('head')[0].appendChild(link);
|
||||
}
|
||||
}
|
||||
},
|
||||
setTextWrapping: function(on) {
|
||||
if (on == this.options.textWrapping) return;
|
||||
this.win.document.body.style.whiteSpace = on ? "" : "nowrap";
|
||||
this.options.textWrapping = on;
|
||||
if (this.lineNumbers) {
|
||||
this.setLineNumbers(false);
|
||||
this.setLineNumbers(true);
|
||||
}
|
||||
},
|
||||
setIndentUnit: function(unit) {this.win.indentUnit = unit;},
|
||||
setUndoDepth: function(depth) {this.editor.history.maxDepth = depth;},
|
||||
setTabMode: function(mode) {this.options.tabMode = mode;},
|
||||
setEnterMode: function(mode) {this.options.enterMode = mode;},
|
||||
setLineNumbers: function(on) {
|
||||
if (on && !this.lineNumbers) {
|
||||
this.lineNumbers = addLineNumberDiv(this.wrapping,this.options.firstLineNumber);
|
||||
this.activateLineNumbers();
|
||||
}
|
||||
else if (!on && this.lineNumbers) {
|
||||
this.wrapping.removeChild(this.lineNumbers);
|
||||
this.wrapping.style.paddingLeft = "";
|
||||
this.lineNumbers = null;
|
||||
}
|
||||
},
|
||||
|
||||
cursorPosition: function(start) {this.focusIfIE(); return this.editor.cursorPosition(start);},
|
||||
firstLine: function() {return this.editor.firstLine();},
|
||||
lastLine: function() {return this.editor.lastLine();},
|
||||
nextLine: function(line) {return this.editor.nextLine(line);},
|
||||
prevLine: function(line) {return this.editor.prevLine(line);},
|
||||
lineContent: function(line) {return this.editor.lineContent(line);},
|
||||
setLineContent: function(line, content) {this.editor.setLineContent(line, content);},
|
||||
removeLine: function(line){this.editor.removeLine(line);},
|
||||
insertIntoLine: function(line, position, content) {this.editor.insertIntoLine(line, position, content);},
|
||||
selectLines: function(startLine, startOffset, endLine, endOffset) {
|
||||
this.win.focus();
|
||||
this.editor.selectLines(startLine, startOffset, endLine, endOffset);
|
||||
},
|
||||
nthLine: function(n) {
|
||||
var line = this.firstLine();
|
||||
for (; n > 1 && line !== false; n--)
|
||||
line = this.nextLine(line);
|
||||
return line;
|
||||
},
|
||||
lineNumber: function(line) {
|
||||
var num = 0;
|
||||
while (line !== false) {
|
||||
num++;
|
||||
line = this.prevLine(line);
|
||||
}
|
||||
return num;
|
||||
},
|
||||
jumpToLine: function(line) {
|
||||
if (typeof line == "number") line = this.nthLine(line);
|
||||
this.selectLines(line, 0);
|
||||
this.win.focus();
|
||||
},
|
||||
currentLine: function() { // Deprecated, but still there for backward compatibility
|
||||
return this.lineNumber(this.cursorLine());
|
||||
},
|
||||
cursorLine: function() {
|
||||
return this.cursorPosition().line;
|
||||
},
|
||||
cursorCoords: function(start) {return this.editor.cursorCoords(start);},
|
||||
|
||||
activateLineNumbers: function() {
|
||||
var frame = this.frame, win = frame.contentWindow, doc = win.document, body = doc.body,
|
||||
nums = this.lineNumbers, scroller = nums.firstChild, self = this;
|
||||
var barWidth = null;
|
||||
|
||||
nums.onclick = function(e) {
|
||||
var handler = self.options.onLineNumberClick;
|
||||
if (handler) {
|
||||
var div = (e || window.event).target || (e || window.event).srcElement;
|
||||
var num = div == nums ? NaN : Number(div.innerHTML);
|
||||
if (!isNaN(num)) handler(num, div);
|
||||
}
|
||||
};
|
||||
|
||||
function sizeBar() {
|
||||
if (frame.offsetWidth == 0) return;
|
||||
for (var root = frame; root.parentNode; root = root.parentNode){}
|
||||
if (!nums.parentNode || root != document || !win.Editor) {
|
||||
// Clear event handlers (their nodes might already be collected, so try/catch)
|
||||
try{clear();}catch(e){}
|
||||
clearInterval(sizeInterval);
|
||||
return;
|
||||
}
|
||||
|
||||
if (nums.offsetWidth != barWidth) {
|
||||
barWidth = nums.offsetWidth;
|
||||
frame.parentNode.style.paddingLeft = barWidth + "px";
|
||||
}
|
||||
}
|
||||
function doScroll() {
|
||||
nums.scrollTop = body.scrollTop || doc.documentElement.scrollTop || 0;
|
||||
}
|
||||
// Cleanup function, registered by nonWrapping and wrapping.
|
||||
var clear = function(){};
|
||||
sizeBar();
|
||||
var sizeInterval = setInterval(sizeBar, 500);
|
||||
|
||||
function ensureEnoughLineNumbers(fill) {
|
||||
var lineHeight = scroller.firstChild.offsetHeight;
|
||||
if (lineHeight == 0) return;
|
||||
var targetHeight = 50 + Math.max(body.offsetHeight, Math.max(frame.offsetHeight, body.scrollHeight || 0)),
|
||||
lastNumber = Math.ceil(targetHeight / lineHeight);
|
||||
for (var i = scroller.childNodes.length; i <= lastNumber; i++) {
|
||||
var div = createHTMLElement("div");
|
||||
div.appendChild(document.createTextNode(fill ? String(i + self.options.firstLineNumber) : "\u00a0"));
|
||||
scroller.appendChild(div);
|
||||
}
|
||||
}
|
||||
|
||||
function nonWrapping() {
|
||||
function update() {
|
||||
ensureEnoughLineNumbers(true);
|
||||
doScroll();
|
||||
}
|
||||
self.updateNumbers = update;
|
||||
var onScroll = win.addEventHandler(win, "scroll", doScroll, true),
|
||||
onResize = win.addEventHandler(win, "resize", update, true);
|
||||
clear = function(){
|
||||
onScroll(); onResize();
|
||||
if (self.updateNumbers == update) self.updateNumbers = null;
|
||||
};
|
||||
update();
|
||||
}
|
||||
|
||||
function wrapping() {
|
||||
var node, lineNum, next, pos, changes = [], styleNums = self.options.styleNumbers;
|
||||
|
||||
function setNum(n, node) {
|
||||
// Does not typically happen (but can, if you mess with the
|
||||
// document during the numbering)
|
||||
if (!lineNum) lineNum = scroller.appendChild(createHTMLElement("div"));
|
||||
if (styleNums) styleNums(lineNum, node, n);
|
||||
// Changes are accumulated, so that the document layout
|
||||
// doesn't have to be recomputed during the pass
|
||||
changes.push(lineNum); changes.push(n);
|
||||
pos = lineNum.offsetHeight + lineNum.offsetTop;
|
||||
lineNum = lineNum.nextSibling;
|
||||
}
|
||||
function commitChanges() {
|
||||
for (var i = 0; i < changes.length; i += 2)
|
||||
changes[i].innerHTML = changes[i + 1];
|
||||
changes = [];
|
||||
}
|
||||
function work() {
|
||||
if (!scroller.parentNode || scroller.parentNode != self.lineNumbers) return;
|
||||
|
||||
var endTime = new Date().getTime() + self.options.lineNumberTime;
|
||||
while (node) {
|
||||
setNum(next++, node.previousSibling);
|
||||
for (; node && !win.isBR(node); node = node.nextSibling) {
|
||||
var bott = node.offsetTop + node.offsetHeight;
|
||||
while (scroller.offsetHeight && bott - 3 > pos) {
|
||||
var oldPos = pos;
|
||||
setNum(" ");
|
||||
if (pos <= oldPos) break;
|
||||
}
|
||||
}
|
||||
if (node) node = node.nextSibling;
|
||||
if (new Date().getTime() > endTime) {
|
||||
commitChanges();
|
||||
pending = setTimeout(work, self.options.lineNumberDelay);
|
||||
return;
|
||||
}
|
||||
}
|
||||
while (lineNum) setNum(next++);
|
||||
commitChanges();
|
||||
doScroll();
|
||||
}
|
||||
function start(firstTime) {
|
||||
doScroll();
|
||||
ensureEnoughLineNumbers(firstTime);
|
||||
node = body.firstChild;
|
||||
lineNum = scroller.firstChild;
|
||||
pos = 0;
|
||||
next = self.options.firstLineNumber;
|
||||
work();
|
||||
}
|
||||
|
||||
start(true);
|
||||
var pending = null;
|
||||
function update() {
|
||||
if (pending) clearTimeout(pending);
|
||||
if (self.editor.allClean()) start();
|
||||
else pending = setTimeout(update, 200);
|
||||
}
|
||||
self.updateNumbers = update;
|
||||
var onScroll = win.addEventHandler(win, "scroll", doScroll, true),
|
||||
onResize = win.addEventHandler(win, "resize", update, true);
|
||||
clear = function(){
|
||||
if (pending) clearTimeout(pending);
|
||||
if (self.updateNumbers == update) self.updateNumbers = null;
|
||||
onScroll();
|
||||
onResize();
|
||||
};
|
||||
}
|
||||
(this.options.textWrapping || this.options.styleNumbers ? wrapping : nonWrapping)();
|
||||
},
|
||||
|
||||
setDynamicHeight: function() {
|
||||
var self = this, activity = self.options.onCursorActivity, win = self.win, body = win.document.body,
|
||||
lineHeight = null, timeout = null, vmargin = 2 * self.frame.offsetTop;
|
||||
body.style.overflowY = "hidden";
|
||||
win.document.documentElement.style.overflowY = "hidden";
|
||||
this.frame.scrolling = "no";
|
||||
|
||||
function updateHeight() {
|
||||
var trailingLines = 0, node = body.lastChild, computedHeight;
|
||||
while (node && win.isBR(node)) {
|
||||
if (!node.hackBR) trailingLines++;
|
||||
node = node.previousSibling;
|
||||
}
|
||||
if (node) {
|
||||
lineHeight = node.offsetHeight;
|
||||
computedHeight = node.offsetTop + (1 + trailingLines) * lineHeight;
|
||||
}
|
||||
else if (lineHeight) {
|
||||
computedHeight = trailingLines * lineHeight;
|
||||
}
|
||||
if (computedHeight)
|
||||
self.wrapping.style.height = Math.max(vmargin + computedHeight, self.options.minHeight) + "px";
|
||||
}
|
||||
setTimeout(updateHeight, 300);
|
||||
self.options.onCursorActivity = function(x) {
|
||||
if (activity) activity(x);
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(updateHeight, 100);
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
CodeMirror.InvalidLineHandle = {toString: function(){return "CodeMirror.InvalidLineHandle";}};
|
||||
|
||||
CodeMirror.replace = function(element) {
|
||||
if (typeof element == "string")
|
||||
element = document.getElementById(element);
|
||||
return function(newElement) {
|
||||
element.parentNode.replaceChild(newElement, element);
|
||||
};
|
||||
};
|
||||
|
||||
CodeMirror.fromTextArea = function(area, options) {
|
||||
if (typeof area == "string")
|
||||
area = document.getElementById(area);
|
||||
|
||||
options = options || {};
|
||||
if (area.style.width && options.width == null)
|
||||
options.width = area.style.width;
|
||||
if (area.style.height && options.height == null)
|
||||
options.height = area.style.height;
|
||||
if (options.content == null) options.content = area.value;
|
||||
|
||||
function updateField() {
|
||||
area.value = mirror.getCode();
|
||||
}
|
||||
if (area.form) {
|
||||
if (typeof area.form.addEventListener == "function")
|
||||
area.form.addEventListener("submit", updateField, false);
|
||||
else
|
||||
area.form.attachEvent("onsubmit", updateField);
|
||||
var realSubmit = area.form.submit;
|
||||
function wrapSubmit() {
|
||||
updateField();
|
||||
// Can't use realSubmit.apply because IE6 is too stupid
|
||||
area.form.submit = realSubmit;
|
||||
area.form.submit();
|
||||
area.form.submit = wrapSubmit;
|
||||
}
|
||||
area.form.submit = wrapSubmit;
|
||||
}
|
||||
|
||||
function insert(frame) {
|
||||
if (area.nextSibling)
|
||||
area.parentNode.insertBefore(frame, area.nextSibling);
|
||||
else
|
||||
area.parentNode.appendChild(frame);
|
||||
}
|
||||
|
||||
area.style.display = "none";
|
||||
var mirror = new CodeMirror(insert, options);
|
||||
mirror.save = updateField;
|
||||
mirror.toTextArea = function() {
|
||||
updateField();
|
||||
area.parentNode.removeChild(mirror.wrapping);
|
||||
area.style.display = "";
|
||||
if (area.form) {
|
||||
area.form.submit = realSubmit;
|
||||
if (typeof area.form.removeEventListener == "function")
|
||||
area.form.removeEventListener("submit", updateField, false);
|
||||
else
|
||||
area.form.detachEvent("onsubmit", updateField);
|
||||
}
|
||||
};
|
||||
|
||||
return mirror;
|
||||
};
|
||||
|
||||
CodeMirror.isProbablySupported = function() {
|
||||
// This is rather awful, but can be useful.
|
||||
var match;
|
||||
if (window.opera)
|
||||
return Number(window.opera.version()) >= 9.52;
|
||||
else if (/Apple Computer, Inc/.test(navigator.vendor) && (match = navigator.userAgent.match(/Version\/(\d+(?:\.\d+)?)\./)))
|
||||
return Number(match[1]) >= 3;
|
||||
else if (document.selection && window.ActiveXObject && (match = navigator.userAgent.match(/MSIE (\d+(?:\.\d*)?)\b/)))
|
||||
return Number(match[1]) >= 6;
|
||||
else if (match = navigator.userAgent.match(/gecko\/(\d{8})/i))
|
||||
return Number(match[1]) >= 20050901;
|
||||
else if (match = navigator.userAgent.match(/AppleWebKit\/(\d+)/))
|
||||
return Number(match[1]) >= 525;
|
||||
else
|
||||
return null;
|
||||
};
|
||||
|
||||
return CodeMirror;
|
||||
})();
|
||||
1670
gulliver/js/codemirror/js/editor.js
Executable file
1670
gulliver/js/codemirror/js/editor.js
Executable file
File diff suppressed because it is too large
Load Diff
68
gulliver/js/codemirror/js/highlight.js
Executable file
68
gulliver/js/codemirror/js/highlight.js
Executable file
@@ -0,0 +1,68 @@
|
||||
// Minimal framing needed to use CodeMirror-style parsers to highlight
|
||||
// code. Load this along with tokenize.js, stringstream.js, and your
|
||||
// parser. Then call highlightText, passing a string as the first
|
||||
// argument, and as the second argument either a callback function
|
||||
// that will be called with an array of SPAN nodes for every line in
|
||||
// the code, or a DOM node to which to append these spans, and
|
||||
// optionally (not needed if you only loaded one parser) a parser
|
||||
// object.
|
||||
|
||||
// Stuff from util.js that the parsers are using.
|
||||
var StopIteration = {toString: function() {return "StopIteration"}};
|
||||
|
||||
var Editor = {};
|
||||
var indentUnit = 2;
|
||||
|
||||
(function(){
|
||||
function normaliseString(string) {
|
||||
var tab = "";
|
||||
for (var i = 0; i < indentUnit; i++) tab += " ";
|
||||
|
||||
string = string.replace(/\t/g, tab).replace(/\u00a0/g, " ").replace(/\r\n?/g, "\n");
|
||||
var pos = 0, parts = [], lines = string.split("\n");
|
||||
for (var line = 0; line < lines.length; line++) {
|
||||
if (line != 0) parts.push("\n");
|
||||
parts.push(lines[line]);
|
||||
}
|
||||
|
||||
return {
|
||||
next: function() {
|
||||
if (pos < parts.length) return parts[pos++];
|
||||
else throw StopIteration;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
window.highlightText = function(string, callback, parser) {
|
||||
parser = (parser || Editor.Parser).make(stringStream(normaliseString(string)));
|
||||
var line = [];
|
||||
if (callback.nodeType == 1) {
|
||||
var node = callback;
|
||||
callback = function(line) {
|
||||
for (var i = 0; i < line.length; i++)
|
||||
node.appendChild(line[i]);
|
||||
node.appendChild(document.createElement("br"));
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
while (true) {
|
||||
var token = parser.next();
|
||||
if (token.value == "\n") {
|
||||
callback(line);
|
||||
line = [];
|
||||
}
|
||||
else {
|
||||
var span = document.createElement("span");
|
||||
span.className = token.style;
|
||||
span.appendChild(document.createTextNode(token.value));
|
||||
line.push(span);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
if (e != StopIteration) throw e;
|
||||
}
|
||||
if (line.length) callback(line);
|
||||
}
|
||||
})();
|
||||
81
gulliver/js/codemirror/js/mirrorframe.js
Executable file
81
gulliver/js/codemirror/js/mirrorframe.js
Executable file
@@ -0,0 +1,81 @@
|
||||
/* Demonstration of embedding CodeMirror in a bigger application. The
|
||||
* interface defined here is a mess of prompts and confirms, and
|
||||
* should probably not be used in a real project.
|
||||
*/
|
||||
|
||||
function MirrorFrame(place, options) {
|
||||
this.home = document.createElement("div");
|
||||
if (place.appendChild)
|
||||
place.appendChild(this.home);
|
||||
else
|
||||
place(this.home);
|
||||
|
||||
var self = this;
|
||||
function makeButton(name, action) {
|
||||
var button = document.createElement("input");
|
||||
button.type = "button";
|
||||
button.value = name;
|
||||
self.home.appendChild(button);
|
||||
button.onclick = function(){self[action].call(self);};
|
||||
}
|
||||
|
||||
makeButton("Search", "search");
|
||||
makeButton("Replace", "replace");
|
||||
makeButton("Current line", "line");
|
||||
makeButton("Jump to line", "jump");
|
||||
makeButton("Insert constructor", "macro");
|
||||
makeButton("Indent all", "reindent");
|
||||
|
||||
this.mirror = new CodeMirror(this.home, options);
|
||||
}
|
||||
|
||||
MirrorFrame.prototype = {
|
||||
search: function() {
|
||||
var text = prompt("Enter search term:", "");
|
||||
if (!text) return;
|
||||
|
||||
var first = true;
|
||||
do {
|
||||
var cursor = this.mirror.getSearchCursor(text, first);
|
||||
first = false;
|
||||
while (cursor.findNext()) {
|
||||
cursor.select();
|
||||
if (!confirm("Search again?"))
|
||||
return;
|
||||
}
|
||||
} while (confirm("End of document reached. Start over?"));
|
||||
},
|
||||
|
||||
replace: function() {
|
||||
// This is a replace-all, but it is possible to implement a
|
||||
// prompting replace.
|
||||
var from = prompt("Enter search string:", ""), to;
|
||||
if (from) to = prompt("What should it be replaced with?", "");
|
||||
if (to == null) return;
|
||||
|
||||
var cursor = this.mirror.getSearchCursor(from, false);
|
||||
while (cursor.findNext())
|
||||
cursor.replace(to);
|
||||
},
|
||||
|
||||
jump: function() {
|
||||
var line = prompt("Jump to line:", "");
|
||||
if (line && !isNaN(Number(line)))
|
||||
this.mirror.jumpToLine(Number(line));
|
||||
},
|
||||
|
||||
line: function() {
|
||||
alert("The cursor is currently at line " + this.mirror.currentLine());
|
||||
this.mirror.focus();
|
||||
},
|
||||
|
||||
macro: function() {
|
||||
var name = prompt("Name your constructor:", "");
|
||||
if (name)
|
||||
this.mirror.replaceSelection("function " + name + "() {\n \n}\n\n" + name + ".prototype = {\n \n};\n");
|
||||
},
|
||||
|
||||
reindent: function() {
|
||||
this.mirror.reindent();
|
||||
}
|
||||
};
|
||||
161
gulliver/js/codemirror/js/parsecss.js
Executable file
161
gulliver/js/codemirror/js/parsecss.js
Executable file
@@ -0,0 +1,161 @@
|
||||
/* Simple parser for CSS */
|
||||
|
||||
var CSSParser = Editor.Parser = (function() {
|
||||
var tokenizeCSS = (function() {
|
||||
function normal(source, setState) {
|
||||
var ch = source.next();
|
||||
if (ch == "@") {
|
||||
source.nextWhileMatches(/\w/);
|
||||
return "css-at";
|
||||
}
|
||||
else if (ch == "/" && source.equals("*")) {
|
||||
setState(inCComment);
|
||||
return null;
|
||||
}
|
||||
else if (ch == "<" && source.equals("!")) {
|
||||
setState(inSGMLComment);
|
||||
return null;
|
||||
}
|
||||
else if (ch == "=") {
|
||||
return "css-compare";
|
||||
}
|
||||
else if (source.equals("=") && (ch == "~" || ch == "|")) {
|
||||
source.next();
|
||||
return "css-compare";
|
||||
}
|
||||
else if (ch == "\"" || ch == "'") {
|
||||
setState(inString(ch));
|
||||
return null;
|
||||
}
|
||||
else if (ch == "#") {
|
||||
source.nextWhileMatches(/\w/);
|
||||
return "css-hash";
|
||||
}
|
||||
else if (ch == "!") {
|
||||
source.nextWhileMatches(/[ \t]/);
|
||||
source.nextWhileMatches(/\w/);
|
||||
return "css-important";
|
||||
}
|
||||
else if (/\d/.test(ch)) {
|
||||
source.nextWhileMatches(/[\w.%]/);
|
||||
return "css-unit";
|
||||
}
|
||||
else if (/[,.+>*\/]/.test(ch)) {
|
||||
return "css-select-op";
|
||||
}
|
||||
else if (/[;{}:\[\]]/.test(ch)) {
|
||||
return "css-punctuation";
|
||||
}
|
||||
else {
|
||||
source.nextWhileMatches(/[\w\\\-_]/);
|
||||
return "css-identifier";
|
||||
}
|
||||
}
|
||||
|
||||
function inCComment(source, setState) {
|
||||
var maybeEnd = false;
|
||||
while (!source.endOfLine()) {
|
||||
var ch = source.next();
|
||||
if (maybeEnd && ch == "/") {
|
||||
setState(normal);
|
||||
break;
|
||||
}
|
||||
maybeEnd = (ch == "*");
|
||||
}
|
||||
return "css-comment";
|
||||
}
|
||||
|
||||
function inSGMLComment(source, setState) {
|
||||
var dashes = 0;
|
||||
while (!source.endOfLine()) {
|
||||
var ch = source.next();
|
||||
if (dashes >= 2 && ch == ">") {
|
||||
setState(normal);
|
||||
break;
|
||||
}
|
||||
dashes = (ch == "-") ? dashes + 1 : 0;
|
||||
}
|
||||
return "css-comment";
|
||||
}
|
||||
|
||||
function inString(quote) {
|
||||
return function(source, setState) {
|
||||
var escaped = false;
|
||||
while (!source.endOfLine()) {
|
||||
var ch = source.next();
|
||||
if (ch == quote && !escaped)
|
||||
break;
|
||||
escaped = !escaped && ch == "\\";
|
||||
}
|
||||
if (!escaped)
|
||||
setState(normal);
|
||||
return "css-string";
|
||||
};
|
||||
}
|
||||
|
||||
return function(source, startState) {
|
||||
return tokenizer(source, startState || normal);
|
||||
};
|
||||
})();
|
||||
|
||||
function indentCSS(inBraces, inRule, base) {
|
||||
return function(nextChars) {
|
||||
if (!inBraces || /^\}/.test(nextChars)) return base;
|
||||
else if (inRule) return base + indentUnit * 2;
|
||||
else return base + indentUnit;
|
||||
};
|
||||
}
|
||||
|
||||
// This is a very simplistic parser -- since CSS does not really
|
||||
// nest, it works acceptably well, but some nicer colouroing could
|
||||
// be provided with a more complicated parser.
|
||||
function parseCSS(source, basecolumn) {
|
||||
basecolumn = basecolumn || 0;
|
||||
var tokens = tokenizeCSS(source);
|
||||
var inBraces = false, inRule = false, inDecl = false;;
|
||||
|
||||
var iter = {
|
||||
next: function() {
|
||||
var token = tokens.next(), style = token.style, content = token.content;
|
||||
|
||||
if (style == "css-hash")
|
||||
style = token.style = inRule ? "css-colorcode" : "css-identifier";
|
||||
if (style == "css-identifier") {
|
||||
if (inRule) token.style = "css-value";
|
||||
else if (!inBraces && !inDecl) token.style = "css-selector";
|
||||
}
|
||||
|
||||
if (content == "\n")
|
||||
token.indentation = indentCSS(inBraces, inRule, basecolumn);
|
||||
|
||||
if (content == "{" && inDecl == "@media")
|
||||
inDecl = false;
|
||||
else if (content == "{")
|
||||
inBraces = true;
|
||||
else if (content == "}")
|
||||
inBraces = inRule = inDecl = false;
|
||||
else if (content == ";")
|
||||
inRule = inDecl = false;
|
||||
else if (inBraces && style != "css-comment" && style != "whitespace")
|
||||
inRule = true;
|
||||
else if (!inBraces && style == "css-at")
|
||||
inDecl = content;
|
||||
|
||||
return token;
|
||||
},
|
||||
|
||||
copy: function() {
|
||||
var _inBraces = inBraces, _inRule = inRule, _tokenState = tokens.state;
|
||||
return function(source) {
|
||||
tokens = tokenizeCSS(source, _tokenState);
|
||||
inBraces = _inBraces;
|
||||
inRule = _inRule;
|
||||
return iter;
|
||||
};
|
||||
}
|
||||
};
|
||||
return iter;
|
||||
}
|
||||
|
||||
return {make: parseCSS, electricChars: "}"};
|
||||
})();
|
||||
32
gulliver/js/codemirror/js/parsedummy.js
Executable file
32
gulliver/js/codemirror/js/parsedummy.js
Executable file
@@ -0,0 +1,32 @@
|
||||
var DummyParser = Editor.Parser = (function() {
|
||||
function tokenizeDummy(source) {
|
||||
while (!source.endOfLine()) source.next();
|
||||
return "text";
|
||||
}
|
||||
function parseDummy(source) {
|
||||
function indentTo(n) {return function() {return n;}}
|
||||
source = tokenizer(source, tokenizeDummy);
|
||||
var space = 0;
|
||||
|
||||
var iter = {
|
||||
next: function() {
|
||||
var tok = source.next();
|
||||
if (tok.type == "whitespace") {
|
||||
if (tok.value == "\n") tok.indentation = indentTo(space);
|
||||
else space = tok.value.length;
|
||||
}
|
||||
return tok;
|
||||
},
|
||||
copy: function() {
|
||||
var _space = space;
|
||||
return function(_source) {
|
||||
space = _space;
|
||||
source = tokenizer(_source, tokenizeDummy);
|
||||
return iter;
|
||||
};
|
||||
}
|
||||
};
|
||||
return iter;
|
||||
}
|
||||
return {make: parseDummy};
|
||||
})();
|
||||
93
gulliver/js/codemirror/js/parsehtmlmixed.js
Executable file
93
gulliver/js/codemirror/js/parsehtmlmixed.js
Executable file
@@ -0,0 +1,93 @@
|
||||
var HTMLMixedParser = Editor.Parser = (function() {
|
||||
|
||||
// tags that trigger seperate parsers
|
||||
var triggers = {
|
||||
"script": "JSParser",
|
||||
"style": "CSSParser"
|
||||
};
|
||||
|
||||
function checkDependencies() {
|
||||
var parsers = ['XMLParser'];
|
||||
for (var p in triggers) parsers.push(triggers[p]);
|
||||
for (var i in parsers) {
|
||||
if (!window[parsers[i]]) throw new Error(parsers[i] + " parser must be loaded for HTML mixed mode to work.");
|
||||
}
|
||||
XMLParser.configure({useHTMLKludges: true});
|
||||
}
|
||||
|
||||
function parseMixed(stream) {
|
||||
checkDependencies();
|
||||
var htmlParser = XMLParser.make(stream), localParser = null, inTag = false;
|
||||
var iter = {next: top, copy: copy};
|
||||
|
||||
function top() {
|
||||
var token = htmlParser.next();
|
||||
if (token.content == "<")
|
||||
inTag = true;
|
||||
else if (token.style == "xml-tagname" && inTag === true)
|
||||
inTag = token.content.toLowerCase();
|
||||
else if (token.content == ">") {
|
||||
if (triggers[inTag]) {
|
||||
var parser = window[triggers[inTag]];
|
||||
iter.next = local(parser, "</" + inTag);
|
||||
}
|
||||
inTag = false;
|
||||
}
|
||||
return token;
|
||||
}
|
||||
function local(parser, tag) {
|
||||
var baseIndent = htmlParser.indentation();
|
||||
localParser = parser.make(stream, baseIndent + indentUnit);
|
||||
return function() {
|
||||
if (stream.lookAhead(tag, false, false, true)) {
|
||||
localParser = null;
|
||||
iter.next = top;
|
||||
return top();
|
||||
}
|
||||
|
||||
var token = localParser.next();
|
||||
var lt = token.value.lastIndexOf("<"), sz = Math.min(token.value.length - lt, tag.length);
|
||||
if (lt != -1 && token.value.slice(lt, lt + sz).toLowerCase() == tag.slice(0, sz) &&
|
||||
stream.lookAhead(tag.slice(sz), false, false, true)) {
|
||||
stream.push(token.value.slice(lt));
|
||||
token.value = token.value.slice(0, lt);
|
||||
}
|
||||
|
||||
if (token.indentation) {
|
||||
var oldIndent = token.indentation;
|
||||
token.indentation = function(chars) {
|
||||
if (chars == "</")
|
||||
return baseIndent;
|
||||
else
|
||||
return oldIndent(chars);
|
||||
};
|
||||
}
|
||||
|
||||
return token;
|
||||
};
|
||||
}
|
||||
|
||||
function copy() {
|
||||
var _html = htmlParser.copy(), _local = localParser && localParser.copy(),
|
||||
_next = iter.next, _inTag = inTag;
|
||||
return function(_stream) {
|
||||
stream = _stream;
|
||||
htmlParser = _html(_stream);
|
||||
localParser = _local && _local(_stream);
|
||||
iter.next = _next;
|
||||
inTag = _inTag;
|
||||
return iter;
|
||||
};
|
||||
}
|
||||
return iter;
|
||||
}
|
||||
|
||||
return {
|
||||
make: parseMixed,
|
||||
electricChars: "{}/:",
|
||||
configure: function(obj) {
|
||||
if (obj.triggers) triggers = obj.triggers;
|
||||
}
|
||||
};
|
||||
|
||||
})();
|
||||
359
gulliver/js/codemirror/js/parsejavascript.js
Executable file
359
gulliver/js/codemirror/js/parsejavascript.js
Executable file
@@ -0,0 +1,359 @@
|
||||
/* Parse function for JavaScript. Makes use of the tokenizer from
|
||||
* tokenizejavascript.js. Note that your parsers do not have to be
|
||||
* this complicated -- if you don't want to recognize local variables,
|
||||
* in many languages it is enough to just look for braces, semicolons,
|
||||
* parentheses, etc, and know when you are inside a string or comment.
|
||||
*
|
||||
* See manual.html for more info about the parser interface.
|
||||
*/
|
||||
|
||||
var JSParser = Editor.Parser = (function() {
|
||||
// Token types that can be considered to be atoms.
|
||||
var atomicTypes = {"atom": true, "number": true, "variable": true, "string": true, "regexp": true};
|
||||
// Setting that can be used to have JSON data indent properly.
|
||||
var json = false;
|
||||
// Constructor for the lexical context objects.
|
||||
function JSLexical(indented, column, type, align, prev, info) {
|
||||
// indentation at start of this line
|
||||
this.indented = indented;
|
||||
// column at which this scope was opened
|
||||
this.column = column;
|
||||
// type of scope ('vardef', 'stat' (statement), 'form' (special form), '[', '{', or '(')
|
||||
this.type = type;
|
||||
// '[', '{', or '(' blocks that have any text after their opening
|
||||
// character are said to be 'aligned' -- any lines below are
|
||||
// indented all the way to the opening character.
|
||||
if (align != null)
|
||||
this.align = align;
|
||||
// Parent scope, if any.
|
||||
this.prev = prev;
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
// My favourite JavaScript indentation rules.
|
||||
function indentJS(lexical) {
|
||||
return function(firstChars) {
|
||||
var firstChar = firstChars && firstChars.charAt(0), type = lexical.type;
|
||||
var closing = firstChar == type;
|
||||
if (type == "vardef")
|
||||
return lexical.indented + 4;
|
||||
else if (type == "form" && firstChar == "{")
|
||||
return lexical.indented;
|
||||
else if (type == "stat" || type == "form")
|
||||
return lexical.indented + indentUnit;
|
||||
else if (lexical.info == "switch" && !closing)
|
||||
return lexical.indented + (/^(?:case|default)\b/.test(firstChars) ? indentUnit : 2 * indentUnit);
|
||||
else if (lexical.align)
|
||||
return lexical.column - (closing ? 1 : 0);
|
||||
else
|
||||
return lexical.indented + (closing ? 0 : indentUnit);
|
||||
};
|
||||
}
|
||||
|
||||
// The parser-iterator-producing function itself.
|
||||
function parseJS(input, basecolumn) {
|
||||
// Wrap the input in a token stream
|
||||
var tokens = tokenizeJavaScript(input);
|
||||
// The parser state. cc is a stack of actions that have to be
|
||||
// performed to finish the current statement. For example we might
|
||||
// know that we still need to find a closing parenthesis and a
|
||||
// semicolon. Actions at the end of the stack go first. It is
|
||||
// initialized with an infinitely looping action that consumes
|
||||
// whole statements.
|
||||
var cc = [json ? expressions : statements];
|
||||
// Context contains information about the current local scope, the
|
||||
// variables defined in that, and the scopes above it.
|
||||
var context = null;
|
||||
// The lexical scope, used mostly for indentation.
|
||||
var lexical = new JSLexical((basecolumn || 0) - indentUnit, 0, "block", false);
|
||||
// Current column, and the indentation at the start of the current
|
||||
// line. Used to create lexical scope objects.
|
||||
var column = 0;
|
||||
var indented = 0;
|
||||
// Variables which are used by the mark, cont, and pass functions
|
||||
// below to communicate with the driver loop in the 'next'
|
||||
// function.
|
||||
var consume, marked;
|
||||
|
||||
// The iterator object.
|
||||
var parser = {next: next, copy: copy};
|
||||
|
||||
function next(){
|
||||
// Start by performing any 'lexical' actions (adjusting the
|
||||
// lexical variable), or the operations below will be working
|
||||
// with the wrong lexical state.
|
||||
while(cc[cc.length - 1].lex)
|
||||
cc.pop()();
|
||||
|
||||
// Fetch a token.
|
||||
var token = tokens.next();
|
||||
|
||||
// Adjust column and indented.
|
||||
if (token.type == "whitespace" && column == 0)
|
||||
indented = token.value.length;
|
||||
column += token.value.length;
|
||||
if (token.content == "\n"){
|
||||
indented = column = 0;
|
||||
// If the lexical scope's align property is still undefined at
|
||||
// the end of the line, it is an un-aligned scope.
|
||||
if (!("align" in lexical))
|
||||
lexical.align = false;
|
||||
// Newline tokens get an indentation function associated with
|
||||
// them.
|
||||
token.indentation = indentJS(lexical);
|
||||
}
|
||||
// No more processing for meaningless tokens.
|
||||
if (token.type == "whitespace" || token.type == "comment")
|
||||
return token;
|
||||
// When a meaningful token is found and the lexical scope's
|
||||
// align is undefined, it is an aligned scope.
|
||||
if (!("align" in lexical))
|
||||
lexical.align = true;
|
||||
|
||||
// Execute actions until one 'consumes' the token and we can
|
||||
// return it.
|
||||
while(true) {
|
||||
consume = marked = false;
|
||||
// Take and execute the topmost action.
|
||||
cc.pop()(token.type, token.content);
|
||||
if (consume){
|
||||
// Marked is used to change the style of the current token.
|
||||
if (marked)
|
||||
token.style = marked;
|
||||
// Here we differentiate between local and global variables.
|
||||
else if (token.type == "variable" && inScope(token.content))
|
||||
token.style = "js-localvariable";
|
||||
return token;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This makes a copy of the parser state. It stores all the
|
||||
// stateful variables in a closure, and returns a function that
|
||||
// will restore them when called with a new input stream. Note
|
||||
// that the cc array has to be copied, because it is contantly
|
||||
// being modified. Lexical objects are not mutated, and context
|
||||
// objects are not mutated in a harmful way, so they can be shared
|
||||
// between runs of the parser.
|
||||
function copy(){
|
||||
var _context = context, _lexical = lexical, _cc = cc.concat([]), _tokenState = tokens.state;
|
||||
|
||||
return function copyParser(input){
|
||||
context = _context;
|
||||
lexical = _lexical;
|
||||
cc = _cc.concat([]); // copies the array
|
||||
column = indented = 0;
|
||||
tokens = tokenizeJavaScript(input, _tokenState);
|
||||
return parser;
|
||||
};
|
||||
}
|
||||
|
||||
// Helper function for pushing a number of actions onto the cc
|
||||
// stack in reverse order.
|
||||
function push(fs){
|
||||
for (var i = fs.length - 1; i >= 0; i--)
|
||||
cc.push(fs[i]);
|
||||
}
|
||||
// cont and pass are used by the action functions to add other
|
||||
// actions to the stack. cont will cause the current token to be
|
||||
// consumed, pass will leave it for the next action.
|
||||
function cont(){
|
||||
push(arguments);
|
||||
consume = true;
|
||||
}
|
||||
function pass(){
|
||||
push(arguments);
|
||||
consume = false;
|
||||
}
|
||||
// Used to change the style of the current token.
|
||||
function mark(style){
|
||||
marked = style;
|
||||
}
|
||||
|
||||
// Push a new scope. Will automatically link the current scope.
|
||||
function pushcontext(){
|
||||
context = {prev: context, vars: {"this": true, "arguments": true}};
|
||||
}
|
||||
// Pop off the current scope.
|
||||
function popcontext(){
|
||||
context = context.prev;
|
||||
}
|
||||
// Register a variable in the current scope.
|
||||
function register(varname){
|
||||
if (context){
|
||||
mark("js-variabledef");
|
||||
context.vars[varname] = true;
|
||||
}
|
||||
}
|
||||
// Check whether a variable is defined in the current scope.
|
||||
function inScope(varname){
|
||||
var cursor = context;
|
||||
while (cursor) {
|
||||
if (cursor.vars[varname])
|
||||
return true;
|
||||
cursor = cursor.prev;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Push a new lexical context of the given type.
|
||||
function pushlex(type, info) {
|
||||
var result = function(){
|
||||
lexical = new JSLexical(indented, column, type, null, lexical, info)
|
||||
};
|
||||
result.lex = true;
|
||||
return result;
|
||||
}
|
||||
// Pop off the current lexical context.
|
||||
function poplex(){
|
||||
if (lexical.type == ")")
|
||||
indented = lexical.indented;
|
||||
lexical = lexical.prev;
|
||||
}
|
||||
poplex.lex = true;
|
||||
// The 'lex' flag on these actions is used by the 'next' function
|
||||
// to know they can (and have to) be ran before moving on to the
|
||||
// next token.
|
||||
|
||||
// Creates an action that discards tokens until it finds one of
|
||||
// the given type.
|
||||
function expect(wanted){
|
||||
return function expecting(type){
|
||||
if (type == wanted) cont();
|
||||
else if (wanted == ";") pass();
|
||||
else cont(arguments.callee);
|
||||
};
|
||||
}
|
||||
|
||||
// Looks for a statement, and then calls itself.
|
||||
function statements(type){
|
||||
return pass(statement, statements);
|
||||
}
|
||||
function expressions(type){
|
||||
return pass(expression, expressions);
|
||||
}
|
||||
// Dispatches various types of statements based on the type of the
|
||||
// current token.
|
||||
function statement(type){
|
||||
if (type == "var") cont(pushlex("vardef"), vardef1, expect(";"), poplex);
|
||||
else if (type == "keyword a") cont(pushlex("form"), expression, statement, poplex);
|
||||
else if (type == "keyword b") cont(pushlex("form"), statement, poplex);
|
||||
else if (type == "{") cont(pushlex("}"), block, poplex);
|
||||
else if (type == ";") cont();
|
||||
else if (type == "function") cont(functiondef);
|
||||
else if (type == "for") cont(pushlex("form"), expect("("), pushlex(")"), forspec1, expect(")"), poplex, statement, poplex);
|
||||
else if (type == "variable") cont(pushlex("stat"), maybelabel);
|
||||
else if (type == "switch") cont(pushlex("form"), expression, pushlex("}", "switch"), expect("{"), block, poplex, poplex);
|
||||
else if (type == "case") cont(expression, expect(":"));
|
||||
else if (type == "default") cont(expect(":"));
|
||||
else if (type == "catch") cont(pushlex("form"), pushcontext, expect("("), funarg, expect(")"), statement, poplex, popcontext);
|
||||
else pass(pushlex("stat"), expression, expect(";"), poplex);
|
||||
}
|
||||
// Dispatch expression types.
|
||||
function expression(type){
|
||||
if (atomicTypes.hasOwnProperty(type)) cont(maybeoperator);
|
||||
else if (type == "function") cont(functiondef);
|
||||
else if (type == "keyword c") cont(expression);
|
||||
else if (type == "(") cont(pushlex(")"), expression, expect(")"), poplex, maybeoperator);
|
||||
else if (type == "operator") cont(expression);
|
||||
else if (type == "[") cont(pushlex("]"), commasep(expression, "]"), poplex, maybeoperator);
|
||||
else if (type == "{") cont(pushlex("}"), commasep(objprop, "}"), poplex, maybeoperator);
|
||||
else cont();
|
||||
}
|
||||
// Called for places where operators, function calls, or
|
||||
// subscripts are valid. Will skip on to the next action if none
|
||||
// is found.
|
||||
function maybeoperator(type, value){
|
||||
if (type == "operator" && /\+\+|--/.test(value)) cont(maybeoperator);
|
||||
else if (type == "operator") cont(expression);
|
||||
else if (type == ";") pass();
|
||||
else if (type == "(") cont(pushlex(")"), commasep(expression, ")"), poplex, maybeoperator);
|
||||
else if (type == ".") cont(property, maybeoperator);
|
||||
else if (type == "[") cont(pushlex("]"), expression, expect("]"), poplex, maybeoperator);
|
||||
}
|
||||
// When a statement starts with a variable name, it might be a
|
||||
// label. If no colon follows, it's a regular statement.
|
||||
function maybelabel(type){
|
||||
if (type == ":") cont(poplex, statement);
|
||||
else pass(maybeoperator, expect(";"), poplex);
|
||||
}
|
||||
// Property names need to have their style adjusted -- the
|
||||
// tokenizer thinks they are variables.
|
||||
function property(type){
|
||||
if (type == "variable") {mark("js-property"); cont();}
|
||||
}
|
||||
// This parses a property and its value in an object literal.
|
||||
function objprop(type){
|
||||
if (type == "variable") mark("js-property");
|
||||
if (atomicTypes.hasOwnProperty(type)) cont(expect(":"), expression);
|
||||
}
|
||||
// Parses a comma-separated list of the things that are recognized
|
||||
// by the 'what' argument.
|
||||
function commasep(what, end){
|
||||
function proceed(type) {
|
||||
if (type == ",") cont(what, proceed);
|
||||
else if (type == end) cont();
|
||||
else cont(expect(end));
|
||||
}
|
||||
return function commaSeparated(type) {
|
||||
if (type == end) cont();
|
||||
else pass(what, proceed);
|
||||
};
|
||||
}
|
||||
// Look for statements until a closing brace is found.
|
||||
function block(type){
|
||||
if (type == "}") cont();
|
||||
else pass(statement, block);
|
||||
}
|
||||
// Variable definitions are split into two actions -- 1 looks for
|
||||
// a name or the end of the definition, 2 looks for an '=' sign or
|
||||
// a comma.
|
||||
function vardef1(type, value){
|
||||
if (type == "variable"){register(value); cont(vardef2);}
|
||||
else cont();
|
||||
}
|
||||
function vardef2(type, value){
|
||||
if (value == "=") cont(expression, vardef2);
|
||||
else if (type == ",") cont(vardef1);
|
||||
}
|
||||
// For loops.
|
||||
function forspec1(type){
|
||||
if (type == "var") cont(vardef1, forspec2);
|
||||
else if (type == ";") pass(forspec2);
|
||||
else if (type == "variable") cont(formaybein);
|
||||
else pass(forspec2);
|
||||
}
|
||||
function formaybein(type, value){
|
||||
if (value == "in") cont(expression);
|
||||
else cont(maybeoperator, forspec2);
|
||||
}
|
||||
function forspec2(type, value){
|
||||
if (type == ";") cont(forspec3);
|
||||
else if (value == "in") cont(expression);
|
||||
else cont(expression, expect(";"), forspec3);
|
||||
}
|
||||
function forspec3(type) {
|
||||
if (type == ")") pass();
|
||||
else cont(expression);
|
||||
}
|
||||
// A function definition creates a new context, and the variables
|
||||
// in its argument list have to be added to this context.
|
||||
function functiondef(type, value){
|
||||
if (type == "variable"){register(value); cont(functiondef);}
|
||||
else if (type == "(") cont(pushcontext, commasep(funarg, ")"), statement, popcontext);
|
||||
}
|
||||
function funarg(type, value){
|
||||
if (type == "variable"){register(value); cont();}
|
||||
}
|
||||
|
||||
return parser;
|
||||
}
|
||||
|
||||
return {
|
||||
make: parseJS,
|
||||
electricChars: "{}:",
|
||||
configure: function(obj) {
|
||||
if (obj.json != null) json = obj.json;
|
||||
}
|
||||
};
|
||||
})();
|
||||
162
gulliver/js/codemirror/js/parsesparql.js
Executable file
162
gulliver/js/codemirror/js/parsesparql.js
Executable file
@@ -0,0 +1,162 @@
|
||||
var SparqlParser = Editor.Parser = (function() {
|
||||
function wordRegexp(words) {
|
||||
return new RegExp("^(?:" + words.join("|") + ")$", "i");
|
||||
}
|
||||
var ops = wordRegexp(["str", "lang", "langmatches", "datatype", "bound", "sameterm", "isiri", "isuri",
|
||||
"isblank", "isliteral", "union", "a"]);
|
||||
var keywords = wordRegexp(["base", "prefix", "select", "distinct", "reduced", "construct", "describe",
|
||||
"ask", "from", "named", "where", "order", "limit", "offset", "filter", "optional",
|
||||
"graph", "by", "asc", "desc"]);
|
||||
var operatorChars = /[*+\-<>=&|]/;
|
||||
|
||||
var tokenizeSparql = (function() {
|
||||
function normal(source, setState) {
|
||||
var ch = source.next();
|
||||
if (ch == "$" || ch == "?") {
|
||||
source.nextWhileMatches(/[\w\d]/);
|
||||
return "sp-var";
|
||||
}
|
||||
else if (ch == "<" && !source.matches(/[\s\u00a0=]/)) {
|
||||
source.nextWhileMatches(/[^\s\u00a0>]/);
|
||||
if (source.equals(">")) source.next();
|
||||
return "sp-uri";
|
||||
}
|
||||
else if (ch == "\"" || ch == "'") {
|
||||
setState(inLiteral(ch));
|
||||
return null;
|
||||
}
|
||||
else if (/[{}\(\),\.;\[\]]/.test(ch)) {
|
||||
return "sp-punc";
|
||||
}
|
||||
else if (ch == "#") {
|
||||
while (!source.endOfLine()) source.next();
|
||||
return "sp-comment";
|
||||
}
|
||||
else if (operatorChars.test(ch)) {
|
||||
source.nextWhileMatches(operatorChars);
|
||||
return "sp-operator";
|
||||
}
|
||||
else if (ch == ":") {
|
||||
source.nextWhileMatches(/[\w\d\._\-]/);
|
||||
return "sp-prefixed";
|
||||
}
|
||||
else {
|
||||
source.nextWhileMatches(/[_\w\d]/);
|
||||
if (source.equals(":")) {
|
||||
source.next();
|
||||
source.nextWhileMatches(/[\w\d_\-]/);
|
||||
return "sp-prefixed";
|
||||
}
|
||||
var word = source.get(), type;
|
||||
if (ops.test(word))
|
||||
type = "sp-operator";
|
||||
else if (keywords.test(word))
|
||||
type = "sp-keyword";
|
||||
else
|
||||
type = "sp-word";
|
||||
return {style: type, content: word};
|
||||
}
|
||||
}
|
||||
|
||||
function inLiteral(quote) {
|
||||
return function(source, setState) {
|
||||
var escaped = false;
|
||||
while (!source.endOfLine()) {
|
||||
var ch = source.next();
|
||||
if (ch == quote && !escaped) {
|
||||
setState(normal);
|
||||
break;
|
||||
}
|
||||
escaped = !escaped && ch == "\\";
|
||||
}
|
||||
return "sp-literal";
|
||||
};
|
||||
}
|
||||
|
||||
return function(source, startState) {
|
||||
return tokenizer(source, startState || normal);
|
||||
};
|
||||
})();
|
||||
|
||||
function indentSparql(context) {
|
||||
return function(nextChars) {
|
||||
var firstChar = nextChars && nextChars.charAt(0);
|
||||
if (/[\]\}]/.test(firstChar))
|
||||
while (context && context.type == "pattern") context = context.prev;
|
||||
|
||||
var closing = context && firstChar == matching[context.type];
|
||||
if (!context)
|
||||
return 0;
|
||||
else if (context.type == "pattern")
|
||||
return context.col;
|
||||
else if (context.align)
|
||||
return context.col - (closing ? context.width : 0);
|
||||
else
|
||||
return context.indent + (closing ? 0 : indentUnit);
|
||||
}
|
||||
}
|
||||
|
||||
function parseSparql(source) {
|
||||
var tokens = tokenizeSparql(source);
|
||||
var context = null, indent = 0, col = 0;
|
||||
function pushContext(type, width) {
|
||||
context = {prev: context, indent: indent, col: col, type: type, width: width};
|
||||
}
|
||||
function popContext() {
|
||||
context = context.prev;
|
||||
}
|
||||
|
||||
var iter = {
|
||||
next: function() {
|
||||
var token = tokens.next(), type = token.style, content = token.content, width = token.value.length;
|
||||
|
||||
if (content == "\n") {
|
||||
token.indentation = indentSparql(context);
|
||||
indent = col = 0;
|
||||
if (context && context.align == null) context.align = false;
|
||||
}
|
||||
else if (type == "whitespace" && col == 0) {
|
||||
indent = width;
|
||||
}
|
||||
else if (type != "sp-comment" && context && context.align == null) {
|
||||
context.align = true;
|
||||
}
|
||||
|
||||
if (content != "\n") col += width;
|
||||
|
||||
if (/[\[\{\(]/.test(content)) {
|
||||
pushContext(content, width);
|
||||
}
|
||||
else if (/[\]\}\)]/.test(content)) {
|
||||
while (context && context.type == "pattern")
|
||||
popContext();
|
||||
if (context && content == matching[context.type])
|
||||
popContext();
|
||||
}
|
||||
else if (content == "." && context && context.type == "pattern") {
|
||||
popContext();
|
||||
}
|
||||
else if ((type == "sp-word" || type == "sp-prefixed" || type == "sp-uri" || type == "sp-var" || type == "sp-literal") &&
|
||||
context && /[\{\[]/.test(context.type)) {
|
||||
pushContext("pattern", width);
|
||||
}
|
||||
|
||||
return token;
|
||||
},
|
||||
|
||||
copy: function() {
|
||||
var _context = context, _indent = indent, _col = col, _tokenState = tokens.state;
|
||||
return function(source) {
|
||||
tokens = tokenizeSparql(source, _tokenState);
|
||||
context = _context;
|
||||
indent = _indent;
|
||||
col = _col;
|
||||
return iter;
|
||||
};
|
||||
}
|
||||
};
|
||||
return iter;
|
||||
}
|
||||
|
||||
return {make: parseSparql, electricChars: "}]"};
|
||||
})();
|
||||
291
gulliver/js/codemirror/js/parsexml.js
Executable file
291
gulliver/js/codemirror/js/parsexml.js
Executable file
@@ -0,0 +1,291 @@
|
||||
/* This file defines an XML parser, with a few kludges to make it
|
||||
* useable for HTML. autoSelfClosers defines a set of tag names that
|
||||
* are expected to not have a closing tag, and doNotIndent specifies
|
||||
* the tags inside of which no indentation should happen (see Config
|
||||
* object). These can be disabled by passing the editor an object like
|
||||
* {useHTMLKludges: false} as parserConfig option.
|
||||
*/
|
||||
|
||||
var XMLParser = Editor.Parser = (function() {
|
||||
var Kludges = {
|
||||
autoSelfClosers: {"br": true, "img": true, "hr": true, "link": true, "input": true,
|
||||
"meta": true, "col": true, "frame": true, "base": true, "area": true},
|
||||
doNotIndent: {"pre": true, "!cdata": true}
|
||||
};
|
||||
var NoKludges = {autoSelfClosers: {}, doNotIndent: {"!cdata": true}};
|
||||
var UseKludges = Kludges;
|
||||
var alignCDATA = false;
|
||||
|
||||
// Simple stateful tokenizer for XML documents. Returns a
|
||||
// MochiKit-style iterator, with a state property that contains a
|
||||
// function encapsulating the current state. See tokenize.js.
|
||||
var tokenizeXML = (function() {
|
||||
function inText(source, setState) {
|
||||
var ch = source.next();
|
||||
if (ch == "<") {
|
||||
if (source.equals("!")) {
|
||||
source.next();
|
||||
if (source.equals("[")) {
|
||||
if (source.lookAhead("[CDATA[", true)) {
|
||||
setState(inBlock("xml-cdata", "]]>"));
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
return "xml-text";
|
||||
}
|
||||
}
|
||||
else if (source.lookAhead("--", true)) {
|
||||
setState(inBlock("xml-comment", "-->"));
|
||||
return null;
|
||||
}
|
||||
else if (source.lookAhead("DOCTYPE", true)) {
|
||||
source.nextWhileMatches(/[\w\._\-]/);
|
||||
setState(inBlock("xml-doctype", ">"));
|
||||
return "xml-doctype";
|
||||
}
|
||||
else {
|
||||
return "xml-text";
|
||||
}
|
||||
}
|
||||
else if (source.equals("?")) {
|
||||
source.next();
|
||||
source.nextWhileMatches(/[\w\._\-]/);
|
||||
setState(inBlock("xml-processing", "?>"));
|
||||
return "xml-processing";
|
||||
}
|
||||
else {
|
||||
if (source.equals("/")) source.next();
|
||||
setState(inTag);
|
||||
return "xml-punctuation";
|
||||
}
|
||||
}
|
||||
else if (ch == "&") {
|
||||
while (!source.endOfLine()) {
|
||||
if (source.next() == ";")
|
||||
break;
|
||||
}
|
||||
return "xml-entity";
|
||||
}
|
||||
else {
|
||||
source.nextWhileMatches(/[^&<\n]/);
|
||||
return "xml-text";
|
||||
}
|
||||
}
|
||||
|
||||
function inTag(source, setState) {
|
||||
var ch = source.next();
|
||||
if (ch == ">") {
|
||||
setState(inText);
|
||||
return "xml-punctuation";
|
||||
}
|
||||
else if (/[?\/]/.test(ch) && source.equals(">")) {
|
||||
source.next();
|
||||
setState(inText);
|
||||
return "xml-punctuation";
|
||||
}
|
||||
else if (ch == "=") {
|
||||
return "xml-punctuation";
|
||||
}
|
||||
else if (/[\'\"]/.test(ch)) {
|
||||
setState(inAttribute(ch));
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
source.nextWhileMatches(/[^\s\u00a0=<>\"\'\/?]/);
|
||||
return "xml-name";
|
||||
}
|
||||
}
|
||||
|
||||
function inAttribute(quote) {
|
||||
return function(source, setState) {
|
||||
while (!source.endOfLine()) {
|
||||
if (source.next() == quote) {
|
||||
setState(inTag);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return "xml-attribute";
|
||||
};
|
||||
}
|
||||
|
||||
function inBlock(style, terminator) {
|
||||
return function(source, setState) {
|
||||
while (!source.endOfLine()) {
|
||||
if (source.lookAhead(terminator, true)) {
|
||||
setState(inText);
|
||||
break;
|
||||
}
|
||||
source.next();
|
||||
}
|
||||
return style;
|
||||
};
|
||||
}
|
||||
|
||||
return function(source, startState) {
|
||||
return tokenizer(source, startState || inText);
|
||||
};
|
||||
})();
|
||||
|
||||
// The parser. The structure of this function largely follows that of
|
||||
// parseJavaScript in parsejavascript.js (there is actually a bit more
|
||||
// shared code than I'd like), but it is quite a bit simpler.
|
||||
function parseXML(source) {
|
||||
var tokens = tokenizeXML(source), token;
|
||||
var cc = [base];
|
||||
var tokenNr = 0, indented = 0;
|
||||
var currentTag = null, context = null;
|
||||
var consume;
|
||||
|
||||
function push(fs) {
|
||||
for (var i = fs.length - 1; i >= 0; i--)
|
||||
cc.push(fs[i]);
|
||||
}
|
||||
function cont() {
|
||||
push(arguments);
|
||||
consume = true;
|
||||
}
|
||||
function pass() {
|
||||
push(arguments);
|
||||
consume = false;
|
||||
}
|
||||
|
||||
function markErr() {
|
||||
token.style += " xml-error";
|
||||
}
|
||||
function expect(text) {
|
||||
return function(style, content) {
|
||||
if (content == text) cont();
|
||||
else {markErr(); cont(arguments.callee);}
|
||||
};
|
||||
}
|
||||
|
||||
function pushContext(tagname, startOfLine) {
|
||||
var noIndent = UseKludges.doNotIndent.hasOwnProperty(tagname) || (context && context.noIndent);
|
||||
context = {prev: context, name: tagname, indent: indented, startOfLine: startOfLine, noIndent: noIndent};
|
||||
}
|
||||
function popContext() {
|
||||
context = context.prev;
|
||||
}
|
||||
function computeIndentation(baseContext) {
|
||||
return function(nextChars, current) {
|
||||
var context = baseContext;
|
||||
if (context && context.noIndent)
|
||||
return current;
|
||||
if (alignCDATA && /<!\[CDATA\[/.test(nextChars))
|
||||
return 0;
|
||||
if (context && /^<\//.test(nextChars))
|
||||
context = context.prev;
|
||||
while (context && !context.startOfLine)
|
||||
context = context.prev;
|
||||
if (context)
|
||||
return context.indent + indentUnit;
|
||||
else
|
||||
return 0;
|
||||
};
|
||||
}
|
||||
|
||||
function base() {
|
||||
return pass(element, base);
|
||||
}
|
||||
var harmlessTokens = {"xml-text": true, "xml-entity": true, "xml-comment": true, "xml-processing": true, "xml-doctype": true};
|
||||
function element(style, content) {
|
||||
if (content == "<") cont(tagname, attributes, endtag(tokenNr == 1));
|
||||
else if (content == "</") cont(closetagname, expect(">"));
|
||||
else if (style == "xml-cdata") {
|
||||
if (!context || context.name != "!cdata") pushContext("!cdata");
|
||||
if (/\]\]>$/.test(content)) popContext();
|
||||
cont();
|
||||
}
|
||||
else if (harmlessTokens.hasOwnProperty(style)) cont();
|
||||
else {markErr(); cont();}
|
||||
}
|
||||
function tagname(style, content) {
|
||||
if (style == "xml-name") {
|
||||
currentTag = content.toLowerCase();
|
||||
token.style = "xml-tagname";
|
||||
cont();
|
||||
}
|
||||
else {
|
||||
currentTag = null;
|
||||
pass();
|
||||
}
|
||||
}
|
||||
function closetagname(style, content) {
|
||||
if (style == "xml-name") {
|
||||
token.style = "xml-tagname";
|
||||
if (context && content.toLowerCase() == context.name) popContext();
|
||||
else markErr();
|
||||
}
|
||||
cont();
|
||||
}
|
||||
function endtag(startOfLine) {
|
||||
return function(style, content) {
|
||||
if (content == "/>" || (content == ">" && UseKludges.autoSelfClosers.hasOwnProperty(currentTag))) cont();
|
||||
else if (content == ">") {pushContext(currentTag, startOfLine); cont();}
|
||||
else {markErr(); cont(arguments.callee);}
|
||||
};
|
||||
}
|
||||
function attributes(style) {
|
||||
if (style == "xml-name") {token.style = "xml-attname"; cont(attribute, attributes);}
|
||||
else pass();
|
||||
}
|
||||
function attribute(style, content) {
|
||||
if (content == "=") cont(value);
|
||||
else if (content == ">" || content == "/>") pass(endtag);
|
||||
else pass();
|
||||
}
|
||||
function value(style) {
|
||||
if (style == "xml-attribute") cont(value);
|
||||
else pass();
|
||||
}
|
||||
|
||||
return {
|
||||
indentation: function() {return indented;},
|
||||
|
||||
next: function(){
|
||||
token = tokens.next();
|
||||
if (token.style == "whitespace" && tokenNr == 0)
|
||||
indented = token.value.length;
|
||||
else
|
||||
tokenNr++;
|
||||
if (token.content == "\n") {
|
||||
indented = tokenNr = 0;
|
||||
token.indentation = computeIndentation(context);
|
||||
}
|
||||
|
||||
if (token.style == "whitespace" || token.type == "xml-comment")
|
||||
return token;
|
||||
|
||||
while(true){
|
||||
consume = false;
|
||||
cc.pop()(token.style, token.content);
|
||||
if (consume) return token;
|
||||
}
|
||||
},
|
||||
|
||||
copy: function(){
|
||||
var _cc = cc.concat([]), _tokenState = tokens.state, _context = context;
|
||||
var parser = this;
|
||||
|
||||
return function(input){
|
||||
cc = _cc.concat([]);
|
||||
tokenNr = indented = 0;
|
||||
context = _context;
|
||||
tokens = tokenizeXML(input, _tokenState);
|
||||
return parser;
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
make: parseXML,
|
||||
electricChars: "/",
|
||||
configure: function(config) {
|
||||
if (config.useHTMLKludges != null)
|
||||
UseKludges = config.useHTMLKludges ? Kludges : NoKludges;
|
||||
if (config.alignCDATA)
|
||||
alignCDATA = config.alignCDATA;
|
||||
}
|
||||
};
|
||||
})();
|
||||
697
gulliver/js/codemirror/js/select.js
Executable file
697
gulliver/js/codemirror/js/select.js
Executable file
@@ -0,0 +1,697 @@
|
||||
/* Functionality for finding, storing, and restoring selections
|
||||
*
|
||||
* This does not provide a generic API, just the minimal functionality
|
||||
* required by the CodeMirror system.
|
||||
*/
|
||||
|
||||
// Namespace object.
|
||||
var select = {};
|
||||
|
||||
(function() {
|
||||
select.ie_selection = document.selection && document.selection.createRangeCollection;
|
||||
|
||||
// Find the 'top-level' (defined as 'a direct child of the node
|
||||
// passed as the top argument') node that the given node is
|
||||
// contained in. Return null if the given node is not inside the top
|
||||
// node.
|
||||
function topLevelNodeAt(node, top) {
|
||||
while (node && node.parentNode != top)
|
||||
node = node.parentNode;
|
||||
return node;
|
||||
}
|
||||
|
||||
// Find the top-level node that contains the node before this one.
|
||||
function topLevelNodeBefore(node, top) {
|
||||
while (!node.previousSibling && node.parentNode != top)
|
||||
node = node.parentNode;
|
||||
return topLevelNodeAt(node.previousSibling, top);
|
||||
}
|
||||
|
||||
var fourSpaces = "\u00a0\u00a0\u00a0\u00a0";
|
||||
|
||||
select.scrollToNode = function(node, cursor) {
|
||||
if (!node) return;
|
||||
var element = node, body = document.body,
|
||||
html = document.documentElement,
|
||||
atEnd = !element.nextSibling || !element.nextSibling.nextSibling
|
||||
|| !element.nextSibling.nextSibling.nextSibling;
|
||||
// In Opera (and recent Webkit versions), BR elements *always*
|
||||
// have a offsetTop property of zero.
|
||||
var compensateHack = 0;
|
||||
while (element && !element.offsetTop) {
|
||||
compensateHack++;
|
||||
element = element.previousSibling;
|
||||
}
|
||||
// atEnd is another kludge for these browsers -- if the cursor is
|
||||
// at the end of the document, and the node doesn't have an
|
||||
// offset, just scroll to the end.
|
||||
if (compensateHack == 0) atEnd = false;
|
||||
|
||||
// WebKit has a bad habit of (sometimes) happily returning bogus
|
||||
// offsets when the document has just been changed. This seems to
|
||||
// always be 5/5, so we don't use those.
|
||||
if (webkit && element && element.offsetTop == 5 && element.offsetLeft == 5)
|
||||
return;
|
||||
|
||||
var y = compensateHack * (element ? element.offsetHeight : 0), x = 0,
|
||||
width = (node ? node.offsetWidth : 0), pos = element;
|
||||
while (pos && pos.offsetParent) {
|
||||
y += pos.offsetTop;
|
||||
// Don't count X offset for <br> nodes
|
||||
if (!isBR(pos))
|
||||
x += pos.offsetLeft;
|
||||
pos = pos.offsetParent;
|
||||
}
|
||||
|
||||
var scroll_x = body.scrollLeft || html.scrollLeft || 0,
|
||||
scroll_y = body.scrollTop || html.scrollTop || 0,
|
||||
scroll = false, screen_width = window.innerWidth || html.clientWidth || 0;
|
||||
|
||||
if (cursor || width < screen_width) {
|
||||
if (cursor) {
|
||||
var off = select.offsetInNode(node), size = nodeText(node).length;
|
||||
if (size) x += width * (off / size);
|
||||
}
|
||||
var screen_x = x - scroll_x;
|
||||
if (screen_x < 0 || screen_x > screen_width) {
|
||||
scroll_x = x;
|
||||
scroll = true;
|
||||
}
|
||||
}
|
||||
var screen_y = y - scroll_y;
|
||||
if (screen_y < 0 || atEnd || screen_y > (window.innerHeight || html.clientHeight || 0) - 50) {
|
||||
scroll_y = atEnd ? 1e6 : y;
|
||||
scroll = true;
|
||||
}
|
||||
if (scroll) window.scrollTo(scroll_x, scroll_y);
|
||||
};
|
||||
|
||||
select.scrollToCursor = function(container) {
|
||||
select.scrollToNode(select.selectionTopNode(container, true) || container.firstChild, true);
|
||||
};
|
||||
|
||||
// Used to prevent restoring a selection when we do not need to.
|
||||
var currentSelection = null;
|
||||
|
||||
select.snapshotChanged = function() {
|
||||
if (currentSelection) currentSelection.changed = true;
|
||||
};
|
||||
|
||||
// Find the 'leaf' node (BR or text) after the given one.
|
||||
function baseNodeAfter(node) {
|
||||
var next = node.nextSibling;
|
||||
if (next) {
|
||||
while (next.firstChild) next = next.firstChild;
|
||||
if (next.nodeType == 3 || isBR(next)) return next;
|
||||
else return baseNodeAfter(next);
|
||||
}
|
||||
else {
|
||||
var parent = node.parentNode;
|
||||
while (parent && !parent.nextSibling) parent = parent.parentNode;
|
||||
return parent && baseNodeAfter(parent);
|
||||
}
|
||||
}
|
||||
|
||||
// This is called by the code in editor.js whenever it is replacing
|
||||
// a text node. The function sees whether the given oldNode is part
|
||||
// of the current selection, and updates this selection if it is.
|
||||
// Because nodes are often only partially replaced, the length of
|
||||
// the part that gets replaced has to be taken into account -- the
|
||||
// selection might stay in the oldNode if the newNode is smaller
|
||||
// than the selection's offset. The offset argument is needed in
|
||||
// case the selection does move to the new object, and the given
|
||||
// length is not the whole length of the new node (part of it might
|
||||
// have been used to replace another node).
|
||||
select.snapshotReplaceNode = function(from, to, length, offset) {
|
||||
if (!currentSelection) return;
|
||||
|
||||
function replace(point) {
|
||||
if (from == point.node) {
|
||||
currentSelection.changed = true;
|
||||
if (length && point.offset > length) {
|
||||
point.offset -= length;
|
||||
}
|
||||
else {
|
||||
point.node = to;
|
||||
point.offset += (offset || 0);
|
||||
}
|
||||
}
|
||||
else if (select.ie_selection && point.offset == 0 && point.node == baseNodeAfter(from)) {
|
||||
currentSelection.changed = true;
|
||||
}
|
||||
}
|
||||
replace(currentSelection.start);
|
||||
replace(currentSelection.end);
|
||||
};
|
||||
|
||||
select.snapshotMove = function(from, to, distance, relative, ifAtStart) {
|
||||
if (!currentSelection) return;
|
||||
|
||||
function move(point) {
|
||||
if (from == point.node && (!ifAtStart || point.offset == 0)) {
|
||||
currentSelection.changed = true;
|
||||
point.node = to;
|
||||
if (relative) point.offset = Math.max(0, point.offset + distance);
|
||||
else point.offset = distance;
|
||||
}
|
||||
}
|
||||
move(currentSelection.start);
|
||||
move(currentSelection.end);
|
||||
};
|
||||
|
||||
// Most functions are defined in two ways, one for the IE selection
|
||||
// model, one for the W3C one.
|
||||
if (select.ie_selection) {
|
||||
function selRange() {
|
||||
var sel = document.selection;
|
||||
return sel && (sel.createRange || sel.createTextRange)();
|
||||
}
|
||||
|
||||
function selectionNode(start) {
|
||||
var range = selRange();
|
||||
range.collapse(start);
|
||||
|
||||
function nodeAfter(node) {
|
||||
var found = null;
|
||||
while (!found && node) {
|
||||
found = node.nextSibling;
|
||||
node = node.parentNode;
|
||||
}
|
||||
return nodeAtStartOf(found);
|
||||
}
|
||||
|
||||
function nodeAtStartOf(node) {
|
||||
while (node && node.firstChild) node = node.firstChild;
|
||||
return {node: node, offset: 0};
|
||||
}
|
||||
|
||||
var containing = range.parentElement();
|
||||
if (!isAncestor(document.body, containing)) return null;
|
||||
if (!containing.firstChild) return nodeAtStartOf(containing);
|
||||
|
||||
var working = range.duplicate();
|
||||
working.moveToElementText(containing);
|
||||
working.collapse(true);
|
||||
for (var cur = containing.firstChild; cur; cur = cur.nextSibling) {
|
||||
if (cur.nodeType == 3) {
|
||||
var size = cur.nodeValue.length;
|
||||
working.move("character", size);
|
||||
}
|
||||
else {
|
||||
working.moveToElementText(cur);
|
||||
working.collapse(false);
|
||||
}
|
||||
|
||||
var dir = range.compareEndPoints("StartToStart", working);
|
||||
if (dir == 0) return nodeAfter(cur);
|
||||
if (dir == 1) continue;
|
||||
if (cur.nodeType != 3) return nodeAtStartOf(cur);
|
||||
|
||||
working.setEndPoint("StartToEnd", range);
|
||||
return {node: cur, offset: size - working.text.length};
|
||||
}
|
||||
return nodeAfter(containing);
|
||||
}
|
||||
|
||||
select.markSelection = function() {
|
||||
currentSelection = null;
|
||||
var sel = document.selection;
|
||||
if (!sel) return;
|
||||
var start = selectionNode(true),
|
||||
end = selectionNode(false);
|
||||
if (!start || !end) return;
|
||||
currentSelection = {start: start, end: end, changed: false};
|
||||
};
|
||||
|
||||
select.selectMarked = function() {
|
||||
if (!currentSelection || !currentSelection.changed) return;
|
||||
|
||||
function makeRange(point) {
|
||||
var range = document.body.createTextRange(),
|
||||
node = point.node;
|
||||
if (!node) {
|
||||
range.moveToElementText(document.body);
|
||||
range.collapse(false);
|
||||
}
|
||||
else if (node.nodeType == 3) {
|
||||
range.moveToElementText(node.parentNode);
|
||||
var offset = point.offset;
|
||||
while (node.previousSibling) {
|
||||
node = node.previousSibling;
|
||||
offset += (node.innerText || "").length;
|
||||
}
|
||||
range.move("character", offset);
|
||||
}
|
||||
else {
|
||||
range.moveToElementText(node);
|
||||
range.collapse(true);
|
||||
}
|
||||
return range;
|
||||
}
|
||||
|
||||
var start = makeRange(currentSelection.start), end = makeRange(currentSelection.end);
|
||||
start.setEndPoint("StartToEnd", end);
|
||||
start.select();
|
||||
};
|
||||
|
||||
select.offsetInNode = function(node) {
|
||||
var range = selRange();
|
||||
if (!range) return 0;
|
||||
var range2 = range.duplicate();
|
||||
try {range2.moveToElementText(node);} catch(e){return 0;}
|
||||
range.setEndPoint("StartToStart", range2);
|
||||
return range.text.length;
|
||||
};
|
||||
|
||||
// Get the top-level node that one end of the cursor is inside or
|
||||
// after. Note that this returns false for 'no cursor', and null
|
||||
// for 'start of document'.
|
||||
select.selectionTopNode = function(container, start) {
|
||||
var range = selRange();
|
||||
if (!range) return false;
|
||||
var range2 = range.duplicate();
|
||||
range.collapse(start);
|
||||
var around = range.parentElement();
|
||||
if (around && isAncestor(container, around)) {
|
||||
// Only use this node if the selection is not at its start.
|
||||
range2.moveToElementText(around);
|
||||
if (range.compareEndPoints("StartToStart", range2) == 1)
|
||||
return topLevelNodeAt(around, container);
|
||||
}
|
||||
|
||||
// Move the start of a range to the start of a node,
|
||||
// compensating for the fact that you can't call
|
||||
// moveToElementText with text nodes.
|
||||
function moveToNodeStart(range, node) {
|
||||
if (node.nodeType == 3) {
|
||||
var count = 0, cur = node.previousSibling;
|
||||
while (cur && cur.nodeType == 3) {
|
||||
count += cur.nodeValue.length;
|
||||
cur = cur.previousSibling;
|
||||
}
|
||||
if (cur) {
|
||||
try{range.moveToElementText(cur);}
|
||||
catch(e){return false;}
|
||||
range.collapse(false);
|
||||
}
|
||||
else range.moveToElementText(node.parentNode);
|
||||
if (count) range.move("character", count);
|
||||
}
|
||||
else {
|
||||
try{range.moveToElementText(node);}
|
||||
catch(e){return false;}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Do a binary search through the container object, comparing
|
||||
// the start of each node to the selection
|
||||
var start = 0, end = container.childNodes.length - 1;
|
||||
while (start < end) {
|
||||
var middle = Math.ceil((end + start) / 2), node = container.childNodes[middle];
|
||||
if (!node) return false; // Don't ask. IE6 manages this sometimes.
|
||||
if (!moveToNodeStart(range2, node)) return false;
|
||||
if (range.compareEndPoints("StartToStart", range2) == 1)
|
||||
start = middle;
|
||||
else
|
||||
end = middle - 1;
|
||||
}
|
||||
|
||||
if (start == 0) {
|
||||
var test1 = selRange(), test2 = test1.duplicate();
|
||||
try {
|
||||
test2.moveToElementText(container);
|
||||
} catch(exception) {
|
||||
return null;
|
||||
}
|
||||
if (test1.compareEndPoints("StartToStart", test2) == 0)
|
||||
return null;
|
||||
}
|
||||
return container.childNodes[start] || null;
|
||||
};
|
||||
|
||||
// Place the cursor after this.start. This is only useful when
|
||||
// manually moving the cursor instead of restoring it to its old
|
||||
// position.
|
||||
select.focusAfterNode = function(node, container) {
|
||||
var range = document.body.createTextRange();
|
||||
range.moveToElementText(node || container);
|
||||
range.collapse(!node);
|
||||
range.select();
|
||||
};
|
||||
|
||||
select.somethingSelected = function() {
|
||||
var range = selRange();
|
||||
return range && (range.text != "");
|
||||
};
|
||||
|
||||
function insertAtCursor(html) {
|
||||
var range = selRange();
|
||||
if (range) {
|
||||
range.pasteHTML(html);
|
||||
range.collapse(false);
|
||||
range.select();
|
||||
}
|
||||
}
|
||||
|
||||
// Used to normalize the effect of the enter key, since browsers
|
||||
// do widely different things when pressing enter in designMode.
|
||||
select.insertNewlineAtCursor = function() {
|
||||
insertAtCursor("<br>");
|
||||
};
|
||||
|
||||
select.insertTabAtCursor = function() {
|
||||
insertAtCursor(fourSpaces);
|
||||
};
|
||||
|
||||
// Get the BR node at the start of the line on which the cursor
|
||||
// currently is, and the offset into the line. Returns null as
|
||||
// node if cursor is on first line.
|
||||
select.cursorPos = function(container, start) {
|
||||
var range = selRange();
|
||||
if (!range) return null;
|
||||
|
||||
var topNode = select.selectionTopNode(container, start);
|
||||
while (topNode && !isBR(topNode))
|
||||
topNode = topNode.previousSibling;
|
||||
|
||||
var range2 = range.duplicate();
|
||||
range.collapse(start);
|
||||
if (topNode) {
|
||||
range2.moveToElementText(topNode);
|
||||
range2.collapse(false);
|
||||
}
|
||||
else {
|
||||
// When nothing is selected, we can get all kinds of funky errors here.
|
||||
try { range2.moveToElementText(container); }
|
||||
catch (e) { return null; }
|
||||
range2.collapse(true);
|
||||
}
|
||||
range.setEndPoint("StartToStart", range2);
|
||||
|
||||
return {node: topNode, offset: range.text.length};
|
||||
};
|
||||
|
||||
select.setCursorPos = function(container, from, to) {
|
||||
function rangeAt(pos) {
|
||||
var range = document.body.createTextRange();
|
||||
if (!pos.node) {
|
||||
range.moveToElementText(container);
|
||||
range.collapse(true);
|
||||
}
|
||||
else {
|
||||
range.moveToElementText(pos.node);
|
||||
range.collapse(false);
|
||||
}
|
||||
range.move("character", pos.offset);
|
||||
return range;
|
||||
}
|
||||
|
||||
var range = rangeAt(from);
|
||||
if (to && to != from)
|
||||
range.setEndPoint("EndToEnd", rangeAt(to));
|
||||
range.select();
|
||||
}
|
||||
|
||||
// Some hacks for storing and re-storing the selection when the editor loses and regains focus.
|
||||
select.getBookmark = function (container) {
|
||||
var from = select.cursorPos(container, true), to = select.cursorPos(container, false);
|
||||
if (from && to) return {from: from, to: to};
|
||||
};
|
||||
|
||||
// Restore a stored selection.
|
||||
select.setBookmark = function(container, mark) {
|
||||
if (!mark) return;
|
||||
select.setCursorPos(container, mark.from, mark.to);
|
||||
};
|
||||
}
|
||||
// W3C model
|
||||
else {
|
||||
// Find the node right at the cursor, not one of its
|
||||
// ancestors with a suitable offset. This goes down the DOM tree
|
||||
// until a 'leaf' is reached (or is it *up* the DOM tree?).
|
||||
function innerNode(node, offset) {
|
||||
while (node.nodeType != 3 && !isBR(node)) {
|
||||
var newNode = node.childNodes[offset] || node.nextSibling;
|
||||
offset = 0;
|
||||
while (!newNode && node.parentNode) {
|
||||
node = node.parentNode;
|
||||
newNode = node.nextSibling;
|
||||
}
|
||||
node = newNode;
|
||||
if (!newNode) break;
|
||||
}
|
||||
return {node: node, offset: offset};
|
||||
}
|
||||
|
||||
// Store start and end nodes, and offsets within these, and refer
|
||||
// back to the selection object from those nodes, so that this
|
||||
// object can be updated when the nodes are replaced before the
|
||||
// selection is restored.
|
||||
select.markSelection = function () {
|
||||
var selection = window.getSelection();
|
||||
if (!selection || selection.rangeCount == 0)
|
||||
return (currentSelection = null);
|
||||
var range = selection.getRangeAt(0);
|
||||
|
||||
currentSelection = {
|
||||
start: innerNode(range.startContainer, range.startOffset),
|
||||
end: innerNode(range.endContainer, range.endOffset),
|
||||
changed: false
|
||||
};
|
||||
};
|
||||
|
||||
select.selectMarked = function () {
|
||||
var cs = currentSelection;
|
||||
// on webkit-based browsers, it is apparently possible that the
|
||||
// selection gets reset even when a node that is not one of the
|
||||
// endpoints get messed with. the most common situation where
|
||||
// this occurs is when a selection is deleted or overwitten. we
|
||||
// check for that here.
|
||||
function focusIssue() {
|
||||
if (cs.start.node == cs.end.node && cs.start.offset == cs.end.offset) {
|
||||
var selection = window.getSelection();
|
||||
if (!selection || selection.rangeCount == 0) return true;
|
||||
var range = selection.getRangeAt(0), point = innerNode(range.startContainer, range.startOffset);
|
||||
return cs.start.node != point.node || cs.start.offset != point.offset;
|
||||
}
|
||||
}
|
||||
if (!cs || !(cs.changed || (webkit && focusIssue()))) return;
|
||||
var range = document.createRange();
|
||||
|
||||
function setPoint(point, which) {
|
||||
if (point.node) {
|
||||
// Some magic to generalize the setting of the start and end
|
||||
// of a range.
|
||||
if (point.offset == 0)
|
||||
range["set" + which + "Before"](point.node);
|
||||
else
|
||||
range["set" + which](point.node, point.offset);
|
||||
}
|
||||
else {
|
||||
range.setStartAfter(document.body.lastChild || document.body);
|
||||
}
|
||||
}
|
||||
|
||||
setPoint(cs.end, "End");
|
||||
setPoint(cs.start, "Start");
|
||||
selectRange(range);
|
||||
};
|
||||
|
||||
// Helper for selecting a range object.
|
||||
function selectRange(range) {
|
||||
var selection = window.getSelection();
|
||||
if (!selection) return;
|
||||
selection.removeAllRanges();
|
||||
selection.addRange(range);
|
||||
}
|
||||
function selectionRange() {
|
||||
var selection = window.getSelection();
|
||||
if (!selection || selection.rangeCount == 0)
|
||||
return false;
|
||||
else
|
||||
return selection.getRangeAt(0);
|
||||
}
|
||||
|
||||
// Finding the top-level node at the cursor in the W3C is, as you
|
||||
// can see, quite an involved process.
|
||||
select.selectionTopNode = function(container, start) {
|
||||
var range = selectionRange();
|
||||
if (!range) return false;
|
||||
|
||||
var node = start ? range.startContainer : range.endContainer;
|
||||
var offset = start ? range.startOffset : range.endOffset;
|
||||
// Work around (yet another) bug in Opera's selection model.
|
||||
if (window.opera && !start && range.endContainer == container && range.endOffset == range.startOffset + 1 &&
|
||||
container.childNodes[range.startOffset] && isBR(container.childNodes[range.startOffset]))
|
||||
offset--;
|
||||
|
||||
// For text nodes, we look at the node itself if the cursor is
|
||||
// inside, or at the node before it if the cursor is at the
|
||||
// start.
|
||||
if (node.nodeType == 3){
|
||||
if (offset > 0)
|
||||
return topLevelNodeAt(node, container);
|
||||
else
|
||||
return topLevelNodeBefore(node, container);
|
||||
}
|
||||
// Occasionally, browsers will return the HTML node as
|
||||
// selection. If the offset is 0, we take the start of the frame
|
||||
// ('after null'), otherwise, we take the last node.
|
||||
else if (node.nodeName.toUpperCase() == "HTML") {
|
||||
return (offset == 1 ? null : container.lastChild);
|
||||
}
|
||||
// If the given node is our 'container', we just look up the
|
||||
// correct node by using the offset.
|
||||
else if (node == container) {
|
||||
return (offset == 0) ? null : node.childNodes[offset - 1];
|
||||
}
|
||||
// In any other case, we have a regular node. If the cursor is
|
||||
// at the end of the node, we use the node itself, if it is at
|
||||
// the start, we use the node before it, and in any other
|
||||
// case, we look up the child before the cursor and use that.
|
||||
else {
|
||||
if (offset == node.childNodes.length)
|
||||
return topLevelNodeAt(node, container);
|
||||
else if (offset == 0)
|
||||
return topLevelNodeBefore(node, container);
|
||||
else
|
||||
return topLevelNodeAt(node.childNodes[offset - 1], container);
|
||||
}
|
||||
};
|
||||
|
||||
select.focusAfterNode = function(node, container) {
|
||||
var range = document.createRange();
|
||||
range.setStartBefore(container.firstChild || container);
|
||||
// In Opera, setting the end of a range at the end of a line
|
||||
// (before a BR) will cause the cursor to appear on the next
|
||||
// line, so we set the end inside of the start node when
|
||||
// possible.
|
||||
if (node && !node.firstChild)
|
||||
range.setEndAfter(node);
|
||||
else if (node)
|
||||
range.setEnd(node, node.childNodes.length);
|
||||
else
|
||||
range.setEndBefore(container.firstChild || container);
|
||||
range.collapse(false);
|
||||
selectRange(range);
|
||||
};
|
||||
|
||||
select.somethingSelected = function() {
|
||||
var range = selectionRange();
|
||||
return range && !range.collapsed;
|
||||
};
|
||||
|
||||
select.offsetInNode = function(node) {
|
||||
var range = selectionRange();
|
||||
if (!range) return 0;
|
||||
range = range.cloneRange();
|
||||
range.setStartBefore(node);
|
||||
return range.toString().length;
|
||||
};
|
||||
|
||||
select.insertNodeAtCursor = function(node) {
|
||||
var range = selectionRange();
|
||||
if (!range) return;
|
||||
|
||||
range.deleteContents();
|
||||
range.insertNode(node);
|
||||
webkitLastLineHack(document.body);
|
||||
|
||||
// work around weirdness where Opera will magically insert a new
|
||||
// BR node when a BR node inside a span is moved around. makes
|
||||
// sure the BR ends up outside of spans.
|
||||
if (window.opera && isBR(node) && isSpan(node.parentNode)) {
|
||||
var next = node.nextSibling, p = node.parentNode, outer = p.parentNode;
|
||||
outer.insertBefore(node, p.nextSibling);
|
||||
var textAfter = "";
|
||||
for (; next && next.nodeType == 3; next = next.nextSibling) {
|
||||
textAfter += next.nodeValue;
|
||||
removeElement(next);
|
||||
}
|
||||
outer.insertBefore(makePartSpan(textAfter, document), node.nextSibling);
|
||||
}
|
||||
range = document.createRange();
|
||||
range.selectNode(node);
|
||||
range.collapse(false);
|
||||
selectRange(range);
|
||||
}
|
||||
|
||||
select.insertNewlineAtCursor = function() {
|
||||
select.insertNodeAtCursor(document.createElement("BR"));
|
||||
};
|
||||
|
||||
select.insertTabAtCursor = function() {
|
||||
select.insertNodeAtCursor(document.createTextNode(fourSpaces));
|
||||
};
|
||||
|
||||
select.cursorPos = function(container, start) {
|
||||
var range = selectionRange();
|
||||
if (!range) return;
|
||||
|
||||
var topNode = select.selectionTopNode(container, start);
|
||||
while (topNode && !isBR(topNode))
|
||||
topNode = topNode.previousSibling;
|
||||
|
||||
range = range.cloneRange();
|
||||
range.collapse(start);
|
||||
if (topNode)
|
||||
range.setStartAfter(topNode);
|
||||
else
|
||||
range.setStartBefore(container);
|
||||
|
||||
var text = range.toString();
|
||||
return {node: topNode, offset: text.length};
|
||||
};
|
||||
|
||||
select.setCursorPos = function(container, from, to) {
|
||||
var range = document.createRange();
|
||||
|
||||
function setPoint(node, offset, side) {
|
||||
if (offset == 0 && node && !node.nextSibling) {
|
||||
range["set" + side + "After"](node);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!node)
|
||||
node = container.firstChild;
|
||||
else
|
||||
node = node.nextSibling;
|
||||
|
||||
if (!node) return;
|
||||
|
||||
if (offset == 0) {
|
||||
range["set" + side + "Before"](node);
|
||||
return true;
|
||||
}
|
||||
|
||||
var backlog = []
|
||||
function decompose(node) {
|
||||
if (node.nodeType == 3)
|
||||
backlog.push(node);
|
||||
else
|
||||
forEach(node.childNodes, decompose);
|
||||
}
|
||||
while (true) {
|
||||
while (node && !backlog.length) {
|
||||
decompose(node);
|
||||
node = node.nextSibling;
|
||||
}
|
||||
var cur = backlog.shift();
|
||||
if (!cur) return false;
|
||||
|
||||
var length = cur.nodeValue.length;
|
||||
if (length >= offset) {
|
||||
range["set" + side](cur, offset);
|
||||
return true;
|
||||
}
|
||||
offset -= length;
|
||||
}
|
||||
}
|
||||
|
||||
to = to || from;
|
||||
if (setPoint(to.node, to.offset, "End") && setPoint(from.node, from.offset, "Start"))
|
||||
selectRange(range);
|
||||
};
|
||||
}
|
||||
})();
|
||||
159
gulliver/js/codemirror/js/stringstream.js
Executable file
159
gulliver/js/codemirror/js/stringstream.js
Executable file
@@ -0,0 +1,159 @@
|
||||
/* String streams are the things fed to parsers (which can feed them
|
||||
* to a tokenizer if they want). They provide peek and next methods
|
||||
* for looking at the current character (next 'consumes' this
|
||||
* character, peek does not), and a get method for retrieving all the
|
||||
* text that was consumed since the last time get was called.
|
||||
*
|
||||
* An easy mistake to make is to let a StopIteration exception finish
|
||||
* the token stream while there are still characters pending in the
|
||||
* string stream (hitting the end of the buffer while parsing a
|
||||
* token). To make it easier to detect such errors, the stringstreams
|
||||
* throw an exception when this happens.
|
||||
*/
|
||||
|
||||
// Make a stringstream stream out of an iterator that returns strings.
|
||||
// This is applied to the result of traverseDOM (see codemirror.js),
|
||||
// and the resulting stream is fed to the parser.
|
||||
var stringStream = function(source){
|
||||
// String that's currently being iterated over.
|
||||
var current = "";
|
||||
// Position in that string.
|
||||
var pos = 0;
|
||||
// Accumulator for strings that have been iterated over but not
|
||||
// get()-ed yet.
|
||||
var accum = "";
|
||||
// Make sure there are more characters ready, or throw
|
||||
// StopIteration.
|
||||
function ensureChars() {
|
||||
while (pos == current.length) {
|
||||
accum += current;
|
||||
current = ""; // In case source.next() throws
|
||||
pos = 0;
|
||||
try {current = source.next();}
|
||||
catch (e) {
|
||||
if (e != StopIteration) throw e;
|
||||
else return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return {
|
||||
// peek: -> character
|
||||
// Return the next character in the stream.
|
||||
peek: function() {
|
||||
if (!ensureChars()) return null;
|
||||
return current.charAt(pos);
|
||||
},
|
||||
// next: -> character
|
||||
// Get the next character, throw StopIteration if at end, check
|
||||
// for unused content.
|
||||
next: function() {
|
||||
if (!ensureChars()) {
|
||||
if (accum.length > 0)
|
||||
throw "End of stringstream reached without emptying buffer ('" + accum + "').";
|
||||
else
|
||||
throw StopIteration;
|
||||
}
|
||||
return current.charAt(pos++);
|
||||
},
|
||||
// get(): -> string
|
||||
// Return the characters iterated over since the last call to
|
||||
// .get().
|
||||
get: function() {
|
||||
var temp = accum;
|
||||
accum = "";
|
||||
if (pos > 0){
|
||||
temp += current.slice(0, pos);
|
||||
current = current.slice(pos);
|
||||
pos = 0;
|
||||
}
|
||||
return temp;
|
||||
},
|
||||
// Push a string back into the stream.
|
||||
push: function(str) {
|
||||
current = current.slice(0, pos) + str + current.slice(pos);
|
||||
},
|
||||
lookAhead: function(str, consume, skipSpaces, caseInsensitive) {
|
||||
function cased(str) {return caseInsensitive ? str.toLowerCase() : str;}
|
||||
str = cased(str);
|
||||
var found = false;
|
||||
|
||||
var _accum = accum, _pos = pos;
|
||||
if (skipSpaces) this.nextWhileMatches(/[\s\u00a0]/);
|
||||
|
||||
while (true) {
|
||||
var end = pos + str.length, left = current.length - pos;
|
||||
if (end <= current.length) {
|
||||
found = str == cased(current.slice(pos, end));
|
||||
pos = end;
|
||||
break;
|
||||
}
|
||||
else if (str.slice(0, left) == cased(current.slice(pos))) {
|
||||
accum += current; current = "";
|
||||
try {current = source.next();}
|
||||
catch (e) {if (e != StopIteration) throw e; break;}
|
||||
pos = 0;
|
||||
str = str.slice(left);
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(found && consume)) {
|
||||
current = accum.slice(_accum.length) + current;
|
||||
pos = _pos;
|
||||
accum = _accum;
|
||||
}
|
||||
|
||||
return found;
|
||||
},
|
||||
// Wont't match past end of line.
|
||||
lookAheadRegex: function(regex, consume) {
|
||||
if (regex.source.charAt(0) != "^")
|
||||
throw new Error("Regexps passed to lookAheadRegex must start with ^");
|
||||
|
||||
// Fetch the rest of the line
|
||||
while (current.indexOf("\n", pos) == -1) {
|
||||
try {current += source.next();}
|
||||
catch (e) {if (e != StopIteration) throw e; break;}
|
||||
}
|
||||
var matched = current.slice(pos).match(regex);
|
||||
if (matched && consume) pos += matched[0].length;
|
||||
return matched;
|
||||
},
|
||||
|
||||
// Utils built on top of the above
|
||||
// more: -> boolean
|
||||
// Produce true if the stream isn't empty.
|
||||
more: function() {
|
||||
return this.peek() !== null;
|
||||
},
|
||||
applies: function(test) {
|
||||
var next = this.peek();
|
||||
return (next !== null && test(next));
|
||||
},
|
||||
nextWhile: function(test) {
|
||||
var next;
|
||||
while ((next = this.peek()) !== null && test(next))
|
||||
this.next();
|
||||
},
|
||||
matches: function(re) {
|
||||
var next = this.peek();
|
||||
return (next !== null && re.test(next));
|
||||
},
|
||||
nextWhileMatches: function(re) {
|
||||
var next;
|
||||
while ((next = this.peek()) !== null && re.test(next))
|
||||
this.next();
|
||||
},
|
||||
equals: function(ch) {
|
||||
return ch === this.peek();
|
||||
},
|
||||
endOfLine: function() {
|
||||
var next = this.peek();
|
||||
return next == null || next == "\n";
|
||||
}
|
||||
};
|
||||
};
|
||||
57
gulliver/js/codemirror/js/tokenize.js
Executable file
57
gulliver/js/codemirror/js/tokenize.js
Executable file
@@ -0,0 +1,57 @@
|
||||
// A framework for simple tokenizers. Takes care of newlines and
|
||||
// white-space, and of getting the text from the source stream into
|
||||
// the token object. A state is a function of two arguments -- a
|
||||
// string stream and a setState function. The second can be used to
|
||||
// change the tokenizer's state, and can be ignored for stateless
|
||||
// tokenizers. This function should advance the stream over a token
|
||||
// and return a string or object containing information about the next
|
||||
// token, or null to pass and have the (new) state be called to finish
|
||||
// the token. When a string is given, it is wrapped in a {style, type}
|
||||
// object. In the resulting object, the characters consumed are stored
|
||||
// under the content property. Any whitespace following them is also
|
||||
// automatically consumed, and added to the value property. (Thus,
|
||||
// content is the actual meaningful part of the token, while value
|
||||
// contains all the text it spans.)
|
||||
|
||||
function tokenizer(source, state) {
|
||||
// Newlines are always a separate token.
|
||||
function isWhiteSpace(ch) {
|
||||
// The messy regexp is because IE's regexp matcher is of the
|
||||
// opinion that non-breaking spaces are no whitespace.
|
||||
return ch != "\n" && /^[\s\u00a0]*$/.test(ch);
|
||||
}
|
||||
|
||||
var tokenizer = {
|
||||
state: state,
|
||||
|
||||
take: function(type) {
|
||||
if (typeof(type) == "string")
|
||||
type = {style: type, type: type};
|
||||
|
||||
type.content = (type.content || "") + source.get();
|
||||
if (!/\n$/.test(type.content))
|
||||
source.nextWhile(isWhiteSpace);
|
||||
type.value = type.content + source.get();
|
||||
return type;
|
||||
},
|
||||
|
||||
next: function () {
|
||||
if (!source.more()) throw StopIteration;
|
||||
|
||||
var type;
|
||||
if (source.equals("\n")) {
|
||||
source.next();
|
||||
return this.take("whitespace");
|
||||
}
|
||||
|
||||
if (source.applies(isWhiteSpace))
|
||||
type = "whitespace";
|
||||
else
|
||||
while (!type)
|
||||
type = this.state(source, function(s) {tokenizer.state = s;});
|
||||
|
||||
return this.take(type);
|
||||
}
|
||||
};
|
||||
return tokenizer;
|
||||
}
|
||||
174
gulliver/js/codemirror/js/tokenizejavascript.js
Executable file
174
gulliver/js/codemirror/js/tokenizejavascript.js
Executable file
@@ -0,0 +1,174 @@
|
||||
/* Tokenizer for JavaScript code */
|
||||
|
||||
var tokenizeJavaScript = (function() {
|
||||
// Advance the stream until the given character (not preceded by a
|
||||
// backslash) is encountered, or the end of the line is reached.
|
||||
function nextUntilUnescaped(source, end) {
|
||||
var escaped = false;
|
||||
while (!source.endOfLine()) {
|
||||
var next = source.next();
|
||||
if (next == end && !escaped)
|
||||
return false;
|
||||
escaped = !escaped && next == "\\";
|
||||
}
|
||||
return escaped;
|
||||
}
|
||||
|
||||
// A map of JavaScript's keywords. The a/b/c keyword distinction is
|
||||
// very rough, but it gives the parser enough information to parse
|
||||
// correct code correctly (we don't care that much how we parse
|
||||
// incorrect code). The style information included in these objects
|
||||
// is used by the highlighter to pick the correct CSS style for a
|
||||
// token.
|
||||
var keywords = function(){
|
||||
function result(type, style){
|
||||
return {type: type, style: "js-" + style};
|
||||
}
|
||||
// keywords that take a parenthised expression, and then a
|
||||
// statement (if)
|
||||
var keywordA = result("keyword a", "keyword");
|
||||
// keywords that take just a statement (else)
|
||||
var keywordB = result("keyword b", "keyword");
|
||||
// keywords that optionally take an expression, and form a
|
||||
// statement (return)
|
||||
var keywordC = result("keyword c", "keyword");
|
||||
var operator = result("operator", "keyword");
|
||||
var atom = result("atom", "atom");
|
||||
return {
|
||||
"if": keywordA, "while": keywordA, "with": keywordA,
|
||||
"else": keywordB, "do": keywordB, "try": keywordB, "finally": keywordB,
|
||||
"return": keywordC, "break": keywordC, "continue": keywordC, "new": keywordC, "delete": keywordC, "throw": keywordC,
|
||||
"in": operator, "typeof": operator, "instanceof": operator,
|
||||
"var": result("var", "keyword"), "function": result("function", "keyword"), "catch": result("catch", "keyword"),
|
||||
"for": result("for", "keyword"), "switch": result("switch", "keyword"),
|
||||
"case": result("case", "keyword"), "default": result("default", "keyword"),
|
||||
"true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom
|
||||
};
|
||||
}();
|
||||
|
||||
// Some helper regexps
|
||||
var isOperatorChar = /[+\-*&%=<>!?|]/;
|
||||
var isHexDigit = /[0-9A-Fa-f]/;
|
||||
var isWordChar = /[\w\$_]/;
|
||||
|
||||
// Wrapper around jsToken that helps maintain parser state (whether
|
||||
// we are inside of a multi-line comment and whether the next token
|
||||
// could be a regular expression).
|
||||
function jsTokenState(inside, regexp) {
|
||||
return function(source, setState) {
|
||||
var newInside = inside;
|
||||
var type = jsToken(inside, regexp, source, function(c) {newInside = c;});
|
||||
var newRegexp = type.type == "operator" || type.type == "keyword c" || type.type.match(/^[\[{}\(,;:]$/);
|
||||
if (newRegexp != regexp || newInside != inside)
|
||||
setState(jsTokenState(newInside, newRegexp));
|
||||
return type;
|
||||
};
|
||||
}
|
||||
|
||||
// The token reader, intended to be used by the tokenizer from
|
||||
// tokenize.js (through jsTokenState). Advances the source stream
|
||||
// over a token, and returns an object containing the type and style
|
||||
// of that token.
|
||||
function jsToken(inside, regexp, source, setInside) {
|
||||
function readHexNumber(){
|
||||
source.next(); // skip the 'x'
|
||||
source.nextWhileMatches(isHexDigit);
|
||||
return {type: "number", style: "js-atom"};
|
||||
}
|
||||
|
||||
function readNumber() {
|
||||
source.nextWhileMatches(/[0-9]/);
|
||||
if (source.equals(".")){
|
||||
source.next();
|
||||
source.nextWhileMatches(/[0-9]/);
|
||||
}
|
||||
if (source.equals("e") || source.equals("E")){
|
||||
source.next();
|
||||
if (source.equals("-"))
|
||||
source.next();
|
||||
source.nextWhileMatches(/[0-9]/);
|
||||
}
|
||||
return {type: "number", style: "js-atom"};
|
||||
}
|
||||
// Read a word, look it up in keywords. If not found, it is a
|
||||
// variable, otherwise it is a keyword of the type found.
|
||||
function readWord() {
|
||||
source.nextWhileMatches(isWordChar);
|
||||
var word = source.get();
|
||||
var known = keywords.hasOwnProperty(word) && keywords.propertyIsEnumerable(word) && keywords[word];
|
||||
return known ? {type: known.type, style: known.style, content: word} :
|
||||
{type: "variable", style: "js-variable", content: word};
|
||||
}
|
||||
function readRegexp() {
|
||||
nextUntilUnescaped(source, "/");
|
||||
source.nextWhileMatches(/[gimy]/); // 'y' is "sticky" option in Mozilla
|
||||
return {type: "regexp", style: "js-string"};
|
||||
}
|
||||
// Mutli-line comments are tricky. We want to return the newlines
|
||||
// embedded in them as regular newline tokens, and then continue
|
||||
// returning a comment token for every line of the comment. So
|
||||
// some state has to be saved (inside) to indicate whether we are
|
||||
// inside a /* */ sequence.
|
||||
function readMultilineComment(start){
|
||||
var newInside = "/*";
|
||||
var maybeEnd = (start == "*");
|
||||
while (true) {
|
||||
if (source.endOfLine())
|
||||
break;
|
||||
var next = source.next();
|
||||
if (next == "/" && maybeEnd){
|
||||
newInside = null;
|
||||
break;
|
||||
}
|
||||
maybeEnd = (next == "*");
|
||||
}
|
||||
setInside(newInside);
|
||||
return {type: "comment", style: "js-comment"};
|
||||
}
|
||||
function readOperator() {
|
||||
source.nextWhileMatches(isOperatorChar);
|
||||
return {type: "operator", style: "js-operator"};
|
||||
}
|
||||
function readString(quote) {
|
||||
var endBackSlash = nextUntilUnescaped(source, quote);
|
||||
setInside(endBackSlash ? quote : null);
|
||||
return {type: "string", style: "js-string"};
|
||||
}
|
||||
|
||||
// Fetch the next token. Dispatches on first character in the
|
||||
// stream, or first two characters when the first is a slash.
|
||||
if (inside == "\"" || inside == "'")
|
||||
return readString(inside);
|
||||
var ch = source.next();
|
||||
if (inside == "/*")
|
||||
return readMultilineComment(ch);
|
||||
else if (ch == "\"" || ch == "'")
|
||||
return readString(ch);
|
||||
// with punctuation, the type of the token is the symbol itself
|
||||
else if (/[\[\]{}\(\),;\:\.]/.test(ch))
|
||||
return {type: ch, style: "js-punctuation"};
|
||||
else if (ch == "0" && (source.equals("x") || source.equals("X")))
|
||||
return readHexNumber();
|
||||
else if (/[0-9]/.test(ch))
|
||||
return readNumber();
|
||||
else if (ch == "/"){
|
||||
if (source.equals("*"))
|
||||
{ source.next(); return readMultilineComment(ch); }
|
||||
else if (source.equals("/"))
|
||||
{ nextUntilUnescaped(source, null); return {type: "comment", style: "js-comment"};}
|
||||
else if (regexp)
|
||||
return readRegexp();
|
||||
else
|
||||
return readOperator();
|
||||
}
|
||||
else if (isOperatorChar.test(ch))
|
||||
return readOperator();
|
||||
else
|
||||
return readWord();
|
||||
}
|
||||
|
||||
// The external interface to the tokenizer.
|
||||
return function(source, startState) {
|
||||
return tokenizer(source, startState || jsTokenState(false, true));
|
||||
};
|
||||
})();
|
||||
413
gulliver/js/codemirror/js/undo.js
Executable file
413
gulliver/js/codemirror/js/undo.js
Executable file
@@ -0,0 +1,413 @@
|
||||
/**
|
||||
* Storage and control for undo information within a CodeMirror
|
||||
* editor. 'Why on earth is such a complicated mess required for
|
||||
* that?', I hear you ask. The goal, in implementing this, was to make
|
||||
* the complexity of storing and reverting undo information depend
|
||||
* only on the size of the edited or restored content, not on the size
|
||||
* of the whole document. This makes it necessary to use a kind of
|
||||
* 'diff' system, which, when applied to a DOM tree, causes some
|
||||
* complexity and hackery.
|
||||
*
|
||||
* In short, the editor 'touches' BR elements as it parses them, and
|
||||
* the UndoHistory stores these. When nothing is touched in commitDelay
|
||||
* milliseconds, the changes are committed: It goes over all touched
|
||||
* nodes, throws out the ones that did not change since last commit or
|
||||
* are no longer in the document, and assembles the rest into zero or
|
||||
* more 'chains' -- arrays of adjacent lines. Links back to these
|
||||
* chains are added to the BR nodes, while the chain that previously
|
||||
* spanned these nodes is added to the undo history. Undoing a change
|
||||
* means taking such a chain off the undo history, restoring its
|
||||
* content (text is saved per line) and linking it back into the
|
||||
* document.
|
||||
*/
|
||||
|
||||
// A history object needs to know about the DOM container holding the
|
||||
// document, the maximum amount of undo levels it should store, the
|
||||
// delay (of no input) after which it commits a set of changes, and,
|
||||
// unfortunately, the 'parent' window -- a window that is not in
|
||||
// designMode, and on which setTimeout works in every browser.
|
||||
function UndoHistory(container, maxDepth, commitDelay, editor) {
|
||||
this.container = container;
|
||||
this.maxDepth = maxDepth; this.commitDelay = commitDelay;
|
||||
this.editor = editor;
|
||||
// This line object represents the initial, empty editor.
|
||||
var initial = {text: "", from: null, to: null};
|
||||
// As the borders between lines are represented by BR elements, the
|
||||
// start of the first line and the end of the last one are
|
||||
// represented by null. Since you can not store any properties
|
||||
// (links to line objects) in null, these properties are used in
|
||||
// those cases.
|
||||
this.first = initial; this.last = initial;
|
||||
// Similarly, a 'historyTouched' property is added to the BR in
|
||||
// front of lines that have already been touched, and 'firstTouched'
|
||||
// is used for the first line.
|
||||
this.firstTouched = false;
|
||||
// History is the set of committed changes, touched is the set of
|
||||
// nodes touched since the last commit.
|
||||
this.history = []; this.redoHistory = []; this.touched = []; this.lostundo = 0;
|
||||
}
|
||||
|
||||
UndoHistory.prototype = {
|
||||
// Schedule a commit (if no other touches come in for commitDelay
|
||||
// milliseconds).
|
||||
scheduleCommit: function() {
|
||||
var self = this;
|
||||
parent.clearTimeout(this.commitTimeout);
|
||||
this.commitTimeout = parent.setTimeout(function(){self.tryCommit();}, this.commitDelay);
|
||||
},
|
||||
|
||||
// Mark a node as touched. Null is a valid argument.
|
||||
touch: function(node) {
|
||||
this.setTouched(node);
|
||||
this.scheduleCommit();
|
||||
},
|
||||
|
||||
// Undo the last change.
|
||||
undo: function() {
|
||||
// Make sure pending changes have been committed.
|
||||
this.commit();
|
||||
|
||||
if (this.history.length) {
|
||||
// Take the top diff from the history, apply it, and store its
|
||||
// shadow in the redo history.
|
||||
var item = this.history.pop();
|
||||
this.redoHistory.push(this.updateTo(item, "applyChain"));
|
||||
this.notifyEnvironment();
|
||||
return this.chainNode(item);
|
||||
}
|
||||
},
|
||||
|
||||
// Redo the last undone change.
|
||||
redo: function() {
|
||||
this.commit();
|
||||
if (this.redoHistory.length) {
|
||||
// The inverse of undo, basically.
|
||||
var item = this.redoHistory.pop();
|
||||
this.addUndoLevel(this.updateTo(item, "applyChain"));
|
||||
this.notifyEnvironment();
|
||||
return this.chainNode(item);
|
||||
}
|
||||
},
|
||||
|
||||
clear: function() {
|
||||
this.history = [];
|
||||
this.redoHistory = [];
|
||||
this.lostundo = 0;
|
||||
},
|
||||
|
||||
// Ask for the size of the un/redo histories.
|
||||
historySize: function() {
|
||||
return {undo: this.history.length, redo: this.redoHistory.length, lostundo: this.lostundo};
|
||||
},
|
||||
|
||||
// Push a changeset into the document.
|
||||
push: function(from, to, lines) {
|
||||
var chain = [];
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
var end = (i == lines.length - 1) ? to : document.createElement("br");
|
||||
chain.push({from: from, to: end, text: cleanText(lines[i])});
|
||||
from = end;
|
||||
}
|
||||
this.pushChains([chain], from == null && to == null);
|
||||
this.notifyEnvironment();
|
||||
},
|
||||
|
||||
pushChains: function(chains, doNotHighlight) {
|
||||
this.commit(doNotHighlight);
|
||||
this.addUndoLevel(this.updateTo(chains, "applyChain"));
|
||||
this.redoHistory = [];
|
||||
},
|
||||
|
||||
// Retrieve a DOM node from a chain (for scrolling to it after undo/redo).
|
||||
chainNode: function(chains) {
|
||||
for (var i = 0; i < chains.length; i++) {
|
||||
var start = chains[i][0], node = start && (start.from || start.to);
|
||||
if (node) return node;
|
||||
}
|
||||
},
|
||||
|
||||
// Clear the undo history, make the current document the start
|
||||
// position.
|
||||
reset: function() {
|
||||
this.history = []; this.redoHistory = []; this.lostundo = 0;
|
||||
},
|
||||
|
||||
textAfter: function(br) {
|
||||
return this.after(br).text;
|
||||
},
|
||||
|
||||
nodeAfter: function(br) {
|
||||
return this.after(br).to;
|
||||
},
|
||||
|
||||
nodeBefore: function(br) {
|
||||
return this.before(br).from;
|
||||
},
|
||||
|
||||
// Commit unless there are pending dirty nodes.
|
||||
tryCommit: function() {
|
||||
if (!window || !window.parent || !window.UndoHistory) return; // Stop when frame has been unloaded
|
||||
if (this.editor.highlightDirty()) this.commit(true);
|
||||
else this.scheduleCommit();
|
||||
},
|
||||
|
||||
// Check whether the touched nodes hold any changes, if so, commit
|
||||
// them.
|
||||
commit: function(doNotHighlight) {
|
||||
parent.clearTimeout(this.commitTimeout);
|
||||
// Make sure there are no pending dirty nodes.
|
||||
if (!doNotHighlight) this.editor.highlightDirty(true);
|
||||
// Build set of chains.
|
||||
var chains = this.touchedChains(), self = this;
|
||||
|
||||
if (chains.length) {
|
||||
this.addUndoLevel(this.updateTo(chains, "linkChain"));
|
||||
this.redoHistory = [];
|
||||
this.notifyEnvironment();
|
||||
}
|
||||
},
|
||||
|
||||
// [ end of public interface ]
|
||||
|
||||
// Update the document with a given set of chains, return its
|
||||
// shadow. updateFunc should be "applyChain" or "linkChain". In the
|
||||
// second case, the chains are taken to correspond the the current
|
||||
// document, and only the state of the line data is updated. In the
|
||||
// first case, the content of the chains is also pushed iinto the
|
||||
// document.
|
||||
updateTo: function(chains, updateFunc) {
|
||||
var shadows = [], dirty = [];
|
||||
for (var i = 0; i < chains.length; i++) {
|
||||
shadows.push(this.shadowChain(chains[i]));
|
||||
dirty.push(this[updateFunc](chains[i]));
|
||||
}
|
||||
if (updateFunc == "applyChain")
|
||||
this.notifyDirty(dirty);
|
||||
return shadows;
|
||||
},
|
||||
|
||||
// Notify the editor that some nodes have changed.
|
||||
notifyDirty: function(nodes) {
|
||||
forEach(nodes, method(this.editor, "addDirtyNode"))
|
||||
this.editor.scheduleHighlight();
|
||||
},
|
||||
|
||||
notifyEnvironment: function() {
|
||||
if (this.onChange) this.onChange(this.editor);
|
||||
// Used by the line-wrapping line-numbering code.
|
||||
if (window.frameElement && window.frameElement.CodeMirror.updateNumbers)
|
||||
window.frameElement.CodeMirror.updateNumbers();
|
||||
},
|
||||
|
||||
// Link a chain into the DOM nodes (or the first/last links for null
|
||||
// nodes).
|
||||
linkChain: function(chain) {
|
||||
for (var i = 0; i < chain.length; i++) {
|
||||
var line = chain[i];
|
||||
if (line.from) line.from.historyAfter = line;
|
||||
else this.first = line;
|
||||
if (line.to) line.to.historyBefore = line;
|
||||
else this.last = line;
|
||||
}
|
||||
},
|
||||
|
||||
// Get the line object after/before a given node.
|
||||
after: function(node) {
|
||||
return node ? node.historyAfter : this.first;
|
||||
},
|
||||
before: function(node) {
|
||||
return node ? node.historyBefore : this.last;
|
||||
},
|
||||
|
||||
// Mark a node as touched if it has not already been marked.
|
||||
setTouched: function(node) {
|
||||
if (node) {
|
||||
if (!node.historyTouched) {
|
||||
this.touched.push(node);
|
||||
node.historyTouched = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.firstTouched = true;
|
||||
}
|
||||
},
|
||||
|
||||
// Store a new set of undo info, throw away info if there is more of
|
||||
// it than allowed.
|
||||
addUndoLevel: function(diffs) {
|
||||
this.history.push(diffs);
|
||||
if (this.history.length > this.maxDepth) {
|
||||
this.history.shift();
|
||||
lostundo += 1;
|
||||
}
|
||||
},
|
||||
|
||||
// Build chains from a set of touched nodes.
|
||||
touchedChains: function() {
|
||||
var self = this;
|
||||
|
||||
// The temp system is a crummy hack to speed up determining
|
||||
// whether a (currently touched) node has a line object associated
|
||||
// with it. nullTemp is used to store the object for the first
|
||||
// line, other nodes get it stored in their historyTemp property.
|
||||
var nullTemp = null;
|
||||
function temp(node) {return node ? node.historyTemp : nullTemp;}
|
||||
function setTemp(node, line) {
|
||||
if (node) node.historyTemp = line;
|
||||
else nullTemp = line;
|
||||
}
|
||||
|
||||
function buildLine(node) {
|
||||
var text = [];
|
||||
for (var cur = node ? node.nextSibling : self.container.firstChild;
|
||||
cur && (!isBR(cur) || cur.hackBR); cur = cur.nextSibling)
|
||||
if (!cur.hackBR && cur.currentText) text.push(cur.currentText);
|
||||
return {from: node, to: cur, text: cleanText(text.join(""))};
|
||||
}
|
||||
|
||||
// Filter out unchanged lines and nodes that are no longer in the
|
||||
// document. Build up line objects for remaining nodes.
|
||||
var lines = [];
|
||||
if (self.firstTouched) self.touched.push(null);
|
||||
forEach(self.touched, function(node) {
|
||||
if (node && (node.parentNode != self.container || node.hackBR)) return;
|
||||
|
||||
if (node) node.historyTouched = false;
|
||||
else self.firstTouched = false;
|
||||
|
||||
var line = buildLine(node), shadow = self.after(node);
|
||||
if (!shadow || shadow.text != line.text || shadow.to != line.to) {
|
||||
lines.push(line);
|
||||
setTemp(node, line);
|
||||
}
|
||||
});
|
||||
|
||||
// Get the BR element after/before the given node.
|
||||
function nextBR(node, dir) {
|
||||
var link = dir + "Sibling", search = node[link];
|
||||
while (search && !isBR(search))
|
||||
search = search[link];
|
||||
return search;
|
||||
}
|
||||
|
||||
// Assemble line objects into chains by scanning the DOM tree
|
||||
// around them.
|
||||
var chains = []; self.touched = [];
|
||||
forEach(lines, function(line) {
|
||||
// Note that this makes the loop skip line objects that have
|
||||
// been pulled into chains by lines before them.
|
||||
if (!temp(line.from)) return;
|
||||
|
||||
var chain = [], curNode = line.from, safe = true;
|
||||
// Put any line objects (referred to by temp info) before this
|
||||
// one on the front of the array.
|
||||
while (true) {
|
||||
var curLine = temp(curNode);
|
||||
if (!curLine) {
|
||||
if (safe) break;
|
||||
else curLine = buildLine(curNode);
|
||||
}
|
||||
chain.unshift(curLine);
|
||||
setTemp(curNode, null);
|
||||
if (!curNode) break;
|
||||
safe = self.after(curNode);
|
||||
curNode = nextBR(curNode, "previous");
|
||||
}
|
||||
curNode = line.to; safe = self.before(line.from);
|
||||
// Add lines after this one at end of array.
|
||||
while (true) {
|
||||
if (!curNode) break;
|
||||
var curLine = temp(curNode);
|
||||
if (!curLine) {
|
||||
if (safe) break;
|
||||
else curLine = buildLine(curNode);
|
||||
}
|
||||
chain.push(curLine);
|
||||
setTemp(curNode, null);
|
||||
safe = self.before(curNode);
|
||||
curNode = nextBR(curNode, "next");
|
||||
}
|
||||
chains.push(chain);
|
||||
});
|
||||
|
||||
return chains;
|
||||
},
|
||||
|
||||
// Find the 'shadow' of a given chain by following the links in the
|
||||
// DOM nodes at its start and end.
|
||||
shadowChain: function(chain) {
|
||||
var shadows = [], next = this.after(chain[0].from), end = chain[chain.length - 1].to;
|
||||
while (true) {
|
||||
shadows.push(next);
|
||||
var nextNode = next.to;
|
||||
if (!nextNode || nextNode == end)
|
||||
break;
|
||||
else
|
||||
next = nextNode.historyAfter || this.before(end);
|
||||
// (The this.before(end) is a hack -- FF sometimes removes
|
||||
// properties from BR nodes, in which case the best we can hope
|
||||
// for is to not break.)
|
||||
}
|
||||
return shadows;
|
||||
},
|
||||
|
||||
// Update the DOM tree to contain the lines specified in a given
|
||||
// chain, link this chain into the DOM nodes.
|
||||
applyChain: function(chain) {
|
||||
// Some attempt is made to prevent the cursor from jumping
|
||||
// randomly when an undo or redo happens. It still behaves a bit
|
||||
// strange sometimes.
|
||||
var cursor = select.cursorPos(this.container, false), self = this;
|
||||
|
||||
// Remove all nodes in the DOM tree between from and to (null for
|
||||
// start/end of container).
|
||||
function removeRange(from, to) {
|
||||
var pos = from ? from.nextSibling : self.container.firstChild;
|
||||
while (pos != to) {
|
||||
var temp = pos.nextSibling;
|
||||
removeElement(pos);
|
||||
pos = temp;
|
||||
}
|
||||
}
|
||||
|
||||
var start = chain[0].from, end = chain[chain.length - 1].to;
|
||||
// Clear the space where this change has to be made.
|
||||
removeRange(start, end);
|
||||
|
||||
// Insert the content specified by the chain into the DOM tree.
|
||||
for (var i = 0; i < chain.length; i++) {
|
||||
var line = chain[i];
|
||||
// The start and end of the space are already correct, but BR
|
||||
// tags inside it have to be put back.
|
||||
if (i > 0)
|
||||
self.container.insertBefore(line.from, end);
|
||||
|
||||
// Add the text.
|
||||
var node = makePartSpan(fixSpaces(line.text));
|
||||
self.container.insertBefore(node, end);
|
||||
// See if the cursor was on this line. Put it back, adjusting
|
||||
// for changed line length, if it was.
|
||||
if (cursor && cursor.node == line.from) {
|
||||
var cursordiff = 0;
|
||||
var prev = this.after(line.from);
|
||||
if (prev && i == chain.length - 1) {
|
||||
// Only adjust if the cursor is after the unchanged part of
|
||||
// the line.
|
||||
for (var match = 0; match < cursor.offset &&
|
||||
line.text.charAt(match) == prev.text.charAt(match); match++){}
|
||||
if (cursor.offset > match)
|
||||
cursordiff = line.text.length - prev.text.length;
|
||||
}
|
||||
select.setCursorPos(this.container, {node: line.from, offset: Math.max(0, cursor.offset + cursordiff)});
|
||||
}
|
||||
// Cursor was in removed line, this is last new line.
|
||||
else if (cursor && (i == chain.length - 1) && cursor.node && cursor.node.parentNode != this.container) {
|
||||
select.setCursorPos(this.container, {node: line.from, offset: line.text.length});
|
||||
}
|
||||
}
|
||||
|
||||
// Anchor the chain in the DOM tree.
|
||||
this.linkChain(chain);
|
||||
return start;
|
||||
}
|
||||
};
|
||||
44
gulliver/js/codemirror/js/unittests.js
Executable file
44
gulliver/js/codemirror/js/unittests.js
Executable file
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* Test Harness for CodeMirror
|
||||
* JS-unit compatible tests here. The two available assertions are
|
||||
* assertEquals (strict equality) and assertEquivalent (looser equivalency).
|
||||
*
|
||||
* 'editor' is a global object for the CodeMirror editor shared between all
|
||||
* tests. After manipulating it in each test, try to restore it to
|
||||
* approximately its original state.
|
||||
*/
|
||||
|
||||
function testSetGet() {
|
||||
var code = 'It was the best of times.\nIt was the worst of times.';
|
||||
editor.setCode(code);
|
||||
assertEquals(code, editor.getCode());
|
||||
editor.setCode('');
|
||||
assertEquals('', editor.getCode());
|
||||
}
|
||||
|
||||
function testSetStylesheet() {
|
||||
function cssStatus() {
|
||||
// Returns a list of tuples, for each CSS link return the filename and
|
||||
// whether it is enabled.
|
||||
links = editor.win.document.getElementsByTagName('link');
|
||||
css = [];
|
||||
for (var x = 0, link; link = links[x]; x++) {
|
||||
if (link.rel.indexOf("stylesheet") !== -1) {
|
||||
css.push([link.href.substring(link.href.lastIndexOf('/') + 1),
|
||||
!link.disabled])
|
||||
}
|
||||
}
|
||||
return css;
|
||||
}
|
||||
assertEquivalent([], cssStatus());
|
||||
editor.setStylesheet('css/jscolors.css');
|
||||
assertEquivalent([['jscolors.css', true]], cssStatus());
|
||||
editor.setStylesheet(['css/csscolors.css', 'css/xmlcolors.css']);
|
||||
assertEquivalent([['jscolors.css', false], ['csscolors.css', true], ['xmlcolors.css', true]], cssStatus());
|
||||
editor.setStylesheet([]);
|
||||
assertEquivalent([['jscolors.css', false], ['csscolors.css', false], ['xmlcolors.css', false]], cssStatus());
|
||||
}
|
||||
|
||||
// Update this list of tests as new ones are added.
|
||||
var tests = ['testSetGet', 'testSetStylesheet'];
|
||||
|
||||
133
gulliver/js/codemirror/js/util.js
Executable file
133
gulliver/js/codemirror/js/util.js
Executable file
@@ -0,0 +1,133 @@
|
||||
/* A few useful utility functions. */
|
||||
|
||||
// Capture a method on an object.
|
||||
function method(obj, name) {
|
||||
return function() {obj[name].apply(obj, arguments);};
|
||||
}
|
||||
|
||||
// The value used to signal the end of a sequence in iterators.
|
||||
var StopIteration = {toString: function() {return "StopIteration"}};
|
||||
|
||||
// Apply a function to each element in a sequence.
|
||||
function forEach(iter, f) {
|
||||
if (iter.next) {
|
||||
try {while (true) f(iter.next());}
|
||||
catch (e) {if (e != StopIteration) throw e;}
|
||||
}
|
||||
else {
|
||||
for (var i = 0; i < iter.length; i++)
|
||||
f(iter[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// Map a function over a sequence, producing an array of results.
|
||||
function map(iter, f) {
|
||||
var accum = [];
|
||||
forEach(iter, function(val) {accum.push(f(val));});
|
||||
return accum;
|
||||
}
|
||||
|
||||
// Create a predicate function that tests a string againsts a given
|
||||
// regular expression. No longer used but might be used by 3rd party
|
||||
// parsers.
|
||||
function matcher(regexp){
|
||||
return function(value){return regexp.test(value);};
|
||||
}
|
||||
|
||||
// Test whether a DOM node has a certain CSS class.
|
||||
function hasClass(element, className) {
|
||||
var classes = element.className;
|
||||
return classes && new RegExp("(^| )" + className + "($| )").test(classes);
|
||||
}
|
||||
function removeClass(element, className) {
|
||||
element.className = element.className.replace(new RegExp(" " + className + "\\b", "g"), "");
|
||||
return element;
|
||||
}
|
||||
|
||||
// Insert a DOM node after another node.
|
||||
function insertAfter(newNode, oldNode) {
|
||||
var parent = oldNode.parentNode;
|
||||
parent.insertBefore(newNode, oldNode.nextSibling);
|
||||
return newNode;
|
||||
}
|
||||
|
||||
function removeElement(node) {
|
||||
if (node.parentNode)
|
||||
node.parentNode.removeChild(node);
|
||||
}
|
||||
|
||||
function clearElement(node) {
|
||||
while (node.firstChild)
|
||||
node.removeChild(node.firstChild);
|
||||
}
|
||||
|
||||
// Check whether a node is contained in another one.
|
||||
function isAncestor(node, child) {
|
||||
while (child = child.parentNode) {
|
||||
if (node == child)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// The non-breaking space character.
|
||||
var nbsp = "\u00a0";
|
||||
var matching = {"{": "}", "[": "]", "(": ")",
|
||||
"}": "{", "]": "[", ")": "("};
|
||||
|
||||
// Standardize a few unportable event properties.
|
||||
function normalizeEvent(event) {
|
||||
if (!event.stopPropagation) {
|
||||
event.stopPropagation = function() {this.cancelBubble = true;};
|
||||
event.preventDefault = function() {this.returnValue = false;};
|
||||
}
|
||||
if (!event.stop) {
|
||||
event.stop = function() {
|
||||
this.stopPropagation();
|
||||
this.preventDefault();
|
||||
};
|
||||
}
|
||||
|
||||
if (event.type == "keypress") {
|
||||
event.code = (event.charCode == null) ? event.keyCode : event.charCode;
|
||||
event.character = String.fromCharCode(event.code);
|
||||
}
|
||||
return event;
|
||||
}
|
||||
|
||||
// Portably register event handlers.
|
||||
function addEventHandler(node, type, handler, removeFunc) {
|
||||
function wrapHandler(event) {
|
||||
handler(normalizeEvent(event || window.event));
|
||||
}
|
||||
if (typeof node.addEventListener == "function") {
|
||||
node.addEventListener(type, wrapHandler, false);
|
||||
if (removeFunc) return function() {node.removeEventListener(type, wrapHandler, false);};
|
||||
}
|
||||
else {
|
||||
node.attachEvent("on" + type, wrapHandler);
|
||||
if (removeFunc) return function() {node.detachEvent("on" + type, wrapHandler);};
|
||||
}
|
||||
}
|
||||
|
||||
function nodeText(node) {
|
||||
return node.textContent || node.innerText || node.nodeValue || "";
|
||||
}
|
||||
|
||||
function nodeTop(node) {
|
||||
var top = 0;
|
||||
while (node.offsetParent) {
|
||||
top += node.offsetTop;
|
||||
node = node.offsetParent;
|
||||
}
|
||||
return top;
|
||||
}
|
||||
|
||||
function isBR(node) {
|
||||
var nn = node.nodeName;
|
||||
return nn == "BR" || nn == "br";
|
||||
}
|
||||
function isSpan(node) {
|
||||
var nn = node.nodeName;
|
||||
return nn == "SPAN" || nn == "span";
|
||||
}
|
||||
@@ -58,35 +58,35 @@ class dynaformEditor extends WebResource
|
||||
* top: 'getAbsoluteTop(document.getElementById("dynaformEditor[0]"))',
|
||||
*/
|
||||
var $defaultConfig = array(
|
||||
'Editor' =>array(
|
||||
'left' =>'0',
|
||||
'top' =>'0',
|
||||
'width' =>'document.body.clientWidth-4',
|
||||
'height'=>'document.body.clientHeight-4'
|
||||
),
|
||||
'Toolbar' =>array(
|
||||
'left' =>'document.body.clientWidth-2-toolbar.clientWidth-24-3+7',
|
||||
'top' =>'52'
|
||||
),
|
||||
'FieldsList'=>array(
|
||||
'left' =>'4+toolbar.clientWidth+24',
|
||||
'top' =>'getAbsoluteTop(document.getElementById("dynaformEditor[0]"))',
|
||||
'width' => 244,
|
||||
'height'=> 400,
|
||||
)
|
||||
);
|
||||
'Editor' => array(
|
||||
'left' => '0',
|
||||
'top' => '0',
|
||||
'width' => 'document.body.clientWidth-4',
|
||||
'height'=> 'document.body.clientHeight-4'
|
||||
),
|
||||
'Toolbar' => array(
|
||||
'left' => 'document.body.clientWidth-2-toolbar.clientWidth-24-3+7',
|
||||
'top' => '52'
|
||||
),
|
||||
'FieldsList' => array(
|
||||
'left' =>'4+toolbar.clientWidth+24',
|
||||
'top' =>'getAbsoluteTop(document.getElementById("dynaformEditor[0]"))',
|
||||
'width' => 244,
|
||||
'height'=> 400,
|
||||
)
|
||||
);
|
||||
var $panelConf=array(
|
||||
'style' =>array(
|
||||
'title'=>array('textAlign'=>'center')
|
||||
),
|
||||
'width' =>700,
|
||||
'height' =>600,
|
||||
'tabWidth' =>120,
|
||||
'modal' =>true,
|
||||
'drag' =>false,
|
||||
'resize' =>false,
|
||||
'blinkToFront'=>false
|
||||
);
|
||||
'style' => array(
|
||||
'title'=> array('textAlign'=>'center')
|
||||
),
|
||||
'width' => 700,
|
||||
'height' => 600,
|
||||
'tabWidth' => 120,
|
||||
'modal' => true,
|
||||
'drag' => false,
|
||||
'resize' => false,
|
||||
'blinkToFront'=> false
|
||||
);
|
||||
|
||||
/**
|
||||
* Constructor of the class dynaformEditor
|
||||
@@ -145,29 +145,30 @@ class dynaformEditor extends WebResource
|
||||
$script='';
|
||||
/* Start Block: Load (Create if not exists) the xmlform */
|
||||
$Parameters = array(
|
||||
'SYS_LANG' => SYS_LANG,
|
||||
'URL' => G::encrypt( $this->file , URL_KEY ),
|
||||
'DYN_UID' => $this->dyn_uid,
|
||||
'PRO_UID' => $this->pro_uid,
|
||||
'DYNAFORM_NAME'=> $this->dyn_title,
|
||||
'FILE' => $this->file,
|
||||
);
|
||||
'SYS_LANG' => SYS_LANG,
|
||||
'URL' => G::encrypt( $this->file , URL_KEY ),
|
||||
'DYN_UID' => $this->dyn_uid,
|
||||
'PRO_UID' => $this->pro_uid,
|
||||
'DYNAFORM_NAME'=> $this->dyn_title,
|
||||
'FILE' => $this->file,
|
||||
);
|
||||
$_SESSION['Current_Dynafom']['Parameters'] = $Parameters;
|
||||
$XmlEditor = array(
|
||||
'URL'=> G::encrypt( $this->file , URL_KEY ),
|
||||
'XML'=> ''//$openDoc->getXml()
|
||||
);
|
||||
'URL'=> G::encrypt( $this->file , URL_KEY ),
|
||||
'XML'=> ''//$openDoc->getXml()
|
||||
);
|
||||
$JSEditor = array(
|
||||
'URL'=> G::encrypt( $this->file , URL_KEY ),
|
||||
);
|
||||
$A=G::encrypt( $this->file , URL_KEY );
|
||||
'URL'=> G::encrypt( $this->file , URL_KEY ),
|
||||
);
|
||||
|
||||
$A = G::encrypt( $this->file , URL_KEY );
|
||||
|
||||
try {
|
||||
$openDoc = new Xml_Document();
|
||||
$fileName= $this->home . $this->file . '.xml';
|
||||
if (file_exists($fileName)) {
|
||||
$openDoc->parseXmlFile($fileName);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$this->_createDefaultXmlForm($fileName);
|
||||
$openDoc->parseXmlFile($fileName);
|
||||
}
|
||||
@@ -250,14 +251,16 @@ class dynaformEditor extends WebResource
|
||||
$G_PUBLISH->AddContent('panel-tab',G::LoadTranslation("ID_CONDITIONS_EDITOR"),$sName.'[9]','dynaformEditor.changeToShowHide','dynaformEditor.saveShowHide');
|
||||
$G_PUBLISH->AddContent('panel-close');
|
||||
$oHeadPublisher->addScriptFile('/jscore/dynaformEditor/core/dynaformEditor.js');
|
||||
$oHeadPublisher->addScriptFile('/js/dveditor/core/dveditor.js');
|
||||
$oHeadPublisher->addScriptFile('/codepress/codepress.js',1);
|
||||
//$oHeadPublisher->addScriptFile('/js/dveditor/core/dveditor.js');
|
||||
//$oHeadPublisher->addScriptFile('/codepress/codepress.js',1);
|
||||
$oHeadPublisher->addScriptFile('/js/codemirror/js/codemirror.js',1);
|
||||
|
||||
$oHeadPublisher->addScriptFile('/js/grid/core/grid.js');
|
||||
$oHeadPublisher->addScriptCode('
|
||||
var DYNAFORM_URL="'.$Parameters['URL'].'";
|
||||
leimnud.event.add(window,"load",function(){ loadEditor(); });
|
||||
');
|
||||
G::RenderPage( "publish-treeview" );
|
||||
G::RenderPage( "publish", 'blank' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
var xmlEditor = null;
|
||||
var clientWinSize = null;
|
||||
|
||||
if (typeof(dynaformEditor)==="undefined")
|
||||
{
|
||||
var dynaformEditor={
|
||||
@@ -56,31 +59,31 @@ var dynaformEditor={
|
||||
url='dynaforms_Saveas';
|
||||
popupWindow('Save as', url+'?DYN_UID='+this.dynUid+'&AA='+this.A , 500, 350);
|
||||
},
|
||||
/*
|
||||
* @function close
|
||||
* @author unknow
|
||||
* @modifier Gustavo Cruz
|
||||
* @desc this function handles the close of a dynaform editor window
|
||||
* now whenever a dynaform window is close, if the form wasn't
|
||||
* saved the function also delete the temporal *_tmp0.xml files
|
||||
* discarding all the changes that were made, bug 3861.
|
||||
*/
|
||||
/*
|
||||
* @function close
|
||||
* @author unknow
|
||||
* @modifier Gustavo Cruz
|
||||
* @desc this function handles the close of a dynaform editor window
|
||||
* now whenever a dynaform window is close, if the form wasn't
|
||||
* saved the function also delete the temporal *_tmp0.xml files
|
||||
* discarding all the changes that were made, bug 3861.
|
||||
*/
|
||||
close:function()
|
||||
{
|
||||
var modified=this.ajax.is_modified(this.A,this.dynUid);
|
||||
if (typeof(modified)==="boolean")
|
||||
{
|
||||
if (!modified || confirm(G_STRINGS.ID_EXIT_WITHOUT_SAVING))
|
||||
if (!modified || confirm(G_STRINGS.ID_EXIT_WITHOUT_SAVING))
|
||||
{
|
||||
res=this.ajax.close(this.A);
|
||||
if (res==0) {
|
||||
//alert(G_STRINGS.ID_DYNAFORM_NOT_SAVED);
|
||||
}
|
||||
else
|
||||
{
|
||||
//alert(res["response"]);
|
||||
alert(res["*message"]);
|
||||
}
|
||||
res=this.ajax.close(this.A);
|
||||
if (res==0) {
|
||||
//alert(G_STRINGS.ID_DYNAFORM_NOT_SAVED);
|
||||
}
|
||||
else
|
||||
{
|
||||
//alert(res["response"]);
|
||||
alert(res["*message"]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@@ -169,10 +172,26 @@ var dynaformEditor={
|
||||
|
||||
this.refresh_xmlcode();
|
||||
this.currentView="xmlcode";
|
||||
if (this.loadPressLoaded && !XMLCodePress)
|
||||
{
|
||||
startXMLCodePress();
|
||||
}
|
||||
//if (this.loadPressLoaded && !XMLCodePress)
|
||||
//{
|
||||
//startXMLCodePress(); -> removing codepress editor
|
||||
//}
|
||||
|
||||
if( ! xmlEditor ) {
|
||||
clientWinSize = getClientWindowSize();
|
||||
|
||||
xmlEditor = CodeMirror.fromTextArea('form[XML]', {
|
||||
height: (clientWinSize.height - 120) + "px",
|
||||
width: (_BROWSER.name == 'msie' ? '100%' : '98%'),
|
||||
parserfile: ["parsexml.js", "parsecss.js", "tokenizejavascript.js", "parsejavascript.js",
|
||||
"../contrib/php/js/tokenizephp.js", "../contrib/php/js/parsephp.js",
|
||||
"../contrib/php/js/parsephphtmlmixed.js"],
|
||||
stylesheet: ["css/xmlcolors.css", "css/jscolors.css", "css/csscolors.css", "contrib/php/css/phpcolors.css"],
|
||||
path: "js/",
|
||||
lineNumbers: true,
|
||||
continuousScanning: 500
|
||||
});
|
||||
}
|
||||
},
|
||||
changeToHtmlCode:function()
|
||||
{
|
||||
@@ -369,26 +388,33 @@ var dynaformEditor={
|
||||
},
|
||||
getXMLCode:function()
|
||||
{
|
||||
if (XMLCodePress)
|
||||
/*if (XMLCodePress)
|
||||
{
|
||||
return XMLCodePress.getCode();
|
||||
}
|
||||
else
|
||||
{
|
||||
{*/
|
||||
//alert(getField("XML","dynaforms_XmlEditor").value);
|
||||
xmlEditor.save();
|
||||
return getField("XML","dynaforms_XmlEditor").value;
|
||||
}
|
||||
//}
|
||||
},
|
||||
setXMLCode:function(newCode)
|
||||
{
|
||||
if (XMLCodePress)
|
||||
{
|
||||
XMLCodePress.setCode(newCode);
|
||||
//if (XMLCodePress)
|
||||
//{
|
||||
//XMLCodePress.setCode(newCode);
|
||||
//XMLCodePress.edit(newCode,"xmlform");
|
||||
//}
|
||||
if( xmlEditor )
|
||||
{
|
||||
xmlEditor.setCode(newCode);
|
||||
}
|
||||
else
|
||||
{
|
||||
var code=getField("XML","dynaforms_XmlEditor");
|
||||
code.value=newCode;
|
||||
//xmlEditor.toTextArea();
|
||||
}
|
||||
},
|
||||
setEnableTemplate:function(value)
|
||||
|
||||
22
workflow/engine/xmlform/dynaforms/dynaforms_XmlEditor.html
Executable file
22
workflow/engine/xmlform/dynaforms/dynaforms_XmlEditor.html
Executable file
@@ -0,0 +1,22 @@
|
||||
<form id="{$form_id}" name="{$form_name}" action="{$form_action}" class="{$form_className}" method="post" encType="multipart/form-data" style="margin:0px;" onsubmit="return validateForm('{$form_objectRequiredFields}');"> <div class="borderForm" style="width:{$form_width}; padding-left:0; padding-right:0; border-width:{$form_border};">
|
||||
<div class="content" style="height:{$form_height};" >
|
||||
<table width="99%">
|
||||
<tr>
|
||||
<td valign='top'>
|
||||
<input type="hidden" class="notValidateThisFields" name="__notValidateThisFields__" id="__notValidateThisFields__" value="{$form_objectRequiredFields}" />
|
||||
<input type="hidden" name="DynaformRequiredFields" id="DynaformRequiredFields" value="{$form_objectRequiredFields}" />
|
||||
<table cellspacing="0" cellpadding="0" border="0" width="100%">
|
||||
<tr>
|
||||
<td colspan="2" class="withoutLabel">{$form.XML}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
{$form.PME_RESIZE_JS}
|
||||
</script>
|
||||
</form>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<dynaForm name="dynaforms_XmlEditor" type="xmlform" width="98%" border="0">
|
||||
<dynaForm name="dynaforms_XmlEditor" type="xmlform" width="98%" border="0" enabletemplate="1">
|
||||
|
||||
|
||||
<URL type="phpvariable"/>
|
||||
@@ -7,7 +7,7 @@
|
||||
<en>XML</en>
|
||||
</XML>
|
||||
<PME_RESIZE_JS type="javascript"><![CDATA[
|
||||
function resizeXmlEditor(){
|
||||
/*function resizeXmlEditor(){
|
||||
getField('XML','dynaforms_XmlEditor').style.height=
|
||||
document.getElementById('dynaformEditor[4]').parentNode.clientHeight-32;
|
||||
}
|
||||
@@ -19,6 +19,7 @@ function startXMLCodePress()
|
||||
XMLCodePress=new CodePress(getField("XML"),'xmlform');
|
||||
getField("XML").parentNode.insertBefore(XMLCodePress,getField("XML"));
|
||||
XMLCodePress.edit(code,'xmlform');
|
||||
}
|
||||
}*/
|
||||
|
||||
]]></PME_RESIZE_JS>
|
||||
</dynaForm>
|
||||
@@ -3125,3 +3125,15 @@ button.x-btn-text:focus,.x-combo-selected{
|
||||
outline:none;
|
||||
}
|
||||
|
||||
.CodeMirror-line-numbers {
|
||||
width: 2.2em;
|
||||
color: #aaa;
|
||||
background-color: #eee;
|
||||
text-align: right;
|
||||
padding-right: .3em;
|
||||
font-size: 10pt;
|
||||
font-family: monospace;
|
||||
padding-top: .4em;
|
||||
line-height: normal;
|
||||
}
|
||||
|
||||
|
||||
@@ -137,7 +137,7 @@ $startingTime = array_sum(explode(' ',microtime()));
|
||||
$virtualURITable['/controls/(*)'] = PATH_GULLIVER_HOME . 'methods/controls/';
|
||||
$virtualURITable['/html2ps_pdf/(*)'] = PATH_THIRDPARTY . 'html2ps_pdf/';
|
||||
$virtualURITable['/Krumo/(*)'] = PATH_THIRDPARTY . 'krumo/';
|
||||
$virtualURITable['/codepress/(*)'] = PATH_THIRDPARTY . 'codepress/';
|
||||
// $virtualURITable['/codepress/(*)'] = PATH_THIRDPARTY . 'codepress/';
|
||||
$virtualURITable['/images/'] = 'errorFile';
|
||||
$virtualURITable['/skins/'] = 'errorFile';
|
||||
$virtualURITable['/files/'] = 'errorFile';
|
||||
|
||||
Reference in New Issue
Block a user