File modules/editor/codemirror/mode/clike/clike.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 function Context(indented, column, type, info, align, prev) { 15 this.indented = indented; 16 this.column = column; 17 this.type = type; 18 this.info = info; 19 this.align = align; 20 this.prev = prev; 21 } 22 function pushContext(state, col, type, info) { 23 var indent = state.indented; 24 if (state.context && state.context.type == "statement" && type != "statement") 25 indent = state.context.indented; 26 return state.context = new Context(indent, col, type, info, null, state.context); 27 } 28 function popContext(state) { 29 var t = state.context.type; 30 if (t == ")" || t == "]" || t == "}") 31 state.indented = state.context.indented; 32 return state.context = state.context.prev; 33 } 34 35 function typeBefore(stream, state, pos) { 36 if (state.prevToken == "variable" || state.prevToken == "type") return true; 37 if (/\S(?:[^- ]>|[*\]])\s*$|\*$/.test(stream.string.slice(0, pos))) return true; 38 if (state.typeAtEndOfLine && stream.column() == stream.indentation()) return true; 39 } 40 41 function isTopScope(context) { 42 for (;;) { 43 if (!context || context.type == "top") return true; 44 if (context.type == "}" && context.prev.info != "namespace") return false; 45 context = context.prev; 46 } 47 } 48 49 CodeMirror.defineMode("clike", function(config, parserConfig) { 50 var indentUnit = config.indentUnit, 51 statementIndentUnit = parserConfig.statementIndentUnit || indentUnit, 52 dontAlignCalls = parserConfig.dontAlignCalls, 53 keywords = parserConfig.keywords || {}, 54 types = parserConfig.types || {}, 55 builtin = parserConfig.builtin || {}, 56 blockKeywords = parserConfig.blockKeywords || {}, 57 defKeywords = parserConfig.defKeywords || {}, 58 atoms = parserConfig.atoms || {}, 59 hooks = parserConfig.hooks || {}, 60 multiLineStrings = parserConfig.multiLineStrings, 61 indentStatements = parserConfig.indentStatements !== false, 62 indentSwitch = parserConfig.indentSwitch !== false, 63 namespaceSeparator = parserConfig.namespaceSeparator, 64 isPunctuationChar = parserConfig.isPunctuationChar || /[\[\]{}\(\),;\:\.]/, 65 numberStart = parserConfig.numberStart || /[\d\.]/, 66 number = parserConfig.number || /^(?:0x[a-f\d]+|0b[01]+|(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?)(u|ll?|l|f)?/i, 67 isOperatorChar = parserConfig.isOperatorChar || /[+\-*&%=<>!?|\/]/, 68 isIdentifierChar = parserConfig.isIdentifierChar || /[\w\$_\xa1-\uffff]/; 69 70 var curPunc, isDefKeyword; 71 72 function tokenBase(stream, state) { 73 var ch = stream.next(); 74 if (hooks[ch]) { 75 var result = hooks[ch](stream, state); 76 if (result !== false) return result; 77 } 78 if (ch == '"' || ch == "'") { 79 state.tokenize = tokenString(ch); 80 return state.tokenize(stream, state); 81 } 82 if (isPunctuationChar.test(ch)) { 83 curPunc = ch; 84 return null; 85 } 86 if (numberStart.test(ch)) { 87 stream.backUp(1) 88 if (stream.match(number)) return "number" 89 stream.next() 90 } 91 if (ch == "/") { 92 if (stream.eat("*")) { 93 state.tokenize = tokenComment; 94 return tokenComment(stream, state); 95 } 96 if (stream.eat("/")) { 97 stream.skipToEnd(); 98 return "comment"; 99 } 100 } 101 if (isOperatorChar.test(ch)) { 102 while (!stream.match(/^\/[\/*]/, false) && stream.eat(isOperatorChar)) {} 103 return "operator"; 104 } 105 stream.eatWhile(isIdentifierChar); 106 if (namespaceSeparator) while (stream.match(namespaceSeparator)) 107 stream.eatWhile(isIdentifierChar); 108 109 var cur = stream.current(); 110 if (contains(keywords, cur)) { 111 if (contains(blockKeywords, cur)) curPunc = "newstatement"; 112 if (contains(defKeywords, cur)) isDefKeyword = true; 113 return "keyword"; 114 } 115 if (contains(types, cur)) return "type"; 116 if (contains(builtin, cur)) { 117 if (contains(blockKeywords, cur)) curPunc = "newstatement"; 118 return "builtin"; 119 } 120 if (contains(atoms, cur)) return "atom"; 121 return "variable"; 122 } 123 124 function tokenString(quote) { 125 return function(stream, state) { 126 var escaped = false, next, end = false; 127 while ((next = stream.next()) != null) { 128 if (next == quote && !escaped) {end = true; break;} 129 escaped = !escaped && next == "\\"; 130 } 131 if (end || !(escaped || multiLineStrings)) 132 state.tokenize = null; 133 return "string"; 134 }; 135 } 136 137 function tokenComment(stream, state) { 138 var maybeEnd = false, ch; 139 while (ch = stream.next()) { 140 if (ch == "/" && maybeEnd) { 141 state.tokenize = null; 142 break; 143 } 144 maybeEnd = (ch == "*"); 145 } 146 return "comment"; 147 } 148 149 function maybeEOL(stream, state) { 150 if (parserConfig.typeFirstDefinitions && stream.eol() && isTopScope(state.context)) 151 state.typeAtEndOfLine = typeBefore(stream, state, stream.pos) 152 } 153 154 // Interface 155 156 return { 157 startState: function(basecolumn) { 158 return { 159 tokenize: null, 160 context: new Context((basecolumn || 0) - indentUnit, 0, "top", null, false), 161 indented: 0, 162 startOfLine: true, 163 prevToken: null 164 }; 165 }, 166 167 token: function(stream, state) { 168 var ctx = state.context; 169 if (stream.sol()) { 170 if (ctx.align == null) ctx.align = false; 171 state.indented = stream.indentation(); 172 state.startOfLine = true; 173 } 174 if (stream.eatSpace()) { maybeEOL(stream, state); return null; } 175 curPunc = isDefKeyword = null; 176 var style = (state.tokenize || tokenBase)(stream, state); 177 if (style == "comment" || style == "meta") return style; 178 if (ctx.align == null) ctx.align = true; 179 180 if (curPunc == ";" || curPunc == ":" || (curPunc == "," && stream.match(/^\s*(?:\/\/.*)?$/, false))) 181 while (state.context.type == "statement") popContext(state); 182 else if (curPunc == "{") pushContext(state, stream.column(), "}"); 183 else if (curPunc == "[") pushContext(state, stream.column(), "]"); 184 else if (curPunc == "(") pushContext(state, stream.column(), ")"); 185 else if (curPunc == "}") { 186 while (ctx.type == "statement") ctx = popContext(state); 187 if (ctx.type == "}") ctx = popContext(state); 188 while (ctx.type == "statement") ctx = popContext(state); 189 } 190 else if (curPunc == ctx.type) popContext(state); 191 else if (indentStatements && 192 (((ctx.type == "}" || ctx.type == "top") && curPunc != ";") || 193 (ctx.type == "statement" && curPunc == "newstatement"))) { 194 pushContext(state, stream.column(), "statement", stream.current()); 195 } 196 197 if (style == "variable" && 198 ((state.prevToken == "def" || 199 (parserConfig.typeFirstDefinitions && typeBefore(stream, state, stream.start) && 200 isTopScope(state.context) && stream.match(/^\s*\(/, false))))) 201 style = "def"; 202 203 if (hooks.token) { 204 var result = hooks.token(stream, state, style); 205 if (result !== undefined) style = result; 206 } 207 208 if (style == "def" && parserConfig.styleDefs === false) style = "variable"; 209 210 state.startOfLine = false; 211 state.prevToken = isDefKeyword ? "def" : style || curPunc; 212 maybeEOL(stream, state); 213 return style; 214 }, 215 216 indent: function(state, textAfter) { 217 if (state.tokenize != tokenBase && state.tokenize != null || state.typeAtEndOfLine) return CodeMirror.Pass; 218 var ctx = state.context, firstChar = textAfter && textAfter.charAt(0); 219 if (ctx.type == "statement" && firstChar == "}") ctx = ctx.prev; 220 if (parserConfig.dontIndentStatements) 221 while (ctx.type == "statement" && parserConfig.dontIndentStatements.test(ctx.info)) 222 ctx = ctx.prev 223 if (hooks.indent) { 224 var hook = hooks.indent(state, ctx, textAfter); 225 if (typeof hook == "number") return hook 226 } 227 var closing = firstChar == ctx.type; 228 var switchBlock = ctx.prev && ctx.prev.info == "switch"; 229 if (parserConfig.allmanIndentation && /[{(]/.test(firstChar)) { 230 while (ctx.type != "top" && ctx.type != "}") ctx = ctx.prev 231 return ctx.indented 232 } 233 if (ctx.type == "statement") 234 return ctx.indented + (firstChar == "{" ? 0 : statementIndentUnit); 235 if (ctx.align && (!dontAlignCalls || ctx.type != ")")) 236 return ctx.column + (closing ? 0 : 1); 237 if (ctx.type == ")" && !closing) 238 return ctx.indented + statementIndentUnit; 239 240 return ctx.indented + (closing ? 0 : indentUnit) + 241 (!closing && switchBlock && !/^(?:case|default)\b/.test(textAfter) ? indentUnit : 0); 242 }, 243 244 electricInput: indentSwitch ? /^\s*(?:case .*?:|default:|\{\}?|\})$/ : /^\s*[{}]$/, 245 blockCommentStart: "/*", 246 blockCommentEnd: "*/", 247 blockCommentContinue: " * ", 248 lineComment: "//", 249 fold: "brace" 250 }; 251 }); 252 253 function words(str) { 254 var obj = {}, words = str.split(" "); 255 for (var i = 0; i < words.length; ++i) obj[words[i]] = true; 256 return obj; 257 } 258 function contains(words, word) { 259 if (typeof words === "function") { 260 return words(word); 261 } else { 262 return words.propertyIsEnumerable(word); 263 } 264 } 265 var cKeywords = "auto if break case register continue return default do sizeof " + 266 "static else struct switch extern typedef union for goto while enum const volatile"; 267 var cTypes = "int long char short double float unsigned signed void size_t ptrdiff_t"; 268 269 function cppHook(stream, state) { 270 if (!state.startOfLine) return false 271 for (var ch, next = null; ch = stream.peek();) { 272 if (ch == "\\" && stream.match(/^.$/)) { 273 next = cppHook 274 break 275 } else if (ch == "/" && stream.match(/^\/[\/\*]/, false)) { 276 break 277 } 278 stream.next() 279 } 280 state.tokenize = next 281 return "meta" 282 } 283 284 function pointerHook(_stream, state) { 285 if (state.prevToken == "type") return "type"; 286 return false; 287 } 288 289 function cpp14Literal(stream) { 290 stream.eatWhile(/[\w\.']/); 291 return "number"; 292 } 293 294 function cpp11StringHook(stream, state) { 295 stream.backUp(1); 296 // Raw strings. 297 if (stream.match(/(R|u8R|uR|UR|LR)/)) { 298 var match = stream.match(/"([^\s\\()]{0,16})\(/); 299 if (!match) { 300 return false; 301 } 302 state.cpp11RawStringDelim = match[1]; 303 state.tokenize = tokenRawString; 304 return tokenRawString(stream, state); 305 } 306 // Unicode strings/chars. 307 if (stream.match(/(u8|u|U|L)/)) { 308 if (stream.match(/["']/, /* eat */ false)) { 309 return "string"; 310 } 311 return false; 312 } 313 // Ignore this hook. 314 stream.next(); 315 return false; 316 } 317 318 function cppLooksLikeConstructor(word) { 319 var lastTwo = /(\w+)::~?(\w+)$/.exec(word); 320 return lastTwo && lastTwo[1] == lastTwo[2]; 321 } 322 323 // C#-style strings where "" escapes a quote. 324 function tokenAtString(stream, state) { 325 var next; 326 while ((next = stream.next()) != null) { 327 if (next == '"' && !stream.eat('"')) { 328 state.tokenize = null; 329 break; 330 } 331 } 332 return "string"; 333 } 334 335 // C++11 raw string literal is <prefix>"<delim>( anything )<delim>", where 336 // <delim> can be a string up to 16 characters long. 337 function tokenRawString(stream, state) { 338 // Escape characters that have special regex meanings. 339 var delim = state.cpp11RawStringDelim.replace(/[^\w\s]/g, '\\$&'); 340 var match = stream.match(new RegExp(".*?\\)" + delim + '"')); 341 if (match) 342 state.tokenize = null; 343 else 344 stream.skipToEnd(); 345 return "string"; 346 } 347 348 function def(mimes, mode) { 349 if (typeof mimes == "string") mimes = [mimes]; 350 var words = []; 351 function add(obj) { 352 if (obj) for (var prop in obj) if (obj.hasOwnProperty(prop)) 353 words.push(prop); 354 } 355 add(mode.keywords); 356 add(mode.types); 357 add(mode.builtin); 358 add(mode.atoms); 359 if (words.length) { 360 mode.helperType = mimes[0]; 361 CodeMirror.registerHelper("hintWords", mimes[0], words); 362 } 363 364 for (var i = 0; i < mimes.length; ++i) 365 CodeMirror.defineMIME(mimes[i], mode); 366 } 367 368 def(["text/x-csrc", "text/x-c", "text/x-chdr"], { 369 name: "clike", 370 keywords: words(cKeywords), 371 types: words(cTypes + " bool _Complex _Bool float_t double_t intptr_t intmax_t " + 372 "int8_t int16_t int32_t int64_t uintptr_t uintmax_t uint8_t uint16_t " + 373 "uint32_t uint64_t"), 374 blockKeywords: words("case do else for if switch while struct"), 375 defKeywords: words("struct"), 376 typeFirstDefinitions: true, 377 atoms: words("null true false"), 378 hooks: {"#": cppHook, "*": pointerHook}, 379 modeProps: {fold: ["brace", "include"]} 380 }); 381 382 def(["text/x-c++src", "text/x-c++hdr"], { 383 name: "clike", 384 keywords: words(cKeywords + " asm dynamic_cast namespace reinterpret_cast try explicit new " + 385 "static_cast typeid catch operator template typename class friend private " + 386 "this using const_cast inline public throw virtual delete mutable protected " + 387 "alignas alignof constexpr decltype nullptr noexcept thread_local final " + 388 "static_assert override"), 389 types: words(cTypes + " bool wchar_t"), 390 blockKeywords: words("catch class do else finally for if struct switch try while"), 391 defKeywords: words("class namespace struct enum union"), 392 typeFirstDefinitions: true, 393 atoms: words("true false null"), 394 dontIndentStatements: /^template$/, 395 isIdentifierChar: /[\w\$_~\xa1-\uffff]/, 396 hooks: { 397 "#": cppHook, 398 "*": pointerHook, 399 "u": cpp11StringHook, 400 "U": cpp11StringHook, 401 "L": cpp11StringHook, 402 "R": cpp11StringHook, 403 "0": cpp14Literal, 404 "1": cpp14Literal, 405 "2": cpp14Literal, 406 "3": cpp14Literal, 407 "4": cpp14Literal, 408 "5": cpp14Literal, 409 "6": cpp14Literal, 410 "7": cpp14Literal, 411 "8": cpp14Literal, 412 "9": cpp14Literal, 413 token: function(stream, state, style) { 414 if (style == "variable" && stream.peek() == "(" && 415 (state.prevToken == ";" || state.prevToken == null || 416 state.prevToken == "}") && 417 cppLooksLikeConstructor(stream.current())) 418 return "def"; 419 } 420 }, 421 namespaceSeparator: "::", 422 modeProps: {fold: ["brace", "include"]} 423 }); 424 425 def("text/x-java", { 426 name: "clike", 427 keywords: words("abstract assert break case catch class const continue default " + 428 "do else enum extends final finally float for goto if implements import " + 429 "instanceof interface native new package private protected public " + 430 "return static strictfp super switch synchronized this throw throws transient " + 431 "try volatile while @interface"), 432 types: words("byte short int long float double boolean char void Boolean Byte Character Double Float " + 433 "Integer Long Number Object Short String StringBuffer StringBuilder Void"), 434 blockKeywords: words("catch class do else finally for if switch try while"), 435 defKeywords: words("class interface enum @interface"), 436 typeFirstDefinitions: true, 437 atoms: words("true false null"), 438 number: /^(?:0x[a-f\d_]+|0b[01_]+|(?:[\d_]+\.?\d*|\.\d+)(?:e[-+]?[\d_]+)?)(u|ll?|l|f)?/i, 439 hooks: { 440 "@": function(stream) { 441 // Don't match the @interface keyword. 442 if (stream.match('interface', false)) return false; 443 444 stream.eatWhile(/[\w\$_]/); 445 return "meta"; 446 } 447 }, 448 modeProps: {fold: ["brace", "import"]} 449 }); 450 451 def("text/x-csharp", { 452 name: "clike", 453 keywords: words("abstract as async await base break case catch checked class const continue" + 454 " default delegate do else enum event explicit extern finally fixed for" + 455 " foreach goto if implicit in interface internal is lock namespace new" + 456 " operator out override params private protected public readonly ref return sealed" + 457 " sizeof stackalloc static struct switch this throw try typeof unchecked" + 458 " unsafe using virtual void volatile while add alias ascending descending dynamic from get" + 459 " global group into join let orderby partial remove select set value var yield"), 460 types: words("Action Boolean Byte Char DateTime DateTimeOffset Decimal Double Func" + 461 " Guid Int16 Int32 Int64 Object SByte Single String Task TimeSpan UInt16 UInt32" + 462 " UInt64 bool byte char decimal double short int long object" + 463 " sbyte float string ushort uint ulong"), 464 blockKeywords: words("catch class do else finally for foreach if struct switch try while"), 465 defKeywords: words("class interface namespace struct var"), 466 typeFirstDefinitions: true, 467 atoms: words("true false null"), 468 hooks: { 469 "@": function(stream, state) { 470 if (stream.eat('"')) { 471 state.tokenize = tokenAtString; 472 return tokenAtString(stream, state); 473 } 474 stream.eatWhile(/[\w\$_]/); 475 return "meta"; 476 } 477 } 478 }); 479 480 function tokenTripleString(stream, state) { 481 var escaped = false; 482 while (!stream.eol()) { 483 if (!escaped && stream.match('"""')) { 484 state.tokenize = null; 485 break; 486 } 487 escaped = stream.next() == "\\" && !escaped; 488 } 489 return "string"; 490 } 491 492 def("text/x-scala", { 493 name: "clike", 494 keywords: words( 495 496 /* scala */ 497 "abstract case catch class def do else extends final finally for forSome if " + 498 "implicit import lazy match new null object override package private protected return " + 499 "sealed super this throw trait try type val var while with yield _ " + 500 501 /* package scala */ 502 "assert assume require print println printf readLine readBoolean readByte readShort " + 503 "readChar readInt readLong readFloat readDouble" 504 ), 505 types: words( 506 "AnyVal App Application Array BufferedIterator BigDecimal BigInt Char Console Either " + 507 "Enumeration Equiv Error Exception Fractional Function IndexedSeq Int Integral Iterable " + 508 "Iterator List Map Numeric Nil NotNull Option Ordered Ordering PartialFunction PartialOrdering " + 509 "Product Proxy Range Responder Seq Serializable Set Specializable Stream StringBuilder " + 510 "StringContext Symbol Throwable Traversable TraversableOnce Tuple Unit Vector " + 511 512 /* package java.lang */ 513 "Boolean Byte Character CharSequence Class ClassLoader Cloneable Comparable " + 514 "Compiler Double Exception Float Integer Long Math Number Object Package Pair Process " + 515 "Runtime Runnable SecurityManager Short StackTraceElement StrictMath String " + 516 "StringBuffer System Thread ThreadGroup ThreadLocal Throwable Triple Void" 517 ), 518 multiLineStrings: true, 519 blockKeywords: words("catch class enum do else finally for forSome if match switch try while"), 520 defKeywords: words("class enum def object package trait type val var"), 521 atoms: words("true false null"), 522 indentStatements: false, 523 indentSwitch: false, 524 isOperatorChar: /[+\-*&%=<>!?|\/#:@]/, 525 hooks: { 526 "@": function(stream) { 527 stream.eatWhile(/[\w\$_]/); 528 return "meta"; 529 }, 530 '"': function(stream, state) { 531 if (!stream.match('""')) return false; 532 state.tokenize = tokenTripleString; 533 return state.tokenize(stream, state); 534 }, 535 "'": function(stream) { 536 stream.eatWhile(/[\w\$_\xa1-\uffff]/); 537 return "atom"; 538 }, 539 "=": function(stream, state) { 540 var cx = state.context 541 if (cx.type == "}" && cx.align && stream.eat(">")) { 542 state.context = new Context(cx.indented, cx.column, cx.type, cx.info, null, cx.prev) 543 return "operator" 544 } else { 545 return false 546 } 547 } 548 }, 549 modeProps: {closeBrackets: {triples: '"'}} 550 }); 551 552 function tokenKotlinString(tripleString){ 553 return function (stream, state) { 554 var escaped = false, next, end = false; 555 while (!stream.eol()) { 556 if (!tripleString && !escaped && stream.match('"') ) {end = true; break;} 557 if (tripleString && stream.match('"""')) {end = true; break;} 558 next = stream.next(); 559 if(!escaped && next == "$" && stream.match('{')) 560 stream.skipTo("}"); 561 escaped = !escaped && next == "\\" && !tripleString; 562 } 563 if (end || !tripleString) 564 state.tokenize = null; 565 return "string"; 566 } 567 } 568 569 def("text/x-kotlin", { 570 name: "clike", 571 keywords: words( 572 /*keywords*/ 573 "package as typealias class interface this super val " + 574 "var fun for is in This throw return " + 575 "break continue object if else while do try when !in !is as? " + 576 577 /*soft keywords*/ 578 "file import where by get set abstract enum open inner override private public internal " + 579 "protected catch finally out final vararg reified dynamic companion constructor init " + 580 "sealed field property receiver param sparam lateinit data inline noinline tailrec " + 581 "external annotation crossinline const operator infix suspend" 582 ), 583 types: words( 584 /* package java.lang */ 585 "Boolean Byte Character CharSequence Class ClassLoader Cloneable Comparable " + 586 "Compiler Double Exception Float Integer Long Math Number Object Package Pair Process " + 587 "Runtime Runnable SecurityManager Short StackTraceElement StrictMath String " + 588 "StringBuffer System Thread ThreadGroup ThreadLocal Throwable Triple Void" 589 ), 590 intendSwitch: false, 591 indentStatements: false, 592 multiLineStrings: true, 593 number: /^(?:0x[a-f\d_]+|0b[01_]+|(?:[\d_]+\.?\d*|\.\d+)(?:e[-+]?[\d_]+)?)(u|ll?|l|f)?/i, 594 blockKeywords: words("catch class do else finally for if where try while enum"), 595 defKeywords: words("class val var object interface fun"), 596 atoms: words("true false null this"), 597 hooks: { 598 '"': function(stream, state) { 599 state.tokenize = tokenKotlinString(stream.match('""')); 600 return state.tokenize(stream, state); 601 } 602 }, 603 modeProps: {closeBrackets: {triples: '"'}} 604 }); 605 606 def(["x-shader/x-vertex", "x-shader/x-fragment"], { 607 name: "clike", 608 keywords: words("sampler1D sampler2D sampler3D samplerCube " + 609 "sampler1DShadow sampler2DShadow " + 610 "const attribute uniform varying " + 611 "break continue discard return " + 612 "for while do if else struct " + 613 "in out inout"), 614 types: words("float int bool void " + 615 "vec2 vec3 vec4 ivec2 ivec3 ivec4 bvec2 bvec3 bvec4 " + 616 "mat2 mat3 mat4"), 617 blockKeywords: words("for while do if else struct"), 618 builtin: words("radians degrees sin cos tan asin acos atan " + 619 "pow exp log exp2 sqrt inversesqrt " + 620 "abs sign floor ceil fract mod min max clamp mix step smoothstep " + 621 "length distance dot cross normalize ftransform faceforward " + 622 "reflect refract matrixCompMult " + 623 "lessThan lessThanEqual greaterThan greaterThanEqual " + 624 "equal notEqual any all not " + 625 "texture1D texture1DProj texture1DLod texture1DProjLod " + 626 "texture2D texture2DProj texture2DLod texture2DProjLod " + 627 "texture3D texture3DProj texture3DLod texture3DProjLod " + 628 "textureCube textureCubeLod " + 629 "shadow1D shadow2D shadow1DProj shadow2DProj " + 630 "shadow1DLod shadow2DLod shadow1DProjLod shadow2DProjLod " + 631 "dFdx dFdy fwidth " + 632 "noise1 noise2 noise3 noise4"), 633 atoms: words("true false " + 634 "gl_FragColor gl_SecondaryColor gl_Normal gl_Vertex " + 635 "gl_MultiTexCoord0 gl_MultiTexCoord1 gl_MultiTexCoord2 gl_MultiTexCoord3 " + 636 "gl_MultiTexCoord4 gl_MultiTexCoord5 gl_MultiTexCoord6 gl_MultiTexCoord7 " + 637 "gl_FogCoord gl_PointCoord " + 638 "gl_Position gl_PointSize gl_ClipVertex " + 639 "gl_FrontColor gl_BackColor gl_FrontSecondaryColor gl_BackSecondaryColor " + 640 "gl_TexCoord gl_FogFragCoord " + 641 "gl_FragCoord gl_FrontFacing " + 642 "gl_FragData gl_FragDepth " + 643 "gl_ModelViewMatrix gl_ProjectionMatrix gl_ModelViewProjectionMatrix " + 644 "gl_TextureMatrix gl_NormalMatrix gl_ModelViewMatrixInverse " + 645 "gl_ProjectionMatrixInverse gl_ModelViewProjectionMatrixInverse " + 646 "gl_TexureMatrixTranspose gl_ModelViewMatrixInverseTranspose " + 647 "gl_ProjectionMatrixInverseTranspose " + 648 "gl_ModelViewProjectionMatrixInverseTranspose " + 649 "gl_TextureMatrixInverseTranspose " + 650 "gl_NormalScale gl_DepthRange gl_ClipPlane " + 651 "gl_Point gl_FrontMaterial gl_BackMaterial gl_LightSource gl_LightModel " + 652 "gl_FrontLightModelProduct gl_BackLightModelProduct " + 653 "gl_TextureColor gl_EyePlaneS gl_EyePlaneT gl_EyePlaneR gl_EyePlaneQ " + 654 "gl_FogParameters " + 655 "gl_MaxLights gl_MaxClipPlanes gl_MaxTextureUnits gl_MaxTextureCoords " + 656 "gl_MaxVertexAttribs gl_MaxVertexUniformComponents gl_MaxVaryingFloats " + 657 "gl_MaxVertexTextureImageUnits gl_MaxTextureImageUnits " + 658 "gl_MaxFragmentUniformComponents gl_MaxCombineTextureImageUnits " + 659 "gl_MaxDrawBuffers"), 660 indentSwitch: false, 661 hooks: {"#": cppHook}, 662 modeProps: {fold: ["brace", "include"]} 663 }); 664 665 def("text/x-nesc", { 666 name: "clike", 667 keywords: words(cKeywords + "as atomic async call command component components configuration event generic " + 668 "implementation includes interface module new norace nx_struct nx_union post provides " + 669 "signal task uses abstract extends"), 670 types: words(cTypes), 671 blockKeywords: words("case do else for if switch while struct"), 672 atoms: words("null true false"), 673 hooks: {"#": cppHook}, 674 modeProps: {fold: ["brace", "include"]} 675 }); 676 677 def("text/x-objectivec", { 678 name: "clike", 679 keywords: words(cKeywords + "inline restrict _Bool _Complex _Imaginary BOOL Class bycopy byref id IMP in " + 680 "inout nil oneway out Protocol SEL self super atomic nonatomic retain copy readwrite readonly"), 681 types: words(cTypes), 682 atoms: words("YES NO NULL NILL ON OFF true false"), 683 hooks: { 684 "@": function(stream) { 685 stream.eatWhile(/[\w\$]/); 686 return "keyword"; 687 }, 688 "#": cppHook, 689 indent: function(_state, ctx, textAfter) { 690 if (ctx.type == "statement" && /^@\w/.test(textAfter)) return ctx.indented 691 } 692 }, 693 modeProps: {fold: "brace"} 694 }); 695 696 def("text/x-squirrel", { 697 name: "clike", 698 keywords: words("base break clone continue const default delete enum extends function in class" + 699 " foreach local resume return this throw typeof yield constructor instanceof static"), 700 types: words(cTypes), 701 blockKeywords: words("case catch class else for foreach if switch try while"), 702 defKeywords: words("function local class"), 703 typeFirstDefinitions: true, 704 atoms: words("true false null"), 705 hooks: {"#": cppHook}, 706 modeProps: {fold: ["brace", "include"]} 707 }); 708 709 // Ceylon Strings need to deal with interpolation 710 var stringTokenizer = null; 711 function tokenCeylonString(type) { 712 return function(stream, state) { 713 var escaped = false, next, end = false; 714 while (!stream.eol()) { 715 if (!escaped && stream.match('"') && 716 (type == "single" || stream.match('""'))) { 717 end = true; 718 break; 719 } 720 if (!escaped && stream.match('``')) { 721 stringTokenizer = tokenCeylonString(type); 722 end = true; 723 break; 724 } 725 next = stream.next(); 726 escaped = type == "single" && !escaped && next == "\\"; 727 } 728 if (end) 729 state.tokenize = null; 730 return "string"; 731 } 732 } 733 734 def("text/x-ceylon", { 735 name: "clike", 736 keywords: words("abstracts alias assembly assert assign break case catch class continue dynamic else" + 737 " exists extends finally for function given if import in interface is let module new" + 738 " nonempty object of out outer package return satisfies super switch then this throw" + 739 " try value void while"), 740 types: function(word) { 741 // In Ceylon all identifiers that start with an uppercase are types 742 var first = word.charAt(0); 743 return (first === first.toUpperCase() && first !== first.toLowerCase()); 744 }, 745 blockKeywords: words("case catch class dynamic else finally for function if interface module new object switch try while"), 746 defKeywords: words("class dynamic function interface module object package value"), 747 builtin: words("abstract actual aliased annotation by default deprecated doc final formal late license" + 748 " native optional sealed see serializable shared suppressWarnings tagged throws variable"), 749 isPunctuationChar: /[\[\]{}\(\),;\:\.`]/, 750 isOperatorChar: /[+\-*&%=<>!?|^~:\/]/, 751 numberStart: /[\d#$]/, 752 number: /^(?:#[\da-fA-F_]+|\$[01_]+|[\d_]+[kMGTPmunpf]?|[\d_]+\.[\d_]+(?:[eE][-+]?\d+|[kMGTPmunpf]|)|)/i, 753 multiLineStrings: true, 754 typeFirstDefinitions: true, 755 atoms: words("true false null larger smaller equal empty finished"), 756 indentSwitch: false, 757 styleDefs: false, 758 hooks: { 759 "@": function(stream) { 760 stream.eatWhile(/[\w\$_]/); 761 return "meta"; 762 }, 763 '"': function(stream, state) { 764 state.tokenize = tokenCeylonString(stream.match('""') ? "triple" : "single"); 765 return state.tokenize(stream, state); 766 }, 767 '`': function(stream, state) { 768 if (!stringTokenizer || !stream.match('`')) return false; 769 state.tokenize = stringTokenizer; 770 stringTokenizer = null; 771 return state.tokenize(stream, state); 772 }, 773 "'": function(stream) { 774 stream.eatWhile(/[\w\$_\xa1-\uffff]/); 775 return "atom"; 776 }, 777 token: function(_stream, state, style) { 778 if ((style == "variable" || style == "type") && 779 state.prevToken == ".") { 780 return "variable-2"; 781 } 782 } 783 }, 784 modeProps: { 785 fold: ["brace", "import"], 786 closeBrackets: {triples: '"'} 787 } 788 }); 789 790 });
Downloadmodules/editor/codemirror/mode/clike/clike.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.