Struct doomdooz_lib::types::Token
source · pub struct Token {
pub token_type: i32,
pub token_value: Bytes,
pub loc: Loc,
pub lex_state_before: LexState,
pub lex_state_after: LexState,
}Expand description
A token that is emitted by a lexer and consumed by a parser
Fields§
§token_type: i32Numeric representation of the token type, e.g. 42 (for example) for tINTEGER
token_value: BytesValue of the token, e.g “42” for 42
loc: LocLocation of the token
lex_state_before: LexStateLex state before reading the token
lex_state_after: LexStateLex state after reading the token
Implementations§
source§impl Token
impl Token
sourcepub fn into_bytes(self) -> Vec<u8, Global> ⓘ
pub fn into_bytes(self) -> Vec<u8, Global> ⓘ
Consumes a token and returns an owned byte array of the token value
sourcepub fn as_str_lossy(&self) -> Result<&str, Utf8Error>
pub fn as_str_lossy(&self) -> Result<&str, Utf8Error>
Converts token value into &str
sourcepub fn to_string_lossy(&self) -> String
pub fn to_string_lossy(&self) -> String
Converts token to a string, replaces unknown chars to U+FFFD
sourcepub fn to_string(&self) -> Result<String, FromUtf8Error>
pub fn to_string(&self) -> Result<String, FromUtf8Error>
Converts token to a string
sourcepub fn into_string(self) -> Result<String, FromUtf8Error>
pub fn into_string(self) -> Result<String, FromUtf8Error>
Consumes a token and converts it into a string
sourcepub fn token_name(&self) -> &'static str
pub fn token_name(&self) -> &'static str
Returns name of the token