zsh-users
 help / color / mirror / code / Atom feed
From: Sebastian Gniazdowski <sgniazdowski@gmail.com>
To: Peter Stephenson <p.stephenson@samsung.com>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: How to best match $( ... ) in a string
Date: Fri, 1 Jun 2018 12:56:13 +0200	[thread overview]
Message-ID: <CAKc7PVCQTdsaBRaji2-H+rMmXxKXOB5rR5otTnC9h8gn=v_PVA@mail.gmail.com> (raw)
In-Reply-To: <20180601095018eucas1p1662451fd258f46cdfdee319db48458a8~0AGeNx_UX2206222062eucas1p1m@eucas1p1.samsung.com>

On 1 June 2018 at 11:50, Peter Stephenson <p.stephenson@samsung.com> wrote:
> On Fri, 1 Jun 2018 10:44:58 +0200
> Sebastian Gniazdowski <sgniazdowski@gmail.com> wrote:
>> the problem is possible quoting, e.g. $( echo \) ). Has anyone a
>> pattern that would handle some sort of quoting?
> (...)
> If you ignore that case, it's possible character by character with
> a bit of extra state for quotes, nested parentheses, etc. (as that's
> what zsh did for two decades) but you're going to need some incredibly
> sophisticated regular expression involving recursion to replace that.

Yes I should state that I'm aware it is not possible. I look for a
best possible solution. Fast-syntax-highlighting now supports
colorizing of command substitution $( ... ), it is called recursively
on it. The point is that 90% of uses will be colored good with my
current pattern:

inputs=( ${(0)${(S)__buf[1,110]//(#b)*\$\((?#)([^\\\"]\)|(#e))/${mbegin[1]};${match[1]}${match[2]%\)}${__nul}}%$__nul*}
)

The meaningful bit in above is: \$\((?#)([^\\\"]\)|(#e)). Match $(,
then look for unquoted (not \), not ")) closing ) or for end of whole
string. I utilize (S) non-greedy matching, and the (0)/$nul trick to
handle multiple substitutions in one command line.The effect is
already quite nice: http://psprint.blinkenshell.org/cmdsubst.png

So the point is, the glob can be hacky and imperfect, if it holds some
valuable solutions then syntax-highlighting user is at better
position. Any uplifts to my current pattern are welcomed.

-- 
Best regards,
Sebastian Gniazdowski


      reply	other threads:[~2018-06-01 10:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20180601084641epcas5p1ca4cd48fa463123bbe980d132fd19473@epcas5p1.samsung.com>
2018-06-01  8:44 ` Sebastian Gniazdowski
2018-06-01  8:49   ` Joey Pabalinas
2018-06-01  9:01     ` Sebastian Gniazdowski
2018-06-01  9:50   ` Peter Stephenson
2018-06-01 10:56     ` Sebastian Gniazdowski [this message]

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

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

  git send-email \
    --in-reply-to='CAKc7PVCQTdsaBRaji2-H+rMmXxKXOB5rR5otTnC9h8gn=v_PVA@mail.gmail.com' \
    --to=sgniazdowski@gmail.com \
    --cc=p.stephenson@samsung.com \
    --cc=zsh-users@zsh.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://git.vuxu.org/mirror/zsh/

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 NNTP newsgroup(s).