caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* programmer-friendly regexp package
@ 2000-10-12 16:42 David Monniaux
  0 siblings, 0 replies; only message in thread
From: David Monniaux @ 2000-10-12 16:42 UTC (permalink / raw)
  To: Liste CAML

Heya all camlers,

I have an alpha version of a CamlP4 preprocessing package enabling the use
of a straightforward, easy syntax for regexps:

http://www.di.ens.fr/~monniaux/download/regexp.tar.gz


(* Defines and compiles the regexp; substrings to be extracted are
   labelled "foo" and "bar" *)
let regexp = let k = "zzz" in (* notice the support for embedded
                                   variables and expressions *)
  RE { "X" (foo: (['0'-'9']+))? bar:(['a'-'z']+) "Y" k };;

(* Now the actual pattern matching *)
REmatch "+++X45aaabYzzz" with
  regexp as contents ~bar ~foo ->
    Printf.printf "str=%s bar=%s foo=%s\n" contents bar
      (match foo with Some x -> x | None -> "<NONE>")
| _ -> Printf.printf "Not found!\n";;


It uses the "Str" library, but it may come to support PCRE as well.

It requires OCaml and CamlP4 3.00 and makes use of the labels (as a side
effect, when using the traditional mode, the user must supply the various
labels in the "as" clause in ASCII ordering).

No documentation is available yet. The syntax for the regexps is supposed
to be compatible with ocamllex. There are currently pitfalls in the
handling of character sets.

I specifically request comments on how to make this hack better, esp. with
syntactic choices. I plan to support the predefinition of regexp parts; it
is not yet decided whether the nesting will be preprocessing-time or
execution-time, or both.

Regards,

David Monniaux            http://www.di.ens.fr/~monniaux
Laboratoire d'informatique de l'École Normale Supérieure,
Paris, France





^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2000-10-12 16:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-10-12 16:42 programmer-friendly regexp package David Monniaux

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).