Re: Regex introduction?

Abramo Bagnara <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Organization BUGSENG srl
Message-ID <[email protected]>
Il 27/11/2013 10:06, Jan Wielemaker ha scritto:
> Thanks for the info.  So far, I found this:
> 
> APIs
> 
>   * XSB and YAP interface return matched positions, ECLiPSe
>     returns matched strings.
>   * XSB does automatic management of a pool of compiled
>     expressions (about 10).
>   * ECLiPSe provides both explicit compilation (with options)
>     and implicit.  Are these `pooled' too?
> 
> RE2 vs PCRE
> 
>   * RE2
>     + linear and has better stack-size behaviour.
>     - C++ (would be only C++ component near the core)
>     - Only processes Latin-1 and UTF-8 text
>     - There is a remark that it is not portable to Windows.
>       Not clear to whether that is an MSVC compiler issue
>       (and MinGW works) or a Windows issue, such as Win64
>       longs that are 32 bits.  Anyone?
>   * PCRE
>     - Exponential behaviour is possible
>     + Mature portable code base in pure C
>     + Can deal with many different encodings, although you
>       need to compile different libraries.  These can
>       co-exist.  One lib has about half the binary size as
>       RE2 (260Kb vs 470Kb, AMD64 code, gcc 4.7).
> 
> All in all, especially the ability of PCRE to work on all
> our datatypes and its guaranteed portability to Windows
> causes me to prefer this.  The ECLiPSe API seems the best
> starting point, although I think there should at least be
> an additional API that returns match positions rather then
> matched strings.

We have recently switched from matched strings to matched positions for
two reasons:
1) matched strings does not represent the full info available
2) to create atoms that perhaps are never used is not sensible

For compiled expressions we use prolog side caching facts (e.g.
compiled_regex(Source, Compiled)). The rationale is that to embed a
caching policy in infrastructure does not permit to adapt it to
different use patterns.

Perhaps you might find interesting our interface:

regexec(+Compiled, +String, +Pos, +EFlags, -Begin, -Length, -Groups)

Compiled is the compiled regex
String is the string to be matched
Pos is the starting position in String
EFlags is a list of flags
Begin is the begin of match
Length is the lenght of match
Groups is a compound groups(...) whose args are pairs begin-length of
matched groups

We decided to use a compound to use arg/3 to get matched groups info.

Unfortunately our implementation of foreign predicates is C++ and uses a
generic wrapper for regex implementation otherwise we would be happy to
donate it to swipl.

-- 
Abramo Bagnara

BUGSENG srl - http://bugseng.com
mailto:[email protected]
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.