Enum wast::lexer::Token

source ·
pub enum Token<'a> {
    LineComment(&'a str),
    BlockComment(&'a str),
    Whitespace(&'a str),
    LParen(&'a str),
    RParen(&'a str),
    String(WasmString<'a>),
    Id(&'a str),
    Keyword(&'a str),
    Reserved(&'a str),
    Integer(Integer<'a>),
    Float(Float<'a>),
}
Expand description

A fragment of source lex’d from an input string.

This enumeration contains all kinds of fragments, including comments and whitespace. For most cases you’ll probably ignore these and simply look at tokens.

Variants§

§

LineComment(&'a str)

A line comment, preceded with ;;

§

BlockComment(&'a str)

A block comment, surrounded by (; and ;). Note that these can be nested.

§

Whitespace(&'a str)

A fragment of source that represents whitespace.

§

LParen(&'a str)

A left-parenthesis, including the source text for where it comes from.

§

RParen(&'a str)

A right-parenthesis, including the source text for where it comes from.

§

String(WasmString<'a>)

A string literal, which is actually a list of bytes.

§

Id(&'a str)

An identifier (like $foo).

All identifiers start with $ and the payload here is the original source text.

§

Keyword(&'a str)

A keyword, or something that starts with an alphabetic character.

The payload here is the original source text.

§

Reserved(&'a str)

A reserved series of idchar symbols. Unknown what this is meant to be used for, you’ll probably generate an error about an unexpected token.

§

Integer(Integer<'a>)

An integer.

§

Float(Float<'a>)

A float.

Implementations§

source§

impl<'a> Token<'a>

source

pub fn src(&self) -> &'a str

Returns the original source text for this token.

Trait Implementations§

source§

impl<'a> Debug for Token<'a>

source§

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

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

impl<'a> PartialEq<Token<'a>> for Token<'a>

source§

fn eq(&self, other: &Token<'a>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> StructuralPartialEq for Token<'a>

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for Token<'a>

§

impl<'a> Send for Token<'a>

§

impl<'a> Sync for Token<'a>

§

impl<'a> Unpin for Token<'a>

§

impl<'a> UnwindSafe for Token<'a>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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, U> TryFrom<U> for Twhere 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 Twhere 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.