Skill v1.0.1
Automated scan100/100+4 new
version: "1.0.1" name: tree-sitter description: Author and bind tree-sitter 0.25.10 grammars for opentide KQL and SPL. Covers grammar.js, vendored parser.c, the tree-sitter CLI pin, Language::from_raw, QueryCursor StreamingIterator, and highlights.scm first-wins. Use when editing grammars/, crates/opentide-syntax, or highlights/queries. license: EUPL-1.2 metadata: author: opentidehq
tree-sitter 0.25
The Rust crate and the CLI are both 0.25.10. CI installs tree-sitter-cli@0.25.10 (npm install --prefix /tmp/ts-cli tree-sitter-cli@0.25.10). scripts/cloud-agent-install.sh installs that same version. A parser generated by any other CLI fails scripts/check-grammars.sh.
Grammars are vendored under grammars/tree-sitter-opentide-{kql,spl}/. There is no scanner (scanner.c). crates/opentide-syntax/build.rs compiles src/parser.c with the cc crate. Do not publish these grammars as separate crates and do not depend on a crates.io grammar.
Read references/grammar-workflow.md before editing grammar.js. Read references/query-api.md before calling QueryCursor.
Generate, do not hand-edit
Generated files:
grammars/tree-sitter-opentide-<id>/src/parser.csrc/grammar.jsonsrc/node-types.json- the headers under
src/tree_sitter/
Edit grammar.js only, then run this from the repository root. tree-sitter generate has to see grammar.js, and scripts/check-grammars.sh is not on the path from inside the grammar directory:
(cd grammars/tree-sitter-opentide-kql && tree-sitter generate) # or -splbash scripts/check-grammars.sh
check-grammars.sh copies the grammar to a temp directory, runs tree-sitter generate, and diffs parser.c. Commit the regenerated files. A hand-edited parser.c will not match the next generate and will fail CI.
Grammar shape this repo uses
grammar.js starts with /// <reference types="tree-sitter-cli/dsl" /> and module.exports = grammar({...}).
nameisopentide_kqloropentide_spl(underscores). That becomes the C symboltree_sitter_opentide_kql. It is not the LSP language id (kql).extrasare whitespace and$.comment.wordis$.identifier.- Pipelines are
prec.leftsequences ofprimarythenrepeat(seq("|", operator)). - KQL control commands (
.plus a name) are a real production so the engine can emitkql_control_command_unsupported. They are not valid detections. - SPL unknown commands are a production (
unknown_command), not a parse error, sospl_unknown_commandcan be diagnosed. - SQL is not a grammar. Do not add a
selectstatement production "for later".
Prefer a JS DSL rule over an external scanner. Adding scanner.c means updating build.rs (compile the extra C file) and check-grammars.sh. Do not add one unless the DSL cannot express the token.
Corpus gate
Every production the engine claims is covered by a fixture under testdata/corpus/<id>/. The first line tags the production:
// prod:take_operator validSecurityEvent | take 1
crates/opentide-syntax/tests/corpus_gate.rs requires those prod:<rule> tags and checks named rules in grammar.json. A new named rule is either added to the required list and given a fixture, or added to the explicit skip set with a reason (structural rules such as expression and source_file are skipped today). docs/LANGUAGE.md gets a row: id, grammar rule, fixture, capture.
A fixture that only lives in a unit-test string does not satisfy the gate.
Highlight queries
highlights/queries/<id>/highlights.scm capture names are a subset of highlights/spec.toml [meta].legend. An unknown capture fails highlight generation.
Order matters. query_captures keeps the earliest pattern for a span, then drops overlaps so semantic tokens never overlap. Specific patterns go before (identifier) @variable. A keyword pattern listed after @variable loses.
; comments in .scm files are query comments, not KQL comments.
Rust binding
opentide-syntax does not use the crates.io LANGUAGE: LanguageFn constant. It calls the generated C symbol and Language::from_raw. That is the supported 0.25 constructor for a raw *const TSLanguage. The pointer must be non-null and point at the static language from tree_sitter_opentide_*. See references/query-api.md for the cast and for StreamingIterator.
Parser::set_language returns Result. Parser::parse returns Option<Tree>. Tree::root_node().has_error() is the parse-error bit. Do not unwrap a parse of user source; surface kql_parse_error / spl_parse_error.
Tests
cargo test -p opentide-syntaxbash scripts/check-grammars.shcargo run -p opentide-lsp -- generate-highlights --check
A grammar change that shifts node kinds must update the .scm file and the engine's node.kind() matches in the same change. Kind strings are the rule names (where_operator), not display names.