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

Re: [GSoC][PATCH] userdiff: add built-in pattern for golang

From
Alban Gruin <alban.gruin@gmail.com>
Date
Feb 28, 2018, 22:17 UTC
Message-ID
<b9aa0939-8b20-0f35-84f4-5b519080ca34@gmail.com>
In-Reply-To
<CAPig+cQ6awH8KfX3C+=OwE3qJLJPQyAt_dmQvMw1NLNnCT73RQ@mail.gmail.com>
Le 28/02/2018 à 23:00, Eric Sunshine a écrit :
Show 41 quoted lines
> On Wed, Feb 28, 2018 at 4:31 PM, Alban Gruin <alban.gruin@gmail.com> wrote:
>>>> diff --git a/userdiff.c b/userdiff.c
>>>> @@ -38,6 +38,15 @@ IPATTERN("fortran",
>>>> +PATTERNS("golang",
>>>> +        /* Functions */
>>>> +        "^[ \t]*(func[ \t]*.*(\\{[ \t]*)?)\n"
>>>
>>> Why is the brace (and possible following whitespace) optional?
>>> Considering that the language demands that the brace be on the same
>>> line, I'd think the brace should be mandatory.
>>
>> I did this to support non-standard formatting. It's a niche case though,
>> maybe we could only support the standard formatting and modify the doc
>> to reflect this change.
> 
> As noted, unlike 'struct' and 'interface', the brace for a 'func'
> _must_ appear on the same line; that's a requirement of the language.
> Placing it on a line is not an option.
> 
>     % cat >foo.go<<\EOF
>     package foo
>     func foo() {
>     }
>     EOF
>     % go build foo.go
> 
> Versus:
> 
>     % cat >bar.go<<\EOF
>     package bar
>     func bar()
>     {
>     }
>     EOF
>     % go build bar.go
>     ./bar.go:2:6: missing function body
>     ./bar.go:3:1: syntax error: unexpected semicolon or newline before {
> 
> So, the regex probably ought to be strict about expecting the brace on
> the same line as 'func'.
> 
Yes, but I can split the line like that:
    % cat >baz.go<<\EOF
    package baz
    func baz(arg1 int64,
    	arg2 int64) {
    }
    EOF
    % go build baz.go

This complies to the standard formatting (at least, gofmt doesn't change it), but making the regex strict about the brace would cause it to ignore those funcs, although I don't know how common they are.

Previous: Eric SunshineNext: Eric Sunshine
Message 5 of 10 in “userdiff: add built-in pattern for golang”
  1. Alban GruinFeb 28, 2018
  2. Eric SunshineFeb 28, 2018
  3. Alban GruinFeb 28, 2018
  4. Eric SunshineFeb 28, 2018
  5. Alban GruinFeb 28, 2018
  6. Eric SunshineFeb 28, 2018
  7. Junio C HamanoFeb 28, 2018
  8. Alban GruinFeb 28, 2018
  9. [GSoC][PATCH v2] userdiff: add built-in pattern for golangAlban Gruin, Mar 1, 2018
  10. Eric SunshineMar 1, 2018

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.