-w, highlighting, --underline

6 views
Skip to first unread message

Andy Lester

unread,
Mar 3, 2017, 11:37:45 AM3/3/17
to ack development
(This whole message is rich text, all fixed with Courier New with some bolding.  If you don't have it fixed width it will be bad.)

The big change in ack 3 that we're discussing now is -w.  Although -w promises "word" matching, it's basically just slapping \b and \b around the regex.  That causes problems that we'll discuss elsewhen.

We also have a big problem with how things get highlighted.  The first match group gets highlighted, which is wrong.  It should match the entire match, effectively $&.

In order to test these things, we're going to need a way to easily set up test cases that verify correct behavior.   I want to add an --underline flag that will make testing of highlighting easier, and will make a handy feature for when ack results go to a file.

I'm stealing the idea from the clang compiler, which does this with error messages:

op.c:13249:21: warning: variable 'is_deref' may be uninitialized when used here [-Wconditional-uninitialized]
                if (is_deref) {
                    ^~~~~~~~

I'm not seeing this in grep, so it looks like it will be new territory.  I also see --underline and --color being mutually exclusive.

Similarly, whereas right now ack 2 does this (which is bad behavior) (the bold would be highlighted on screen).

$ ack 'calculate_(foo|bar|bat)'
text.pl:12:    my $x = calculate_foo();
text.pl:14:    my $y = calculate_football();
blah.pm:179:    say recalculate_bar();

and ack 2 SHOULD do this:

$ ack 'calculate_(foo|bar|bat)'
text.pl:12:    my $x = calculate_foo();
text.pl:14:    my $y = calculate_football();
blah.pm:179:    say recalculate_bar();

I want ack3 to also be able to do this:

$ ack 'calculate_(foo|bar|bat)' --underline
text.pl:12:    my $x = calculate_foo();
                       ^^^^^^^^^^^^^

text.pl:14:    my $y = calculate_football();
                       ^^^^^^^^^^^^^

blah.pm:179:    say recalculate_bar();
                      ^^^^^^^^^^^^^

And with the newly worked-out -w flag in ack3, it should do this:

$ ack 'calculate_(foo|bar|bat)' --underline
text.pl:12:    my $x = calculate_foo();
                       ^^^^^^^^^^^^^

$ ack 'calculate_(foo|bar|bat)'
text.pl:12:    my $x = calculate_foo();

The two big uses cases I see for --underline are for dumping lots of ack hits into a file for later perusal, and for our testing purposes.

Comments on this plan?

--
Andy Lester => www.petdance.com

Edward Avis

unread,
Mar 6, 2017, 9:06:43 AM3/6/17
to ack development
--underline sounds like a great plan.  It will make the test cases much richer since instead of just match/no match you can specify exactly what is matched.

Possibly, for test cases, some more compact syntax could be used like putting square brackets around the expected match (or whatever, insert bikeshed here) just so that the test cases don't have to become twice as many lines long.

--underline and --color could still be given together though I agree that it seems a bit pointless.

Another idea - just to suggest it - is to include a start and end column number for the match.

text.pl:12:15:    my $x = calculate_foo();

If it's a half-closed interval, then this would also let you report zero-length matches correctly.  This column numbering gives the same information as --underline but might be easier to parse in test cases, and for anybody else who wants to process the output of ack.
Reply all
Reply to author
Forward
0 new messages