From: Pickfire <pickfire@riseup.net>
To: gitster@pobox.com
Cc: git@vger.kernel.org
Subject: Re: Re: [PATCH] userdiff: add build-in pattern for shell
Date: Thu, 30 Mar 2017 10:28:22 +0800 [thread overview]
Message-ID: <20170330022822.YGyP5YgSE%pickfire@riseup.net> (raw)
In-Reply-To: <xmqqzig49e4j.fsf@gitster.mtv.corp.google.com>
Junio C Hamano <gitster@pobox.com> wrote:
> Ivan Tham <pickfire@riseup.net> writes:
>
> > Shell are widely used but comes with lots of different patterns. The
> > build-in pattern aim for POSIX-compatible shells with some additions:
> >
> > - Notably ${g//re/s} and ${g#cut}
> > - "function" from bash
> >
> > Signed-off-by: Ivan Tham <pickfire@riseup.net>
> > ---
> > Documentation/gitattributes.txt | 2 ++
> > t/t4034-diff-words.sh | 1 +
> > t/t4034/sh/expect | 14 ++++++++++++++
> > t/t4034/sh/post | 7 +++++++
> > t/t4034/sh/pre | 7 +++++++
> > userdiff.c | 5 +++++
> > 6 files changed, 36 insertions(+)
> > create mode 100644 t/t4034/sh/expect
> > create mode 100644 t/t4034/sh/post
> > create mode 100644 t/t4034/sh/pre
> >
> > diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
> > index a53d093ca..1bad72df2 100644
> > --- a/Documentation/gitattributes.txt
> > +++ b/Documentation/gitattributes.txt
> > @@ -706,6 +706,8 @@ patterns are available:
> >
> > - `ruby` suitable for source code in the Ruby language.
> >
> > +- `sh` suitable for source code in POSIX-compatible shells.
>
> The new test you added seems to show that this is not limited to
> POSIX shells but also understands bashisms like ${x//x/x}. Perhaps
> drop "POSIX-compatible" from here
Those shells are still POSIX-compatible so I think it is true to put
that or otherwise, something like fish shell will break since it is
as well a shell but the syntax is totally different.
> > diff --git a/userdiff.c b/userdiff.c
> > index 8b732e40b..8d5127fb6 100644
> > --- a/userdiff.c
> > +++ b/userdiff.c
> > @@ -148,6 +148,11 @@ PATTERNS("csharp",
> > "[a-zA-Z_][a-zA-Z0-9_]*"
> > "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?"
> > "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"),
> > +PATTERNS("sh",
> > + "^[ \t]*(function )?[A-Za-z_][A-Za-z_0-9]*[ \t]*()[\t]*\\{?$",
>
> There is something funky going on around parentheses on this line.
> The ones around "function " is meant to be syntactic metacharacters
> to produce a group in the regexp so that you can apply '?'
> (i.e. zero or one occurrence) to it. But I think the second pair of
> parentheses that appears later on the line, which enclose nothing,
> are meant to be literal? E.g. "hello (){\n\techo world;\n}\n" They
> would need some quoting, perhaps like
>
> ...[ \t]*\\(\\)[\t]*....
Ah, I think I forgot to escape the quoting of ( and ). I will send in another
patch for that.
> > + /* -- */
> > + "(\\$|--?)?([a-zA-Z_][a-zA-Z0-9._]*|[0-9]+|#)|--" /* command/param */
>
> TBH, I have no idea what this line-noise is doing.
That breaks word into "a", "$a" and "-a" as well as "$1" and "$#". I tried
supporting $? by adding +|#|\\?)--" but it doesn't seemed like it is working.
> $foobar, $4, --foobar, foobar, 123 and -- can be seen easily out of
> these patterns. I am not sure what --# would be (perhaps you meant
> to only catch $# and --# is included by accident, in which case it
> is understandable). It feels a bit strange to see that $# is
> supported but not $?; --foo but not --foo=bar; foobar but not "foo
> bar" inside a dq-pair.
Yes, getting --# will be very rare in shell. I think it is better to seperate
the --foo=bar into --foo and bar. I don't get what you man by the dq-pair.
> > + "|\\$[({]|[)}]|[-+*/=!]=?|[\\]&%#/|]{1,2}|[<>]{1,3}|[ \t]#.*"),
>
> And this one is even more dense.
Yes, that takes care of the operators, special symbols and stuff.
next prev parent reply other threads:[~2017-03-30 2:28 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-29 16:53 [PATCH] userdiff: add build-in pattern for shell Ivan Tham
2017-03-29 17:39 ` Junio C Hamano
2017-03-30 2:28 ` Pickfire [this message]
2017-03-30 6:25 ` Junio C Hamano
2017-03-30 7:20 ` Ivan Tham
2017-03-30 18:08 ` [PATCH v2] " Ivan Tham
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=20170330022822.YGyP5YgSE%pickfire@riseup.net \
--to=pickfire@riseup.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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).