Token

Trait Token 

Source
pub trait Token: Debug {
    // Required method
    fn from_str<S: Into<String>>(string: S) -> Option<Self>
       where Self: Sized;

    // Provided method
    fn to_string(&self) -> String { ... }
}
Expand description

Represents a generic token within the language processing system.

All token types must implement this trait to ensure they can be debugged and dynamically handled via polymorphism. Tokens are generally created from strings and can be represented back as strings for debugging and logging purposes.

Required Methods§

Source

fn from_str<S: Into<String>>(string: S) -> Option<Self>
where Self: Sized,

Constructs an instance of a token from a string, if possible.

Provided Methods§

Source

fn to_string(&self) -> String

Returns a string representation of the token, typically used for debugging.

Examples found in repository?
examples/main_tester.rs (line 25)
17fn main() {
18    app_dt!(file!());
19    set_max_level(Level::Debug);
20
21    let src = "g2+3 & 3^ &";
22    let lexer = Lexer::<CompleteLexer>::new(src);
23
24    for token in lexer.clone() {
25        debug!("{}", token.to_string());
26    }
27
28    for token in lexer.clone() {
29        debug!("{:?}", token);
30    }
31
32    debug!("src: {}", lexer.src_code);
33
34}

Implementors§