pub struct ParserContext {
pub id_generator: NodeIdGenerator,
/* private fields */
}Expand description
Parser context with error tracking and recovery
Fields§
§id_generator: NodeIdGeneratorNode ID generator
Implementations§
Source§impl ParserContext
impl ParserContext
Sourcepub fn new(source: String) -> ParserContext
pub fn new(source: String) -> ParserContext
Create a new parser context
Sourcepub fn with_budget(source: String, budget: ParseBudget) -> ParserContext
pub fn with_budget(source: String, budget: ParseBudget) -> ParserContext
Create a new parser context with a custom budget.
Sourcepub fn budget(&self) -> &ParseBudget
pub fn budget(&self) -> &ParseBudget
Get the current budget.
Sourcepub fn budget_tracker(&self) -> &BudgetTracker
pub fn budget_tracker(&self) -> &BudgetTracker
Get the budget tracker.
Sourcepub fn budget_tracker_mut(&mut self) -> &mut BudgetTracker
pub fn budget_tracker_mut(&mut self) -> &mut BudgetTracker
Get mutable access to the budget tracker.
Sourcepub fn errors_exhausted(&self) -> bool
pub fn errors_exhausted(&self) -> bool
Check if error budget is exhausted.
Sourcepub fn depth_would_exceed(&self) -> bool
pub fn depth_would_exceed(&self) -> bool
Check if depth budget would be exceeded.
Sourcepub fn enter_depth(&mut self) -> bool
pub fn enter_depth(&mut self) -> bool
Enter a nesting level, tracking depth.
Sourcepub fn exit_depth(&mut self)
pub fn exit_depth(&mut self)
Exit a nesting level.
Sourcepub fn current_token(&self) -> Option<&TokenWithPosition>
pub fn current_token(&self) -> Option<&TokenWithPosition>
Get current token
Sourcepub fn peek_token(&self, offset: usize) -> Option<&TokenWithPosition>
pub fn peek_token(&self, offset: usize) -> Option<&TokenWithPosition>
Peek at next token
Sourcepub fn advance(&mut self) -> Option<&TokenWithPosition>
pub fn advance(&mut self) -> Option<&TokenWithPosition>
Advance to next token
Sourcepub fn current_position(&self) -> Position
pub fn current_position(&self) -> Position
Get current position
Sourcepub fn current_position_range(&self) -> Range
pub fn current_position_range(&self) -> Range
Get current position range
Sourcepub fn add_error(&mut self, error: ParseError) -> bool
pub fn add_error(&mut self, error: ParseError) -> bool
Add a parse error, tracking budget consumption.
Returns true if the error was added, false if error budget exhausted.
Sourcepub fn add_error_unchecked(&mut self, error: ParseError)
pub fn add_error_unchecked(&mut self, error: ParseError)
Add a parse error without checking budget (for critical errors).
Sourcepub fn take_errors(&mut self) -> Vec<ParseError>
pub fn take_errors(&mut self) -> Vec<ParseError>
Get all accumulated errors
Sourcepub fn current_index(&self) -> usize
pub fn current_index(&self) -> usize
Get current token index (for saving/restoring)
Sourcepub fn expect(
&mut self,
expected: TokenType,
) -> Result<&TokenWithPosition, ParseError>
pub fn expect( &mut self, expected: TokenType, ) -> Result<&TokenWithPosition, ParseError>
Match and consume a specific token type
Sourcepub fn source_slice(&self, range: &Range) -> &str
pub fn source_slice(&self, range: &Range) -> &str
Get source slice for a range