Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Some sugar for regexp matching using camlp4
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-07-17 (10:36)
From: Markus Mottl <markus@m...>
Subject: Re: [Caml-list] Some sugar for regexp matching using camlp4
On Mon, 16 Jul 2001, Francois Pottier wrote:
> 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

Nice! This example could surely be used to build a convenient special
purpose language for text manipulation.

>   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.

Note that it should be possible to assert the required number of subgroups
at compile-time if the user supplied a constant string: you'd only have
to compile the pattern string to a regexp within the camlp4-rule and
check things there. This would even allow you to catch illegal patterns:
static typing for regular expression :-)

Best regards,
Markus Mottl

Markus Mottl                                   
Austrian Research Institute
for Artificial Intelligence        
Bug reports:  FAQ:
To unsubscribe, mail  Archives: