GPQAPP
112 строк · 3.1 Кб
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") // CommonJS6mod(require("../../lib/codemirror"));7else if (typeof define == "function" && define.amd) // AMD8define(["../../lib/codemirror"], mod);9else // Plain browser env10mod(CodeMirror);11})(function(CodeMirror) {12"use strict";13
14CodeMirror.defineMode("spreadsheet", function () {15return {16startState: function () {17return {18stringType: null,19stack: []20};21},22token: function (stream, state) {23if (!stream) return;24
25//check for state changes26if (state.stack.length === 0) {27//strings28if ((stream.peek() == '"') || (stream.peek() == "'")) {29state.stringType = stream.peek();30stream.next(); // Skip quote31state.stack.unshift("string");32}33}34
35//return state36//stack has37switch (state.stack[0]) {38case "string":39while (state.stack[0] === "string" && !stream.eol()) {40if (stream.peek() === state.stringType) {41stream.next(); // Skip quote42state.stack.shift(); // Clear flag43} else if (stream.peek() === "\\") {44stream.next();45stream.next();46} else {47stream.match(/^.[^\\\"\']*/);48}49}50return "string";51
52case "characterClass":53while (state.stack[0] === "characterClass" && !stream.eol()) {54if (!(stream.match(/^[^\]\\]+/) || stream.match(/^\\./)))55state.stack.shift();56}57return "operator";58}59
60var peek = stream.peek();61
62//no stack63switch (peek) {64case "[":65stream.next();66state.stack.unshift("characterClass");67return "bracket";68case ":":69stream.next();70return "operator";71case "\\":72if (stream.match(/\\[a-z]+/)) return "string-2";73else {74stream.next();75return "atom";76}77case ".":78case ",":79case ";":80case "*":81case "-":82case "+":83case "^":84case "<":85case "/":86case "=":87stream.next();88return "atom";89case "$":90stream.next();91return "builtin";92}93
94if (stream.match(/\d+/)) {95if (stream.match(/^\w+/)) return "error";96return "number";97} else if (stream.match(/^[a-zA-Z_]\w*/)) {98if (stream.match(/(?=[\(.])/, false)) return "keyword";99return "variable-2";100} else if (["[", "]", "(", ")", "{", "}"].indexOf(peek) != -1) {101stream.next();102return "bracket";103} else if (!stream.eatSpace()) {104stream.next();105}106return null;107}108};109});110
111CodeMirror.defineMIME("text/x-spreadsheet", "spreadsheet");112});113