summaryrefslogtreecommitdiff
path: root/Userland/Shell/Formatter.cpp
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2022-04-15 01:50:36 +0430
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2022-04-18 19:53:10 +0430
commit4ede121d31f43a787b32fc4c137582638ea305e1 (patch)
treee8a011b40e00d6848eafb72c401d8b4e884c49eb /Userland/Shell/Formatter.cpp
parent6aceec45357f8e253bc169f1ed961fc26038a3da (diff)
downloadserenity-4ede121d31f43a787b32fc4c137582638ea305e1.zip
Shell: Add support for regex match patterns
We previously allowed globs as match pattern, but for more complex matching needs, it's nice to have regular expressions. And as the existing "name a part of the match" concept maps nicely to named capture groups, we can simply reuse the same code and make groups with names available in the match body.
Diffstat (limited to 'Userland/Shell/Formatter.cpp')
-rw-r--r--Userland/Shell/Formatter.cpp24
1 files changed, 18 insertions, 6 deletions
diff --git a/Userland/Shell/Formatter.cpp b/Userland/Shell/Formatter.cpp
index f005a2c71d..5f3ab9d840 100644
--- a/Userland/Shell/Formatter.cpp
+++ b/Userland/Shell/Formatter.cpp
@@ -583,12 +583,24 @@ void Formatter::visit(const AST::MatchExpr* node)
insert_separator();
first_entry = false;
auto first = true;
- for (auto& option : entry.options) {
- if (!first)
- current_builder().append(" | ");
- first = false;
- option.visit(*this);
- }
+ entry.options.visit(
+ [&](NonnullRefPtrVector<AST::Node> const& patterns) {
+ for (auto& option : patterns) {
+ if (!first)
+ current_builder().append(" | ");
+ first = false;
+ option.visit(*this);
+ }
+ },
+ [&](Vector<Regex<ECMA262>> const& patterns) {
+ for (auto& option : patterns) {
+ if (!first)
+ current_builder().append(" | ");
+ first = false;
+ auto node = make_ref_counted<AST::BarewordLiteral>(AST::Position {}, option.pattern_value);
+ node->visit(*this);
+ }
+ });
current_builder().append(' ');
if (entry.match_names.has_value() && !entry.match_names.value().is_empty()) {