1 |
|
2 |
|
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 |
|
41 | if (ch === '$') {
|
42 | if (stream.match(variable_regex)) {
|
43 | return 'variable-2';
|
44 | }
|
45 | return 'variable';
|
46 | }
|
47 |
|
48 | if (state.continueString) {
|
49 |
|
50 | stream.backUp(1);
|
51 | return tokenString(stream, state);
|
52 | }
|
53 |
|
54 |
|
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 |
|
64 | if (ch == "'" || ch == '"') {
|
65 |
|
66 | state.pending = ch;
|
67 |
|
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 | });
|