Hello all, I have experimented a bit with custom syntax for regular expression matching. My goal was to implement some high-level constructs on top of a low-level regexp library such as PCRE. The result of my (modest) experiment is attached. It is a camlp4 grammar extension, which allows writing extract x, y, ... matching e against r in e' The semantics is as follows. The expression e is evaluated, yielding a string which is matched against the regular expression r. r must be either a constant string, or a compiled regular expression; if the former, pre-compilation code is inserted transparently. The variables x, y, ... etc. are then bound to the appropriate groups (i.e. x is bound to the sub-string which matched the whole pattern, y is bound to the sub-string which matched the first group, etc.) and can be referred to within e'. Wildcards _ can be used instead of variables. This is of course pretty modest, but it seems that, with a small number of such constructs, O'Caml could be turned into a rather nice textual manipulation language. (Something often requested on this list.) Opinions and further suggestions are welcome. -- François Pottier Francois.Pottier@inria.fr http://pauillac.inria.fr/~fpottier/ Here's how to use the syntax extension: 1. Compile it: ocamlc -pp "camlp4o -I `camlp4o -where`" -I `camlp4o -where` -c pcreg.ml 2. At the beginning of your source files, insert #load "pcreg.cmo";; 3. Compile your source files using the following option: -pp "camlp4o -I ." (in addition to any options necessary to include the PCRE library, e.g. -I +contrib).