diff options
Diffstat (limited to 'help3/xhpeditor/cm/mode/scheme/scheme.js')
-rw-r--r-- | help3/xhpeditor/cm/mode/scheme/scheme.js | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/help3/xhpeditor/cm/mode/scheme/scheme.js b/help3/xhpeditor/cm/mode/scheme/scheme.js index 370250d8..d11a132d 100644 --- a/help3/xhpeditor/cm/mode/scheme/scheme.js +++ b/help3/xhpeditor/cm/mode/scheme/scheme.js @@ -3,6 +3,7 @@ /** * Author: Koh Zi Han, based on implementation by Koh Zi Chun + * Improved by: Jakub T. Jankiewicz */ (function(mod) { @@ -17,7 +18,7 @@ CodeMirror.defineMode("scheme", function () { var BUILTIN = "builtin", COMMENT = "comment", STRING = "string", - ATOM = "atom", NUMBER = "number", BRACKET = "bracket"; + SYMBOL = "symbol", ATOM = "atom", NUMBER = "number", BRACKET = "bracket"; var INDENT_WORD_SKIP = 2; function makeKeywords(str) { @@ -67,6 +68,18 @@ CodeMirror.defineMode("scheme", function () { return stream.match(hexMatcher); } + function processEscapedSequence(stream, options) { + var next, escaped = false; + while ((next = stream.next()) != null) { + if (next == options.token && !escaped) { + + options.state.mode = false; + break; + } + escaped = !escaped && next == "\\"; + } + } + return { startState: function () { return { @@ -92,17 +105,19 @@ CodeMirror.defineMode("scheme", function () { switch(state.mode){ case "string": // multi-line string parsing mode - var next, escaped = false; - while ((next = stream.next()) != null) { - if (next == "\"" && !escaped) { - - state.mode = false; - break; - } - escaped = !escaped && next == "\\"; - } + processEscapedSequence(stream, { + token: "\"", + state: state + }); returnType = STRING; // continue on in scheme-string mode break; + case "symbol": // escape symbol + processEscapedSequence(stream, { + token: "|", + state: state + }); + returnType = SYMBOL; // continue on in scheme-symbol mode + break; case "comment": // comment parsing mode var next, maybeEnd = false; while ((next = stream.next()) != null) { @@ -143,6 +158,9 @@ CodeMirror.defineMode("scheme", function () { stream.eatWhile(/[\w_\-!$%&*+\.\/:<=>?@\^~]/); returnType = ATOM; } + } else if (ch == '|') { + state.mode = "symbol"; + returnType = SYMBOL; } else if (ch == '#') { if (stream.eat("|")) { // Multi-line comment state.mode = "comment"; // toggle to comment mode @@ -255,6 +273,7 @@ CodeMirror.defineMode("scheme", function () { return state.indentStack.indent; }, + fold: "brace-paren", closeBrackets: {pairs: "()[]{}\"\""}, lineComment: ";;" }; |