tree-sitter-lmcode skill
Use tree-sitter-lmcode to parse standalone lmcode chunks for syntax highlighting, static analysis, editor outlines, and AST inspections.
Purpose
Provide a fast, incremental Tree-sitter parser and external C scanner for the inner lmcode language without executing scripts or invoking the compiler.
When to use it
Use tree-sitter-lmcode when building editor integrations, syntax highlighters, linter rules, or AST analysis tools for _lmcode_ blocks.
Install
Install tree-sitter-cli 0.27.1 in a private prefix (or compile the committed src/parser.c and src/scanner.c directly with a C compiler) alongside Node 24 and Python 3.
Commands
tree-sitter generate
tree-sitter test --rebuild
python3 scripts/conformance.py
python3 scripts/negative.py
python3 scripts/incremental.py
python3 scripts/scanner-limits.py
python3 scripts/controls.py
Inputs and outputs
- Input: standalone lmcode source text (extracted from _lmcode_ bodies) or grammar.js during regeneration.
- Output: concrete syntax trees with named AST nodes (function_declaration, annotation, implements_clause, map_entry, return_assignment, splice, heredoc_start, heredoc_body).
- Fixtures: test/fixtures/conformance/manifest.json pinning 127 real extracted lmcode bodies by SHA-256.
Safety rules
- Remember that tree-sitter-lmcode is a syntactic parser only; it does not verify dsl.schema: 2 types, overloads, or bytecode stack safety.
- Standalone lmcode rejects f"..." formatted strings; those belong to the outer lmscript body companion in tree-sitter-lmscript.
- Pair heredoc_start nodes with heredoc_body extra tokens in strict FIFO source order.
Worked examples
# Parse a single lmcode file and inspect its s-expression tree
tree-sitter parse test/fixtures/conformance/067-rule-method.lmcode
Errors and exit codes
| Exit code | Stage | Result | Condition |
|---|---|---|---|
| 0 | parse / test | Exit 0 | All grammar generation, corpus cases, negative syntax-refusal checks, incremental edit gates, and mutation controls pass |
| 1 | conformance | Exit 1 | A corpus fixture produces unexpected ERROR or MISSING nodes, or a negative refusal fixture parses without syntax errors |
| 1 | freshness | Exit 1 | Generated src/parser.c, grammar.json, or node-types.json differs from grammar.js after tree-sitter generate |
| 2 | cli / pin | Exit 2 | Missing TREE_SITTER CLI binary, mismatched tree-sitter-cli version (requires 0.27.1), or missing live corpus root |
How to verify
tree-sitter test --rebuild
python3 scripts/conformance.py
python3 scripts/negative.py
python3 scripts/controls.py