| 1 |
export const spreadsheet = { |
| 2 |
name: "spreadsheet", |
| 3 |
|
| 4 |
startState: function () { |
| 5 |
return { |
| 6 |
stringType: null, |
| 7 |
stack: [] |
| 8 |
}; |
| 9 |
}, |
| 10 |
token: function (stream, state) { |
| 11 |
if (!stream) return; |
| 12 |
|
| 13 |
//check for state changes |
| 14 |
if (state.stack.length === 0) { |
| 15 |
//strings |
| 16 |
if ((stream.peek() == '"') || (stream.peek() == "'")) { |
| 17 |
state.stringType = stream.peek(); |
| 18 |
stream.next(); // Skip quote |
| 19 |
state.stack.unshift("string"); |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
//return state |
| 24 |
//stack has |
| 25 |
switch (state.stack[0]) { |
| 26 |
case "string": |
| 27 |
while (state.stack[0] === "string" && !stream.eol()) { |
| 28 |
if (stream.peek() === state.stringType) { |
| 29 |
stream.next(); // Skip quote |
| 30 |
state.stack.shift(); // Clear flag |
| 31 |
} else if (stream.peek() === "\\") { |
| 32 |
stream.next(); |
| 33 |
stream.next(); |
| 34 |
} else { |
| 35 |
stream.match(/^.[^\\\"\']*/); |
| 36 |
} |
| 37 |
} |
| 38 |
return "string"; |
| 39 |
|
| 40 |
case "characterClass": |
| 41 |
while (state.stack[0] === "characterClass" && !stream.eol()) { |
| 42 |
if (!(stream.match(/^[^\]\\]+/) || stream.match(/^\\./))) |
| 43 |
state.stack.shift(); |
| 44 |
} |
| 45 |
return "operator"; |
| 46 |
} |
| 47 |
|
| 48 |
var peek = stream.peek(); |
| 49 |
|
| 50 |
//no stack |
| 51 |
switch (peek) { |
| 52 |
case "[": |
| 53 |
stream.next(); |
| 54 |
state.stack.unshift("characterClass"); |
| 55 |
return "bracket"; |
| 56 |
case ":": |
| 57 |
stream.next(); |
| 58 |
return "operator"; |
| 59 |
case "\\": |
| 60 |
if (stream.match(/\\[a-z]+/)) return "string.special"; |
| 61 |
else { |
| 62 |
stream.next(); |
| 63 |
return "atom"; |
| 64 |
} |
| 65 |
case ".": |
| 66 |
case ",": |
| 67 |
case ";": |
| 68 |
case "*": |
| 69 |
case "-": |
| 70 |
case "+": |
| 71 |
case "^": |
| 72 |
case "<": |
| 73 |
case "/": |
| 74 |
case "=": |
| 75 |
stream.next(); |
| 76 |
return "atom"; |
| 77 |
case "$": |
| 78 |
stream.next(); |
| 79 |
return "builtin"; |
| 80 |
} |
| 81 |
|
| 82 |
if (stream.match(/\d+/)) { |
| 83 |
if (stream.match(/^\w+/)) return "error"; |
| 84 |
return "number"; |
| 85 |
} else if (stream.match(/^[a-zA-Z_]\w*/)) { |
| 86 |
if (stream.match(/(?=[\(.])/, false)) return "keyword"; |
| 87 |
return "variable"; |
| 88 |
} else if (["[", "]", "(", ")", "{", "}"].indexOf(peek) != -1) { |
| 89 |
stream.next(); |
| 90 |
return "bracket"; |
| 91 |
} else if (!stream.eatSpace()) { |
| 92 |
stream.next(); |
| 93 |
} |
| 94 |
return null; |
| 95 |
} |
| 96 |
}; |