[][src]Enum erl_tokenize::Token

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

Token.

Variants

Atom(AtomToken)Char(CharToken)Comment(CommentToken)Float(FloatToken)Integer(IntegerToken)Keyword(KeywordToken)String(StringToken)Symbol(SymbolToken)Variable(VariableToken)Whitespace(WhitespaceToken)

Methods

impl Token[src]

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

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));

pub fn text(&self) -> &str[src]

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"#);

pub fn is_lexical_token(&self) -> bool[src]

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

pub fn is_hidden_token(&self) -> bool[src]

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

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

Tries to convert into LexicalToken.

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

Tries to convert into HiddenToken.

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

Tries to return the reference to the inner AtomToken.

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

Tries to return the reference to the inner CharToken.

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

Tries to return the reference to the inner FloatToken.

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

Tries to return the reference to the inner IntegerToken.

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

Tries to return the reference to the inner KeywordToken.

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

Tries to return the reference to the inner StringToken.

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

Tries to return the reference to the inner SymbolToken.

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

Tries to return the reference to the inner VariableToken.

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

Tries to return the reference to the inner CommentToken.

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

Tries to return the reference to the inner WhitespaceToken.

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

Tries to return the inner AtomToken.

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

Tries to return the inner CharToken.

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

Tries to return the inner FloatToken.

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

Tries to return the inner IntegerToken.

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

Tries to return the inner KeywordToken.

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

Tries to return the inner StringToken.

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

Tries to return the inner SymbolToken.

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

Tries to return the inner VariableToken.

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

Tries to return the inner CommentToken.

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

Tries to return the inner WhitespaceToken.

Trait Implementations

impl PositionRange for Token[src]

impl Clone for Token[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl From<AtomToken> for Token[src]

impl From<CharToken> for Token[src]

impl From<CommentToken> for Token[src]

impl From<FloatToken> for Token[src]

impl From<IntegerToken> for Token[src]

impl From<KeywordToken> for Token[src]

impl From<StringToken> for Token[src]

impl From<SymbolToken> for Token[src]

impl From<VariableToken> for Token[src]

impl From<WhitespaceToken> for Token[src]

impl From<HiddenToken> for Token[src]

impl From<LexicalToken> for Token[src]

impl Display for Token[src]

impl Debug for Token[src]

Auto Trait Implementations

impl Send for Token

impl Sync for Token

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]