bug-grep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [patch #4604] Fix left anchors and -w problems


From: Julian Foad
Subject: Re: [patch #4604] Fix left anchors and -w problems
Date: Thu, 10 Nov 2005 02:48:46 +0000
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.8) Gecko/20050511

Jakub Jelinek, there's a question for you below about Grep tests you wrote.


Charles Levert wrote:
* On Wednesday 2005-11-09 at 15:50:33 +0000, Julian Foad wrote:

Charles Levert wrote:

<http://savannah.gnu.org/patch/?func=detailitem&item_id=4604>
<http://savannah.gnu.org/patch/download.php?item_id=4604&item_file_id=5449>

The following set of changes make previously failing tests relative to left
anchors (^ and \<) and -w pass.
[...]
It now makes fmbtest.sh Test #6 (G and E) fail, but isn't it that test that
has wrong expectations?  (Test that -{G,E} --color=always prefers earlier
pattern matches.  Earlier as in -e/-f order.)

[...]
The Test #6 logic prefers earlier patterns in
the pattern list.  My patch tries to consider all
patterns equally, possibly skipping computations
when what one of these matches is worst than the
best we have so far.

Oh, OK. I realised there were two different meanings of "earlier" but I misunderstood your log message which said:

+       * src/search.c (EGexecute): Consider all patterns if many and,
+         for an exact match, return the best one (leftmost, then longest).

In this sentence, "the best one" doesn't seem to refer to a match because "an exact match" seems to be talking about only one match, so I thought it referred to the best of "all patterns". I'm sure you'll rewrite that to make it clear - something like "when seeking an exact match, return the best match".


Now that I understand you, we need to determine whether returning the first pattern that matches was accidental or intentional behaviour.

My patch tries to find the match that's leftmost
in the data string.  The old code and Test #6 put
themselves at the mercy of the first pattern in
the list that matches with regard to the position
of that match in the data string.

(Presumably you meant "without regard".)
So, you believe there is no reason to prefer the first given pattern, and that there is reason to prefer the leftmost match. On the latter point I agree, since it is consistent with other forms of search that Grep performs internally, and is also convenient for the "--color" and "--only-matching" higher-level code. On the former point, perhaps we should ask Jakub Jelinek who wrote that test. Google gives me his address, so I'm copying this mail to him.

Jakub, can you remember why you added tests to ensure that grep highlights a match to the first pattern that matches?


I forgot to cite this bug:

   <https://savannah.gnu.org/bugs/?func=detailitem&item_id=8243>

My patch attempts to fix the issue it raises.
This issue conflicts with what Test #6 implies.

That bug is about egrep not highlighting all matches in the data when several patterns are given. I don't think there is strictly a semantic conflict, but it would certainly require a different and perhaps more complex implementation of the "--color" and "--only-matching" logic.

So, +1 on returning the match that is leftmost in the data, and changing the tests accordingly, unless we soon discover (maybe from Jakub) a good reason not to do so.

- Julian




reply via email to

[Prev in Thread] Current Thread [Next in Thread]