[][src]Struct logos::Lexer

pub struct Lexer<Token: Logos, Source> {
    pub source: Source,
    pub token: Token,
    pub extras: Token::Extras,
    // some fields omitted
}

Lexer is the main struct of the crate that allows you to read through a Source and produce tokens for enums implementing the Logos trait.

Fields

source: Source

Source from which the Lexer is reading tokens.

token: Token

Current token. Call the advance method to get a new token.

extras: Token::Extras

Extras associated with the Token.

Methods

impl<'source, Token, Source> Lexer<Token, Source> where
    Token: Logos + WithSource<Source>,
    Source: Source<'source>, 
[src]

pub fn new(source: Source) -> Self[src]

Create a new Lexer.

Due to type inference, it might be more ergonomic to construct it by calling Token::lexer(source), where Token implements Logos.

pub fn advance(&mut self)[src]

Advance the Lexer and attempt to produce the next Token.

pub fn range(&self) -> Range<usize>[src]

Get the range for the current token in Source.

pub fn slice(&self) -> Source::Slice[src]

Get a string slice of the current token.

pub fn morph<Token2>(self) -> Lexer<Token2, Source> where
    Token2: Logos + WithSource<Source>,
    Token::Extras: Into<Token2::Extras>, 
[src]

Turn this lexer into a lexer for a new token type.

The new lexer continues to point at the same span as the current lexer, and the current token becomes the error token of the new token type. If you want to start reading from the new lexer immediately, consider using Lexer::advance_as instead.

pub fn advance_as<Token2>(self) -> Lexer<Token2, Source> where
    Token2: Logos + WithSource<Source>,
    Token::Extras: Into<Token2::Extras>, 
[src]

Advance the Lexer and attempt to produce the next Token of a new token type.

This function takes self by value as a lint. If you're working with a &mut Lexer, clone the old lexer to call this method, then don't forget to update the old lexer!

Trait Implementations

impl<Token: Clone + Logos, Source: Clone> Clone for Lexer<Token, Source> where
    Token::Extras: Clone
[src]

Auto Trait Implementations

impl<Token, Source> RefUnwindSafe for Lexer<Token, Source> where
    Source: RefUnwindSafe,
    Token: RefUnwindSafe,
    <Token as Logos>::Extras: RefUnwindSafe

impl<Token, Source> Send for Lexer<Token, Source> where
    Source: Send,
    Token: Send,
    <Token as Logos>::Extras: Send

impl<Token, Source> Sync for Lexer<Token, Source> where
    Source: Sync,
    Token: Sync,
    <Token as Logos>::Extras: Sync

impl<Token, Source> Unpin for Lexer<Token, Source> where
    Source: Unpin,
    Token: Unpin,
    <Token as Logos>::Extras: Unpin

impl<Token, Source> UnwindSafe for Lexer<Token, Source> where
    Source: UnwindSafe,
    Token: UnwindSafe,
    <Token as Logos>::Extras: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.