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

Re: [PATCH v2] Teach git diff about Objective-C syntax

From
Jonathan del Strother <maillist@steelskies.com>
Date
Oct 2, 2008, 10:40 UTC
Message-ID
<57518fd10810020340t15d9441av521b7ef088ea09ca@mail.gmail.com>
In-Reply-To
<1222818394-11547-1-git-send-email-jon.delStrother@bestbefore.tv>

On Wed, Oct 1, 2008 at 12:46 AM, Jonathan del Strother <jon.delStrother@bestbefore.tv> wrote:

Show 45 quoted lines
> Add support for recognition of Objective-C class & instance methods, C functions, and class implementation/interfaces.
>
> Signed-off-by: Jonathan del Strother <jon.delStrother@bestbefore.tv>
> ---
> This version is much the same, but rebuilt on top of 1883a0d3b to use the extended regexp stuff, and it doesn't attempt to tidy up other patterns.
>
>  Documentation/gitattributes.txt |    2 ++
>  diff.c                          |   10 ++++++++++
>  2 files changed, 12 insertions(+), 0 deletions(-)
>
> diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
> index 2ae771f..2694559 100644
> --- a/Documentation/gitattributes.txt
> +++ b/Documentation/gitattributes.txt
> @@ -315,6 +315,8 @@ patterns are available:
>
>  - `java` suitable for source code in the Java language.
>
> +- `objc` suitable for source code in the Objective-C language.
> +
>  - `pascal` suitable for source code in the Pascal/Delphi language.
>
>  - `php` suitable for source code in the PHP language.
> diff --git a/diff.c b/diff.c
> index b001d7b..3694602 100644
> --- a/diff.c
> +++ b/diff.c
> @@ -1429,6 +1429,16 @@ static const struct funcname_pattern_entry builtin_funcname_pattern[] = {
>          "!^[ \t]*(catch|do|for|if|instanceof|new|return|switch|throw|while)\n"
>          "^[ \t]*(([ \t]*[A-Za-z_][A-Za-z_0-9]*){2,}[ \t]*\\([^;]*)$",
>          REG_EXTENDED },
> +       { "objc",
> +         /* Negate C statements that can look like functions */
> +         "!^[ \t]*(do|for|if|else|return|switch|while)\n"
> +         /* Objective-C methods */
> +         "^[ \t]*([-+][ \t]*\\([ \t]*[A-Za-z_][A-Za-z_0-9* \t]*\\)[ \t]*[A-Za-z_].*)$\n"
> +         /* C functions */
> +         "^[ \t]*(([ \t]*[A-Za-z_][A-Za-z_0-9]*){2,}[ \t]*\\([^;]*)$\n"
> +         /* Objective-C class/protocol definitions */
> +         "^(@(implementation|interface|protocol)[ \t].*)$",
> +         REG_EXTENDED },
>        { "pascal",
>          "^((procedure|function|constructor|destructor|interface|"
>                "implementation|initialization|finalization)[ \t]*.*)$"
> --

Given Brandon's "strip newline (and cr) from line before pattern matching" patch, the objective C line could be changed to "^[ \t]*([-+][ \t]*\\([ \t]*[A-Za-z_][A-Za-z_0-9* \t]*\\)[ \t]*[A-Za-z_][A-Za-z_0-9:{()*& \t]*)$\n" to be more specific about what's allowed to occur on a method line. Depends how often we really care about getting the funcname right - for instance, do we want to deal with cases like :

-(void)doStuff:(NSString*)foo { // TODO : This is a %@^$#@ method name, change it.

? I suspect the additional complexity that would be added to the regex isn't worth the small gain - any thoughts?

Previous: Jonathan del StrotherNext: Andreas Ericsson
Message 19 of 23 in “Teach git diff about Objective-C syntax”
  1. Teach git diff about Objective-C syntaxJonathan del Strother, Sep 16, 2008
  2. Miklos VajnaSep 16, 2008
  3. Teach git diff about Objective-C syntaxJonathan del Strother, Sep 17, 2008
  4. Teach git diff about Objective-C syntaxJonathan del Strother, Sep 17, 2008
  5. Johannes SchindelinSep 17, 2008
  6. Jonathan del StrotherSep 17, 2008
  7. Teach git diff about Objective-C syntaxJonathan del Strother, Sep 17, 2008
  8. Andreas EricssonSep 17, 2008
  9. Jonathan del StrotherSep 17, 2008
  10. Miklos VajnaSep 17, 2008
  11. Jonathan del StrotherSep 17, 2008
  12. Junio C HamanoSep 17, 2008
  13. Jonathan del StrotherSep 17, 2008
  14. Teach git diff about Objective-C syntaxJonathan del Strother, Sep 30, 2008
  15. Brandon CaseyOct 1, 2008
  16. xdiff-interface.c: strip newline (and cr) from line before pattern matchingBrandon Casey, Oct 1, 2008
  17. Johannes SchindelinOct 1, 2008
  18. Jonathan del StrotherOct 2, 2008
  19. Jonathan del StrotherOct 2, 2008
  20. Andreas EricssonSep 18, 2008
  21. Jonathan del StrotherSep 17, 2008
  22. Johannes SchindelinSep 17, 2008
  23. Jonathan del StrotherSep 17, 2008

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.