~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>
26 lines
874 B
JavaScript
26 lines
874 B
JavaScript
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: "//" } },
|
|
});
|