git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Eric Sunshine <sunshine@sunshineco.com>
To: Alban Gruin <alban.gruin@gmail.com>
Cc: Git List <git@vger.kernel.org>
Subject: Re: [GSoC][PATCH] userdiff: add built-in pattern for golang
Date: Wed, 28 Feb 2018 13:47:31 -0500	[thread overview]
Message-ID: <CAPig+cTOv+jAQHA8p76MHcbbvv4SAs4y_1BxeRpexWwTT4+8hA@mail.gmail.com> (raw)
In-Reply-To: <20180228172906.30582-1-alban.gruin@gmail.com>

On Wed, Feb 28, 2018 at 12:29 PM, Alban Gruin <alban.gruin@gmail.com> wrote:
> 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 an updated documentation.

s/an //

> The xfuncname regex finds functions, structs and interfaces. 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>
> ---
> diff --git a/t/t4018/golang-complex-function b/t/t4018/golang-complex-function
> @@ -0,0 +1,8 @@
> +func (t *Test) RIGHT(a Type) (Type, error) {
> +       t.a = a
> +        return ChangeMe, nil
> +}

Most of these files use a mix of spaces and tabs for indentation.
Please use tabs only.

> 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 suppose you made whitespace after 'func' optional to be able to
recognize a method (which hasn't been gofmt'd):

    func(x *X) name {

rather than the more typical:

    func (x *X) name {

I wonder if it would make sense to tighten the expression to recognize
functions and methods as distinct cases:

    function: mandatory whitespace following 'func'
    method: optional whitespace but mandatory '(' following 'func'

Your current expression could accidentally match:

    /*
      Fish like to have
      functors for lunch {
      just like eels}.
    */

but, even the suggested tighter expression could "accidentally" match
example code in a comment block anyhow, so I guess it probably doesn't
matter much in practice.

> +        /* Structs and interfaces */
> +        "^[ \t]*(type[ \t].*(struct|interface)[ \t]*(\\{[ \t]*)?)",

Whitespace is required after 'type'. Good. The language doesn't
require '{' to be on the same line as 'struct' or 'interface', and
this expression makes it optional. Okay.

> +        /* -- */
> +        "[a-zA-Z_][a-zA-Z0-9_]*"
> +        "|[-+0-9.eE]+i?|0[xX]?[0-9a-fA-F]+i?"
> +        "|[-+*/<>%&^|=!:]=|--|\\+\\+|<<=?|>>=?|&\\^=?|&&|\\|\\||<-|\\.{3}"),

  reply	other threads:[~2018-02-28 18:47 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-28 17:29 [GSoC][PATCH] userdiff: add built-in pattern for golang Alban Gruin
2018-02-28 18:47 ` Eric Sunshine [this message]
2018-02-28 21:31   ` Alban Gruin
2018-02-28 22:00     ` Eric Sunshine
2018-02-28 22:17       ` Alban Gruin
2018-02-28 22:22         ` Eric Sunshine
2018-02-28 22:32           ` Junio C Hamano
2018-02-28 22:43             ` Alban Gruin
2018-03-01 11:19 ` [GSoC][PATCH v2] " Alban Gruin
2018-03-01 18:24   ` Eric Sunshine

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAPig+cTOv+jAQHA8p76MHcbbvv4SAs4y_1BxeRpexWwTT4+8hA@mail.gmail.com \
    --to=sunshine@sunshineco.com \
    --cc=alban.gruin@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).