Browse Source

AsyncFunctionDecl/Expr parser created (not impl)

pull/836/head
Paul Lancaster 4 years ago
parent
commit
c2bf1b3cfb
  1. 42
      boa/src/syntax/parser/expression/primary/async_function_expression.rs
  2. 8
      boa/src/syntax/parser/expression/primary/mod.rs
  3. 47
      boa/src/syntax/parser/statement/declaration/hoistable.rs

42
boa/src/syntax/parser/expression/primary/async_function_expression.rs

@ -0,0 +1,42 @@
//! Async Function expression parsing.
//!
//! More information:
//! - [MDN documentation][mdn]
//! - [ECMAScript specification][spec]
//!
//! [mdn]:
//! [spec]:
use crate::{
syntax::{
ast::node::AsyncFunctionExpr,
parser::{Cursor, ParseError, TokenParser},
},
BoaProfiler,
};
use std::io::Read;
/// Async Function expression parsing.
///
/// More information:
/// - [MDN documentation][mdn]
/// - [ECMAScript specification][spec]
///
/// [mdn]:
/// [spec]:
#[derive(Debug, Clone, Copy)]
pub(super) struct AsyncFunctionExpression;
impl<R> TokenParser<R> for AsyncFunctionExpression
where
R: Read,
{
type Output = AsyncFunctionExpr;
fn parse(self, cursor: &mut Cursor<R>) -> Result<Self::Output, ParseError> {
let _timer = BoaProfiler::global().start_event("AsyncFunctionExpression", "Parsing");
unimplemented!("Async function expression parse");
}
}

8
boa/src/syntax/parser/expression/primary/mod.rs

@ -8,14 +8,15 @@
//! [spec]: https://tc39.es/ecma262/#prod-PrimaryExpression //! [spec]: https://tc39.es/ecma262/#prod-PrimaryExpression
mod array_initializer; mod array_initializer;
mod async_function_expression;
mod function_expression; mod function_expression;
mod object_initializer; mod object_initializer;
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;
use self::{ use self::{
array_initializer::ArrayLiteral, function_expression::FunctionExpression, array_initializer::ArrayLiteral, async_function_expression::AsyncFunctionExpression,
object_initializer::ObjectLiteral, function_expression::FunctionExpression, object_initializer::ObjectLiteral,
}; };
use super::Expression; use super::Expression;
use crate::{ use crate::{
@ -77,6 +78,9 @@ where
TokenKind::Keyword(Keyword::Function) => { TokenKind::Keyword(Keyword::Function) => {
FunctionExpression.parse(cursor).map(Node::from) FunctionExpression.parse(cursor).map(Node::from)
} }
TokenKind::Keyword(Keyword::Async) => {
AsyncFunctionExpression.parse(cursor).map(Node::from)
}
TokenKind::Punctuator(Punctuator::OpenParen) => { TokenKind::Punctuator(Punctuator::OpenParen) => {
cursor.set_goal(InputElement::RegExp); cursor.set_goal(InputElement::RegExp);
let expr = let expr =

47
boa/src/syntax/parser/statement/declaration/hoistable.rs

@ -7,7 +7,10 @@
use crate::{ use crate::{
syntax::{ syntax::{
ast::{node::FunctionDecl, Keyword, Node, Punctuator}, ast::{
node::{AsyncFunctionDecl, FunctionDecl},
Keyword, Node, Punctuator,
},
parser::{ parser::{
function::FormalParameters, function::FunctionBody, statement::BindingIdentifier, function::FormalParameters, function::FunctionBody, statement::BindingIdentifier,
AllowAwait, AllowDefault, AllowYield, Cursor, ParseError, ParseResult, TokenParser, AllowAwait, AllowDefault, AllowYield, Cursor, ParseError, ParseResult, TokenParser,
@ -119,3 +122,45 @@ where
Ok(FunctionDecl::new(name, params, body)) Ok(FunctionDecl::new(name, params, body))
} }
} }
/// Async Function declaration parsing.
///
/// More information:
/// - [MDN documentation][mdn]
/// - [ECMAScript specification][spec]
///
/// [mdn]:
/// [spec]:
#[derive(Debug, Clone, Copy)]
struct AsyncFunctionDeclaration {
allow_yield: AllowYield,
allow_await: AllowAwait,
is_default: AllowDefault,
}
impl AsyncFunctionDeclaration {
/// Creates a new `FunctionDeclaration` parser.
fn new<Y, A, D>(allow_yield: Y, allow_await: A, is_default: D) -> Self
where
Y: Into<AllowYield>,
A: Into<AllowAwait>,
D: Into<AllowDefault>,
{
Self {
allow_yield: allow_yield.into(),
allow_await: allow_await.into(),
is_default: is_default.into(),
}
}
}
impl<R> TokenParser<R> for AsyncFunctionDeclaration
where
R: Read,
{
type Output = AsyncFunctionDecl;
fn parse(self, cursor: &mut Cursor<R>) -> Result<Self::Output, ParseError> {
unimplemented!("AsyncFunctionDecl parse");
}
}

Loading…
Cancel
Save