From: Phil Pennock <zsh-workers+phil.pennock@spodhuis.org>
To: zsh-workers@sunsite.dk
Subject: Re: PATCH: =~ regex match
Date: Thu, 26 Apr 2007 13:19:28 -0700 [thread overview]
Message-ID: <20070426201928.GA52120@redoubt.spodhuis.org> (raw)
In-Reply-To: <200704260931.l3Q9V2Ak014589@news01.csr.com>
On 2007-04-26 at 10:31 +0100, Peter Stephenson wrote:
> I thought about =~ and it seemed to me that since it would be largely
> there for bash compatibility it would be better to do it with the system
> regexp library, which would be more compatible and wouldn't depend on
> optional packages. It shouldn't be too hard to do. We probably
> wouldn't support BASH_REMATCH, however.
Bash uses extended regexps, so the PCRE stuff should be vaguely a
superset, although it might be worth adding a different match operator,
overloading with condid, to specify some PCRE options to pcre_compile; I
was thinking sticking another case before CPCRE_PLAIN in cond_pcre_match
which sets pcre_opts and then falls through to the plain case. That
would mostly affect newline handling.
I was also thinking about how to deal with UTF8, which is another
potential advantage to sticking with PCRE. Zsh isn't specifically
UTF-8 when in widechar, is it? Is the "right" way something like
(untested):
#if defined(MULTIBYTE_SUPPORT) && defined(HAVE_NL_LANGINFO) && defined(CODESET)
{
static int have_utf8_pcre = -1;
if (!strcmp(nl_langinfo(CODESET), "UTF-8")) {
if (have_utf8_pcre == -1) {
if (pcre_config(PCRE_CONFIG_UTF8, &have_utf8_pcre) {
have_utf8_pcre = -2; /* erk, failed to ask */
}
}
if (have_utf8_pcre > 0) {
pcre_opts |= PCRE_UTF8;
}
}
}
#endif
Which means that in non-UTF-8 multibyte locales, you'll get per-octet
regexps, but in UTF-8 locales, a multibyte zsh with a libpcre also built
with UTF-8 support will let you get "proper" matching.
I'm envious of the =~ operator but that doesn't mean that I want to lose
the funky stuff of PCRE when I use it -- I like negative lookahead
assertions, freak that I am.
As to BASH_REMATCH ... how frowned upon are new zsh options which
auto-set for compatibility? It wouldn't be hard, since the
infrastructure's all already in place. Call the zsh option BASH_REMATCH
to set the BASH_REMATCH variable. :^)
% [[ alphabetical =~ ^a([^a]+)a([^a]+)a ]] && print -l $match
lph
betic
Change the last parameter in cond_pcre_match()'s call to
zpcre_get_substrings() to be non-NULL if the zsh option is set so that a
different receptacle to "match" is set.
If I code this up, is it likely to make it in? If not, I won't bother
as full bash compatibility isn't so important to me, only having =~.
It's not like POSIX is involved here ...
Thanks,
-Phil
next prev parent reply other threads:[~2007-04-26 20:19 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-26 4:19 Phil Pennock
2007-04-26 5:12 ` Phil Pennock
2007-04-26 9:31 ` Peter Stephenson
2007-04-26 20:19 ` Phil Pennock [this message]
2007-04-27 0:06 ` Phil Pennock
2007-04-27 9:33 ` Peter Stephenson
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=20070426201928.GA52120@redoubt.spodhuis.org \
--to=zsh-workers+phil.pennock@spodhuis.org \
--cc=zsh-workers@sunsite.dk \
/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).