Skip to main content

Lexer

Struct Lexer 

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

A streaming lexer over one source text.

Clone is implemented deliberately: the parser snapshots the lexer to backtrack (arrow-function cover grammar), and cloning is a handful of words.

Implementations§

Source§

impl<'a> Lexer<'a>

Source

pub fn new(src: &'a str) -> Lexer<'a>

Create a lexer positioned at the beginning of src.

Source

pub fn set_strict(&mut self, strict: bool)

Enable strict-mode lexical rules (octal escapes become syntax errors).

Source

pub fn is_strict(&self) -> bool

Whether strict-mode lexical rules are active.

Source

pub fn position(&self) -> Position

Current position of the cursor.

Source

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

The source text being lexed.

Source

pub fn had_legacy_octal(&self) -> bool

Whether the token most recently returned by Lexer::next_token contained an Annex B legacy octal escape ("\101").

The flag is reset by every next_token call, so it always describes the token currently held by the caller. The parser uses it because strictness is only known once the directive prologue has been read, which happens after the offending literal was already scanned.

Source

pub fn next_token(&mut self) -> Result<Token>

Scan the next token.

Source

pub fn tokenize(self) -> Result<Vec<Token>>

Scan every remaining token (tests and tooling; the parser drives the lexer one token at a time).

Source

pub fn re_scan_template_continue(&mut self, brace: Position) -> Result<Token>

Resume a template literal after the } closing a substitution.

brace is the position of that } (the parser keeps the token span).

Source

pub fn re_scan_regex(&mut self, start: Position) -> Result<Token>

Re-scan the token starting at start (the /) as a regular expression literal. Called by the parser when it expects an expression.

Trait Implementations§

Source§

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<'a> Forget for Lexer<'a>

§

impl<'a> Freeze for Lexer<'a>

§

impl<'a> Move for Lexer<'a>

§

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> UnsafeUnpin 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.