pactole-syntax
Tolerant syntax analysis of .pactole source text: positions,
diagnostics, never an unrecoverable failure.
Role
pactole-syntax sits between the raw tree-sitter grammar
(tree-sitter-pactole) and higher-level consumers such as
pactole-storage-fs or pactole-lsp. It performs no I/O and never
depends on pactole-core: it only manipulates the concrete syntax tree
(CST) and its diagnostics, never domain models. The parsing it provides
always succeeds, even on invalid text: errors are reported as
positioned diagnostics rather than blocking failures.
Main API
Re-exported from src/lib.rs:
span:Point(byte offset + zero-indexed row/column) andSpan(a pair ofPointforming a half-open interval), withSpan::byte_range()to slice the source text.diagnostics:SyntaxDiagnostic(aDiagnosticKind, aSpan, and a message) andDiagnosticKind(Errorfor tree-sitterERRORnodes,Missingfor "missing" nodes).document:parse_document(source: &str) -> ParsedDocument— entry point of the tolerant parsing;analyzeis an alias of this function;ParsedDocument— source + tree-sitterTree+ collected diagnostics;ParsedDocument::into_result()provides a strict conversion toResult<ParsedDocument, Vec<SyntaxDiagnostic>>for consumers (such aspactole-storage-fs::parser/printer) that only want to proceed on a syntactically clean document;collect_error_nodes(tree: &Tree) -> Vec<SyntaxDiagnostic>— walks a tree-sitterTreeand collectsERROR/MISSINGnodes.
Dependencies / boundaries
tree-sitter,tree-sitter-pactole(compiled grammar).- Never depends on
pactole-core: this crate is purely syntactic by construction, a shared foundation for any future tooling that needs positioned diagnostics on possibly-invalid text, without duplicating the tree-sitter plumbing for each consumer.
Tests / validation
Unit tests (in src/lib.rs) cover valid/invalid parsing, the strict
conversion via into_result, and the consistency between
collect_error_nodes and a ParsedDocument's diagnostics.
See also
../../ARCHITECTURE.md— the role ofpactole-syntaxin the tolerant/positioned flow and its boundaries withpactole-storage-fsandpactole-lsp.