aboutsummaryrefslogtreecommitdiff
path: root/js/codemirror/mode/scheme/scheme.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/codemirror/mode/scheme/scheme.js')
-rw-r--r--js/codemirror/mode/scheme/scheme.js181
1 files changed, 0 insertions, 181 deletions
diff --git a/js/codemirror/mode/scheme/scheme.js b/js/codemirror/mode/scheme/scheme.js
deleted file mode 100644
index 2b5af227..00000000
--- a/js/codemirror/mode/scheme/scheme.js
+++ /dev/null
@@ -1,181 +0,0 @@
1/**
2 * Author: Koh Zi Han, based on implementation by Koh Zi Chun
3 */
4CodeMirror.defineMode("scheme", function (config, mode) {
5 var numRegex = /[0-9]/;
6 var BUILTIN = "builtin", COMMENT = "comment", STRING = "string",
7 ATOM = "atom", NUMBER = "number", BRACKET = "bracket";
8 var INDENT_WORD_SKIP = 2, KEYWORDS_SKIP = 1;
9
10 function makeKeywords(str) {
11 var obj = {}, words = str.split(" ");
12 for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
13 return obj;
14 }
15
16 var keywords = makeKeywords("case-lambda call/cc class define-class exit-handler field import inherit init-field interface let*-values let-values let/ec mixin opt-lambda override protect provide public rename require require-for-syntax syntax syntax-case syntax-error unit/sig unless when with-syntax and begin call-with-current-continuation call-with-input-file call-with-output-file case cond define define-syntax delay do dynamic-wind else for-each if lambda let let* let-syntax letrec letrec-syntax map or syntax-rules abs acos angle append apply asin assoc assq assv atan boolean? caar cadr call-with-input-file call-with-output-file call-with-values car cdddar cddddr cdr ceiling char->integer char-alphabetic? char-ci<=? char-ci<? char-ci=? char-ci>=? char-ci>? char-downcase char-lower-case? char-numeric? char-ready? char-upcase char-upper-case? char-whitespace? char<=? char<? char=? char>=? char>? char? close-input-port close-output-port complex? cons cos current-input-port current-output-port denominator display eof-object? eq? equal? eqv? eval even? exact->inexact exact? exp expt #f floor force gcd imag-part inexact->exact inexact? input-port? integer->char integer? interaction-environment lcm length list list->string list->vector list-ref list-tail list? load log magnitude make-polar make-rectangular make-string make-vector max member memq memv min modulo negative? newline not null-environment null? number->string number? numerator odd? open-input-file open-output-file output-port? pair? peek-char port? positive? procedure? quasiquote quote quotient rational? rationalize read read-char real-part real? remainder reverse round scheme-report-environment set! set-car! set-cdr! sin sqrt string string->list string->number string->symbol string-append string-ci<=? string-ci<? string-ci=? string-ci>=? string-ci>? string-copy string-fill! string-length string-ref string-set! string<=? string<? string=? string>=? string>? string? substring symbol->string symbol? #t tan transcript-off transcript-on truncate values vector vector->list vector-fill! vector-length vector-ref vector-set! with-input-from-file with-output-to-file write write-char zero?");
17 var indentKeys = makeKeywords("define let letrec let* lambda begin");
18
19
20 function stateStack(indent, type, prev) { // represents a state stack object
21 this.indent = indent;
22 this.type = type;
23 this.prev = prev;
24 }
25
26 function pushStack(state, indent, type) {
27 state.indentStack = new stateStack(indent, type, state.indentStack);
28 }
29
30 function popStack(state) {
31 state.indentStack = state.indentStack.prev;
32 }
33
34 return {
35 startState: function () {
36 return {
37 indentStack: null,
38 indentation: 0,
39 mode: false,
40 sExprComment: false
41 };
42 },
43
44 token: function (stream, state) {
45 if (state.indentStack == null && stream.sol()) {
46 // update indentation, but only if indentStack is empty
47 state.indentation = stream.indentation();
48 }
49
50 // skip spaces
51 if (stream.eatSpace()) {
52 return null;
53 }
54 var returnType = null;
55
56 switch(state.mode){
57 case "string": // multi-line string parsing mode
58 var next, escaped = false;
59 while ((next = stream.next()) != null) {
60 if (next == "\"" && !escaped) {
61
62 state.mode = false;
63 break;
64 }
65 escaped = !escaped && next == "\\";
66 }
67 returnType = STRING; // continue on in scheme-string mode
68 break;
69 case "comment": // comment parsing mode
70 var next, maybeEnd = false;
71 while ((next = stream.next()) != null) {
72 if (next == "#" && maybeEnd) {
73
74 state.mode = false;
75 break;
76 }
77 maybeEnd = (next == "|");
78 }
79 returnType = COMMENT;
80 break;
81 case "s-expr-comment": // s-expr commenting mode
82 state.mode = false;
83 if(stream.peek() == "(" || stream.peek() == "["){
84 // actually start scheme s-expr commenting mode
85 state.sExprComment = 0;
86 }else{
87 // if not we just comment the entire of the next token
88 stream.eatWhile(/[^/s]/); // eat non spaces
89 returnType = COMMENT;
90 break;
91 }
92 default: // default parsing mode
93 var ch = stream.next();
94
95 if (ch == "\"") {
96 state.mode = "string";
97 returnType = STRING;
98
99 } else if (ch == "'") {
100 returnType = ATOM;
101 } else if (ch == '#') {
102 if (stream.eat("|")) { // Multi-line comment
103 state.mode = "comment"; // toggle to comment mode
104 returnType = COMMENT;
105 } else if (stream.eat(/[tf]/)) { // #t/#f (atom)
106 returnType = ATOM;
107 } else if (stream.eat(';')) { // S-Expr comment
108 state.mode = "s-expr-comment";
109 returnType = COMMENT;
110 }
111
112 } else if (ch == ";") { // comment
113 stream.skipToEnd(); // rest of the line is a comment
114 returnType = COMMENT;
115
116 } else if (numRegex.exec(ch) != null) { // numbers
117 returnType = NUMBER;
118
119 } else if (ch == "(" || ch == "[") {
120 var keyWord = ''; var indentTemp = stream.column();
121 /**
122 Either
123 (indent-word ..
124 (non-indent-word ..
125 (;something else, bracket, etc.
126 */
127
128 while ((letter = stream.eat(/[^\s\(\[\;\)\]]/)) != null) {
129 keyWord += letter;
130 }
131
132 if (keyWord.length > 0 && indentKeys.propertyIsEnumerable(keyWord)) { // indent-word
133
134 pushStack(state, indentTemp + INDENT_WORD_SKIP, ch);
135 } else { // non-indent word
136 // we continue eating the spaces
137 stream.eatSpace();
138 if (stream.eol() || stream.peek() == ";") {
139 // nothing significant after
140 // we restart indentation 1 space after
141 pushStack(state, indentTemp + 1, ch);
142 } else {
143 pushStack(state, indentTemp + stream.current().length, ch); // else we match
144 }
145 }
146 stream.backUp(stream.current().length - 1); // undo all the eating
147
148 if(typeof state.sExprComment == "number") state.sExprComment++;
149
150 returnType = BRACKET;
151 } else if (ch == ")" || ch == "]") {
152 returnType = BRACKET;
153 if (state.indentStack != null && state.indentStack.type == (ch == ")" ? "(" : "[")) {
154 popStack(state);
155
156 if(typeof state.sExprComment == "number"){
157 if(--state.sExprComment == 0){
158 returnType = COMMENT; // final closing bracket
159 state.sExprComment = false; // turn off s-expr commenting mode
160 }
161 }
162 }
163 } else {
164 stream.eatWhile(/[\w\$_]/);
165
166 if (keywords && keywords.propertyIsEnumerable(stream.current())) {
167 returnType = BUILTIN;
168 } else returnType = null;
169 }
170 }
171 return (typeof state.sExprComment == "number") ? COMMENT : returnType;
172 },
173
174 indent: function (state, textAfter) {
175 if (state.indentStack == null) return state.indentation;
176 return state.indentStack.indent;
177 }
178 };
179});
180
181CodeMirror.defineMIME("text/x-scheme", "css");