File modules/editor/codemirror/mode/cmake/cmake.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") 6 mod(require("../../lib/codemirror")); 7 else if (typeof define == "function" && define.amd) 8 define(["../../lib/codemirror"], mod); 9 else 10 mod(CodeMirror); 11 })(function(CodeMirror) { 12 "use strict"; 13 14 CodeMirror.defineMode("cmake", function () { 15 var variable_regex = /({)?[a-zA-Z0-9_]+(})?/; 16 17 function tokenString(stream, state) { 18 var current, prev, found_var = false; 19 while (!stream.eol() && (current = stream.next()) != state.pending) { 20 if (current === '$' && prev != '\\' && state.pending == '"') { 21 found_var = true; 22 break; 23 } 24 prev = current; 25 } 26 if (found_var) { 27 stream.backUp(1); 28 } 29 if (current == state.pending) { 30 state.continueString = false; 31 } else { 32 state.continueString = true; 33 } 34 return "string"; 35 } 36 37 function tokenize(stream, state) { 38 var ch = stream.next(); 39 40 // Have we found a variable? 41 if (ch === '$') { 42 if (stream.match(variable_regex)) { 43 return 'variable-2'; 44 } 45 return 'variable'; 46 } 47 // Should we still be looking for the end of a string? 48 if (state.continueString) { 49 // If so, go through the loop again 50 stream.backUp(1); 51 return tokenString(stream, state); 52 } 53 // Do we just have a function on our hands? 54 // In 'cmake_minimum_required (VERSION 2.8.8)', 'cmake_minimum_required' is matched 55 if (stream.match(/(\s+)?\w+\(/) || stream.match(/(\s+)?\w+\ \(/)) { 56 stream.backUp(1); 57 return 'def'; 58 } 59 if (ch == "#") { 60 stream.skipToEnd(); 61 return "comment"; 62 } 63 // Have we found a string? 64 if (ch == "'" || ch == '"') { 65 // Store the type (single or double) 66 state.pending = ch; 67 // Perform the looping function to find the end 68 return tokenString(stream, state); 69 } 70 if (ch == '(' || ch == ')') { 71 return 'bracket'; 72 } 73 if (ch.match(/[0-9]/)) { 74 return 'number'; 75 } 76 stream.eatWhile(/[\w-]/); 77 return null; 78 } 79 return { 80 startState: function () { 81 var state = {}; 82 state.inDefinition = false; 83 state.inInclude = false; 84 state.continueString = false; 85 state.pending = false; 86 return state; 87 }, 88 token: function (stream, state) { 89 if (stream.eatSpace()) return null; 90 return tokenize(stream, state); 91 } 92 }; 93 }); 94 95 CodeMirror.defineMIME("text/x-cmake", "cmake"); 96 97 });
Download modules/editor/codemirror/mode/cmake/cmake.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.