Struct full_moon::tokenizer::TokenReference
source · pub struct TokenReference { /* private fields */ }
Expand description
A reference to a token used by Ast’s.
Dereferences to a Token
Implementations§
source§impl TokenReference
impl TokenReference
sourcepub fn new(
leading_trivia: Vec<Token>,
token: Token,
trailing_trivia: Vec<Token>
) -> Self
pub fn new( leading_trivia: Vec<Token>, token: Token, trailing_trivia: Vec<Token> ) -> Self
Creates a TokenReference from leading/trailing trivia as well as the leading token
sourcepub fn symbol(text: &str) -> Result<Self, TokenizerErrorType>
pub fn symbol(text: &str) -> Result<Self, TokenizerErrorType>
Returns a symbol with the leading and trailing whitespace Only whitespace is supported
let symbol = TokenReference::symbol("\nreturn ")?;
assert_eq!(symbol.leading_trivia().next().unwrap().to_string(), "\n");
assert_eq!(symbol.token().token_type(), &TokenType::Symbol {
symbol: Symbol::Return,
});
assert_eq!(symbol.trailing_trivia().next().unwrap().to_string(), " ");
assert!(TokenReference::symbol("isnt whitespace").is_err());
assert!(TokenReference::symbol(" notasymbol ").is_err());
sourcepub fn leading_trivia(&self) -> impl Iterator<Item = &Token>
pub fn leading_trivia(&self) -> impl Iterator<Item = &Token>
Returns the leading trivia
sourcepub fn trailing_trivia(&self) -> impl Iterator<Item = &Token>
pub fn trailing_trivia(&self) -> impl Iterator<Item = &Token>
Returns the trailing trivia
sourcepub fn with_token(&self, token: Token) -> Self
pub fn with_token(&self, token: Token) -> Self
Creates a clone of the current TokenReference with the new inner token, preserving trivia.
Methods from Deref<Target = Token>§
sourcepub fn start_position(&self) -> Position
pub fn start_position(&self) -> Position
The position a token begins at
sourcepub fn end_position(&self) -> Position
pub fn end_position(&self) -> Position
The position a token ends at
sourcepub fn token_type(&self) -> &TokenType
pub fn token_type(&self) -> &TokenType
The type of token as well as the data needed to represent it
If you don’t need any other information, use token_kind
instead.
sourcepub fn token_kind(&self) -> TokenKind
pub fn token_kind(&self) -> TokenKind
The kind of token with no additional data.
If you need any information such as idenitfier names, use token_type
instead.
Trait Implementations§
source§impl Borrow<Token> for &TokenReference
impl Borrow<Token> for &TokenReference
source§impl Clone for TokenReference
impl Clone for TokenReference
source§fn clone(&self) -> TokenReference
fn clone(&self) -> TokenReference
Returns a copy 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 moresource§impl Debug for TokenReference
impl Debug for TokenReference
source§impl Deref for TokenReference
impl Deref for TokenReference
source§impl<'de> Deserialize<'de> for TokenReference
impl<'de> Deserialize<'de> for TokenReference
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl Display for TokenReference
impl Display for TokenReference
source§impl Node for TokenReference
impl Node for TokenReference
source§fn start_position(&self) -> Option<Position>
fn start_position(&self) -> Option<Position>
The start position of a node. None if can’t be determined
source§fn end_position(&self) -> Option<Position>
fn end_position(&self) -> Option<Position>
The end position of a node. None if it can’t be determined
source§fn similar(&self, other: &Self) -> bool
fn similar(&self, other: &Self) -> bool
Whether another node of the same type is the same as this one semantically, ignoring position
source§impl Ord for TokenReference
impl Ord for TokenReference
source§impl PartialEq<TokenReference> for TokenReference
impl PartialEq<TokenReference> for TokenReference
source§impl PartialOrd<TokenReference> for TokenReference
impl PartialOrd<TokenReference> for TokenReference
1.0.0 · source§fn 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