git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Pickfire <pickfire@riseup.net>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] userdiff: add build-in pattern for shell
Date: Wed, 29 Mar 2017 23:25:15 -0700	[thread overview]
Message-ID: <xmqqefxf7038.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <20170330022822.YGyP5YgSE%pickfire@riseup.net> (pickfire@riseup.net's message of "Thu, 30 Mar 2017 10:28:22 +0800")

Pickfire <pickfire@riseup.net> writes:

>> > +- `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.

Scripts with bash-isms are not necessarily usable by POSIX
compatible shells (think "dash") and this highlighter recognises
bash specific enhancements (which by the way is a plus), so if you
absolutely want to say "POSIX something" in order to clarify that
csh and friends do not apply, say "POSIX-like".

>> 	...[ \t]*\\(\\)[\t]*....
>
> Ah, I think I forgot to escape the quoting of ( and ). I will send in another
> patch for that.

OK.  Note that we usually avoid applying a patch whose brokenness
was noticed while review (which then necessitates a follow up patch
"oops, the previous was botched; here is a fix-up").  The "another
patch" needs to be a v2, i.e. pretending as if the version of the
patch we are discussing never happened, not an incremental on top of
the patch we are discussing..

>> > +	 /* -- */
>> > +	 "(\\$|--?)?([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.

This ...

>> $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.

These design decisions (e.g. what you decided are the tokens to be
taken as a word---taking "--foo" and "bar" as separate things when
given "--foo=bar" is a good example but with this regexp you are
making many other design decisions) need to be explained in the log
message.  A string inside a double-quote pair is taken as a single
parameter to the shell, e.g.

    cmd "arg that is quoted inside double-quote pair" $#

It is unclear what your regexp is doing to such an argument.

>> > +	 "|\\$[({]|[)}]|[-+*/=!]=?|[\\]&%#/|]{1,2}|[<>]{1,3}|[ \t]#.*"),
>> 
>> And this one is even more dense.

FYI, this is also pointing out the need to explain what kind of
things you wanted to recognise as words; explaining in a reply
message is a good first step, as the questioner may find the
explanation in your response still inadequate, in which case you
have a chance to refine it, but the ultimate goal is to put the
polished explanation that would help people who later want to
understand what you added to the codebase by describing what you
wanted to do with the change in either in-code comment or commit log
message when you send an updated patch.

Thanks.

  reply	other threads:[~2017-03-30  6:25 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
2017-03-30  6:25     ` Junio C Hamano [this message]
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=xmqqefxf7038.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=pickfire@riseup.net \
    /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).