From b511a4ced9c0e48fdc35db2b0ae9d454e72bf800 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Wed, 26 May 2021 01:54:09 +0200 Subject: mum: Clean up regular expression --- src/mum | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/mum b/src/mum index 3c7d0b0..402053e 100755 --- a/src/mum +++ b/src/mum @@ -14,26 +14,30 @@ open my $tty, '+<:unix', '/dev/tty' or die "Could not open /dev/tty: $!"; # Define range syntax my @range; # range (one/two references) -our %ref; # current reference in range +our %ref; # current reference my $d = qr{ (?(DEFINE) - (? (?{ @range = () }) + (? (?{ @range = () }) ( (?&ref) | (?&ref),(?&ref) - | (?&pattern) + | (?&grep) ) - (?{ push @range, \%ref }) + (?{ push @range, \%ref }) ) - (? ( (\d+) (?{ local %ref = (line => $^N) }) - | (\.|\$) (?{ local %ref = (spec => $^N) }) - | ' ([a-z]) (?{ local %ref = (mark => $^N) }) - | /((\\/|[^/])*)/ (?{ local %ref = (next => $^N) }) - | \?((\\\?|[^?])*)\? (?{ local %ref = (prev => $^N) }) + (? ( (\d+) (?{ local %ref = (line => $^N) }) + | (\.|\$) (?{ local %ref = (spec => $^N) }) + | ' ([a-z]) (?{ local %ref = (mark => $^N) }) + | (?&next) (?{ local %ref = (next => $^R) }) + | (?&prev) (?{ local %ref = (prev => $^R) }) ) - ( ([+-] \d+) (?{ local %ref = (%ref, plus => $^N) }) + ( ([+-] \d+) (?{ local %ref = (%ref, plus => $^N) }) )? ) - (? g/((\\/|[^/])*)/ (?{ local %ref = (patt => $^N) }) + (? g((?&next)) (?{ local %ref = (grep => $^R) }) + ) + (? /(([^/\\]++ | \\.)*+)/ (?{ $^N }) + ) + (? \?(([^?\\]++ | \\.)*+)\? (?{ $^N }) ) ) }x; -- cgit v1.2.3