swc_ecma_parser

Trait Tokens

Source
pub trait Tokens: Clone + Iterator<Item = TokenAndSpan> {
Show 15 methods // Required methods fn set_ctx(&mut self, ctx: Context); fn ctx(&self) -> Context; fn syntax(&self) -> Syntax; fn target(&self) -> EsVersion; fn set_expr_allowed(&mut self, allow: bool); fn set_next_regexp(&mut self, start: Option<BytePos>); fn token_context(&self) -> &TokenContexts; fn token_context_mut(&mut self) -> &mut TokenContexts; fn set_token_context(&mut self, _c: TokenContexts); fn add_error(&self, error: Error); fn add_module_mode_error(&self, error: Error); fn end_pos(&self) -> BytePos; fn take_errors(&mut self) -> Vec<Error>; fn take_script_module_errors(&mut self) -> Vec<Error>; // Provided method fn start_pos(&self) -> BytePos { ... }
}
Expand description

Clone should be cheap if you are parsing typescript because typescript syntax requires backtracking.

Required Methods§

Source

fn set_ctx(&mut self, ctx: Context)

Source

fn ctx(&self) -> Context

Source

fn syntax(&self) -> Syntax

Source

fn target(&self) -> EsVersion

Source

fn set_expr_allowed(&mut self, allow: bool)

Source

fn set_next_regexp(&mut self, start: Option<BytePos>)

Source

fn token_context(&self) -> &TokenContexts

Source

fn token_context_mut(&mut self) -> &mut TokenContexts

Source

fn set_token_context(&mut self, _c: TokenContexts)

Source

fn add_error(&self, error: Error)

Implementors should use Rc<RefCell<Vec>>.

It is required because parser should backtrack while parsing typescript code.

Source

fn add_module_mode_error(&self, error: Error)

Add an error which is valid syntax in script mode.

This errors should be dropped if it’s not a module.

Implementor should check for if Context.module, and buffer errors if module is false. Also, implementors should move errors to the error buffer on set_ctx if the parser mode become module mode.

Source

fn end_pos(&self) -> BytePos

Source

fn take_errors(&mut self) -> Vec<Error>

Source

fn take_script_module_errors(&mut self) -> Vec<Error>

If the program was parsed as a script, this contains the module errors should the program be identified as a module in the future.

Provided Methods§

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§