JSSpecCompiler: Parse "Perform <expression>." steps

This commit is contained in:
Dan Klishch 2024-01-21 00:11:56 -05:00 committed by Andrew Kaster
parent d1fc84c638
commit ddf26a768c
Notes: sideshowbarker 2024-07-17 01:13:25 +09:00
2 changed files with 21 additions and 0 deletions

View file

@ -463,6 +463,18 @@ TextParseErrorOr<Tree> TextParser::parse_assignment()
return make_ref_counted<BinaryOperation>(op, lvalue, rvalue); return make_ref_counted<BinaryOperation>(op, lvalue, rvalue);
} }
// perform <expr>
TextParseErrorOr<Tree> TextParser::parse_perform()
{
auto rollback = rollback_point();
TRY(consume_word("perform"sv));
auto value = TRY(parse_expression());
rollback.disarm();
return value;
}
// <simple_step> // <simple_step>
TextParseErrorOr<Tree> TextParser::parse_simple_step_or_inline_if_branch() TextParseErrorOr<Tree> TextParser::parse_simple_step_or_inline_if_branch()
{ {
@ -493,6 +505,14 @@ TextParseErrorOr<Tree> TextParser::parse_simple_step_or_inline_if_branch()
return result.release_value(); return result.release_value();
} }
// Perform <expr>.$
if (auto result = parse_perform(); !result.is_error()) {
TRY(consume_token_with_type(TokenType::Dot));
TRY(expect_eof());
rollback.disarm();
return result.release_value();
}
return TextParseError {}; return TextParseError {};
} }

View file

@ -84,6 +84,7 @@ private:
TextParseErrorOr<Tree> parse_return_statement(); TextParseErrorOr<Tree> parse_return_statement();
TextParseErrorOr<Tree> parse_assert(); TextParseErrorOr<Tree> parse_assert();
TextParseErrorOr<Tree> parse_assignment(); TextParseErrorOr<Tree> parse_assignment();
TextParseErrorOr<Tree> parse_perform();
TextParseErrorOr<Tree> parse_simple_step_or_inline_if_branch(); TextParseErrorOr<Tree> parse_simple_step_or_inline_if_branch();
TextParseErrorOr<IfConditionParseResult> parse_if_beginning(); TextParseErrorOr<IfConditionParseResult> parse_if_beginning();
TextParseErrorOr<Tree> parse_inline_if_else(); TextParseErrorOr<Tree> parse_inline_if_else();