pub struct Lexer {
pub remaining: Fragment,
}
Available on crate feature
lexer
only.Expand description
The lexical analyser for wright. This produces a series of tokens that make up the larger elements of the language.
Fields§
§remaining: Fragment
The remaining source code that has not been processed and returned as a token from the iterator yet.
Implementations§
Source§impl Lexer
impl Lexer
Sourcepub const fn bytes_remaining(&self) -> usize
pub const fn bytes_remaining(&self) -> usize
Get the number of bytes remaining that we need to transform into tokens.
Sourcepub fn fork(&self) -> Self
pub fn fork(&self) -> Self
“Fork” this lexer, creating a new Lexer
at the same position as this one that can be used for
failable parsing. This can be compared to the original lexer it was forked from using Lexer::offset_from.
Sourcepub fn offset_from(&self, origin: &Self) -> usize
pub fn offset_from(&self, origin: &Self) -> usize
Get the number of bytes between the origin’s remaining and
this Lexer’s remaining using Fragment::offset_from
.
§Panics
- This function panics under the same conditions as
Fragment::offset_from
. - Generally the best way to avoid panics is to only call this function on
Lexers created using Lexer::fork on the
origin
lexer.
Sourcepub fn matches(&self, pattern: &str) -> bool
pub fn matches(&self, pattern: &str) -> bool
Check if a pattern matches at the start of the Lexer::remaining Fragment.
Sourcepub fn next_token(&mut self) -> Option<Token>
pub fn next_token(&mut self) -> Option<Token>
Get the next token from the lexer.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Lexer
impl RefUnwindSafe for Lexer
impl Send for Lexer
impl Sync for Lexer
impl Unpin for Lexer
impl UnwindSafe for Lexer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more