@enspirit/codemirror-lang-elo
v0.1.0
Published
Elo language support for CodeMirror 6
Readme
@enspirit/codemirror-lang-elo
Elo language support for CodeMirror 6.
Provides syntax highlighting, bracket matching, code folding, indentation, comment toggling, and autocompletion for the Elo expression language via a proper Lezer grammar (incremental parsing, full syntax tree).
Installation
npm install @enspirit/codemirror-lang-eloUsage
import { EditorView, basicSetup } from "codemirror";
import { elo } from "@enspirit/codemirror-lang-elo";
new EditorView({
extensions: [basicSetup, elo()],
parent: document.querySelector("#editor"),
});What you get
- Syntax highlighting for all Elo constructs: keywords, strings, numbers, dates, durations, temporal keywords, types, operators, comments.
- Bracket matching for
(),[],{}. - Code folding for objects, arrays, lambdas, and type schemas.
- Indentation support inside delimited blocks.
- Comment toggling with
#. - Autocompletion for stdlib functions, keywords, temporal keywords, and built-in type names.
Advanced: accessing the language object
If you need the LRLanguage instance (e.g. for custom extensions):
import { eloLanguage } from "@enspirit/codemirror-lang-elo";
// eloLanguage is an LRLanguage — use it to build custom LanguageSupport,
// access the parser, etc.
const parser = eloLanguage.parser;Theming
This package provides language support only, not a theme. Syntax nodes are
mapped to standard @lezer/highlight tags, so any CodeMirror theme will
work. The tags used are:
| Elo construct | Highlight tag |
|---|---|
| let, in, fn | definitionKeyword |
| if, then, else, guard, check | controlKeyword |
| and, or, not | operatorKeyword |
| true, false | bool |
| null | null |
| Numbers | number |
| Strings | string |
| Date / DateTime literals | special(literal) |
| Duration literals | special(number) |
| Temporal keywords (NOW, TODAY, ...) | standard(variableName) |
| Type names (Int, String, ...) | typeName |
| Function calls | function(variableName) |
| Property names | propertyName |
| Comments | lineComment |
| Operators | compareOperator, arithmeticOperator, logicOperator, operator |
Development
Building
npm install
npm run prepare # compiles the Lezer grammar and bundles with RollupTesting
npm test # runs Lezer grammar tests (test/cases.txt)Grammar test format
Tests live in test/cases.txt using the
Lezer test format:
# Test name
source code here
==>
Expected(TreeStructure)Publishing
Make sure all tests pass:
npm testBump the version in
package.json.Build the package:
npm run preparePublish to npm:
npm publish --access publicThe
--access publicflag is required for scoped packages on the first publish.
License
MIT
