regex with boolean operations over character classes built_in on DCG
Kuniaki Mukai <[email protected]> Fri, 1 Aug 2014 18:34:35 +0900
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
Hi,
I have completely rewritten my old codes for regex in SWI-Prolog DCG, so that
now it is working stable on SWI-Prolog develop version.
Features are:
1. Character classes
2. Boolean operations
3. States are minimized as taught in automata theory.
4. Built_in on DCG.
5. Hybrid syntax of unix-like regex and prolog terms.
6. regex expressions are term-expanded on being read.
7. No runtime library needed except generated predicates as state labels.
A few of examples queries are at p.s. below.
For those interested in theory, the whole design of composing automata
are guided by coalgebra point of view on automata, although
difference from the traditional automata theory may be trivial, but I take
the latter view since correcteness of the composition procedure is
more direct than that for e-move introduction / elimination based method.
I am not sure that this is new or interested to the list, as I was
away off from Prolog for a long time and still not so active as before. But
I will appreciate if someone kindly tell me about related works on
regex in prolog which shares above features. So far I have failed on
searching over the net. I have read the thread on regex in prolog in
the list, but I have failed also to see that my current posting is subsumed
by the discussions there. I am awefully sorry for possible ignorance of
other related existing works.
My implementation of regex on DCG is based on my private
term-expansion clause definition for "PAC" ( the "pred" anonymous
predicate ). Unfortunately, it is not easy task for me to make the
regex on DCG standing alone off away from the PAC macros expansion.
BTW, character classes are modelled as union of disjoint intervals of
integers. This idea is a main starting point for me to rewrite the old
codes. Other parts of codes are rather routine and stragihtforward, I think.
Regards
Kuniaki Mukai
p.s.
Queries:
?- phrase(w(".*", X, []), [a,b,c], R).
?- phrase(w("[a-c]*"), [a,b,x,c,y], R).
?- phrase(wl(".*************************", X, []), [a,b,c], R).
?- phrase(w(*char([a-c]), X, []), [a,b,x,c,y], R).
?- phrase(w("[a-c]*", H, T), [a,b,x,c,y], R).
?- phrase(wl(".*", X, []), [a,b,c], R).
Results for these:
?- phrase(w(".*", X, []), [a,b,c], R).
%@ X = [],
%@ R = [a, b, c] ;
%@ X = [a],
%@ R = [b, c] ;
%@ X = [a, b],
%@ R = [c] ;
%@ X = [a, b, c],
%@ R = [] ;
%@ false.
?- phrase(w("[a-c]*"), [a,b,x,c,y], R).
%@ R = [a, b, x, c, y] ;
%@ R = [b, x, c, y] ;
%@ R = [x, c, y] ;
%@ false.
?- phrase(wl(".*************************", X, []), [a,b,c], R).
%@ X = [a, b, c],
%@ R = [] ;
%@ X = [a, b],
%@ R = [c] ;
%@ X = [a],
%@ R = [b, c] ;
%@ X = [],
%@ R = [a, b, c].
?- phrase(w(*char([a-c]), X, []), [a,b,x,c,y], R).
%@ X = [],
%@ R = [a, b, x, c, y] ;
%@ X = [a],
%@ R = [b, x, c, y] ;
%@ X = [a, b],
%@ R = [x, c, y] ;
%@ false.
?- phrase(w("[a-c]*", H, T), [a,b,x,c,y], R).
%@ H = T,
%@ R = [a, b, x, c, y] ;
%@ H = [a|T],
%@ R = [b, x, c, y] ;
%@ H = [a, b|T],
%@ R = [x, c, y] ;
%@ false.
?- phrase(wl(".*", X, []), [a,b,c], R).
%@ X = [a, b, c],
%@ R = [] ;
%@ X = [a, b],
%@ R = [c] ;
%@ X = [a],
%@ R = [b, c] ;
%@ X = [],
%@ R = [a, b, c].
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 496 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <https://lists.iai.uni-bonn.de/pipermail/swi-prolog/attachments/20140801/8790be85/signature.asc>