1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 09:28:11 +00:00

Shell: Add support for brace expansions

This adds support for (basic) brace expansions with the following
syntaxes:
- `{expr?,expr?,expr?,...}` which is directly equivalent to `(expr expr
  expr ...)`, with the missing expressions replaced with an empty string
  literal.
- `{expr..expr}` which is a new range expansion, with two modes:
    - if both expressions are one unicode code point long, the range is
      equivalent to the two code points and all code points between the
      two (numerically).
    - if both expressions are numeric, the range is equivalent to both
      numbers, and all numbers between the two.
    - otherwise, it is equivalent to `(expr expr)`.

Closes #3832.
This commit is contained in:
AnotherTest 2020-10-24 18:13:02 +03:30 committed by Andreas Kling
parent 567f2f3548
commit 5640e1bc3a
9 changed files with 374 additions and 3 deletions

View file

@ -55,6 +55,12 @@ void NodeVisitor::visit(const AST::BarewordLiteral*)
{
}
void NodeVisitor::visit(const AST::BraceExpansion* node)
{
for (auto& entry : node->entries())
entry.visit(*this);
}
void NodeVisitor::visit(const AST::CastToCommand* node)
{
node->inner()->visit(*this);
@ -153,6 +159,12 @@ void NodeVisitor::visit(const AST::Pipe* node)
node->right()->visit(*this);
}
void NodeVisitor::visit(const AST::Range* node)
{
node->start()->visit(*this);
node->end()->visit(*this);
}
void NodeVisitor::visit(const AST::ReadRedirection* node)
{
visit(static_cast<const AST::PathRedirectionNode*>(node));