git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/2] diff: add custom regular expressions for function names

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jul 5, 2007, 11:44 UTC
Message-ID
<Pine.LNX.4.64.0707051227380.9789@racer.site>
In-Reply-To
<7vwsxfe96i.fsf@assigned-by-dhcp.cox.net>
Hi,
On Wed, 4 Jul 2007, Junio C Hamano wrote:
Show 7 quoted lines
> *NOTE IN BIG RED LETTERS*
> 
> I do not particularly like the way multiple regexps are used in
> Johannes's patch, but I left it as-is, as that part of the
> change is orthogonal from the support to use the gitattribute
> mechanism, and the primary reason I got involved in this topic
> is to give help around the latter area.

I do not like it particularly, either. Until two days ago, that POSIX regexps suck so much, in that they do not even have a look-ahead, let alone a negative look-ahead. _That_ is what I wanted.

Alas, that is the first valid argument I encounter that would speak _for_ pcre. It speaks volumes that _nobody_ pointed this out before, but all pcre fans put out bogus arguments.

Show 28 quoted lines
> I think using multiple regexp is cute, but if we do that, it
> should allow people to pick from:
> 
> 	public class Beer
> 	{
> 		int special;
> 		public static void main(String args[])
>                 {
>                 	... modified part is here ...
> 
> with two regexp matches, say:
> 
> 	/^(public|private|protectd) class (.*)/ then
>         /^	+.* (\w*\(.*)$/
> 
> and define the hunk_header format as something like:
> 
> 	"\[1,2]::\[2,1]"
> 
> meaning, "pick the second capture group from the match data of
> the first regexp, followed by double-colon, and pick the first
> capture group from the match data of the second regexp", to
> result in "Beer::main(String args[])".  You should be able
> to pick "/package (\w+);/ then /^sub (\w+)/" in Perl code using
> the same idea.
> 
> I am not married to the syntax I used in the above examples,
> though.
Is that really necessary?

But yeah, it is possible. You'd have to have some state in the struct, and introduce yet another escape (probably in place of the first line of the regexp), similar to

	*[2,2]::[1,1]
	*keep-searching-after-match 1
	^	+.* (\w*\(.*)$
	^(public|private|protected) class (.*)

Of course, there _has_ to be a way to handle exceptions, such as in Perl, where you do not necessarily have a package, and thus do not want that silly "::" in front of the rest.

But frankly, I think this is too complicated. Maybe somebody more intelligent than me can actually come up with a sane syntax and implementation of this, but at some point I think it is Good Enough(tm). And IMHO it is already good enough matching just one line.

Ciao, Dscho

Previous: Florian Weimer
Message 29 of 29 in “diff: add custom regular expressions for function names”
  1. 2/2 diff: add custom regular expressions for function namesJohannes Schindelin, Jul 4, 2007
  2. Linus TorvaldsJul 4, 2007
  3. Johannes SchindelinJul 4, 2007
  4. Junio C HamanoJul 4, 2007
  5. Johannes SchindelinJul 4, 2007
  6. Junio C HamanoJul 5, 2007
  7. 1/2 Future-proof source for changes in xdemitconf_tJunio C Hamano, Jul 5, 2007
  8. Johannes SchindelinJul 5, 2007
  9. 2/2 WIP per-path attribute based hunk header selection.Junio C Hamano, Jul 5, 2007
  10. Johannes SchindelinJul 5, 2007
  11. Junio C HamanoJul 5, 2007
  12. 1/3 Introduce diff_filespec_is_binary()Junio C Hamano, Jul 6, 2007
  13. Johannes SchindelinJul 6, 2007
  14. Per-path attribute based hunk header selection.Junio C Hamano, Jul 6, 2007
  15. Johannes SchindelinJul 6, 2007
  16. Linus TorvaldsJul 6, 2007
  17. Junio C HamanoJul 7, 2007
  18. しらいしななこJul 7, 2007
  19. Junio C HamanoJul 7, 2007
  20. Johannes SchindelinJul 7, 2007
  21. Junio C HamanoJul 7, 2007
  22. Junio C HamanoJul 8, 2007
  23. Johannes SchindelinJul 8, 2007
  24. Nicolas PitreJul 9, 2007
  25. Junio C HamanoJul 9, 2007
  26. Johannes SchindelinJul 9, 2007
  27. Fix configuration syntax to specify customized hunk header patterns.Junio C Hamano, Jul 7, 2007
  28. Florian WeimerJul 5, 2007
  29. Johannes SchindelinJul 5, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.