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:
parent
7497cf5416
commit
9226963516
1 changed files with 26 additions and 0 deletions
26
l4d2web/scripts/editor-src/srccfg-mode.js
Normal file
26
l4d2web/scripts/editor-src/srccfg-mode.js
Normal 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: "//" } },
|
||||
});
|
||||
Loading…
Reference in a new issue