Skip to main content

Lexer

Struct Lexer 

Source
pub struct Lexer<'src> { /* private fields */ }
Expand description

Public API for Lexer.

Implementations§

Source§

impl<'src> Lexer<'src>

Source

pub fn new(src: &'src str) -> Self

Public API for new.

Source

pub fn peek(&mut self) -> Result<&Token, &LexError>

Peek at the next token without consuming it.

Source

pub fn next(&mut self) -> Result<Token, LexError>

Consume and return the next token.

Source

pub fn eat(&mut self, expected: &Token) -> bool

Consume if next token matches; otherwise leave it in the peek buffer.

Source

pub fn eat_kw(&mut self, kw: Keyword) -> bool

Public API for eat_kw.

Source

pub fn expect(&mut self, expected: &Token) -> Result<(), LexError>

Consume a token and verify it matches expected; return an error otherwise.

Source

pub fn expect_kw(&mut self, kw: &Keyword) -> Result<(), LexError>

Public API for expect_kw.

Source

pub fn expect_local_ident(&mut self) -> Result<String, LexError>

Public API for expect_local_ident.

Source

pub fn expect_global_ident(&mut self) -> Result<String, LexError>

Public API for expect_global_ident.

Source

pub fn expect_int_lit(&mut self) -> Result<i64, LexError>

Public API for expect_int_lit.

Source

pub fn expect_uint_lit(&mut self) -> Result<u64, LexError>

Public API for expect_uint_lit.

Source

pub fn expect_string_lit(&mut self) -> Result<String, LexError>

Public API for expect_string_lit.

Source

pub fn current_line(&self) -> usize

Public API for current_line.

Source

pub fn current_col(&self) -> usize

Public API for current_col.

Auto Trait Implementations§

§

impl<'src> Freeze for Lexer<'src>

§

impl<'src> RefUnwindSafe for Lexer<'src>

§

impl<'src> Send for Lexer<'src>

§

impl<'src> Sync for Lexer<'src>

§

impl<'src> Unpin for Lexer<'src>

§

impl<'src> UnsafeUnpin for Lexer<'src>

§

impl<'src> UnwindSafe for Lexer<'src>

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.