Files
Decodal/packages/decodal-codemirror

decodal-codemirror

CodeMirror 6 language support for Decodal.

This package provides the Lezer parser metadata, highlighting tags, indentation rules, block folding, and formatter command used by the Decodal Web playground. It does not include the Decodal runtime evaluator. Use decodal-wasm when you want to evaluate Decodal in a browser.

Install

npm install decodal-codemirror

JSR:

deno add jsr:@hare/decodal-codemirror

Usage

import { basicSetup } from 'codemirror';
import { EditorView } from '@codemirror/view';
import { decodal } from 'decodal-codemirror';

new EditorView({
  doc: 'Server = { port = Int default 8080; };',
  extensions: [
    basicSetup,
    decodal(),
  ],
  parent: document.querySelector('#editor'),
});

Exports

import {
  decodal,
  decodalLanguage,
  decodalHighlightStyle,
} from 'decodal-codemirror';

decodal() accepts a small options object:

decodal({ highlight: false })

Use this when you want the language support without the bundled highlight style.

Formatting

The formatter is exposed as a separate subpath so plain syntax highlighting does not force callers to initialize WebAssembly.

import {
  formatDecodal,
  formatDecodalCommand,
  initDecodalFormatter,
} from 'decodal-codemirror/format';
import formatterWasm from 'decodal-codemirror/wasm/decodal_language_tools_bg.wasm?url';

await initDecodalFormatter(formatterWasm);

const result = formatDecodal('Server={port=Int default 8080;};');
if (result.ok) console.log(result.source);

formatDecodalCommand(view);