Documentation
¶
Overview ¶
Package treesitter is strictcode's single parsing path: a thin, disciplined layer over the official tree-sitter CGo bindings (the binding-benchmark winner; see BUILDLOG.md). It owns the three responsibilities the rest of the codebase must never re-implement:
- grammar selection for the language trio (Python, Go, TS/JS);
- LF normalization before parsing, so every byte span in the system is a span over LF-normalized UTF-8 (schema/SPEC.md section 3);
- CGo resource lifecycle (Close on parsers, trees, queries, cursors), so extractors cannot leak C memory.
There is no fallback parser and no regex path; a parse failure is an error.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NormalizeLF ¶
NormalizeLF converts CRLF and lone CR line endings to LF. Canonical byte positions everywhere in strictcode are offsets into this normalized form (schema/SPEC.md section 3). The input slice is never modified; when no normalization is needed the input is returned as-is.
Types ¶
type Grammar ¶
type Grammar int
Grammar identifies a concrete tree-sitter grammar. The TS/JS profile column ("ts") spans two grammar variants: the typescript grammar parses .ts and plain JavaScript; the tsx grammar parses .tsx/.jsx (JSX syntax conflicts with TS type assertions, so tree-sitter ships them as separate grammars).
func GrammarForFile ¶
GrammarForFile maps a filename to its grammar. The boolean is false for files strictcode does not parse. Extension mapping follows DESIGN.md section 6.2 (TS/JS resolution probes .ts/.tsx/.js/.jsx/.mjs/.cjs).
type Match ¶
Match is one query match: the pattern index within the query and its captures in capture order.
type Query ¶
type Query struct {
Grammar Grammar
// contains filtered or unexported fields
}
Query is a compiled tree-sitter query for one grammar. Callers must Close it. Queries are compiled once and reused across many trees.
func CompileQuery ¶
CompileQuery compiles a query pattern against a grammar. Pattern errors are hard errors carrying the tree-sitter diagnostic.
func (*Query) Matches ¶
Matches runs the query over the tree and returns all matches with text predicates (#eq?, #match?, #any-of?, ...) applied. The cursor is created and closed internally; returned nodes are valid until the tree is Closed. Matches panics if the query and tree grammars differ — that is a programming error in the caller, never an input condition.
type Tree ¶
type Tree struct {
// Source is the LF-normalized UTF-8 the tree was parsed from. All node
// spans index into this slice, never into the raw file bytes.
Source []byte
Grammar Grammar
// contains filtered or unexported fields
}
Tree is a parsed file: the LF-normalized source and the syntax tree over it. Node byte offsets index Source. Callers must Close it.
func Parse ¶
Parse normalizes src to LF and parses it with the given grammar. The returned tree must be Closed. A nil tree from the runtime (the only failure mode of ts_parser_parse without timeouts/cancellation, e.g. a grammar/runtime version mismatch) is a hard error.
func (*Tree) HasParseErrors ¶
HasParseErrors reports whether the tree contains ERROR or MISSING nodes. tree-sitter is error-tolerant; strictcode is honest about it — extractors consult this instead of silently analyzing a broken tree.