1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 05:27:43 +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:
AnotherTest 2021-03-05 18:25:09 +03:30 committed by Andreas Kling
parent a45b2ea6fb
commit 13b65b632a
8 changed files with 133 additions and 23 deletions

View file

@ -261,6 +261,35 @@ private:
set_offset_range_end(in_span.range, position.end_line);
in_span.attributes.color = m_palette.syntax_keyword();
}
// "index"
if (auto maybe_position = node->index_keyword_position(); maybe_position.has_value()) {
auto& position = maybe_position.value();
auto& index_span = span_for_node(node);
set_offset_range_start(index_span.range, position.start_line);
set_offset_range_end(index_span.range, position.end_line);
index_span.attributes.color = m_palette.syntax_keyword();
}
// variables
if (auto maybe_variable = node->variable(); maybe_variable.has_value()) {
auto& position = maybe_variable->position;
auto& variable_span = span_for_node(node);
set_offset_range_start(variable_span.range, position.start_line);
set_offset_range_end(variable_span.range, position.end_line);
variable_span.attributes.color = m_palette.syntax_identifier();
}
if (auto maybe_variable = node->index_variable(); maybe_variable.has_value()) {
auto& position = maybe_variable->position;
auto& variable_span = span_for_node(node);
set_offset_range_start(variable_span.range, position.start_line);
set_offset_range_end(variable_span.range, position.end_line);
variable_span.attributes.color = m_palette.syntax_identifier();
}
}
virtual void visit(const AST::Glob* node) override
{