Expand description
Tree-sitter parser singleton and convenience functions.
Provides a global GrammarLoader singleton so that grammars are loaded once
and shared across all call sites. This is the canonical way to parse source
code with tree-sitter in the normalize ecosystem.
§Lifetime Safety
The singleton is stored in a 'static OnceLock, so the backing shared
libraries are never unloaded. This satisfies the lifetime requirement
documented in GrammarLoader.
§Missing-grammar reporting
When a grammar fails to load (not installed, ABI mismatch, etc.), we emit
a single user-visible warning to stderr (deduplicated per process) and
record the failure in a process-wide tracker so callers like
normalize structure rebuild can summarise affected files. Use
try_get_grammar / parse_with_grammar / parser_for to get the
warning automatically; call report_missing_grammar directly if you
call GrammarLoader::get yourself.
Structs§
- Missing
Grammar - Summary entry returned by
take_missing_grammars.
Functions§
- available_
external_ grammars - List grammars available in external search paths.
- available_
external_ grammars_ with_ paths - List grammars available in external search paths, with their file paths.
- grammar_
loader - Get the global grammar loader singleton.
- parse_
with_ grammar - Parse source code with a specific grammar.
- parser_
for - Create a parser for a specific grammar.
- peek_
missing_ grammars - Peek at the missing-grammar tracker without resetting it.
- report_
missing_ grammar - Record a grammar load failure and emit a one-shot stderr warning.
- take_
missing_ grammars - Drain and return the missing-grammar tracker.
- try_
get_ grammar - Try to load a grammar, surfacing missing-grammar failures as a one-shot
stderr warning. Returns
Noneon any load failure (caller can short-circuit like?).