pub struct Parser<'a, R> { /* private fields */ }Expand description
Parser for the ECMAScript language.
This parser implementation tries to be conformant to the most recent [ECMAScript language specification], and it also implements some legacy features like labelled functions or duplicated block-level function definitions.
Implementations§
Source§impl<'a, R> Parser<'a, R>where
R: ReadChar,
impl<'a, R> Parser<'a, R>where
R: ReadChar,
Sourcepub fn new(source: Source<'a, R>) -> Parser<'a, R>
pub fn new(source: Source<'a, R>) -> Parser<'a, R>
Create a new Parser with a Source as the input to parse.
Sourcepub fn parse_script(
&mut self,
scope: &Scope,
interner: &mut Interner,
) -> Result<Script, Error>
pub fn parse_script( &mut self, scope: &Scope, interner: &mut Interner, ) -> Result<Script, Error>
Parse the full input as a ECMAScript Script into the boa AST representation without source text.
The resulting Script can be compiled into boa bytecode and executed in the boa vm.
§Errors
Will return Err on any parsing error, including invalid reads of the bytes being parsed.
Sourcepub fn parse_script_with_source(
&mut self,
scope: &Scope,
interner: &mut Interner,
) -> Result<(Script, SourceText), Error>
pub fn parse_script_with_source( &mut self, scope: &Scope, interner: &mut Interner, ) -> Result<(Script, SourceText), Error>
Parse the full input as a ECMAScript Script into the boa AST representation with source text.
The resulting Script can be compiled into boa bytecode and executed in the boa vm.
§Errors
Will return Err on any parsing error, including invalid reads of the bytes being parsed.
Sourcepub fn parse_module(
&mut self,
scope: &Scope,
interner: &mut Interner,
) -> Result<Module, Error>where
R: ReadChar,
pub fn parse_module(
&mut self,
scope: &Scope,
interner: &mut Interner,
) -> Result<Module, Error>where
R: ReadChar,
Parse the full input as an ECMAScript Module into the boa AST representation without source text.
The resulting ModuleItemList can be compiled into boa bytecode and executed in the boa vm.
§Errors
Will return Err on any parsing error, including invalid reads of the bytes being parsed.
Sourcepub fn parse_module_with_source(
&mut self,
scope: &Scope,
interner: &mut Interner,
) -> Result<(Module, SourceText), Error>where
R: ReadChar,
pub fn parse_module_with_source(
&mut self,
scope: &Scope,
interner: &mut Interner,
) -> Result<(Module, SourceText), Error>where
R: ReadChar,
Parse the full input as an ECMAScript Module into the boa AST representation with source text.
The resulting ModuleItemList can be compiled into boa bytecode and executed in the boa vm.
§Errors
Will return Err on any parsing error, including invalid reads of the bytes being parsed.
Sourcepub fn parse_eval(
&mut self,
direct: bool,
interner: &mut Interner,
) -> Result<(Script, SourceText), Error>
pub fn parse_eval( &mut self, direct: bool, interner: &mut Interner, ) -> Result<(Script, SourceText), Error>
19.2.1.1 PerformEval ( x, strictCaller, direct )
Parses the source text input of an eval call.
§Errors
Will return Err on any parsing error, including invalid reads of the bytes being parsed.
Sourcepub fn parse_function_body(
&mut self,
interner: &mut Interner,
allow_yield: bool,
allow_await: bool,
) -> Result<FunctionBody, Error>
pub fn parse_function_body( &mut self, interner: &mut Interner, allow_yield: bool, allow_await: bool, ) -> Result<FunctionBody, Error>
Parses the full input as an ECMAScript FunctionBody into the boa AST representation.
§Errors
Will return Err on any parsing error, including invalid reads of the bytes being parsed.
Sourcepub fn parse_formal_parameters(
&mut self,
interner: &mut Interner,
allow_yield: bool,
allow_await: bool,
) -> Result<FormalParameterList, Error>
pub fn parse_formal_parameters( &mut self, interner: &mut Interner, allow_yield: bool, allow_await: bool, ) -> Result<FormalParameterList, Error>
Parses the full input as an ECMAScript FormalParameterList into the boa AST representation.
§Errors
Will return Err on any parsing error, including invalid reads of the bytes being parsed.
Source§impl<R> Parser<'_, R>
impl<R> Parser<'_, R>
Sourcepub fn set_strict(&mut self)where
R: ReadChar,
pub fn set_strict(&mut self)where
R: ReadChar,
Set the parser strict mode to true.
Sourcepub fn set_json_parse(&mut self)where
R: ReadChar,
pub fn set_json_parse(&mut self)where
R: ReadChar,
Set the parser JSON mode to true.
Sourcepub fn set_identifier(&mut self, identifier: u32)where
R: ReadChar,
pub fn set_identifier(&mut self, identifier: u32)where
R: ReadChar,
Set the unique identifier for the parser.
Trait Implementations§
Auto Trait Implementations§
impl<'a, R> Freeze for Parser<'a, R>where
Cursor<R>: Freeze,
impl<'a, R> RefUnwindSafe for Parser<'a, R>where
Cursor<R>: RefUnwindSafe,
impl<'a, R> Send for Parser<'a, R>where
Cursor<R>: Send,
impl<'a, R> Sync for Parser<'a, R>where
Cursor<R>: Sync,
impl<'a, R> Unpin for Parser<'a, R>where
Cursor<R>: Unpin,
impl<'a, R> UnsafeUnpin for Parser<'a, R>where
Cursor<R>: UnsafeUnpin,
impl<'a, R> UnwindSafe for Parser<'a, R>where
Cursor<R>: UnwindSafe,
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
impl<T> ErasedDestructor for Twhere
T: 'static,
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> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.