#[cfg(test)]
mod tests;
use crate::{
syntax::{
ast::{node::Continue, Keyword, Punctuator, TokenKind},
parser::{
statement::LabelIdentifier, AllowAwait, AllowYield, Cursor, ParseError, TokenParser,
},
},
BoaProfiler,
};
#[derive(Debug, Clone, Copy)]
pub(super) struct ContinueStatement {
allow_yield: AllowYield,
allow_await: AllowAwait,
}
impl ContinueStatement {
pub(super) fn new<Y, A>(allow_yield: Y, allow_await: A) -> Self
where
Y: Into<AllowYield>,
A: Into<AllowAwait>,
{
Self {
allow_yield: allow_yield.into(),
allow_await: allow_await.into(),
}
}
}
impl TokenParser for ContinueStatement {
type Output = Continue;
fn parse(self, cursor: &mut Cursor<'_>) -> Result<Self::Output, ParseError> {
let _timer = BoaProfiler::global().start_event("ContinueStatement", "Parsing");
cursor.expect(Keyword::Continue, "continue statement")?;
let label = if let (true, tok) = cursor.peek_semicolon(false) {
match tok {
Some(tok) if tok.kind == TokenKind::Punctuator(Punctuator::Semicolon) => {
let _ = cursor.next();
}
_ => {}
}
None
} else {
let label = LabelIdentifier::new(self.allow_yield, self.allow_await).parse(cursor)?;
cursor.expect_semicolon(false, "continue statement")?;
Some(label)
};
Ok(Continue::new::<_, Box<str>>(label))
}
}