File modules/editor/codemirror/mode/dart/dart.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"), require("../clike/clike")); 7 else if (typeof define == "function" && define.amd) // AMD 8 define(["../../lib/codemirror", "../clike/clike"], mod); 9 else // Plain browser env 10 mod(CodeMirror); 11 })(function(CodeMirror) { 12 "use strict"; 13 14 var keywords = ("this super static final const abstract class extends external factory " + 15 "implements get native set typedef with enum throw rethrow " + 16 "assert break case continue default in return new deferred async await covariant " + 17 "try catch finally do else for if switch while import library export " + 18 "part of show hide is as").split(" "); 19 var blockKeywords = "try catch finally do else for if switch while".split(" "); 20 var atoms = "true false null".split(" "); 21 var builtins = "void bool num int double dynamic var String".split(" "); 22 23 function set(words) { 24 var obj = {}; 25 for (var i = 0; i < words.length; ++i) obj[words[i]] = true; 26 return obj; 27 } 28 29 function pushInterpolationStack(state) { 30 (state.interpolationStack || (state.interpolationStack = [])).push(state.tokenize); 31 } 32 33 function popInterpolationStack(state) { 34 return (state.interpolationStack || (state.interpolationStack = [])).pop(); 35 } 36 37 function sizeInterpolationStack(state) { 38 return state.interpolationStack ? state.interpolationStack.length : 0; 39 } 40 41 CodeMirror.defineMIME("application/dart", { 42 name: "clike", 43 keywords: set(keywords), 44 blockKeywords: set(blockKeywords), 45 builtin: set(builtins), 46 atoms: set(atoms), 47 hooks: { 48 "@": function(stream) { 49 stream.eatWhile(/[\w\$_\.]/); 50 return "meta"; 51 }, 52 53 // custom string handling to deal with triple-quoted strings and string interpolation 54 "'": function(stream, state) { 55 return tokenString("'", stream, state, false); 56 }, 57 "\"": function(stream, state) { 58 return tokenString("\"", stream, state, false); 59 }, 60 "r": function(stream, state) { 61 var peek = stream.peek(); 62 if (peek == "'" || peek == "\"") { 63 return tokenString(stream.next(), stream, state, true); 64 } 65 return false; 66 }, 67 68 "}": function(_stream, state) { 69 // "}" is end of interpolation, if interpolation stack is non-empty 70 if (sizeInterpolationStack(state) > 0) { 71 state.tokenize = popInterpolationStack(state); 72 return null; 73 } 74 return false; 75 }, 76 77 "/": function(stream, state) { 78 if (!stream.eat("*")) return false 79 state.tokenize = tokenNestedComment(1) 80 return state.tokenize(stream, state) 81 } 82 } 83 }); 84 85 function tokenString(quote, stream, state, raw) { 86 var tripleQuoted = false; 87 if (stream.eat(quote)) { 88 if (stream.eat(quote)) tripleQuoted = true; 89 else return "string"; //empty string 90 } 91 function tokenStringHelper(stream, state) { 92 var escaped = false; 93 while (!stream.eol()) { 94 if (!raw && !escaped && stream.peek() == "$") { 95 pushInterpolationStack(state); 96 state.tokenize = tokenInterpolation; 97 return "string"; 98 } 99 var next = stream.next(); 100 if (next == quote && !escaped && (!tripleQuoted || stream.match(quote + quote))) { 101 state.tokenize = null; 102 break; 103 } 104 escaped = !raw && !escaped && next == "\\"; 105 } 106 return "string"; 107 } 108 state.tokenize = tokenStringHelper; 109 return tokenStringHelper(stream, state); 110 } 111 112 function tokenInterpolation(stream, state) { 113 stream.eat("$"); 114 if (stream.eat("{")) { 115 // let clike handle the content of ${...}, 116 // we take over again when "}" appears (see hooks). 117 state.tokenize = null; 118 } else { 119 state.tokenize = tokenInterpolationIdentifier; 120 } 121 return null; 122 } 123 124 function tokenInterpolationIdentifier(stream, state) { 125 stream.eatWhile(/[\w_]/); 126 state.tokenize = popInterpolationStack(state); 127 return "variable"; 128 } 129 130 function tokenNestedComment(depth) { 131 return function (stream, state) { 132 var ch 133 while (ch = stream.next()) { 134 if (ch == "*" && stream.eat("/")) { 135 if (depth == 1) { 136 state.tokenize = null 137 break 138 } else { 139 state.tokenize = tokenNestedComment(depth - 1) 140 return state.tokenize(stream, state) 141 } 142 } else if (ch == "/" && stream.eat("*")) { 143 state.tokenize = tokenNestedComment(depth + 1) 144 return state.tokenize(stream, state) 145 } 146 } 147 return "comment" 148 } 149 } 150 151 CodeMirror.registerHelper("hintWords", "application/dart", keywords.concat(atoms).concat(builtins)); 152 153 // This is needed to make loading through meta.js work. 154 CodeMirror.defineMode("dart", function(conf) { 155 return CodeMirror.getMode(conf, "application/dart"); 156 }, "clike"); 157 });
Download modules/editor/codemirror/mode/dart/dart.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.