tree-sitter-lmscript guide
This guide explains how tree-sitter-lmscript parses outer LMScript syntax, tracks queued data blocks in src/scanner.c, and injects the companion lmscript_lmcode grammar.
Overview
LMScript files interleave outer orchestration code with queued data blocks opened by _lmcode_ (or _dsl_) headers and closed by end _lmcode_. The outer parser in grammar.js and src/scanner.c scans queued block markers on a single statement line, captures each physical body in an opaque lmcode_body (or data_body) node excluding the header and closer lines, and serializes pending queue state across incremental edits.
Grammar and external scanner rules
To support LMScript's compile-time f"..." body template expansion without polluting standalone lmcode, tree-sitter-lmscript includes a companion grammar in lmcode-body/ named lmscript_lmcode. The companion inherits the pinned tree-sitter-lmcode rules and adds single-line formatted string rules inside a root lmscript_lmcode_body node. queries/injections.scm maps lmcode_body to lmscript_lmcode automatically.
REST, CLI, and rule entry syntax coverage
When an .lms script defines an _lmcode_ block with @"/users/:id" RestGet endpoints, @"status" CliCommand entries, rest_config, rest_route, rest_serve, rest_stop, rest_cli, or $return assignments, the outer parser isolates the block inside data_block_statement -> lmcode_body and the injected lmscript_lmcode parser produces the inner function_declaration, annotation, implements_clause, and return_assignment AST nodes.
# Run the public corpus, 39 Tree-sitter corpus cases, and 3 mutant controls
npm install --prefix /tmp/lmscript-tree-sitter tree-sitter-cli@0.27.1
export TREE_SITTER=/tmp/lmscript-tree-sitter/node_modules/.bin/tree-sitter
npm test
Conformance and mutation controls
Running npm test regenerates the parser with tree-sitter-cli 0.27.1, runs 39 Tree-sitter corpus cases and contract checks, parses the public corpus with zero ERROR or MISSING nodes, and verifies that three production-copy mutants fail closed.