pub enum Lexeme {
}
Expand description
The possible tokens within a Dmgrs program.
At this early stage of the processing all keywords, instructions, and register names just count as an “ident”. A simple string interning mechanism is used, so it’s not a super allocation fest to do this.
Variants
Error
An error during lexing.
HorizontalWhitespace
Spaces and tabs, but not line endings.
EndOfLineComment
Starts with //
and eats characters until the end of line.
StartMultiComment
Multi-line comments start with /*
EndMultiComment
Multi-line comments end with */
EndOfLine
A line ends with \r\n
(windows), \n
(unix), or \r
(pre-unix mac).
Punct(char)
A punctuation character (using the [:punct:]
regex class) that does
not match any other case.
KwConst
Starts a constant declaration
KwFn
Starts a function declaration
KwLoop
Used at the opening of a loop
KwIf
Used for branching around code blocks
KwElse
Used for branching around code blocks
KwContinue
Continue a loop (jump to the start)
KwBreak
Break a loop (jump to the end)
KwStatic
Starts a static declaration
Ident(&'static str)
A standard identifier in C-style langs: [_a-zA-Z][_a-zA-Z0-9]*
The lone character _
ends up matching as an Ident rather than a
Punctuation.
Str(&'static str)
Holds all the stuff between "
.
This allows \"
and \\
within the string literal that’s collected, but
doesn’t actually handle escape sequence processing.
Thanks to Quirl
, who made this regex: “works by specifying all of the
escape sequences you allow (here just \"
, and \\
for a \
itself) up
front and then requiring the rest of the literal to not be a quote or
escape (that would start with \
)”
BinaryLiteral(u16)
The digits of a binary literal (no prefix).
- Binary literals are a digit sequence (
0-1
) prefixed with%
or0b
- Use of
_
is allowed in the literal, but they don’t change the value.
DecimalLiteral(u16)
The digits of a decimal literal.
- Decimal literals are a digit sequence (
0-9
) with no prefix. - Use of
_
is allowed in the literal, but they don’t change the value.
HexLiteral(u16)
The digits of a hex literal (no prefix).
- Hex literals are a digit sequence (
0-9a-fA-F
) prefixed with$
or0x
- Use of
_
is allowed in the literal, but they don’t change the value.
Trait Implementations
sourceimpl<'s> Logos<'s> for Lexeme
impl<'s> Logos<'s> for Lexeme
type Extras = ()
type Extras = ()
Associated type Extras
for the particular lexer. This can be set using
#[logos(extras = MyExtras)]
and accessed inside callbacks. Read more
type Source = str
type Source = str
Source type this token can be lexed from. This will default to str
,
unless one of the defined patterns explicitly uses non-unicode byte values
or byte slices, in which case that implementation will use [u8]
. Read more
sourcefn lex(lex: &mut Lexer<'s, Self>)
fn lex(lex: &mut Lexer<'s, Self>)
The heart of Logos. Called by the Lexer
. The implementation for this function
is generated by the logos-derive
crate. Read more
sourceimpl Ord for Lexeme
impl Ord for Lexeme
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl PartialEq<Lexeme> for Lexeme
impl PartialEq<Lexeme> for Lexeme
sourceimpl PartialOrd<Lexeme> for Lexeme
impl PartialOrd<Lexeme> for Lexeme
sourcefn partial_cmp(&self, other: &Lexeme) -> Option<Ordering>
fn partial_cmp(&self, other: &Lexeme) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl Copy for Lexeme
impl Eq for Lexeme
impl StructuralEq for Lexeme
impl StructuralPartialEq for Lexeme
Auto Trait Implementations
impl RefUnwindSafe for Lexeme
impl Send for Lexeme
impl Sync for Lexeme
impl Unpin for Lexeme
impl UnwindSafe for Lexeme
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more