diff --git a/l4d2web/scripts/editor-src/srccfg-mode.js b/l4d2web/scripts/editor-src/srccfg-mode.js new file mode 100644 index 0000000..9c1944c --- /dev/null +++ b/l4d2web/scripts/editor-src/srccfg-mode.js @@ -0,0 +1,26 @@ +import { StreamLanguage } from "@codemirror/language"; + +// Source-engine .cfg syntax (server.cfg style). +// Linewise. No nesting. Tokens: comment, string, number, keyword, identifier. +const KEYWORDS = new Set(["exec", "alias", "bind", "unbindall", "wait"]); + +export const srccfgLanguage = StreamLanguage.define({ + name: "srccfg", + startState: () => ({}), + token(stream) { + if (stream.eatSpace()) return null; + if (stream.match("//")) { + stream.skipToEnd(); + return "comment"; + } + if (stream.match(/^"(?:[^"\\]|\\.)*"?/)) return "string"; + if (stream.match(/^-?\d+(?:\.\d+)?/)) return "number"; + if (stream.match(/^[A-Za-z_][A-Za-z0-9_]*/)) { + const word = stream.current(); + return KEYWORDS.has(word) ? "keyword" : "variableName"; + } + stream.next(); + return null; + }, + languageData: { commentTokens: { line: "//" } }, +});