Provides syntax highlighting, code folding, and autocompletion for the Scanspec language in CodeMirror 6.
- Syntax highlighting for keywords, types, operators, strings, numbers, comments, and variables
- Code folding for
if/endandfor/endblocks - Autocompletion for keywords, types, built-in functions (
len,toInt64), and all module functions (math.*,graphs.*,strings.*,numbers.*,arrays.*,matrices.*,regexp.*) with parameter hints
Install dependencies and build the Lezer grammar:
npm install
npm run build
This compiles scanspec.grammar into scanspec.grammar.js, which is imported by scanspec.js.
import { scanspec } from "./scanspec.js"
import { EditorView, basicSetup } from "codemirror"
new EditorView({
extensions: [basicSetup, scanspec()],
parent: document.getElementById("editor"),
})scanspec.grammar— Lezer grammar source defining the Scanspec syntaxscanspec.js— Language definition, highlighting rules, and autocompletionscanspec.grammar.js— Compiled parser (generated bynpm run build, not checked in)scanspec.grammar.terms.js— Compiled token terms (generated bynpm run build, not checked in)
When new modules or functions are added to Scanspec, update the moduleFunctions array in scanspec.js to include them in autocompletion.
If the Scanspec grammar changes (new statement types, operators, etc.), update scanspec.grammar and rebuild.