Debian Codegraph @

codemirror-legacy-modes/mode/cmake.js

raw
1 var variable_regex = /({)?[a-zA-Z0-9_]+(})?/;
2
3 function tokenString(stream, state) {
4 var current, prev, found_var = false;
5 while (!stream.eol() && (current = stream.next()) != state.pending) {
6 if (current === '$' && prev != '\\' && state.pending == '"') {
7 found_var = true;
8 break;
9 }
10 prev = current;
11 }
12 if (found_var) {
13 stream.backUp(1);
14 }
15 if (current == state.pending) {
16 state.continueString = false;
17 } else {
18 state.continueString = true;
19 }
20 return "string";
21 }
22
23 function tokenize(stream, state) {
24 var ch = stream.next();
25
26 // Have we found a variable?
27 if (ch === '$') {
28 if (stream.match(variable_regex)) {
29 return 'variableName.special';
30 }
31 return 'variable';
32 }
33 // Should we still be looking for the end of a string?
34 if (state.continueString) {
35 // If so, go through the loop again
36 stream.backUp(1);
37 return tokenString(stream, state);
38 }
39 // Do we just have a function on our hands?
40 // In 'cmake_minimum_required (VERSION 2.8.8)', 'cmake_minimum_required' is matched
41 if (stream.match(/(\s+)?\w+\(/) || stream.match(/(\s+)?\w+\ \(/)) {
42 stream.backUp(1);
43 return 'def';
44 }
45 if (ch == "#") {
46 stream.skipToEnd();
47 return "comment";
48 }
49 // Have we found a string?
50 if (ch == "'" || ch == '"') {
51 // Store the type (single or double)
52 state.pending = ch;
53 // Perform the looping function to find the end
54 return tokenString(stream, state);
55 }
56 if (ch == '(' || ch == ')') {
57 return 'bracket';
58 }
59 if (ch.match(/[0-9]/)) {
60 return 'number';
61 }
62 stream.eatWhile(/[\w-]/);
63 return null;
64 }
65 export const cmake = {
66 name: "cmake",
67 startState: function () {
68 var state = {};
69 state.inDefinition = false;
70 state.inInclude = false;
71 state.continueString = false;
72 state.pending = false;
73 return state;
74 },
75 token: function (stream, state) {
76 if (stream.eatSpace()) return null;
77 return tokenize(stream, state);
78 }
79 };
80