Code editor language support

This commit is contained in:
space-nuko
2023-06-20 02:08:36 -05:00
parent 43ed176502
commit c875f9c4f6
6 changed files with 91 additions and 33 deletions

View File

@@ -0,0 +1,36 @@
@top Program { expression* }
@skip {} {
BlockComment { "/*" (blockCommentContent | blockCommentNewline)* blockCommentEnd }
}
@skip { space | LineComment | BlockComment }
@local tokens {
blockCommentEnd { "*/" }
blockCommentNewline { "\n" }
@else blockCommentContent
}
expression {
Identifier |
String |
Boolean |
Application { "(" expression* ")" }
}
@tokens {
Identifier { $[a-zA-Z_\-0-9]+ }
String { '"' (!["\\] | "\\" _)* '"' }
Boolean { "#t" | "#f" }
LineComment { "//" ![\n]* }
space { $[ \t\n\r]+ }
"(" ")"
}
@detectDelim

3
src/lib/widgets/ComfyUI.grammar.d.ts vendored Normal file
View File

@@ -0,0 +1,3 @@
import { LRParser } from "@lezer/lr"
export declare const parser: LRParser

View File

@@ -14,7 +14,8 @@ import {
indentOnInput,
syntaxHighlighting,
defaultHighlightStyle,
foldKeymap
foldKeymap,
LRLanguage, LanguageSupport, indentNodeProp, foldNodeProp, foldInside, delimitedIndent
} from "@codemirror/language";
import { history, defaultKeymap, historyKeymap } from "@codemirror/commands";
import {
@@ -27,8 +28,26 @@ import {
type CompletionSource, autocompletion, CompletionContext, startCompletion,
currentCompletions, completionStatus, completeFromList, acceptCompletion
} from "@codemirror/autocomplete"
import { styleTags, tags as t } from "@lezer/highlight"
import DanbooruTags from "$lib/DanbooruTags";
import { parser } from "./ComfyUI.grammar"
export const comfyUILanguage = LRLanguage.define({
name: "ComfyUI",
parser: parser.configure({
props: [
styleTags({
LineComment: t.lineComment,
BlockComment: t.blockComment,
})
]
}),
languageData: {
commentTokens: { line: "//", block: { open: "/*", close: "*/" } },
}
})
export const basicSetup: Extension = /*@__PURE__*/ (() => [
lineNumbers(),
highlightSpecialChars(),
@@ -43,6 +62,7 @@ export const basicSetup: Extension = /*@__PURE__*/ (() => [
crosshairCursor(),
EditorView.lineWrapping,
DanbooruTags.getCompletionExt(),
new LanguageSupport(comfyUILanguage),
keymap.of([
...closeBracketsKeymap,