Regex introduction?
Jan Wielemaker <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
Hi, With strings not being lists of codes/chars, the idea to have meaningful and efficient operations on them becomes more appealing. For a long time, I thought that the solution was the approach started (for SWI-Prolog) by Michael Hendrix in the pack regex (http://www.swi-prolog.org/pack/list?p=regex). If (code) lists are the prime data structure to work on, this makes sense. On the other hand, regular expressions are a well established field and redoing it all in Prolog seems a waste. Just like building your own Prolog like inference engine in language X :-) As strings are low-level data structures anyway, we can use standard regex implementations on the low-level data. I'm seriously considering to add regular expression support based on the pcre (Perl Compatible Regular Expressions) library. This seems to be the library of choice for most modern languages and provides support for the two internal representations used in SWI-Prolog for Unicode text. PCRE will (at least initially) be provided as a package. There will be a low level interface that quite directly implements the full C api of PCRE. The idea is to provide a re_compile that compiles a pattern with options into a `blob', which makes it efficiently available and subject to (atom-)GC and an re_exec that returns positions for matches and an re_replace that does a regex replacement, returning a new string. On top of that, we can define more high level libraries. It seems only YAP and XSB provide regular expressions as a native feature. YAP based on Henry Spencer's library and XSB on POSIX 2 regex support. Did I miss something? Any precedence of well balanced interfaces for Prolog? The YAP interface is rather limited. The XSB one is richer, but a bit weird due to issues with atom-GC in XSB you should not be bothered with as a user. Thanks --- Jan