OPEL language support for CodeMirror — syntax highlighting, indentation, folding, autocomplete, and linting.
npm install @allegro/codemirror-lang-opelimport { opelExtensions } from '@allegro/codemirror-lang-opel';
const extensions = opelExtensions();import { EditorState } from '@codemirror/state';
import { EditorView } from '@codemirror/view';
import { opelExtensions } from '@allegro/codemirror-lang-opel';
const state = EditorState.create({
doc: 'if (true) { val x = 1 }',
extensions: opelExtensions({
enableLinter: true,
includeLintGutter: true,
warnOnLambdaDefinitions: true,
runtimeGlobals: ['ctx', 'env'],
}),
});
new EditorView({
state,
parent: document.querySelector('#editor')!,
});Available options:
enableLinter(default:true)includeLintGutter(default:true)warnOnLambdaDefinitions(default:true) — emits a linter warning for each lambda definition.runtimeGlobals(default:[]) — variable names treated as globally available at runtime, so linter does not report them as undeclared.
Node ≥ 22 and npm ≥ 10.
npm run devThis command:
- Regenerates the Lezer parser from
src/grammar/opel.grammaronce at startup. - Starts Storybook at http://localhost:6006 for an interactive playground.
- Watches
src/grammar/opel.grammar— any grammar change automatically rerunsgenerate-parser, which Vite hot-reloads into the running stories.
npm run generate-parser:watchnpm run buildRuns parser generation, TypeScript type-check, and Rollup bundling. Output goes to dist/.
Stories live in examples/storybook/stories/ and import directly from src/, so parser changes are immediately reflected without a separate build step.
Each story category file also generates its own Docs page (autodocs), so OPEL/Basic Expressions, OPEL/If Else, etc. have separate category-level documentation.
| Story group | What it shows |
|---|---|
| Basic Expressions | Arithmetic, string concat, comparisons |
| Variable Declarations | val declarations, scope, duplicate warning |
| If Else | Conditional expressions, nesting |
| Linting | Syntax errors, undeclared variables, warnings |