Skip to main content

ParseContext

Struct ParseContext 

Source
pub struct ParseContext<'a> { /* private fields */ }
Expand description

Parser context: a cursor over the token stream.

Implementations§

Source§

impl<'a> ParseContext<'a>

Source

pub fn new(tokens: &'a [Token], source: &'a str) -> Self

Source

pub fn source(&self) -> &'a str

Source

pub fn record_error(&mut self, message: &str)

Record a parse error at the current position.

Source

pub fn record_error_at(&mut self, offset: u32, message: &str)

Record a parse error at a specific byte offset.

Source

pub fn take_diagnostics(&mut self) -> Vec<ParseDiagnostic>

Take collected diagnostics, leaving the internal list empty.

Source

pub fn pos(&self) -> usize

Current position in the token stream.

Source

pub fn save(&self) -> usize

Save cursor position for backtracking.

Source

pub fn restore(&mut self, pos: usize)

Restore cursor to a saved position.

Source

pub fn peek(&self) -> Option<&'a Token>

Peek at the current token without consuming.

Source

pub fn peek_kind(&self) -> Option<TokenKind>

Peek at the current non-trivia token kind.

Source

pub fn peek_non_trivia(&self) -> Option<&'a Token>

Peek at the next non-trivia token (skipping whitespace/comments).

Source

pub fn peek_keyword(&self, kw: &str) -> bool

Check if the next non-trivia token is a keyword matching kw (case-insensitive).

Source

pub fn peek_keywords(&self, kws: &[&str]) -> bool

Check if next non-trivia tokens form a keyword sequence (e.g. “GROUP”, “BY”).

Source

pub fn advance(&mut self) -> Option<&'a Token>

Consume and return the current token, advancing the cursor.

Source

pub fn eat_trivia(&mut self) -> Vec<&'a Token>

Consume all leading trivia tokens and return them.

Source

pub fn eat_keyword(&mut self, kw: &str) -> Option<&'a Token>

Try to consume a keyword (case-insensitive). Returns the token if matched.

Source

pub fn eat_kind(&mut self, kind: TokenKind) -> Option<&'a Token>

Try to consume a specific token kind.

Source

pub fn at_eof(&self) -> bool

Are we at EOF?

Source

pub fn remaining(&self) -> &'a [Token]

Remaining tokens from current position.

Auto Trait Implementations§

§

impl<'a> Freeze for ParseContext<'a>

§

impl<'a> RefUnwindSafe for ParseContext<'a>

§

impl<'a> Send for ParseContext<'a>

§

impl<'a> Sync for ParseContext<'a>

§

impl<'a> Unpin for ParseContext<'a>

§

impl<'a> UnsafeUnpin for ParseContext<'a>

§

impl<'a> UnwindSafe for ParseContext<'a>

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, 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, 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.