Struct esr::lexer::Lexer

source ·
pub struct Lexer<'arena> {
    pub token: Token,
    pub quasi: &'arena str,
    /* private fields */
}

Fields

token: Token

Current Token from the source.

quasi: &'arena str

Implementations

Create a new Lexer from source using an existing arena.

Create a new Lexer from a raw pointer to byte string.

The source must be null terminated! Passing a pointer that is not null terminated is undefined behavior!

The source must be valid UTF8! Passing a pointer to data that is not valid UTF8 will lead to bugs or undefined behavior.

Advances the lexer, produces a new Token and stores it on self.token.

Create an &str slice from source spanning current token.

Specialized version of token_as_str that crates an &str slice for the identifier following an accessor (.).

Get the start and end positions of the current token.

Get the start position of the current token.

Get the end position of the current token.

Get the start position of the current token, then advance the lexer.

Get the end position of the current token, then advance the lexer.

On top of being called when the opening backtick (`) of a template literal occurs, this method needs to be used by the parser while parsing a complex template string expression.

Note: Parser needs to expect a BraceClose token before calling this method to ensure that the tokenizer state is not corrupted.

Get a definition of which ASI rules can be applied.

This is a specialized method that expects the next token to be an identifier, even if it would otherwise be a keyword.

This is useful when parsing member expressions such as foo.function, where function is actually allowed as a regular identifier, not a keyword.

The perf gain here comes mainly from avoiding having to first match the &str to a keyword token, and then match that token back to a &str.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.