pub enum TokenValue {
None,
Ident(usize),
Number(i64),
Comment(String),
Stat {
comments: Vec<String>,
value: Option<i64>,
},
}Expand description
The payload carried by a lexical token.
Tokens may or may not carry extra data depending on their kind. For example, identifiers and numbers store auxiliary information such as a symbol-table index or a literal integer value.
This payload is paired with a TokenID inside a CalcToken.
§Variants
-
TokenValue::None: No extra data (typical for punctuation or operators). -
[
TokenValue::Ident(usize)]: The symbol table index for an identifier. Theusizerefers to an entry managed by the symbol table (see your crate’sSymTabtype). -
[
TokenValue::Number(i64)]: A parsed integer literal.
§Example
// Construct a token representing a number
let token = TokenValue::Number(42);
// Ensure that it is a number, and extract its value
let TokenValue::Number(n) = token else {
panic!("Expected a numeric token");
};
println!("Numeric literal: {n}");
assert_eq!(n, 42);Variants§
None
No associated data (for symbols or keywords).
Ident(usize)
Identifier token with an index into the symbol table.
Number(i64)
Integer literal token.
Comment(String)
Comment.
Stat
Statement
Trait Implementations§
Source§impl Clone for TokenValue
impl Clone for TokenValue
Source§fn clone(&self) -> TokenValue
fn clone(&self) -> TokenValue
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for TokenValue
impl RefUnwindSafe for TokenValue
impl Send for TokenValue
impl Sync for TokenValue
impl Unpin for TokenValue
impl UnwindSafe for TokenValue
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