1
0
Fork 0
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:
AnotherTest 2020-07-12 01:41:24 +04:30 committed by Andreas Kling
parent 9c1da8fca1
commit 95fc7dd03a
Notes: sideshowbarker 2024-07-19 04:46:45 +09:00
4 changed files with 96 additions and 49 deletions

View file

@ -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()