[−][src]Struct logos::Lexer
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]
Token: Logos + WithSource<Source>,
Source: Source<'source>,
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]
Token2: Logos + WithSource<Source>,
Token::Extras: Into<Token2::Extras>,
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]
Token2: Logos + WithSource<Source>,
Token::Extras: Into<Token2::Extras>,
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]
Token::Extras: Clone,
Auto Trait Implementations
impl<Token, Source> RefUnwindSafe for Lexer<Token, Source> where
Source: RefUnwindSafe,
Token: RefUnwindSafe,
<Token as Logos>::Extras: RefUnwindSafe,
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,
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,
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,
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,
Source: UnwindSafe,
Token: UnwindSafe,
<Token as Logos>::Extras: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,