Skip to main content

Parser

Struct Parser 

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

Parser state wrapping a token slice with a cursor.

Implementations§

Source§

impl<'a> Parser<'a>

Source

pub fn parse_constraints_block(&mut self) -> Result<Vec<Constraint>, ParseError>

Parse a constraints { ... } block.

Source§

impl<'a> Parser<'a>

Source

pub fn parse_variables_block(&mut self) -> Result<Vec<VarDecl>, ParseError>

Parse a variables { ... } block.

Source

pub fn parse_ident_list(&mut self) -> Result<Vec<String>, ParseError>

Parse a comma-separated list of identifiers (at least one).

Source§

impl<'a> Parser<'a>

Source

pub fn parse_domains_block(&mut self) -> Result<Vec<DomainStmt>, ParseError>

Parse a domains { ... } block.

Source§

impl<'a> Parser<'a>

Source

pub fn parse_expr(&mut self) -> Result<Expr, ParseError>

Parse an expression.

Source§

impl<'a> Parser<'a>

Source

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

Create a new parser over the given token slice.

Source

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

Peek at the current token’s kind without consuming it.

Source

pub fn advance(&mut self)

Advance the cursor by one token.

Source

pub fn current_span(&self) -> Span

Get the span of the current token (or a default EOF span).

Source

pub fn is_eof(&self) -> bool

Return true if there are no more tokens.

Source

pub fn expect_token(&mut self, expected: TokenKind) -> Result<(), ParseError>

Expect and consume a specific token kind.

Source

pub fn expect_ident(&mut self) -> Result<String, ParseError>

Expect and consume an identifier, returning its name.

Source

pub fn expect_ident_matching( &mut self, expected: &str, ) -> Result<(), ParseError>

Expect and consume a specific identifier.

Source

pub fn expect_number(&mut self) -> Result<i64, ParseError>

Expect and consume a number literal.

Auto Trait Implementations§

§

impl<'a> Freeze for Parser<'a>

§

impl<'a> RefUnwindSafe for Parser<'a>

§

impl<'a> Send for Parser<'a>

§

impl<'a> Sync for Parser<'a>

§

impl<'a> Unpin for Parser<'a>

§

impl<'a> UnsafeUnpin for Parser<'a>

§

impl<'a> UnwindSafe for Parser<'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.