{"thread":{"id":"47947","subject":"[GSoC][PATCH] userdiff: add built-in pattern for golang","startedAt":"2018-02-28T17:29:42Z","lastAt":"2018-03-01T18:24:37Z","messageCount":10,"participants":["Alban Gruin","Eric Sunshine","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"340577","messageId":"20180228172906.30582-1-alban.gruin@gmail.com","threadId":"47947","inReplyTo":null,"subject":"[GSoC][PATCH] userdiff: add built-in pattern for golang","fromName":"Alban Gruin","fromEmail":"alban.gruin@gmail.com","sentAt":"2018-02-28T17:29:06Z","receivedAt":"2018-02-28T17:29:42Z","isPatch":true,"sender":{"key":"alban.gruin@gmail.com","avatar":"https://avatars.githubusercontent.com/u/6310153?v=4"},"body":"This adds xfuncname and word_regex patterns for golang, a quite\npopular programming language. It also includes test cases for the\nxfuncname regex (t4018) and an updated documentation.\n\nThe xfuncname regex finds functions, structs and interfaces. The\nword_regex pattern finds identifiers, integers, floats, complex\nnumbers and operators, according to the go specification.\n\nSigned-off-by: Alban Gruin <alban.gruin@gmail.com>\n---\n Documentation/gitattributes.txt | 2 ++\n t/t4018-diff-funcname.sh        | 1 +\n t/t4018/golang-complex-function | 8 ++++++++\n t/t4018/golang-func             | 4 ++++\n t/t4018/golang-interface        | 4 ++++\n t/t4018/golang-long-func        | 5 +++++\n t/t4018/golang-struct           | 4 ++++\n userdiff.c                      | 9 +++++++++\n 8 files changed, 37 insertions(+)\n create mode 100644 t/t4018/golang-complex-function\n create mode 100644 t/t4018/golang-func\n create mode 100644 t/t4018/golang-interface\n create mode 100644 t/t4018/golang-long-func\n create mode 100644 t/t4018/golang-struct\n\ndiff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt\nindex c21f5ca10..d52b254a2 100644\n--- a/Documentation/gitattributes.txt\n+++ b/Documentation/gitattributes.txt\n@@ -714,6 +714,8 @@ patterns are available:\n \n - `fountain` suitable for Fountain documents.\n \n+- `golang` suitable for source code in the Go language.\n+\n - `html` suitable for HTML/XHTML documents.\n \n - `java` suitable for source code in the Java language.\ndiff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh\nindex 1795ffc3a..22f9f88f0 100755\n--- a/t/t4018-diff-funcname.sh\n+++ b/t/t4018-diff-funcname.sh\n@@ -33,6 +33,7 @@ diffpatterns=\"\n \tcss\n \tfortran\n \tfountain\n+\tgolang\n \thtml\n \tjava\n \tmatlab\ndiff --git a/t/t4018/golang-complex-function b/t/t4018/golang-complex-function\nnew file mode 100644\nindex 000000000..a9211ed18\n--- /dev/null\n+++ b/t/t4018/golang-complex-function\n@@ -0,0 +1,8 @@\n+type Test struct {\n+\ta Type\n+}\n+\n+func (t *Test) RIGHT(a Type) (Type, error) {\n+\tt.a = a\n+        return ChangeMe, nil\n+}\ndiff --git a/t/t4018/golang-func b/t/t4018/golang-func\nnew file mode 100644\nindex 000000000..b17698218\n--- /dev/null\n+++ b/t/t4018/golang-func\n@@ -0,0 +1,4 @@\n+func RIGHT() {\n+\ta := 5\n+        b := ChangeMe\n+}\ndiff --git a/t/t4018/golang-interface b/t/t4018/golang-interface\nnew file mode 100644\nindex 000000000..2e03d4fc0\n--- /dev/null\n+++ b/t/t4018/golang-interface\n@@ -0,0 +1,4 @@\n+type RIGHT interface {\n+\ta() Type\n+        b() ChangeMe\n+}\ndiff --git a/t/t4018/golang-long-func b/t/t4018/golang-long-func\nnew file mode 100644\nindex 000000000..ac3a77b5c\n--- /dev/null\n+++ b/t/t4018/golang-long-func\n@@ -0,0 +1,5 @@\n+func RIGHT(aVeryVeryVeryLongVariableName AVeryVeryVeryLongType,\n+\tanotherLongVariableName AnotherLongType) {\n+\ta := 5\n+\tb := ChangeMe\n+}\ndiff --git a/t/t4018/golang-struct b/t/t4018/golang-struct\nnew file mode 100644\nindex 000000000..5cd70c8dc\n--- /dev/null\n+++ b/t/t4018/golang-struct\n@@ -0,0 +1,4 @@\n+type RIGHT struct {\n+\ta Type\n+        b ChangeMe\n+}\ndiff --git a/userdiff.c b/userdiff.c\nindex dbfb4e13c..8f5028f6b 100644\n--- a/userdiff.c\n+++ b/userdiff.c\n@@ -38,6 +38,15 @@ IPATTERN(\"fortran\",\n \t \"|//|\\\\*\\\\*|::|[/<>=]=\"),\n IPATTERN(\"fountain\", \"^((\\\\.[^.]|(int|ext|est|int\\\\.?/ext|i/e)[. ]).*)$\",\n \t \"[^ \\t-]+\"),\n+PATTERNS(\"golang\",\n+\t /* Functions */\n+\t \"^[ \\t]*(func[ \\t]*.*(\\\\{[ \\t]*)?)\\n\"\n+\t /* Structs and interfaces */\n+\t \"^[ \\t]*(type[ \\t].*(struct|interface)[ \\t]*(\\\\{[ \\t]*)?)\",\n+\t /* -- */\n+\t \"[a-zA-Z_][a-zA-Z0-9_]*\"\n+\t \"|[-+0-9.eE]+i?|0[xX]?[0-9a-fA-F]+i?\"\n+\t \"|[-+*/<>%&^|=!:]=|--|\\\\+\\\\+|<<=?|>>=?|&\\\\^=?|&&|\\\\|\\\\||<-|\\\\.{3}\"),\n PATTERNS(\"html\", \"^[ \\t]*(<[Hh][1-6]([ \\t].*)?>.*)$\",\n \t \"[^<>= \\t]+\"),\n PATTERNS(\"java\",\n-- \n2.16.1\n\n"},{"id":"340592","messageId":"CAPig+cTOv+jAQHA8p76MHcbbvv4SAs4y_1BxeRpexWwTT4+8hA@mail.gmail.com","threadId":"47947","inReplyTo":"20180228172906.30582-1-alban.gruin@gmail.com","subject":"Re: [GSoC][PATCH] userdiff: add built-in pattern for golang","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2018-02-28T18:47:31Z","receivedAt":"2018-02-28T18:47:37Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Wed, Feb 28, 2018 at 12:29 PM, Alban Gruin <alban.gruin@gmail.com> wrote:\n> This adds xfuncname and word_regex patterns for golang, a quite\n> popular programming language. It also includes test cases for the\n> xfuncname regex (t4018) and an updated documentation.\n\ns/an //\n\n> The xfuncname regex finds functions, structs and interfaces. The\n> word_regex pattern finds identifiers, integers, floats, complex\n> numbers and operators, according to the go specification.\n>\n> Signed-off-by: Alban Gruin <alban.gruin@gmail.com>\n> ---\n> diff --git a/t/t4018/golang-complex-function b/t/t4018/golang-complex-function\n> @@ -0,0 +1,8 @@\n> +func (t *Test) RIGHT(a Type) (Type, error) {\n> +       t.a = a\n> +        return ChangeMe, nil\n> +}\n\nMost of these files use a mix of spaces and tabs for indentation.\nPlease use tabs only.\n\n> diff --git a/userdiff.c b/userdiff.c\n> @@ -38,6 +38,15 @@ IPATTERN(\"fortran\",\n> +PATTERNS(\"golang\",\n> +        /* Functions */\n> +        \"^[ \\t]*(func[ \\t]*.*(\\\\{[ \\t]*)?)\\n\"\n\nWhy is the brace (and possible following whitespace) optional?\nConsidering that the language demands that the brace be on the same\nline, I'd think the brace should be mandatory.\n\nI suppose you made whitespace after 'func' optional to be able to\nrecognize a method (which hasn't been gofmt'd):\n\n    func(x *X) name {\n\nrather than the more typical:\n\n    func (x *X) name {\n\nI wonder if it would make sense to tighten the expression to recognize\nfunctions and methods as distinct cases:\n\n    function: mandatory whitespace following 'func'\n    method: optional whitespace but mandatory '(' following 'func'\n\nYour current expression could accidentally match:\n\n    /*\n      Fish like to have\n      functors for lunch {\n      just like eels}.\n    */\n\nbut, even the suggested tighter expression could \"accidentally\" match\nexample code in a comment block anyhow, so I guess it probably doesn't\nmatter much in practice.\n\n> +        /* Structs and interfaces */\n> +        \"^[ \\t]*(type[ \\t].*(struct|interface)[ \\t]*(\\\\{[ \\t]*)?)\",\n\nWhitespace is required after 'type'. Good. The language doesn't\nrequire '{' to be on the same line as 'struct' or 'interface', and\nthis expression makes it optional. Okay.\n\n> +        /* -- */\n> +        \"[a-zA-Z_][a-zA-Z0-9_]*\"\n> +        \"|[-+0-9.eE]+i?|0[xX]?[0-9a-fA-F]+i?\"\n> +        \"|[-+*/<>%&^|=!:]=|--|\\\\+\\\\+|<<=?|>>=?|&\\\\^=?|&&|\\\\|\\\\||<-|\\\\.{3}\"),\n"},{"id":"340622","messageId":"763c5ee4-0bee-7f76-1e2a-4ad07a813e29@gmail.com","threadId":"47947","inReplyTo":"CAPig+cTOv+jAQHA8p76MHcbbvv4SAs4y_1BxeRpexWwTT4+8hA@mail.gmail.com","subject":"Re: [GSoC][PATCH] userdiff: add built-in pattern for golang","fromName":"Alban Gruin","fromEmail":"alban.gruin@gmail.com","sentAt":"2018-02-28T21:31:46Z","receivedAt":"2018-02-28T21:32:27Z","isPatch":true,"sender":{"key":"alban.gruin@gmail.com","avatar":"https://avatars.githubusercontent.com/u/6310153?v=4"},"body":">> diff --git a/userdiff.c b/userdiff.c\n>> @@ -38,6 +38,15 @@ IPATTERN(\"fortran\",\n>> +PATTERNS(\"golang\",\n>> +        /* Functions */\n>> +        \"^[ \\t]*(func[ \\t]*.*(\\\\{[ \\t]*)?)\\n\"\n> \n> Why is the brace (and possible following whitespace) optional?\n> Considering that the language demands that the brace be on the same\n> line, I'd think the brace should be mandatory.\n> \n\nI did this to support non-standard formatting. It's a niche case though,\nmaybe we could only support the standard formatting and modify the doc\nto reflect this change.\n\n> I suppose you made whitespace after 'func' optional to be able to\n> recognize a method (which hasn't been gofmt'd):\n> \n>     func(x *X) name {\n> \n> rather than the more typical:\n> \n>     func (x *X) name {\n> \n> I wonder if it would make sense to tighten the expression to recognize\n> functions and methods as distinct cases:\n> \n>     function: mandatory whitespace following 'func'\n>     method: optional whitespace but mandatory '(' following 'func'\n> \n> Your current expression could accidentally match:\n> \n>     /*\n>       Fish like to have\n>       functors for lunch {\n>       just like eels}.\n>     */\n> \n> but, even the suggested tighter expression could \"accidentally\" match\n> example code in a comment block anyhow, so I guess it probably doesn't\n> matter much in practice.\n> \n\nSame as before, I did this to support non-standard formatting.\n"},{"id":"340627","messageId":"CAPig+cQ6awH8KfX3C+=OwE3qJLJPQyAt_dmQvMw1NLNnCT73RQ@mail.gmail.com","threadId":"47947","inReplyTo":"763c5ee4-0bee-7f76-1e2a-4ad07a813e29@gmail.com","subject":"Re: [GSoC][PATCH] userdiff: add built-in pattern for golang","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2018-02-28T22:00:42Z","receivedAt":"2018-02-28T22:00:49Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Wed, Feb 28, 2018 at 4:31 PM, Alban Gruin <alban.gruin@gmail.com> wrote:\n>>> diff --git a/userdiff.c b/userdiff.c\n>>> @@ -38,6 +38,15 @@ IPATTERN(\"fortran\",\n>>> +PATTERNS(\"golang\",\n>>> +        /* Functions */\n>>> +        \"^[ \\t]*(func[ \\t]*.*(\\\\{[ \\t]*)?)\\n\"\n>>\n>> Why is the brace (and possible following whitespace) optional?\n>> Considering that the language demands that the brace be on the same\n>> line, I'd think the brace should be mandatory.\n>\n> I did this to support non-standard formatting. It's a niche case though,\n> maybe we could only support the standard formatting and modify the doc\n> to reflect this change.\n\nAs noted, unlike 'struct' and 'interface', the brace for a 'func'\n_must_ appear on the same line; that's a requirement of the language.\nPlacing it on a line is not an option.\n\n    % cat >foo.go<<\\EOF\n    package foo\n    func foo() {\n    }\n    EOF\n    % go build foo.go\n\nVersus:\n\n    % cat >bar.go<<\\EOF\n    package bar\n    func bar()\n    {\n    }\n    EOF\n    % go build bar.go\n    ./bar.go:2:6: missing function body\n    ./bar.go:3:1: syntax error: unexpected semicolon or newline before {\n\nSo, the regex probably ought to be strict about expecting the brace on\nthe same line as 'func'.\n"},{"id":"340632","messageId":"b9aa0939-8b20-0f35-84f4-5b519080ca34@gmail.com","threadId":"47947","inReplyTo":"CAPig+cQ6awH8KfX3C+=OwE3qJLJPQyAt_dmQvMw1NLNnCT73RQ@mail.gmail.com","subject":"Re: [GSoC][PATCH] userdiff: add built-in pattern for golang","fromName":"Alban Gruin","fromEmail":"alban.gruin@gmail.com","sentAt":"2018-02-28T22:17:28Z","receivedAt":"2018-02-28T22:17:40Z","isPatch":true,"sender":{"key":"alban.gruin@gmail.com","avatar":"https://avatars.githubusercontent.com/u/6310153?v=4"},"body":"Le 28/02/2018 à 23:00, Eric Sunshine a écrit :\n> On Wed, Feb 28, 2018 at 4:31 PM, Alban Gruin <alban.gruin@gmail.com> wrote:\n>>>> diff --git a/userdiff.c b/userdiff.c\n>>>> @@ -38,6 +38,15 @@ IPATTERN(\"fortran\",\n>>>> +PATTERNS(\"golang\",\n>>>> +        /* Functions */\n>>>> +        \"^[ \\t]*(func[ \\t]*.*(\\\\{[ \\t]*)?)\\n\"\n>>>\n>>> Why is the brace (and possible following whitespace) optional?\n>>> Considering that the language demands that the brace be on the same\n>>> line, I'd think the brace should be mandatory.\n>>\n>> I did this to support non-standard formatting. It's a niche case though,\n>> maybe we could only support the standard formatting and modify the doc\n>> to reflect this change.\n> \n> As noted, unlike 'struct' and 'interface', the brace for a 'func'\n> _must_ appear on the same line; that's a requirement of the language.\n> Placing it on a line is not an option.\n> \n>     % cat >foo.go<<\\EOF\n>     package foo\n>     func foo() {\n>     }\n>     EOF\n>     % go build foo.go\n> \n> Versus:\n> \n>     % cat >bar.go<<\\EOF\n>     package bar\n>     func bar()\n>     {\n>     }\n>     EOF\n>     % go build bar.go\n>     ./bar.go:2:6: missing function body\n>     ./bar.go:3:1: syntax error: unexpected semicolon or newline before {\n> \n> So, the regex probably ought to be strict about expecting the brace on\n> the same line as 'func'.\n> \n\nYes, but I can split the line like that:\n\n    % cat >baz.go<<\\EOF\n    package baz\n    func baz(arg1 int64,\n    \targ2 int64) {\n    }\n    EOF\n    % go build baz.go\n\nThis complies to the standard formatting (at least, gofmt doesn't change\nit), but making the regex strict about the brace would cause it to\nignore those funcs, although I don't know how common they are.\n"},{"id":"340633","messageId":"CAPig+cQ3MuFhMHKGyejE2o0WnVZGvLwcLVgVLpshU_j01MkcaA@mail.gmail.com","threadId":"47947","inReplyTo":"b9aa0939-8b20-0f35-84f4-5b519080ca34@gmail.com","subject":"Re: [GSoC][PATCH] userdiff: add built-in pattern for golang","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2018-02-28T22:22:27Z","receivedAt":"2018-02-28T22:22:33Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Wed, Feb 28, 2018 at 5:17 PM, Alban Gruin <alban.gruin@gmail.com> wrote:\n> Yes, but I can split the line like that:\n>\n>     % cat >baz.go<<\\EOF\n>     package baz\n>     func baz(arg1 int64,\n>         arg2 int64) {\n>     }\n>     EOF\n>     % go build baz.go\n>\n> This complies to the standard formatting (at least, gofmt doesn't change\n> it), but making the regex strict about the brace would cause it to\n> ignore those funcs, although I don't know how common they are.\n\nMakes sense. Thanks for the clarifying example. I wouldn't be at all\nsurprised it such formatting exists in the wild, so keeping the regex\nas-is seems a good idea.\n"},{"id":"340636","messageId":"xmqqvaegiw3o.fsf@gitster-ct.c.googlers.com","threadId":"47947","inReplyTo":"CAPig+cQ3MuFhMHKGyejE2o0WnVZGvLwcLVgVLpshU_j01MkcaA@mail.gmail.com","subject":"Re: [GSoC][PATCH] userdiff: add built-in pattern for golang","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-02-28T22:32:27Z","receivedAt":"2018-02-28T22:32:35Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Eric Sunshine <sunshine@sunshineco.com> writes:\n\n> On Wed, Feb 28, 2018 at 5:17 PM, Alban Gruin <alban.gruin@gmail.com> wrote:\n>> Yes, but I can split the line like that:\n>>\n>>     % cat >baz.go<<\\EOF\n>>     package baz\n>>     func baz(arg1 int64,\n>>         arg2 int64) {\n>>     }\n>>     EOF\n>>     % go build baz.go\n>>\n>> This complies to the standard formatting (at least, gofmt doesn't change\n>> it), but making the regex strict about the brace would cause it to\n>> ignore those funcs, although I don't know how common they are.\n>\n> Makes sense. Thanks for the clarifying example. I wouldn't be at all\n> surprised it such formatting exists in the wild, so keeping the regex\n> as-is seems a good idea.\n\nDoes input like that appear in the tests the patch adds?  If not, it\nprobably is a good idea to have it somewhere in the commit (even if\nthere is no test addition, having it in the log message to explain\nwhy the regex is done like so would be a good idea).\n\nThanks.\n"},{"id":"340637","messageId":"5683c0ae-9510-a54f-c50e-79718cb2eb1e@gmail.com","threadId":"47947","inReplyTo":"xmqqvaegiw3o.fsf@gitster-ct.c.googlers.com","subject":"Re: [GSoC][PATCH] userdiff: add built-in pattern for golang","fromName":"Alban Gruin","fromEmail":"alban.gruin@gmail.com","sentAt":"2018-02-28T22:43:11Z","receivedAt":"2018-02-28T22:43:18Z","isPatch":true,"sender":{"key":"alban.gruin@gmail.com","avatar":"https://avatars.githubusercontent.com/u/6310153?v=4"},"body":"Le 28/02/2018 à 23:32, Junio C Hamano a écrit :\n> Eric Sunshine <sunshine@sunshineco.com> writes:\n> \n>> On Wed, Feb 28, 2018 at 5:17 PM, Alban Gruin <alban.gruin@gmail.com> wrote:\n>>> Yes, but I can split the line like that:\n>>>\n>>>     % cat >baz.go<<\\EOF\n>>>     package baz\n>>>     func baz(arg1 int64,\n>>>         arg2 int64) {\n>>>     }\n>>>     EOF\n>>>     % go build baz.go\n>>>\n>>> This complies to the standard formatting (at least, gofmt doesn't change\n>>> it), but making the regex strict about the brace would cause it to\n>>> ignore those funcs, although I don't know how common they are.\n>>\n>> Makes sense. Thanks for the clarifying example. I wouldn't be at all\n>> surprised it such formatting exists in the wild, so keeping the regex\n>> as-is seems a good idea.\n> \n> Does input like that appear in the tests the patch adds?  If not, it\n> probably is a good idea to have it somewhere in the commit (even if\n> there is no test addition, having it in the log message to explain\n> why the regex is done like so would be a good idea).\n> \n> Thanks.\n> \n\nYes, it's in a file called \"golang-long-func\".  I'll send another patch\nlater to fix the typo in the commit message and the indentation in the\ntests. I'll clarify the regex in the message, too.\n"},{"id":"340721","messageId":"20180301111907.17607-1-alban.gruin@gmail.com","threadId":"47947","inReplyTo":"20180228172906.30582-1-alban.gruin@gmail.com","subject":"[GSoC][PATCH v2] userdiff: add built-in pattern for golang","fromName":"Alban Gruin","fromEmail":"alban.gruin@gmail.com","sentAt":"2018-03-01T11:19:07Z","receivedAt":"2018-03-01T11:19:34Z","isPatch":true,"sender":{"key":"alban.gruin@gmail.com","avatar":"https://avatars.githubusercontent.com/u/6310153?v=4"},"body":"This adds xfuncname and word_regex patterns for golang, a quite\npopular programming language. It also includes test cases for the\nxfuncname regex (t4018) and updated documentation.\n\nThe xfuncname regex finds functions, structs and interfaces.  Although\nthe Go language prohibits the opening brace from being on its own\nline, the regex does not makes it mandatory, to be able to match\n`func` statements like this:\n\n    func foo(bar int,\n    \tbaz int) {\n    }\n\nThis is covered by the test case t4018/golang-long-func.\n\nThe word_regex pattern finds identifiers, integers, floats, complex\nnumbers and operators, according to the go specification.\n\nSigned-off-by: Alban Gruin <alban.gruin@gmail.com>\n---\n Documentation/gitattributes.txt | 2 ++\n t/t4018-diff-funcname.sh        | 1 +\n t/t4018/golang-complex-function | 8 ++++++++\n t/t4018/golang-func             | 4 ++++\n t/t4018/golang-interface        | 4 ++++\n t/t4018/golang-long-func        | 5 +++++\n t/t4018/golang-struct           | 4 ++++\n userdiff.c                      | 9 +++++++++\n 8 files changed, 37 insertions(+)\n create mode 100644 t/t4018/golang-complex-function\n create mode 100644 t/t4018/golang-func\n create mode 100644 t/t4018/golang-interface\n create mode 100644 t/t4018/golang-long-func\n create mode 100644 t/t4018/golang-struct\n\ndiff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt\nindex c21f5ca10..d52b254a2 100644\n--- a/Documentation/gitattributes.txt\n+++ b/Documentation/gitattributes.txt\n@@ -714,6 +714,8 @@ patterns are available:\n \n - `fountain` suitable for Fountain documents.\n \n+- `golang` suitable for source code in the Go language.\n+\n - `html` suitable for HTML/XHTML documents.\n \n - `java` suitable for source code in the Java language.\ndiff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh\nindex 1795ffc3a..22f9f88f0 100755\n--- a/t/t4018-diff-funcname.sh\n+++ b/t/t4018-diff-funcname.sh\n@@ -33,6 +33,7 @@ diffpatterns=\"\n \tcss\n \tfortran\n \tfountain\n+\tgolang\n \thtml\n \tjava\n \tmatlab\ndiff --git a/t/t4018/golang-complex-function b/t/t4018/golang-complex-function\nnew file mode 100644\nindex 000000000..e057dcefe\n--- /dev/null\n+++ b/t/t4018/golang-complex-function\n@@ -0,0 +1,8 @@\n+type Test struct {\n+\ta Type\n+}\n+\n+func (t *Test) RIGHT(a Type) (Type, error) {\n+\tt.a = a\n+\treturn ChangeMe, nil\n+}\ndiff --git a/t/t4018/golang-func b/t/t4018/golang-func\nnew file mode 100644\nindex 000000000..8e9c9ac7c\n--- /dev/null\n+++ b/t/t4018/golang-func\n@@ -0,0 +1,4 @@\n+func RIGHT() {\n+\ta := 5\n+\tb := ChangeMe\n+}\ndiff --git a/t/t4018/golang-interface b/t/t4018/golang-interface\nnew file mode 100644\nindex 000000000..553bedec9\n--- /dev/null\n+++ b/t/t4018/golang-interface\n@@ -0,0 +1,4 @@\n+type RIGHT interface {\n+\ta() Type\n+\tb() ChangeMe\n+}\ndiff --git a/t/t4018/golang-long-func b/t/t4018/golang-long-func\nnew file mode 100644\nindex 000000000..ac3a77b5c\n--- /dev/null\n+++ b/t/t4018/golang-long-func\n@@ -0,0 +1,5 @@\n+func RIGHT(aVeryVeryVeryLongVariableName AVeryVeryVeryLongType,\n+\tanotherLongVariableName AnotherLongType) {\n+\ta := 5\n+\tb := ChangeMe\n+}\ndiff --git a/t/t4018/golang-struct b/t/t4018/golang-struct\nnew file mode 100644\nindex 000000000..5deda77fe\n--- /dev/null\n+++ b/t/t4018/golang-struct\n@@ -0,0 +1,4 @@\n+type RIGHT struct {\n+\ta Type\n+\tb ChangeMe\n+}\ndiff --git a/userdiff.c b/userdiff.c\nindex dbfb4e13c..8f5028f6b 100644\n--- a/userdiff.c\n+++ b/userdiff.c\n@@ -38,6 +38,15 @@ IPATTERN(\"fortran\",\n \t \"|//|\\\\*\\\\*|::|[/<>=]=\"),\n IPATTERN(\"fountain\", \"^((\\\\.[^.]|(int|ext|est|int\\\\.?/ext|i/e)[. ]).*)$\",\n \t \"[^ \\t-]+\"),\n+PATTERNS(\"golang\",\n+\t /* Functions */\n+\t \"^[ \\t]*(func[ \\t]*.*(\\\\{[ \\t]*)?)\\n\"\n+\t /* Structs and interfaces */\n+\t \"^[ \\t]*(type[ \\t].*(struct|interface)[ \\t]*(\\\\{[ \\t]*)?)\",\n+\t /* -- */\n+\t \"[a-zA-Z_][a-zA-Z0-9_]*\"\n+\t \"|[-+0-9.eE]+i?|0[xX]?[0-9a-fA-F]+i?\"\n+\t \"|[-+*/<>%&^|=!:]=|--|\\\\+\\\\+|<<=?|>>=?|&\\\\^=?|&&|\\\\|\\\\||<-|\\\\.{3}\"),\n PATTERNS(\"html\", \"^[ \\t]*(<[Hh][1-6]([ \\t].*)?>.*)$\",\n \t \"[^<>= \\t]+\"),\n PATTERNS(\"java\",\n-- \n2.16.1\n\n"},{"id":"340743","messageId":"CAPig+cSPHa_A05iLBKUSr8dZcaOoEJ28TF+nAZzvQN2dQc6csw@mail.gmail.com","threadId":"47947","inReplyTo":"20180301111907.17607-1-alban.gruin@gmail.com","subject":"Re: [GSoC][PATCH v2] userdiff: add built-in pattern for golang","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2018-03-01T18:24:30Z","receivedAt":"2018-03-01T18:24:37Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Thu, Mar 1, 2018 at 6:19 AM, Alban Gruin <alban.gruin@gmail.com> wrote:\n> This adds xfuncname and word_regex patterns for golang, a quite\n> popular programming language. It also includes test cases for the\n> xfuncname regex (t4018) and updated documentation.\n>\n> The xfuncname regex finds functions, structs and interfaces.  Although\n> the Go language prohibits the opening brace from being on its own\n> line, the regex does not makes it mandatory, to be able to match\n> `func` statements like this:\n>\n>     func foo(bar int,\n>         baz int) {\n>     }\n>\n> This is covered by the test case t4018/golang-long-func.\n\nA possible suggested rewrite to make it flow a bit better and to\nmention the loose whitespace matching:\n\n    The xfuncname regex finds functions, structs and interfaces.\n    Although the Go language prohibits the opening brace of a 'func'\n    from being on its own line, the regex makes the brace optional so\n    it can match function declarations wrapped over multiple lines\n    (covered by new test case t4018/golang-long-func):\n\n        func foo(bar int,\n            baz int) {\n        }\n\n    Whitespace matching is also a bit lax in order to handle\n    non-standard formatting of method declarations. For instance:\n\n        func(x *X) foo() {\n\n    versus typical 'gofmt' formatted:\n\n        func (x *x) foo() {\n\n(Not necessarily worth a re-roll; perhaps Junio can pick it up when\nqueueing if he considers it an improvement.)\n\nThanks.\n\n> The word_regex pattern finds identifiers, integers, floats, complex\n> numbers and operators, according to the go specification.\n>\n> Signed-off-by: Alban Gruin <alban.gruin@gmail.com>\n"}]}