[go: up one dir, main page]

Struct wast::lexer::Lexer

source ·
pub struct Lexer<'a> { /* private fields */ }
Expand description

A structure used to lex the s-expression syntax of WAT files.

This structure is used to generate Token items, which should account for every single byte of the input as we iterate over it. A LexError is returned for any non-lexable text.

Implementations§

source§

impl<'a> Lexer<'a>

source

pub fn new(input: &str) -> Lexer<'_>

Creates a new lexer which will lex the input source string.

source

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

Returns the original source input that we’re lexing.

source

pub fn allow_confusing_unicode(&mut self, allow: bool) -> &mut Self

Configures whether “confusing” unicode characters are allowed while lexing.

If allowed then no error will happen if these characters are found, but otherwise if disallowed a lex error will be produced when these characters are found. Confusing characters are denied by default.

For now “confusing characters” are primarily related to the “trojan source” problem where it refers to characters which cause humans to read text differently than this lexer, such as characters that alter the left-to-right display of the source code.

source

pub fn parse(&self, pos: &mut usize) -> Result<Option<Token>, Error>

Lexes the next at the byte position pos in the input.

Returns Some if a token is found or None if we’re at EOF.

The pos argument will be updated to point to the next token on a successful parse.

Errors

Returns an error if the input is malformed.

source

pub fn iter( &self, pos: usize ) -> impl Iterator<Item = Result<Token, Error>> + '_

Returns an iterator over all tokens in the original source string starting at the pos specified.

source

pub fn annotation(&self, pos: usize) -> Option<&'a str>

Returns whether an annotation is present at pos and the name of the annotation.

Trait Implementations§

source§

impl<'a> Clone for Lexer<'a>

source§

fn clone(&self) -> Lexer<'a>

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

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for Lexer<'a>

§

impl<'a> Send for Lexer<'a>

§

impl<'a> Sync for Lexer<'a>

§

impl<'a> Unpin for Lexer<'a>

§

impl<'a> UnwindSafe for Lexer<'a>

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, 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.