zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@ibmth.df.unipi.it>
To: "Zsh hackers list" <zsh-workers@sunsite.auc.dk>
Subject: Re: Pattern matching
Date: Fri, 30 Jul 1999 11:29:36 +0200	[thread overview]
Message-ID: <9907300929.AA23882@ibmth.df.unipi.it> (raw)
In-Reply-To: ""Andrej Borsenkow""'s message of "Fri, 30 Jul 1999 13:27:51 DFT." <000901beda6d$cb8034e0$21c9ca95@mow.siemens.ru>

"Andrej Borsenkow" wrote:
> Just using the occasion. I once suggested to replace ad hoc code with convers
> ion
> to standard regexps. I believe, now a days all systems have standard POSIX
> regexps available. This will be much more clean and I hope faster. Zsh patter
> ns
> are pretty close to normal regular experssions so it should be not a problem
> (even SAMBA takes this course for wildcard matching :-) 

I don't think zsh is close enough to be able to do this, even without the
possible vagaries of pattern matching on some of the machines zsh supports.
I'm converting some existing regexp code (it's Henry Spencer's, which has a
relaxed copyright) which should do this more smoothly, keeping pretty much
all of the existing behaviour.

> Just some points:
> 
>  - currently code scans pattern for every match. This may really be
> inefficient
> for globbing (even more so, as code has to dequote string every time). Using
> rgexps pattern can be compiled once - for recursive globbing quite a gain.

The current system *does* compile patterns.  The complete path for a glob
pattern is stored in a struct complist, and each segment in a struct comp,
which is also used for standard patterns; each pattern is compiled only
once every time it is encountered.  Maybe you mean there's no easy way of
duplicating patterns for future use, which is true, but there's currently
no real application for that since patterns have to be recompiled
separately for each command line after expansion anyway.  When I've
finished, the code will all be in a single string, so can be duplicated in
one go, but I still don't how this can easily be used.  You could cache
simple patterns, those which previous expansions (parameter, etc.) don't
change, and use the cached programme inside a function, but that's already
a lot of work to do properly.

>  - this may automatically solve the original problem of this post. Regexps ar
> e
> required to match the longest string, even if every subregexp is not the long
> est
> one.

Yes, but there's no equivalent for numerical matches in normal regexps, nor
any obvious way that I can see of telling a regexp how to match a numeric
range at all without some immensely complicated pattern.  That's why I
think the only solution is to write an ad-hoc pattern matcher, but do it
properly.  The rough basics are already working.  Globbing flags are going
to be harder to fit in --- but these would be quite impossible to do with a
standard regexp matcher anyway, particularly approximate matching.

-- 
Peter Stephenson <pws@ibmth.df.unipi.it>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy


      reply	other threads:[~1999-07-30 10:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-07-28 12:25 Numeric range bug Peter Stephenson
1999-07-30  9:27 ` Pattern matching Andrej Borsenkow
1999-07-30  9:29   ` Peter Stephenson [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=9907300929.AA23882@ibmth.df.unipi.it \
    --to=pws@ibmth.df.unipi.it \
    --cc=zsh-workers@sunsite.auc.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).