mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 15:48:12 +00:00
Shell: Add support for enumerating lists in for loops
With some odd syntax to boot: ```sh $ for index i x in $whatever {} ```
This commit is contained in:
parent
a45b2ea6fb
commit
13b65b632a
8 changed files with 133 additions and 23 deletions
|
@ -341,8 +341,13 @@ void Formatter::visit(const AST::ForLoop* node)
|
|||
TemporaryChange<const AST::Node*> parent { m_parent_node, node };
|
||||
|
||||
if (!is_loop) {
|
||||
if (node->variable_name() != "it") {
|
||||
current_builder().append(node->variable_name());
|
||||
if (node->index_variable().has_value()) {
|
||||
current_builder().append("index ");
|
||||
current_builder().append(node->index_variable()->name);
|
||||
current_builder().append(" ");
|
||||
}
|
||||
if (node->variable().has_value() && node->variable()->name != "it") {
|
||||
current_builder().append(node->variable()->name);
|
||||
current_builder().append(" in ");
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue