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
sourceimpl 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
sourceimpl Borrow<Token> for &TokenReference
impl Borrow<Token> for &TokenReference
sourceimpl Clone for TokenReference
impl Clone for TokenReference
sourcefn clone(&self) -> TokenReference
fn clone(&self) -> TokenReference
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for TokenReference
impl Debug for TokenReference
sourceimpl Deref for TokenReference
impl Deref for TokenReference
sourceimpl<'de> Deserialize<'de> for TokenReference
impl<'de> Deserialize<'de> for TokenReference
sourcefn 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
sourceimpl Display for TokenReference
impl Display for TokenReference
sourceimpl Node for TokenReference
impl Node for TokenReference
sourcefn start_position(&self) -> Option<Position>
fn start_position(&self) -> Option<Position>
The start position of a node. None if can’t be determined
sourcefn end_position(&self) -> Option<Position>
fn end_position(&self) -> Option<Position>
The end position of a node. None if it can’t be determined
sourcefn 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
sourcefn tokens(&self) -> Tokens<'_>ⓘNotable traits for Tokens<'a>impl<'a> Iterator for Tokens<'a> type Item = &'a TokenReference;
fn tokens(&self) -> Tokens<'_>ⓘNotable traits for Tokens<'a>impl<'a> Iterator for Tokens<'a> type Item = &'a TokenReference;
The token references that comprise a node
sourceimpl Ord for TokenReference
impl Ord for TokenReference
sourceimpl PartialEq<TokenReference> for TokenReference
impl PartialEq<TokenReference> for TokenReference
sourceimpl PartialOrd<TokenReference> for TokenReference
impl PartialOrd<TokenReference> for TokenReference
sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn 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
sourceimpl Serialize for TokenReference
impl Serialize for TokenReference
impl Eq for TokenReference
Auto Trait Implementations
impl RefUnwindSafe for TokenReference
impl Send for TokenReference
impl Sync for TokenReference
impl Unpin for TokenReference
impl UnwindSafe for TokenReference
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more