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

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

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Mar 1, 2018, 18:24 UTC
Message-ID
<CAPig+cSPHa_A05iLBKUSr8dZcaOoEJ28TF+nAZzvQN2dQc6csw@mail.gmail.com>
In-Reply-To
<20180301111907.17607-1-alban.gruin@gmail.com>
On Thu, Mar 1, 2018 at 6:19 AM, Alban Gruin <alban.gruin@gmail.com> wrote:
Show 14 quoted lines
> This adds xfuncname and word_regex patterns for golang, a quite
> popular programming language. It also includes test cases for the
> xfuncname regex (t4018) and updated documentation.
>
> The xfuncname regex finds functions, structs and interfaces.  Although
> the Go language prohibits the opening brace from being on its own
> line, the regex does not makes it mandatory, to be able to match
> `func` statements like this:
>
>     func foo(bar int,
>         baz int) {
>     }
>
> This is covered by the test case t4018/golang-long-func.

A possible suggested rewrite to make it flow a bit better and to mention the loose whitespace matching:

    The xfuncname regex finds functions, structs and interfaces.
    Although the Go language prohibits the opening brace of a 'func'
    from being on its own line, the regex makes the brace optional so
    it can match function declarations wrapped over multiple lines
    (covered by new test case t4018/golang-long-func):
        func foo(bar int,
            baz int) {
        }
    Whitespace matching is also a bit lax in order to handle
    non-standard formatting of method declarations. For instance:
        func(x *X) foo() {
    versus typical 'gofmt' formatted:
        func (x *x) foo() {

(Not necessarily worth a re-roll; perhaps Junio can pick it up when queueing if he considers it an improvement.)

Thanks.
> The word_regex pattern finds identifiers, integers, floats, complex
> numbers and operators, according to the go specification.
>
> Signed-off-by: Alban Gruin <alban.gruin@gmail.com>
Previous: Alban Gruin
Message 10 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.