feat(editor-v2): srccfg StreamLanguage mode

~30 LOC StreamLanguage definition for Source-engine .cfg syntax.
Tokens: line comment (//…), string, number, keyword (exec/alias/bind/
unbindall/wait), identifier. Linewise, no nesting — matches the
shape we authored as a Prism regex grammar in the v1 attempt.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
mwiegand 2026-05-17 01:55:59 +02:00
parent 7497cf5416
commit 9226963516
No known key found for this signature in database

View file

@ -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: "//" } },
});