Skip to main content

Scanner

Struct Scanner 

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

A stateful lexical cursor over one immutable source text.

A caller may drive it token by token with Scanner::next_token and, at a grammatical decision point, request an explicit reinterpretation with one of the rescan_*/scan_jsx_* operations.

Implementations§

Source§

impl<'a> Scanner<'a>

Source

pub fn new( source_id: SourceId, script_kind: ScriptKind, source: &'a SourceText, ) -> Self

Creates a scanner positioned at the start of source.

Source

pub const fn script_kind(&self) -> ScriptKind

Returns the syntax this scanner lexes.

Source

pub const fn position(&self) -> Utf16Pos

Returns the current UTF-16 cursor position.

Source

pub fn is_at_end(&self) -> bool

Returns whether the whole source has been consumed.

Source

pub fn diagnostics(&self) -> &[Diagnostic]

Returns the diagnostics recorded so far, in emission order.

Source

pub fn into_diagnostics(self) -> Vec<Diagnostic>

Consumes the scanner and returns its recorded diagnostics.

Source

pub fn next_token(&mut self) -> Token

Scans the next token, or an end-of-file token at the end of the source.

Source

pub fn rescan_regex(&mut self) -> Token

Reinterprets the most recent ///= token as a regular-expression literal starting at the same position, advancing past its body and flags.

This is the explicit division-versus-regex decision. The caller supplies the grammatical context; the scanner never guesses it.

Source

pub fn rescan_greater_than(&mut self) -> Token

Reinterprets the most recent >-family token as a single >, advancing exactly one code unit past the last token’s start.

A caller closing type arguments or a JSX element uses this to split a greedily formed shift/compound operator.

Source

pub fn rescan_template_continuation(&mut self) -> Token

Reinterprets the most recent } token as a template continuation, producing TokenKind::TemplateMiddle or TokenKind::TemplateTail.

This serves a caller that drives the scanner without relying on the single-pass brace tracking used by scan.

Source

pub fn scan_jsx_text(&mut self) -> Token

Scans a run of JSX character data up to the next < or {.

The token kind is TokenKind::StringLiteral: the fixed token space has no dedicated JSX kind, and JSX text is uninterpreted character content whose lexeme the caller reads directly. The run may be empty when the caller is already positioned at a < or {.

Source

pub fn scan_jsx_identifier(&mut self) -> Token

Scans a JSX name, which unlike an ECMAScript identifier admits interior hyphens (for example data-role).

Source

pub fn scan_jsx_attribute_string(&mut self) -> Token

Scans a JSX attribute string, which is delimited by matching quotes, performs no escape processing, and may span line terminators.

Auto Trait Implementations§

§

impl<'a> Freeze for Scanner<'a>

§

impl<'a> RefUnwindSafe for Scanner<'a>

§

impl<'a> Send for Scanner<'a>

§

impl<'a> Sync for Scanner<'a>

§

impl<'a> Unpin for Scanner<'a>

§

impl<'a> UnsafeUnpin for Scanner<'a>

§

impl<'a> UnwindSafe for Scanner<'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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

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.