Trait Lexer

Source
pub trait Lexer<'a> {
    type Token: Eq;
    type Position: Clone + Hash + Eq + PartialOrd;

    // Required methods
    fn new(input: &'a str) -> Self;
    fn lexeme(&self) -> &str;
    fn span(&self) -> Span;
    fn pos(&self) -> &Self::Position;
    fn next(&mut self) -> Option<Self::Token>;
    fn is_empty(&self) -> bool;
    fn advance_to_pos(&mut self, pos: &Self::Position);
    fn fork(&self) -> Self;
}
Expand description

A lexer for the parser.

Required Associated Types§

Source

type Token: Eq

The lexed token type.

Source

type Position: Clone + Hash + Eq + PartialOrd

The lexeme type.

Required Methods§

Source

fn new(input: &'a str) -> Self

Create a new lexer from the given input.

Source

fn lexeme(&self) -> &str

Get the current lexeme.

Source

fn span(&self) -> Span

Get the current span.

Source

fn pos(&self) -> &Self::Position

Get the current position.

Source

fn next(&mut self) -> Option<Self::Token>

Consume the next token.

Source

fn is_empty(&self) -> bool

Whether the lexer is at the end of the input.

Source

fn advance_to_pos(&mut self, pos: &Self::Position)

Advance the lexer to the given lexeme.

Source

fn fork(&self) -> Self

Fork the lexer.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§