mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-10 10:01:13 +09:00
Shell: Parse lists serially, and flatten them only when needed
This allows `((1 2 3) (4 5 6))` to remain nested until we explicitly flatten it out.
This commit is contained in:
parent
9c1da8fca1
commit
95fc7dd03a
Notes:
sideshowbarker
2024-07-19 04:46:45 +09:00
Author: https://github.com/alimpfard
Commit: 95fc7dd03a
Pull-request: https://github.com/SerenityOS/serenity/pull/2767
Issue: https://github.com/SerenityOS/serenity/issues/2760
4 changed files with 96 additions and 49 deletions
|
@ -420,19 +420,19 @@ RefPtr<AST::Node> Parser::parse_list_expression()
|
|||
consume_while(is_whitespace);
|
||||
|
||||
auto rule_start = push_start();
|
||||
Vector<RefPtr<AST::Node>> nodes;
|
||||
|
||||
auto expr = parse_expression();
|
||||
if (!expr)
|
||||
do {
|
||||
auto expr = parse_expression();
|
||||
if (!expr)
|
||||
break;
|
||||
nodes.append(move(expr));
|
||||
} while (!consume_while(is_whitespace).is_empty());
|
||||
|
||||
if (nodes.is_empty())
|
||||
return nullptr;
|
||||
|
||||
if (consume_while(is_whitespace).is_empty())
|
||||
return expr;
|
||||
|
||||
auto list = parse_list_expression();
|
||||
if (!list)
|
||||
return create<AST::CastToList>(move(expr));
|
||||
|
||||
return create<AST::ListConcatenate>(move(expr), move(list)); // Join Element List
|
||||
return create<AST::ListConcatenate>(move(nodes)); // Concatenate List
|
||||
}
|
||||
|
||||
RefPtr<AST::Node> Parser::parse_expression()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue