Enum erl_tokenize::Token

source ·
pub enum Token {
    Atom(AtomToken),
    Char(CharToken),
    Comment(CommentToken),
    Float(FloatToken),
    Integer(IntegerToken),
    Keyword(KeywordToken),
    SigilString(SigilStringToken),
    String(StringToken),
    Symbol(SymbolToken),
    Variable(VariableToken),
    Whitespace(WhitespaceToken),
}
Expand description

Token.

Variants§

Implementations§

source§

impl Token

source

pub fn from_text(text: &str, pos: Position) -> Result<Self>

Tries to convert from any prefixes of the text to a token.

§Examples
use erl_tokenize::{Token, Position};
use erl_tokenize::values::Symbol;

let pos = Position::new();

// Atom
let token = Token::from_text("foo", pos.clone()).unwrap();
assert_eq!(token.as_atom_token().map(|t| t.value()), Some("foo"));

// Symbol
let token = Token::from_text("[foo]", pos.clone()).unwrap();
assert_eq!(token.as_symbol_token().map(|t| t.value()), Some(Symbol::OpenSquare));
source

pub fn text(&self) -> &str

Returns the original textual representation of this token.

§Examples
use erl_tokenize::{Token, Position};

let pos = Position::new();

// Comment
assert_eq!(Token::from_text("% foo", pos.clone()).unwrap().text(), "% foo");

// Char
assert_eq!(Token::from_text(r#"$\t"#, pos.clone()).unwrap().text(), r#"$\t"#);
source

pub fn is_lexical_token(&self) -> bool

Returns true if this is a lexical token, otherwise false.

source

pub fn is_hidden_token(&self) -> bool

Returns true if this is a hidden token, otherwise false.

source

pub fn into_lexical_token(self) -> Result<LexicalToken, Self>

Tries to convert into LexicalToken.

source

pub fn into_hidden_token(self) -> Result<HiddenToken, Self>

Tries to convert into HiddenToken.

source

pub fn as_atom_token(&self) -> Option<&AtomToken>

Tries to return the reference to the inner AtomToken.

source

pub fn as_char_token(&self) -> Option<&CharToken>

Tries to return the reference to the inner CharToken.

source

pub fn as_float_token(&self) -> Option<&FloatToken>

Tries to return the reference to the inner FloatToken.

source

pub fn as_integer_token(&self) -> Option<&IntegerToken>

Tries to return the reference to the inner IntegerToken.

source

pub fn as_keyword_token(&self) -> Option<&KeywordToken>

Tries to return the reference to the inner KeywordToken.

source

pub fn as_string_token(&self) -> Option<&StringToken>

Tries to return the reference to the inner StringToken.

source

pub fn as_symbol_token(&self) -> Option<&SymbolToken>

Tries to return the reference to the inner SymbolToken.

source

pub fn as_variable_token(&self) -> Option<&VariableToken>

Tries to return the reference to the inner VariableToken.

source

pub fn as_comment_token(&self) -> Option<&CommentToken>

Tries to return the reference to the inner CommentToken.

source

pub fn as_whitespace_token(&self) -> Option<&WhitespaceToken>

Tries to return the reference to the inner WhitespaceToken.

source

pub fn into_atom_token(self) -> Result<AtomToken, Self>

Tries to return the inner AtomToken.

source

pub fn into_char_token(self) -> Result<CharToken, Self>

Tries to return the inner CharToken.

source

pub fn into_float_token(self) -> Result<FloatToken, Self>

Tries to return the inner FloatToken.

source

pub fn into_integer_token(self) -> Result<IntegerToken, Self>

Tries to return the inner IntegerToken.

source

pub fn into_keyword_token(self) -> Result<KeywordToken, Self>

Tries to return the inner KeywordToken.

source

pub fn into_string_token(self) -> Result<StringToken, Self>

Tries to return the inner StringToken.

source

pub fn into_symbol_token(self) -> Result<SymbolToken, Self>

Tries to return the inner SymbolToken.

source

pub fn into_variable_token(self) -> Result<VariableToken, Self>

Tries to return the inner VariableToken.

source

pub fn into_comment_token(self) -> Result<CommentToken, Self>

Tries to return the inner CommentToken.

source

pub fn into_whitespace_token(self) -> Result<WhitespaceToken, Self>

Tries to return the inner WhitespaceToken.

Trait Implementations§

source§

impl Clone for Token

source§

fn clone(&self) -> Token

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Token

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for Token

source§

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 Token

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<AtomToken> for Token

source§

fn from(f: AtomToken) -> Self

Converts to this type from the input type.
source§

impl From<CharToken> for Token

source§

fn from(f: CharToken) -> Self

Converts to this type from the input type.
source§

impl From<CommentToken> for Token

source§

fn from(f: CommentToken) -> Self

Converts to this type from the input type.
source§

impl From<FloatToken> for Token

source§

fn from(f: FloatToken) -> Self

Converts to this type from the input type.
source§

impl From<HiddenToken> for Token

source§

fn from(f: HiddenToken) -> Self

Converts to this type from the input type.
source§

impl From<IntegerToken> for Token

source§

fn from(f: IntegerToken) -> Self

Converts to this type from the input type.
source§

impl From<KeywordToken> for Token

source§

fn from(f: KeywordToken) -> Self

Converts to this type from the input type.
source§

impl From<LexicalToken> for Token

source§

fn from(f: LexicalToken) -> Self

Converts to this type from the input type.
source§

impl From<SigilStringToken> for Token

source§

fn from(f: SigilStringToken) -> Self

Converts to this type from the input type.
source§

impl From<StringToken> for Token

source§

fn from(f: StringToken) -> Self

Converts to this type from the input type.
source§

impl From<SymbolToken> for Token

source§

fn from(f: SymbolToken) -> Self

Converts to this type from the input type.
source§

impl From<VariableToken> for Token

source§

fn from(f: VariableToken) -> Self

Converts to this type from the input type.
source§

impl From<WhitespaceToken> for Token

source§

fn from(f: WhitespaceToken) -> Self

Converts to this type from the input type.
source§

impl PositionRange for Token

source§

fn start_position(&self) -> Position

Returns the (inclusive) start position of this.
source§

fn end_position(&self) -> Position

Returns the (exclusive) end position of this.
source§

impl Serialize for Token

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for Token

§

impl Send for Token

§

impl Sync for Token

§

impl Unpin for Token

§

impl UnwindSafe for Token

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,