Expand description
GLR parser generation algorithms for Adze This module implements the core GLR state machine generation and conflict resolution
§Contracts & Invariants
This crate maintains several critical invariants for correct parsing:
§EOF Symbol Invariants
- EOF symbol must be a terminal sentinel id at or beyond the terminal boundary
(
token_count + external_token_count). - EOF symbol must not be the internal ERROR sentinel
(
parse_forest::ERROR_SYMBOL, currently 0xFFFF). - EOF symbol is always present in the symbol_to_index mapping
- EOF column actions are byte-for-byte copies of the TS “end” column, guaranteeing per-state equality.
§Error Recovery Invariants
has_error: true if any error chunks exist in the parse forestmissing: count of unique missing terminal symbols insertedcost: total error recovery cost (insertions + deletions)- No double counting: each missing symbol counted exactly once
- Extras (whitespace/comments) are never inserted during recovery
§Table Normalization
- Action cells are sorted deterministically by action type and value
- Duplicate actions are removed from cells
- Action ordering: Shift < Reduce < Accept < Error < Recover < Fork
§API Stability
ForestViewtrait is sealed and cannot be implemented outside this crateActionenum is marked#[non_exhaustive]for future extensibility- Test-only APIs are gated behind
test-helpersfeature
§Validation
Enable the strict-invariants feature to validate parse tables at runtime.
This adds overhead but catches invariant violations early in development.
Re-exports§
pub use error::Result as GlrResult;pub use GLRError as GlrError;pub use driver::Driver;pub use forest_view::Forest;pub use forest_view::ForestView;pub use forest_view::Span;
Modules§
- conflict_
inspection - Conflict inspection API for analyzing GLR parse table conflicts Conflict Inspection API for GLR Parse Tables
- driver
- Public driver that runs the GLR engine and returns a trait-object forest.
- error
- Error types and Result alias for GLR operations. Error and result types for GLR parsing operations.
- forest_
view - Object-safe view over a GLR forest/SPPF used by downstream runtimes.
- lib_v2
- Improved LR(1) automaton construction with proper conflict handling.
- perf
- Internal performance counters (diagnostics only).
- prelude
- Stable imports for downstream users during 0.8.0-dev.
- serialization
- ParseTable serialization for GLR mode ParseTable serialization for GLR mode
- stack
- Persistent stack implementation for GLR parser
- telemetry
- Telemetry counters for tracking GLR parser operations. Low-overhead telemetry counters for GLR parser performance monitoring.
- test_
helpers - Utilities for constructing test parse tables and grammars.
- ts_
lexer - Tree-sitter compatible lexer interface for GLR parsing. Tree-sitter FFI lexer wrapper for calling grammar’s lex_fn
Macros§
- debug_
trace - Internal tracing macro used by the GLR runtime in debug/test builds.
- glr_
trace - Backward-compatible trace macro.
Structs§
- Conflict
- Conflict information for GLR parsing
- Conflict
Resolver - Conflict detection and resolution
- First
Follow Sets - FIRST/FOLLOW sets computation for GLR parsing
- Grammar
- Re-exported IR types used throughout GLR construction. Core grammar representation supporting all Tree-sitter features including GLR
- ItemSet
- Set of LR(1) items representing a parser state
- Item
SetCollection - Collection of all LR(1) item sets (parser states)
- LRItem
- LR(1) item for GLR parsing
- LexMode
- Lexer mode for a parser state
- Parse
Rule - Parse rule for reduction
- Parse
Table - GLR-compatible parse table supporting multiple actions per state
- RuleId
- Re-exported IR types used throughout GLR construction. Rule identifier
- StateId
- Re-exported IR types used throughout GLR construction. State identifier
- Symbol
Id - Re-exported IR types used throughout GLR construction. Symbol identifier
- Symbol
Metadata - Symbol metadata for the parse table
Enums§
- Action
- Actions in GLR parse table (supporting multiple actions per state)
- Conflict
Type - Type of parser conflict
- GLRError
- Error types for GLR processing
- Goto
Indexing - How GOTO table columns are indexed
- Table
Error - Errors related to parse table validation
Functions§
- build_
lr1_ automaton - Build LR(1) automaton (parse table) from grammar.
- build_
lr1_ automaton_ res - Build LR(1) automaton using the GlrResult type alias
- sanity_
check_ tables - Sanity check parse table for correctness
Type Aliases§
- Action
Cell - Action cell that can hold multiple actions for GLR