Ann: regex pack

Michael Hendricks <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <CAFHuXuZ2xxtc6p+wR9W8Tqp2rw_aAmA9Ywonsg9AwTWf2hZyyA@mail.gmail.com>
I love DCGs as much as the next Prolog fan, but sometimes a tiny regular
expression will do the job.  Or perhaps regular expressions are part of
your app's UI.  Anyway, this
pack<http://www.swi-prolog.org/pack/list?p=regex>supports many
features of Perl compatible regex (see link for full support).

As the semantic version number indicates, the API is very early and will
probably change. It currently uses =~ (as do Haskell and Perl), but that
gives no access to captured values.  A YAP-compatible API would support
captures so I might do that.  I'd also love to use
prolog_load_context(variable_names, _) with regex named captures to
automatically bind clause variables by name.

I considered supporting quasiquotation (so one doesn't have to escape all
the slashes), but decided for now that a regex that complex should probably
be rewritten as a DCG anyway.

The regular expression engine is currently a naive interpreter.  I partly
did that so that I have an interpreter to play with as I experiment with
some partial evaluation ideas.  It would be cool to partially evaluate the
regex interpreter against a regex to generate fast, concise Prolog code.

Last thought: I tried to design the library to support pluggable regex
engines.  The idea is that one just adds a single line:

    :- use_module(library(regex/engine/re2)).

and your regular expressions are now handled by the re2
engine<https://code.google.com/p/re2/> (or
PCRE or POSIX or ...).  Any interest in such things?  I've used similar
tools to good effect in both Haskell and Perl.

-- 
Michael
-------------- next part --------------
HTML attachment scrubbed and removed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.