Skip to main content

ParserContext

Struct ParserContext 

Source
pub struct ParserContext {
    pub id_generator: NodeIdGenerator,
    /* private fields */
}
Expand description

Parser context with error tracking and recovery

Fields§

§id_generator: NodeIdGenerator

Node ID generator

Implementations§

Source§

impl ParserContext

Source

pub fn new(source: String) -> ParserContext

Create a new parser context

Source

pub fn with_budget(source: String, budget: ParseBudget) -> ParserContext

Create a new parser context with a custom budget.

Source

pub fn budget(&self) -> &ParseBudget

Get the current budget.

Source

pub fn budget_tracker(&self) -> &BudgetTracker

Get the budget tracker.

Source

pub fn budget_tracker_mut(&mut self) -> &mut BudgetTracker

Get mutable access to the budget tracker.

Source

pub fn errors_exhausted(&self) -> bool

Check if error budget is exhausted.

Source

pub fn depth_would_exceed(&self) -> bool

Check if depth budget would be exceeded.

Source

pub fn enter_depth(&mut self) -> bool

Enter a nesting level, tracking depth.

Source

pub fn exit_depth(&mut self)

Exit a nesting level.

Source

pub fn current_token(&self) -> Option<&TokenWithPosition>

Get current token

Source

pub fn peek_token(&self, offset: usize) -> Option<&TokenWithPosition>

Peek at next token

Source

pub fn advance(&mut self) -> Option<&TokenWithPosition>

Advance to next token

Source

pub fn is_eof(&self) -> bool

Check if at end of tokens

Source

pub fn current_position(&self) -> Position

Get current position

Source

pub fn current_position_range(&self) -> Range

Get current position range

Source

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.

Source

pub fn add_error_unchecked(&mut self, error: ParseError)

Add a parse error without checking budget (for critical errors).

Source

pub fn take_errors(&mut self) -> Vec<ParseError>

Get all accumulated errors

Source

pub fn current_index(&self) -> usize

Get current token index (for saving/restoring)

Source

pub fn set_index(&mut self, index: usize)

Set current token index (for restoring)

Source

pub fn expect( &mut self, expected: TokenType, ) -> Result<&TokenWithPosition, ParseError>

Match and consume a specific token type

Source

pub fn check(&self, token_type: &TokenType) -> bool

Check if current token matches

Source

pub fn consume(&mut self, token_type: &TokenType) -> bool

Consume token if it matches

Source

pub fn source_slice(&self, range: &Range) -> &str

Get source slice for a range

Trait Implementations§

Source§

impl ErrorRecovery for ParserContext

Source§

fn create_error_node( &mut self, message: String, expected: Vec<String>, partial: Option<Node>, ) -> Node

Create an error node and recover
Source§

fn synchronize(&mut self, sync_points: &[SyncPoint]) -> bool

Synchronize to a recovery point
Source§

fn recover_with_node(&mut self, error: ParseError) -> Node

Try to recover from an error
Source§

fn skip_until(&mut self, sync_points: &[SyncPoint]) -> usize

Skip tokens until a sync point. Read more
Source§

fn skip_until_with_budget( &mut self, sync_points: &[SyncPoint], budget: &ParseBudget, tracker: &mut BudgetTracker, ) -> RecoveryResult

Budget-aware skip that respects limits. Read more
Source§

fn is_sync_point(&self, sync_point: SyncPoint) -> bool

Check if current token is a sync point

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more