Skip to content

Commit

Permalink
Got NOT highlighting going OK
Browse files Browse the repository at this point in the history
  • Loading branch information
petdance committed Dec 15, 2024
1 parent 029fc9b commit 767db96
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions andor.pl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


MAIN: {
my @words = @ARGV;
my @words = @ARGV or die "No words";

my @lines = <DATA>;
chomp @lines;
Expand All @@ -25,7 +25,7 @@
my $hl_re = join( '|', @words );
$hl_re = qr/($hl_re)/;

_iter( $match_and_re, $hl_re, @lines );
_iter( $match_and_re, undef, $hl_re, @lines );
}

OR: {
Expand All @@ -37,7 +37,21 @@
my $hl_re = join( '|', @words );
$hl_re = qr/($hl_re)/;

_iter( $match_or_re, $hl_re, @lines );
_iter( $match_or_re, undef, $hl_re, @lines );
}

NOT: {
say '';
say "NOT";
my ($keep, @not) = @words;
my $not_re;
if ( @not ) {
$not_re = join( '|', @not );
$not_re = qr/$not_re/;
}
my $hl_re = qr/($keep)/;

_iter( $keep, $not_re, $hl_re, @lines );
}
}

Expand All @@ -47,16 +61,22 @@

sub _iter {
my $match_re = shift;
my $not_re = shift;
my $hl_re = shift;
my @lines = @_;

say "match=$match_re";
say "hlite=$hl_re";
say " match=$match_re";
say " notre=", ($not_re // 'undef');
say " hlite=$hl_re";

for ( @lines ) {
my $line = "$_";

if ( $line =~ /$match_re/ ) {
my $match = $line =~ /$match_re/;
if ( $match && defined $not_re ) {
$match = $line !~ /$not_re/;
}
if ( $match ) {
while ( $line =~ /$hl_re/g ) {
my $match_start = $-[0] // next;
my $match_end = $+[0];
Expand Down Expand Up @@ -86,3 +106,5 @@ sub _iter {
sox got no
table and apple and penny
table only
penny saved an apple
penny sat at the table

0 comments on commit 767db96

Please sign in to comment.