pub struct Token {
pub loc: Loc,
/* private fields */
}Expand description
A Token consists of a string and its location in the parsed files.
Fields§
§loc: LocImplementations§
source§impl Token
impl Token
pub fn new(s: &str, loc: Loc) -> Self
pub fn from_static_str(s: &'static str, loc: Loc) -> Self
sourcepub fn subtoken<R>(&self, range: R, loc: Loc) -> Token
pub fn subtoken<R>(&self, range: R, loc: Loc) -> Token
Create a Token from a substring of the given Token.
sourcepub fn subtoken_stripped(&self, range: Range<usize>, loc: Loc) -> Token
pub fn subtoken_stripped(&self, range: Range<usize>, loc: Loc) -> Token
Create a Token from a subtring of the given Token,
stripping any whitespace from the created token.
pub fn as_str(&self) -> &'static str
pub fn is(&self, s: &str) -> bool
pub fn lowercase_is(&self, s: &str) -> bool
pub fn starts_with(&self, s: &str) -> bool
sourcepub fn split(&self, ch: char) -> Vec<Token>
pub fn split(&self, ch: char) -> Vec<Token>
Split the token into one or more subtokens, with ch as the delimiter.
Updates the locs for the created subtokens.
This is not meant for multiline tokens.
§Panics
May panic if the token’s column location exceeds 65535.
pub fn strip_suffix(&self, sfx: &str) -> Option<Token>
pub fn strip_prefix(&self, pfx: &str) -> Option<Token>
sourcepub fn split_once(&self, ch: char) -> Option<(Token, Token)>
pub fn split_once(&self, ch: char) -> Option<(Token, Token)>
Split the token into two subtokens, with the split at the first occurrence of ch.
Updates the locs for the created subtokens.
This is not meant for multiline tokens.
Returns None if ch was not found in the token.
§Panics
May panic if the token’s column location exceeds 65535.
sourcepub fn split_after(&self, ch: char) -> Option<(Token, Token)>
pub fn split_after(&self, ch: char) -> Option<(Token, Token)>
Split the token into two subtokens, with the split at the first instance of ch, such that ch is part of the first returned token.
Updates the locs for the created subtokens.
This is not meant for multiline tokens.
Returns None if ch was not found in the token.
§Panics
May panic if the token’s column location exceeds 65535.
sourcepub fn combine(&mut self, other: &Token, c: char)
pub fn combine(&mut self, other: &Token, c: char)
Create a new token that is a concatenation of this token and other, with c between them.
sourcepub fn trim(&self) -> Token
pub fn trim(&self) -> Token
Return a subtoken of this token, such that all whitespace is removed from the start and end. Will update the loc of the subtoken. This is not meant for multiline tokens.
§Panics
May panic if the token’s column location exceeds 65535.
pub fn expect_number(&self) -> Option<f64>
pub fn get_number(&self) -> Option<f64>
pub fn is_number(&self) -> bool
pub fn check_number(&self)
sourcepub fn expect_precise_number(&self) -> Option<f64>
pub fn expect_precise_number(&self) -> Option<f64>
Some files seem not to have the 5-decimal limitation
pub fn expect_integer(&self) -> Option<i64>
pub fn get_integer(&self) -> Option<i64>
pub fn is_integer(&self) -> bool
pub fn expect_date(&self) -> Option<Date>
pub fn get_date(&self) -> Option<Date>
pub fn is_date(&self) -> bool
pub fn linked(self, link_idx: Option<NonZeroU32>) -> Self
Trait Implementations§
source§impl PartialEq for Token
impl PartialEq for Token
Tokens are compared for equality regardless of their loc.