1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 08:57:35 +00:00

Shell: Add support for 'immediate' expressions as variable substitutions

This commit adds a few basic variable substitution operations:
- length
    Find the length of a string or a list
- length_across
    Find the lengths of things inside a list
- remove_{suffix,prefix}
    Remove a suffix or a prefix from all the passed values
- regex_replace
    Replace all matches of a given regex with a given template
- split
    Split the given string with the given delimiter (or to its
    code points if the delimiter is empty)
- concat_lists
    concatenates any given lists into one

Closes #4316 (the ancient version of this same feature)
This commit is contained in:
AnotherTest 2021-03-05 16:33:23 +03:30 committed by Andreas Kling
parent a303b69caa
commit a45b2ea6fb
16 changed files with 911 additions and 37 deletions

View file

@ -33,7 +33,7 @@ namespace Shell {
String Formatter::format()
{
auto node = Parser(m_source).parse();
auto node = m_root_node ? m_root_node : Parser(m_source).parse();
if (m_cursor >= 0)
m_output_cursor = m_cursor;
@ -472,6 +472,27 @@ void Formatter::visit(const AST::IfCond* node)
visited(node);
}
void Formatter::visit(const AST::ImmediateExpression* node)
{
will_visit(node);
test_and_update_output_cursor(node);
current_builder().append("${");
TemporaryChange<const AST::Node*> parent { m_parent_node, node };
current_builder().append(node->function_name());
for (auto& node : node->arguments()) {
current_builder().append(' ');
node.visit(*this);
}
if (node->has_closing_brace())
current_builder().append('}');
visited(node);
}
void Formatter::visit(const AST::Join* node)
{
will_visit(node);