Skip to main content

Module parsers

Module parsers 

Source
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§

MissingGrammar
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 None on any load failure (caller can short-circuit like ?).