mirror of https://github.com/boa-dev/boa.git
7 changed files with 140 additions and 2 deletions
@ -0,0 +1,59 @@
|
||||
//! Await expression node.
|
||||
|
||||
use super::Node; |
||||
use crate::{exec::Executable, BoaProfiler, Context, Result, Value}; |
||||
use gc::{Finalize, Trace}; |
||||
use std::fmt; |
||||
|
||||
#[cfg(feature = "serde")] |
||||
use serde::{Deserialize, Serialize}; |
||||
|
||||
///
|
||||
///
|
||||
/// More information:
|
||||
/// - [ECMAScript reference][spec]
|
||||
/// - [MDN documentation][mdn]
|
||||
///
|
||||
/// [spec]:
|
||||
/// [mdn]:
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
||||
#[derive(Clone, Debug, Trace, Finalize, PartialEq)] |
||||
pub struct AwaitExpr { |
||||
expr: Box<Node>, |
||||
} |
||||
|
||||
impl Executable for AwaitExpr { |
||||
fn run(&self, interpreter: &mut Context) -> Result<Value> { |
||||
let _timer = BoaProfiler::global().start_event("AwaitExpression", "exec"); |
||||
unimplemented!("Await expression execution"); |
||||
} |
||||
} |
||||
|
||||
impl AwaitExpr { |
||||
/// Implements the display formatting with indentation.
|
||||
pub(super) fn display(&self, f: &mut fmt::Formatter<'_>, indentation: usize) -> fmt::Result { |
||||
writeln!(f, "await ")?; |
||||
self.expr.display(f, indentation) |
||||
} |
||||
} |
||||
|
||||
impl<T> From<T> for AwaitExpr |
||||
where |
||||
T: Into<Box<Node>>, |
||||
{ |
||||
fn from(e: T) -> Self { |
||||
Self { expr: e.into() } |
||||
} |
||||
} |
||||
|
||||
impl fmt::Display for AwaitExpr { |
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
||||
self.display(f, 0) |
||||
} |
||||
} |
||||
|
||||
impl From<AwaitExpr> for Node { |
||||
fn from(awaitexpr: AwaitExpr) -> Self { |
||||
Self::AwaitExpr(awaitexpr) |
||||
} |
||||
} |
@ -0,0 +1,58 @@
|
||||
//! Await expression parsing.
|
||||
//!
|
||||
//! More information:
|
||||
//! - [MDN documentation][mdn]
|
||||
//! - [ECMAScript specification][spec]
|
||||
//!
|
||||
//! [mdn]:
|
||||
//! [spec]:
|
||||
|
||||
use super::unary::UnaryExpression; |
||||
|
||||
use crate::syntax::{ |
||||
ast::{node::AwaitExpr, Keyword}, |
||||
lexer::TokenKind, |
||||
parser::{AllowYield, Cursor, ParseError, TokenParser}, |
||||
}; |
||||
use std::io::Read; |
||||
|
||||
/// Parses a await expression.
|
||||
///
|
||||
/// More information:
|
||||
/// - [MDN documentation][mdn]
|
||||
/// - [ECMAScript specification][spec]
|
||||
///
|
||||
/// [mdn]:
|
||||
/// [spec]:
|
||||
#[derive(Debug, Clone, Copy)] |
||||
pub(in crate::syntax::parser) struct AwaitExpression { |
||||
allow_yield: AllowYield, |
||||
} |
||||
|
||||
impl AwaitExpression { |
||||
/// Creates a new `AwaitExpression` parser.
|
||||
pub(in crate::syntax::parser) fn new<Y>(allow_yield: Y) -> Self |
||||
where |
||||
Y: Into<AllowYield>, |
||||
{ |
||||
Self { |
||||
allow_yield: allow_yield.into(), |
||||
} |
||||
} |
||||
} |
||||
|
||||
impl<R> TokenParser<R> for AwaitExpression |
||||
where |
||||
R: Read, |
||||
{ |
||||
type Output = AwaitExpr; |
||||
|
||||
fn parse(self, cursor: &mut Cursor<R>) -> Result<Self::Output, ParseError> { |
||||
cursor.expect( |
||||
TokenKind::Keyword(Keyword::Await), |
||||
"Await expression parsing", |
||||
)?; |
||||
let expr = UnaryExpression::new(self.allow_yield, true).parse(cursor)?; |
||||
Ok(expr.into()) |
||||
} |
||||
} |
Loading…
Reference in new issue