pub struct ScannerState {
pub interner: Interner,
/* private fields */
}Expand description
The scanner state that holds the current position and token information.
ZERO-COPY OPTIMIZATION: Source is stored as UTF-8 text directly (no Vec
Fields§
§interner: InternerString interner for identifier deduplication
Implementations§
Source§impl ScannerState
impl ScannerState
Sourcepub fn new(text: String, skip_trivia: bool) -> ScannerState
pub fn new(text: String, skip_trivia: bool) -> ScannerState
Exported scanner accessors are JS bindings and cannot be made const
because #[wasm_bindgen] methods in this crate are non-const.
Create a new scanner state with the given text.
ZERO-COPY: No Vec
Sourcepub fn set_pos(&mut self, pos: usize)
pub fn set_pos(&mut self, pos: usize)
Set the current position (used for rescanning compound tokens).
This allows consuming partial tokens like splitting >> into > + >.
Sourcepub fn get_token_full_start(&self) -> usize
pub fn get_token_full_start(&self) -> usize
Get the full start position (including leading trivia).
Sourcepub fn get_token_start(&self) -> usize
pub fn get_token_start(&self) -> usize
Get the start position of the current token (excluding trivia).
Sourcepub fn get_token_end(&self) -> usize
pub fn get_token_end(&self) -> usize
Get the end position of the current token.
Sourcepub fn get_token(&self) -> SyntaxKind
pub fn get_token(&self) -> SyntaxKind
Get the current token kind.
Sourcepub fn get_token_value(&self) -> String
pub fn get_token_value(&self) -> String
Get the current token’s string value.
Note: Prefer get_token_value_ref() to avoid allocation when possible.
Sourcepub fn get_token_text(&self) -> String
pub fn get_token_text(&self) -> String
Get the current token’s text from the source.
Sourcepub fn get_token_flags(&self) -> u32
pub fn get_token_flags(&self) -> u32
Get the token flags.
Sourcepub fn has_preceding_line_break(&self) -> bool
pub fn has_preceding_line_break(&self) -> bool
Check if there was a preceding line break.
Sourcepub fn is_unterminated(&self) -> bool
pub fn is_unterminated(&self) -> bool
Check if the token is unterminated.
Sourcepub fn is_identifier(&self) -> bool
pub fn is_identifier(&self) -> bool
Check if the current token is an identifier.
Sourcepub fn is_reserved_word(&self) -> bool
pub fn is_reserved_word(&self) -> bool
Check if the current token is a reserved word.
Sourcepub fn set_text(
&mut self,
text: String,
start: Option<usize>,
length: Option<usize>,
)
pub fn set_text( &mut self, text: String, start: Option<usize>, length: Option<usize>, )
Set the text to scan. ZERO-COPY: Works directly with UTF-8 bytes.
Sourcepub fn reset_token_state(&mut self, new_pos: usize)
pub fn reset_token_state(&mut self, new_pos: usize)
Reset the token state to a specific position.
Sourcepub fn scan(&mut self) -> SyntaxKind
pub fn scan(&mut self) -> SyntaxKind
Scan the next token.
Sourcepub fn re_scan_greater_token(&mut self) -> SyntaxKind
pub fn re_scan_greater_token(&mut self) -> SyntaxKind
Re-scan the current > token to see if it should be >=, >>, >>>, >>=, or >>>=.
This is used by the parser for type arguments and bitwise operators.
Sourcepub fn re_scan_slash_token(&mut self) -> SyntaxKind
pub fn re_scan_slash_token(&mut self) -> SyntaxKind
Re-scan the current / or /= token as a regex literal.
This is used by the parser when it determines the context requires a regex.
Sourcepub fn re_scan_asterisk_equals_token(&mut self) -> SyntaxKind
pub fn re_scan_asterisk_equals_token(&mut self) -> SyntaxKind
Re-scan the current *= token as * followed by =.
Used when parsing computed property names.
Sourcepub fn re_scan_template_token(
&mut self,
_is_tagged_template: bool,
) -> SyntaxKind
pub fn re_scan_template_token( &mut self, _is_tagged_template: bool, ) -> SyntaxKind
Re-scan the current } token as the continuation of a template literal.
Called by the parser when it determines that a } is closing a template expression.
§Arguments
is_tagged_template- If true, invalid escape sequences should not report errors (tagged templates can have invalid escapes that get passed to the tag function as raw). For now, we don’t report errors anyway, so this parameter affects nothing.
Sourcepub fn re_scan_template_head_or_no_substitution_template(
&mut self,
) -> SyntaxKind
pub fn re_scan_template_head_or_no_substitution_template( &mut self, ) -> SyntaxKind
Re-scan template head or no-substitution template. Used when the parser needs to rescan the start of a template.
Sourcepub fn scan_jsx_identifier(&mut self) -> SyntaxKind
pub fn scan_jsx_identifier(&mut self) -> SyntaxKind
Scan a JSX identifier.
In JSX, identifiers can contain hyphens (like data-testid).
Sourcepub fn re_scan_jsx_token(
&mut self,
allow_multiline_jsx_text: bool,
) -> SyntaxKind
pub fn re_scan_jsx_token( &mut self, allow_multiline_jsx_text: bool, ) -> SyntaxKind
Re-scan the current token as a JSX token.
Used when the parser enters JSX context and needs to rescan.
Must reset to full_start_pos (before trivia), not token_start (after trivia),
so that JSX text nodes include leading whitespace/newlines.
Matches tsc: pos = tokenStart = fullStartPos;
Sourcepub fn scan_jsx_attribute_value(&mut self) -> SyntaxKind
pub fn scan_jsx_attribute_value(&mut self) -> SyntaxKind
Scan a JSX attribute value (string literal or expression).
Sourcepub fn re_scan_jsx_attribute_value(&mut self) -> SyntaxKind
pub fn re_scan_jsx_attribute_value(&mut self) -> SyntaxKind
Re-scan a JSX attribute value from the current token position.
Sourcepub fn re_scan_less_than_token(&mut self) -> SyntaxKind
pub fn re_scan_less_than_token(&mut self) -> SyntaxKind
Re-scan a < token in JSX context.
Returns LessThanSlashToken if followed by /, otherwise LessThanToken.
Sourcepub fn re_scan_hash_token(&mut self) -> SyntaxKind
pub fn re_scan_hash_token(&mut self) -> SyntaxKind
Re-scan the current # token as a hash token or private identifier.
Sourcepub fn re_scan_question_token(&mut self) -> SyntaxKind
pub fn re_scan_question_token(&mut self) -> SyntaxKind
Re-scan the current ? token for optional chaining.
Sourcepub fn scan_jsdoc_token(&mut self) -> SyntaxKind
pub fn scan_jsdoc_token(&mut self) -> SyntaxKind
Scan a JSDoc token.
Used when parsing JSDoc comments.
Sourcepub fn scan_jsdoc_comment_text_token(
&mut self,
in_backticks: bool,
) -> SyntaxKind
pub fn scan_jsdoc_comment_text_token( &mut self, in_backticks: bool, ) -> SyntaxKind
Scan JSDoc comment text token.
Used for scanning the text content within JSDoc comments.
Sourcepub fn scan_shebang_trivia(&mut self) -> usize
pub fn scan_shebang_trivia(&mut self) -> usize
Scan a shebang (#!) at the start of the file. Returns the length of the shebang line (including newline), or 0 if no shebang.
Sourcepub fn re_scan_invalid_identifier(&mut self) -> SyntaxKind
pub fn re_scan_invalid_identifier(&mut self) -> SyntaxKind
Re-scan an invalid identifier to check if it’s valid in a specific context.
Source§impl ScannerState
impl ScannerState
Sourcepub fn save_state(&self) -> ScannerSnapshot
pub fn save_state(&self) -> ScannerSnapshot
Save the current scanner state for look-ahead.
Sourcepub fn restore_state(&mut self, snapshot: ScannerSnapshot)
pub fn restore_state(&mut self, snapshot: ScannerSnapshot)
Restore a saved scanner state.
Sourcepub const fn get_token_atom(&self) -> Atom
pub const fn get_token_atom(&self) -> Atom
Get the interned atom for the current identifier token.
Returns Atom::NONE if the current token is not an identifier.
This enables O(1) string comparison for identifiers.
pub const fn get_invalid_separator_pos(&self) -> Option<usize>
pub const fn invalid_separator_is_consecutive(&self) -> bool
Sourcepub fn get_regex_flag_errors(&self) -> &[RegexFlagError]
pub fn get_regex_flag_errors(&self) -> &[RegexFlagError]
Get the regex flag errors detected during scanning.
Sourcepub fn get_scanner_diagnostics(&self) -> &[ScannerDiagnostic]
pub fn get_scanner_diagnostics(&self) -> &[ScannerDiagnostic]
Get general scanner diagnostics (e.g., conflict marker errors).
Sourcepub fn resolve_atom(&self, atom: Atom) -> &str
pub fn resolve_atom(&self, atom: Atom) -> &str
Resolve an atom back to its string value. Panics if the atom is invalid.
Sourcepub const fn interner(&self) -> &Interner
pub const fn interner(&self) -> &Interner
Get a reference to the interner for direct use by the parser.
Sourcepub const fn interner_mut(&mut self) -> &mut Interner
pub const fn interner_mut(&mut self) -> &mut Interner
Get a mutable reference to the interner.
Sourcepub fn take_interner(&mut self) -> Interner
pub fn take_interner(&mut self) -> Interner
Take ownership of the interner, replacing it with a new empty one.
Used to transfer the interner to NodeArena after parsing.
Sourcepub fn get_token_value_ref(&self) -> &str
pub fn get_token_value_ref(&self) -> &str
ZERO-COPY: Get the current token value as a reference.
For identifiers/keywords, returns the interned string.
For other tokens, returns the token_value or raw source slice.
This avoids allocation compared to get_token_value().
Sourcepub fn get_token_text_ref(&self) -> &str
pub fn get_token_text_ref(&self) -> &str
ZERO-COPY: Get the raw token text directly from source.
This is the unprocessed text from token_start to current pos.
Sourcepub fn source_slice(&self, start: usize, end: usize) -> &str
pub fn source_slice(&self, start: usize, end: usize) -> &str
ZERO-COPY: Get a slice of the source text by positions.
Sourcepub fn source_text(&self) -> &str
pub fn source_text(&self) -> &str
Get the source text reference.
Source§impl ScannerState
impl ScannerState
Sourcepub fn source_text_arc(&self) -> Arc<str>
pub fn source_text_arc(&self) -> Arc<str>
Get a cloned handle to the shared source text.
Trait Implementations§
Source§impl From<ScannerState> for JsValue
impl From<ScannerState> for JsValue
Source§fn from(value: ScannerState) -> JsValue
fn from(value: ScannerState) -> JsValue
Source§impl FromWasmAbi for ScannerState
impl FromWasmAbi for ScannerState
Source§impl IntoWasmAbi for ScannerState
impl IntoWasmAbi for ScannerState
Source§impl LongRefFromWasmAbi for ScannerState
impl LongRefFromWasmAbi for ScannerState
Source§type Anchor = RcRef<ScannerState>
type Anchor = RcRef<ScannerState>
RefFromWasmAbi::AnchorSource§unsafe fn long_ref_from_abi(
js: <ScannerState as LongRefFromWasmAbi>::Abi,
) -> <ScannerState as LongRefFromWasmAbi>::Anchor
unsafe fn long_ref_from_abi( js: <ScannerState as LongRefFromWasmAbi>::Abi, ) -> <ScannerState as LongRefFromWasmAbi>::Anchor
RefFromWasmAbi::ref_from_abiSource§impl OptionFromWasmAbi for ScannerState
impl OptionFromWasmAbi for ScannerState
Source§fn is_none(abi: &<ScannerState as FromWasmAbi>::Abi) -> bool
fn is_none(abi: &<ScannerState as FromWasmAbi>::Abi) -> bool
None, and otherwise it will be passed to
FromWasmAbi.Source§impl OptionIntoWasmAbi for ScannerState
impl OptionIntoWasmAbi for ScannerState
Source§fn none() -> <ScannerState as IntoWasmAbi>::Abi
fn none() -> <ScannerState as IntoWasmAbi>::Abi
None branch of this option. Read moreSource§impl RefFromWasmAbi for ScannerState
impl RefFromWasmAbi for ScannerState
Source§type Anchor = RcRef<ScannerState>
type Anchor = RcRef<ScannerState>
Self for the duration of the
invocation of the function that has an &Self parameter. This is
required to ensure that the lifetimes don’t persist beyond one function
call, and so that they remain anonymous.Source§unsafe fn ref_from_abi(
js: <ScannerState as RefFromWasmAbi>::Abi,
) -> <ScannerState as RefFromWasmAbi>::Anchor
unsafe fn ref_from_abi( js: <ScannerState as RefFromWasmAbi>::Abi, ) -> <ScannerState as RefFromWasmAbi>::Anchor
Source§impl RefMutFromWasmAbi for ScannerState
impl RefMutFromWasmAbi for ScannerState
Source§type Anchor = RcRefMut<ScannerState>
type Anchor = RcRefMut<ScannerState>
RefFromWasmAbi::AnchorSource§unsafe fn ref_mut_from_abi(
js: <ScannerState as RefMutFromWasmAbi>::Abi,
) -> <ScannerState as RefMutFromWasmAbi>::Anchor
unsafe fn ref_mut_from_abi( js: <ScannerState as RefMutFromWasmAbi>::Abi, ) -> <ScannerState as RefMutFromWasmAbi>::Anchor
RefFromWasmAbi::ref_from_abiSource§impl TryFromJsValue for ScannerState
impl TryFromJsValue for ScannerState
Source§fn try_from_js_value(value: JsValue) -> Result<ScannerState, JsValue>
fn try_from_js_value(value: JsValue) -> Result<ScannerState, JsValue>
Source§fn try_from_js_value_ref(value: &JsValue) -> Option<ScannerState>
fn try_from_js_value_ref(value: &JsValue) -> Option<ScannerState>
Source§impl VectorFromWasmAbi for ScannerState
impl VectorFromWasmAbi for ScannerState
type Abi = <Box<[JsValue]> as FromWasmAbi>::Abi
unsafe fn vector_from_abi( js: <ScannerState as VectorFromWasmAbi>::Abi, ) -> Box<[ScannerState]>
Source§impl VectorIntoWasmAbi for ScannerState
impl VectorIntoWasmAbi for ScannerState
type Abi = <Box<[JsValue]> as IntoWasmAbi>::Abi
fn vector_into_abi( vector: Box<[ScannerState]>, ) -> <ScannerState as VectorIntoWasmAbi>::Abi
Auto Trait Implementations§
impl Freeze for ScannerState
impl RefUnwindSafe for ScannerState
impl Send for ScannerState
impl Sync for ScannerState
impl Unpin for ScannerState
impl UnsafeUnpin for ScannerState
impl UnwindSafe for ScannerState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
Source§type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
IntoWasmAbi::AbiSource§fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
IntoWasmAbi::into_abi, except that it may throw and never
return in the case of Err.