From c2bf1b3cfbcd157236ed06f381bd8e69078417ef Mon Sep 17 00:00:00 2001 From: Paul Lancaster Date: Fri, 9 Oct 2020 23:47:35 +0100 Subject: [PATCH] AsyncFunctionDecl/Expr parser created (not impl) --- .../primary/async_function_expression.rs | 42 +++++++++++++++++ .../syntax/parser/expression/primary/mod.rs | 8 +++- .../parser/statement/declaration/hoistable.rs | 47 ++++++++++++++++++- 3 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 boa/src/syntax/parser/expression/primary/async_function_expression.rs diff --git a/boa/src/syntax/parser/expression/primary/async_function_expression.rs b/boa/src/syntax/parser/expression/primary/async_function_expression.rs new file mode 100644 index 0000000000..61f24e8412 --- /dev/null +++ b/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 TokenParser for AsyncFunctionExpression +where + R: Read, +{ + type Output = AsyncFunctionExpr; + + fn parse(self, cursor: &mut Cursor) -> Result { + let _timer = BoaProfiler::global().start_event("AsyncFunctionExpression", "Parsing"); + + unimplemented!("Async function expression parse"); + } +} diff --git a/boa/src/syntax/parser/expression/primary/mod.rs b/boa/src/syntax/parser/expression/primary/mod.rs index 50cc95cc8a..9963df4b57 100644 --- a/boa/src/syntax/parser/expression/primary/mod.rs +++ b/boa/src/syntax/parser/expression/primary/mod.rs @@ -8,14 +8,15 @@ //! [spec]: https://tc39.es/ecma262/#prod-PrimaryExpression mod array_initializer; +mod async_function_expression; mod function_expression; mod object_initializer; #[cfg(test)] mod tests; use self::{ - array_initializer::ArrayLiteral, function_expression::FunctionExpression, - object_initializer::ObjectLiteral, + array_initializer::ArrayLiteral, async_function_expression::AsyncFunctionExpression, + function_expression::FunctionExpression, object_initializer::ObjectLiteral, }; use super::Expression; use crate::{ @@ -77,6 +78,9 @@ where TokenKind::Keyword(Keyword::Function) => { FunctionExpression.parse(cursor).map(Node::from) } + TokenKind::Keyword(Keyword::Async) => { + AsyncFunctionExpression.parse(cursor).map(Node::from) + } TokenKind::Punctuator(Punctuator::OpenParen) => { cursor.set_goal(InputElement::RegExp); let expr = diff --git a/boa/src/syntax/parser/statement/declaration/hoistable.rs b/boa/src/syntax/parser/statement/declaration/hoistable.rs index 1f18c09976..a059bbe95d 100644 --- a/boa/src/syntax/parser/statement/declaration/hoistable.rs +++ b/boa/src/syntax/parser/statement/declaration/hoistable.rs @@ -7,7 +7,10 @@ use crate::{ syntax::{ - ast::{node::FunctionDecl, Keyword, Node, Punctuator}, + ast::{ + node::{AsyncFunctionDecl, FunctionDecl}, + Keyword, Node, Punctuator, + }, parser::{ function::FormalParameters, function::FunctionBody, statement::BindingIdentifier, AllowAwait, AllowDefault, AllowYield, Cursor, ParseError, ParseResult, TokenParser, @@ -119,3 +122,45 @@ where 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(allow_yield: Y, allow_await: A, is_default: D) -> Self + where + Y: Into, + A: Into, + D: Into, + { + Self { + allow_yield: allow_yield.into(), + allow_await: allow_await.into(), + is_default: is_default.into(), + } + } +} + +impl TokenParser for AsyncFunctionDeclaration +where + R: Read, +{ + type Output = AsyncFunctionDecl; + + fn parse(self, cursor: &mut Cursor) -> Result { + unimplemented!("AsyncFunctionDecl parse"); + } +}