diff options
author | John Ankarström <john@ankarstrom.se> | 2021-05-26 01:54:09 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2021-05-26 01:54:09 +0200 |
commit | b511a4ced9c0e48fdc35db2b0ae9d454e72bf800 (patch) | |
tree | 2e7a17c450a92afaa4945342a68329bfe841ed06 | |
parent | b9ed52e3684e49b9b00ef08b29111758cc4777ee (diff) | |
download | mum-b511a4ced9c0e48fdc35db2b0ae9d454e72bf800.tar.gz |
mum: Clean up regular expression
-rwxr-xr-x | src/mum | 26 |
1 files changed, 15 insertions, 11 deletions
@@ -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 = () }) + (?<range> (?{ @range = () }) ( (?&ref) | (?&ref),(?&ref) - | (?&pattern) + | (?&grep) ) - (?{ push @range, \%ref }) + (?{ push @range, \%ref }) ) - (?<ref> ( (\d+) (?{ local %ref = (line => $^N) }) - | (\.|\$) (?{ local %ref = (spec => $^N) }) - | ' ([a-z]) (?{ local %ref = (mark => $^N) }) - | /((\\/|[^/])*)/ (?{ local %ref = (next => $^N) }) - | \?((\\\?|[^?])*)\? (?{ local %ref = (prev => $^N) }) + (?<ref> ( (\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) }) )? ) - (?<pattern> g/((\\/|[^/])*)/ (?{ local %ref = (patt => $^N) }) + (?<grep> g((?&next)) (?{ local %ref = (grep => $^R) }) + ) + (?<next> /(([^/\\]++ | \\.)*+)/ (?{ $^N }) + ) + (?<prev> \?(([^?\\]++ | \\.)*+)\? (?{ $^N }) ) ) }x; |