mirror of https://github.com/boa-dev/boa.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
2.2 KiB
78 lines
2.2 KiB
//! Continue expression parsing. |
|
//! |
|
//! More information: |
|
//! - [MDN documentation][mdn] |
|
//! - [ECMAScript specification][spec] |
|
//! |
|
//! [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/continue |
|
//! [spec]: https://tc39.es/ecma262/#sec-continue-statement |
|
|
|
#[cfg(test)] |
|
mod tests; |
|
|
|
use crate::syntax::{ |
|
ast::{keyword::Keyword, node::Node, punc::Punctuator, token::TokenKind}, |
|
parser::{AllowAwait, AllowYield, Cursor, ParseError, ParseResult, TokenParser}, |
|
}; |
|
|
|
/// For statement parsing |
|
/// |
|
/// More information: |
|
/// - [MDN documentation][mdn] |
|
/// - [ECMAScript specification][spec] |
|
/// |
|
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/continue |
|
/// [spec]: https://tc39.es/ecma262/#prod-ContinueStatement |
|
#[derive(Debug, Clone, Copy)] |
|
pub(super) struct ContinueStatement { |
|
allow_yield: AllowYield, |
|
allow_await: AllowAwait, |
|
} |
|
|
|
impl ContinueStatement { |
|
/// Creates a new `ContinueStatement` parser. |
|
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 = Node; |
|
|
|
fn parse(self, cursor: &mut Cursor<'_>) -> ParseResult { |
|
cursor.expect(Keyword::Continue, "continue statement")?; |
|
|
|
if let (true, tok) = cursor.peek_semicolon(false) { |
|
match tok { |
|
Some(tok) if tok.kind == TokenKind::Punctuator(Punctuator::Semicolon) => { |
|
let _ = cursor.next(); |
|
} |
|
_ => {} |
|
} |
|
|
|
return Ok(Node::Continue(None)); |
|
} |
|
|
|
let tok = cursor.next().ok_or(ParseError::AbruptEnd)?; |
|
let node = if let TokenKind::Identifier(name) = &tok.kind { |
|
Node::continue_node(name) |
|
} else { |
|
return Err(ParseError::Expected( |
|
vec![TokenKind::identifier("identifier")], |
|
tok.clone(), |
|
"continue statement", |
|
)); |
|
}; |
|
|
|
cursor.expect_semicolon(false, "continue statement")?; |
|
|
|
Ok(node) |
|
} |
|
}
|
|
|