tree-sitter-oxl
A tree-sitter grammar for OxL ([С III.3], D-6780), for editors that highlight with
tree-sitter (Neovim, Helix, Zed, Emacs 29+, …). Semantic features (types, rename, diagnostics, inlay hints) come from the
language server oxl lsp (docs/lsp.md); this grammar only needs the text.
What it parses#
A structural grammar: top-level items with their kind and name (function_item, data_item, enum_item,
interface_item, actor_item, service_item, impl_item, type_item, const_item, static_item, test_item,
fixture_item, pipeline_item, saga_item, topic_item, config_item, cluster_item, policy_item, use_item, …,
plus attribute_item / visibility_item for the @attr / pub(api) / comptime that precede a declaration); bodies
are balanced token trees (block, parenthesized, bracketed) in which a few shapes are recognised: fn_head,
rpc_head, msg_head (member names), binding (let x / var x), call (name(…) with no space before (),
attribute, function_type (fn(A) -> R), and every literal of §1.5 (strings with interpolation, raw / prefixed /
multiline strings, chars, labels, integers, floats, durations, sizes, dates).
OxL ends statements at newlines (§1.2); a token tree needs no statement boundaries, so newlines are whitespace and an item
ends where the next item keyword starts at the top level. The compiler's parser remains the reference: the grammar accepts
more than the language. Contextual keywords (on, durable, within, retry, role, effects, …) are identifiers in
the tree; queries/highlights.scm highlights them by name.
Checking#
python3 scripts/check.py -v # always: grammar.js evaluates, queries name only nodes of the grammar
npm install && python3 scripts/check.py -v # with the CLI (devDependency): generate, compile the queries, parse the corpus
python3 scripts/check.py --corpus ../../examples --corpus ../../stdThe corpus check parses conformance/**/*.oxl and requires at least 95 % of the files to have no ERROR / MISSING
node (files whose conformance annotations expect a lexer or parser error are not counted). Current result: 100 % of
1290 files (also of examples/ and std/). The check runs in ctest as tree_sitter_grammar (structural only when the
CLI is not installed).
Using it#
npm install
npx tree-sitter generate # src/parser.c (not committed)
npx tree-sitter parse file.oxl
npx tree-sitter highlight file.oxlИсходник: tools/tree-sitter-oxl/README.md