File modules/editor/codemirror/mode/mllike/mllike.js
Last commit: Sun Dec 17 01:14:09 2017 +0100 Jan Dankert Integration eines weiteren Code-Editors: Codemirror. Demnächst müssen wir hier mal aufräumen und andere Editoren rauswerfen.
1 // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 // Distributed under an MIT license: http://codemirror.net/LICENSE 3 4 (function(mod) { 5 if (typeof exports == "object" && typeof module == "object") // CommonJS 6 mod(require("../../lib/codemirror")); 7 else if (typeof define == "function" && define.amd) // AMD 8 define(["../../lib/codemirror"], mod); 9 else // Plain browser env 10 mod(CodeMirror); 11 })(function(CodeMirror) { 12 "use strict"; 13 14 CodeMirror.defineMode('mllike', function(_config, parserConfig) { 15 var words = { 16 'let': 'keyword', 17 'rec': 'keyword', 18 'in': 'keyword', 19 'of': 'keyword', 20 'and': 'keyword', 21 'if': 'keyword', 22 'then': 'keyword', 23 'else': 'keyword', 24 'for': 'keyword', 25 'to': 'keyword', 26 'while': 'keyword', 27 'do': 'keyword', 28 'done': 'keyword', 29 'fun': 'keyword', 30 'function': 'keyword', 31 'val': 'keyword', 32 'type': 'keyword', 33 'mutable': 'keyword', 34 'match': 'keyword', 35 'with': 'keyword', 36 'try': 'keyword', 37 'open': 'builtin', 38 'ignore': 'builtin', 39 'begin': 'keyword', 40 'end': 'keyword' 41 }; 42 43 var extraWords = parserConfig.extraWords || {}; 44 for (var prop in extraWords) { 45 if (extraWords.hasOwnProperty(prop)) { 46 words[prop] = parserConfig.extraWords[prop]; 47 } 48 } 49 50 function tokenBase(stream, state) { 51 var ch = stream.next(); 52 53 if (ch === '"') { 54 state.tokenize = tokenString; 55 return state.tokenize(stream, state); 56 } 57 if (ch === '(') { 58 if (stream.eat('*')) { 59 state.commentLevel++; 60 state.tokenize = tokenComment; 61 return state.tokenize(stream, state); 62 } 63 } 64 if (ch === '~') { 65 stream.eatWhile(/\w/); 66 return 'variable-2'; 67 } 68 if (ch === '`') { 69 stream.eatWhile(/\w/); 70 return 'quote'; 71 } 72 if (ch === '/' && parserConfig.slashComments && stream.eat('/')) { 73 stream.skipToEnd(); 74 return 'comment'; 75 } 76 if (/\d/.test(ch)) { 77 stream.eatWhile(/[\d]/); 78 if (stream.eat('.')) { 79 stream.eatWhile(/[\d]/); 80 } 81 return 'number'; 82 } 83 if ( /[+\-*&%=<>!?|]/.test(ch)) { 84 return 'operator'; 85 } 86 if (/[\w\xa1-\uffff]/.test(ch)) { 87 stream.eatWhile(/[\w\xa1-\uffff]/); 88 var cur = stream.current(); 89 return words.hasOwnProperty(cur) ? words[cur] : 'variable'; 90 } 91 return null 92 } 93 94 function tokenString(stream, state) { 95 var next, end = false, escaped = false; 96 while ((next = stream.next()) != null) { 97 if (next === '"' && !escaped) { 98 end = true; 99 break; 100 } 101 escaped = !escaped && next === '\\'; 102 } 103 if (end && !escaped) { 104 state.tokenize = tokenBase; 105 } 106 return 'string'; 107 }; 108 109 function tokenComment(stream, state) { 110 var prev, next; 111 while(state.commentLevel > 0 && (next = stream.next()) != null) { 112 if (prev === '(' && next === '*') state.commentLevel++; 113 if (prev === '*' && next === ')') state.commentLevel--; 114 prev = next; 115 } 116 if (state.commentLevel <= 0) { 117 state.tokenize = tokenBase; 118 } 119 return 'comment'; 120 } 121 122 return { 123 startState: function() {return {tokenize: tokenBase, commentLevel: 0};}, 124 token: function(stream, state) { 125 if (stream.eatSpace()) return null; 126 return state.tokenize(stream, state); 127 }, 128 129 blockCommentStart: "(*", 130 blockCommentEnd: "*)", 131 lineComment: parserConfig.slashComments ? "//" : null 132 }; 133 }); 134 135 CodeMirror.defineMIME('text/x-ocaml', { 136 name: 'mllike', 137 extraWords: { 138 'succ': 'keyword', 139 'trace': 'builtin', 140 'exit': 'builtin', 141 'print_string': 'builtin', 142 'print_endline': 'builtin', 143 'true': 'atom', 144 'false': 'atom', 145 'raise': 'keyword' 146 } 147 }); 148 149 CodeMirror.defineMIME('text/x-fsharp', { 150 name: 'mllike', 151 extraWords: { 152 'abstract': 'keyword', 153 'as': 'keyword', 154 'assert': 'keyword', 155 'base': 'keyword', 156 'class': 'keyword', 157 'default': 'keyword', 158 'delegate': 'keyword', 159 'downcast': 'keyword', 160 'downto': 'keyword', 161 'elif': 'keyword', 162 'exception': 'keyword', 163 'extern': 'keyword', 164 'finally': 'keyword', 165 'global': 'keyword', 166 'inherit': 'keyword', 167 'inline': 'keyword', 168 'interface': 'keyword', 169 'internal': 'keyword', 170 'lazy': 'keyword', 171 'let!': 'keyword', 172 'member' : 'keyword', 173 'module': 'keyword', 174 'namespace': 'keyword', 175 'new': 'keyword', 176 'null': 'keyword', 177 'override': 'keyword', 178 'private': 'keyword', 179 'public': 'keyword', 180 'return': 'keyword', 181 'return!': 'keyword', 182 'select': 'keyword', 183 'static': 'keyword', 184 'struct': 'keyword', 185 'upcast': 'keyword', 186 'use': 'keyword', 187 'use!': 'keyword', 188 'val': 'keyword', 189 'when': 'keyword', 190 'yield': 'keyword', 191 'yield!': 'keyword', 192 193 'List': 'builtin', 194 'Seq': 'builtin', 195 'Map': 'builtin', 196 'Set': 'builtin', 197 'int': 'builtin', 198 'string': 'builtin', 199 'raise': 'builtin', 200 'failwith': 'builtin', 201 'not': 'builtin', 202 'true': 'builtin', 203 'false': 'builtin' 204 }, 205 slashComments: true 206 }); 207 208 });
Downloadmodules/editor/codemirror/mode/mllike/mllike.js
History Sun, 17 Dec 2017 01:14:09 +0100 Jan Dankert Integration eines weiteren Code-Editors: Codemirror. Demnächst müssen wir hier mal aufräumen und andere Editoren rauswerfen.