mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:27:43 +00:00
Shell: Allow newlines between else
and if
's closing brace
This is more flexible and intuitive. Fixes #4992.
This commit is contained in:
parent
a6917465d7
commit
5b79d0d1a3
2 changed files with 15 additions and 3 deletions
|
@ -718,19 +718,23 @@ RefPtr<AST::Node> Parser::parse_if_expr()
|
|||
return body;
|
||||
};
|
||||
|
||||
consume_while(is_whitespace);
|
||||
consume_while(is_any_of(" \t\n"));
|
||||
auto true_branch = parse_braced_toplevel();
|
||||
|
||||
consume_while(is_whitespace);
|
||||
auto end_before_else = m_offset;
|
||||
auto line_before_else = line();
|
||||
consume_while(is_any_of(" \t\n"));
|
||||
Optional<AST::Position> else_position;
|
||||
{
|
||||
auto else_start = push_start();
|
||||
if (expect("else"))
|
||||
else_position = AST::Position { else_start->offset, m_offset, else_start->line, line() };
|
||||
else
|
||||
restore_to(end_before_else, line_before_else);
|
||||
}
|
||||
|
||||
if (else_position.has_value()) {
|
||||
consume_while(is_whitespace);
|
||||
consume_while(is_any_of(" \t\n"));
|
||||
if (peek() == '{') {
|
||||
auto false_branch = parse_braced_toplevel();
|
||||
return create<AST::IfCond>(else_position, condition.release_nonnull(), move(true_branch), move(false_branch)); // If expr true_branch Else false_branch
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue