Skip to content

Commit

Permalink
fix(grammar): add syntax highlighting for main phases
Browse files Browse the repository at this point in the history
  • Loading branch information
puria committed Aug 28, 2024
1 parent 107df0c commit 7a5ebd2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
1 change: 1 addition & 0 deletions grammar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"types": "dist/index.d.ts",
"sideEffects": false,
"dependencies": {
"@codemirror/autocomplete": "^6.18.0",
"@codemirror/language": "^6.0.0",
"@lezer/highlight": "^1.0.0",
"@lezer/lr": "^1.0.0"
Expand Down
58 changes: 34 additions & 24 deletions grammar/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,43 @@
//
// SPDX-License-Identifier: AGPL-3.0-or-later

import {parser} from "./syntax.grammar"
import {LRLanguage, LanguageSupport, indentNodeProp, foldNodeProp, foldInside, delimitedIndent} from "@codemirror/language"
import {styleTags, tags as t} from "@lezer/highlight"
import { parser } from "./syntax.grammar"
import { LRLanguage, LanguageSupport, indentNodeProp, foldNodeProp, foldInside, delimitedIndent } from "@codemirror/language"
import { styleTags, tags as t } from "@lezer/highlight"
import { completeFromList } from "@codemirror/autocomplete"

export const SlangroomLanguage = LRLanguage.define({
parser: parser.configure({
props: [
indentNodeProp.add({
Application: delimitedIndent({closing: ")", align: false})
}),
foldNodeProp.add({
Application: foldInside
}),
styleTags({
Identifier: t.variableName,
Boolean: t.bool,
String: t.string,
LineComment: t.lineComment,
"( )": t.paren
})
]
}),
languageData: {
commentTokens: {line: ";"}
}
parser: parser.configure({
props: [
indentNodeProp.add({
Application: delimitedIndent({ closing: ")", align: false })
}),
foldNodeProp.add({
Application: foldInside
}),
styleTags({
Identifier: t.variableName,
WhenStatement: t.variableName,
ThenStatement: t.bool,
Rule: t.string,
StringLitteral: t.string,
LineComment: t.lineComment
})
]
}),
languageData: {
commentTokens: { line: "#" }
}
})

export const ac = SlangroomLanguage.data.of({
autocomplete: completeFromList([
{ label: "given", type: "keyword" },
{ label: "then", type: "keyword" },
{ label: "when", type: "keyword" }
])
})

export function Slangroom() {
return new LanguageSupport(SlangroomLanguage)
return new LanguageSupport(SlangroomLanguage, [ac])
}

0 comments on commit 7a5ebd2

Please sign in to comment.