LaravelTest
97 строк · 2.5 Кб
1// CodeMirror, copyright (c) by Marijn Haverbeke and others
2// Distributed under an MIT license: https://codemirror.net/LICENSE
3
4(function(mod) {5if (typeof exports == "object" && typeof module == "object")6mod(require("../../lib/codemirror"));7else if (typeof define == "function" && define.amd)8define(["../../lib/codemirror"], mod);9else10mod(CodeMirror);11})(function(CodeMirror) {12"use strict";13
14CodeMirror.defineMode("cmake", function () {15var variable_regex = /({)?[a-zA-Z0-9_]+(})?/;16
17function tokenString(stream, state) {18var current, prev, found_var = false;19while (!stream.eol() && (current = stream.next()) != state.pending) {20if (current === '$' && prev != '\\' && state.pending == '"') {21found_var = true;22break;23}24prev = current;25}26if (found_var) {27stream.backUp(1);28}29if (current == state.pending) {30state.continueString = false;31} else {32state.continueString = true;33}34return "string";35}36
37function tokenize(stream, state) {38var ch = stream.next();39
40// Have we found a variable?41if (ch === '$') {42if (stream.match(variable_regex)) {43return 'variable-2';44}45return 'variable';46}47// Should we still be looking for the end of a string?48if (state.continueString) {49// If so, go through the loop again50stream.backUp(1);51return 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 matched55if (stream.match(/(\s+)?\w+\(/) || stream.match(/(\s+)?\w+\ \(/)) {56stream.backUp(1);57return 'def';58}59if (ch == "#") {60stream.skipToEnd();61return "comment";62}63// Have we found a string?64if (ch == "'" || ch == '"') {65// Store the type (single or double)66state.pending = ch;67// Perform the looping function to find the end68return tokenString(stream, state);69}70if (ch == '(' || ch == ')') {71return 'bracket';72}73if (ch.match(/[0-9]/)) {74return 'number';75}76stream.eatWhile(/[\w-]/);77return null;78}79return {80startState: function () {81var state = {};82state.inDefinition = false;83state.inInclude = false;84state.continueString = false;85state.pending = false;86return state;87},88token: function (stream, state) {89if (stream.eatSpace()) return null;90return tokenize(stream, state);91}92};93});94
95CodeMirror.defineMIME("text/x-cmake", "cmake");96
97});98