Version française
Home     About     Download     Resources     Contact us    
Browse thread
Camlp4 as a universal pre-processor ?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Nicolas Pouillard <nicolas.pouillard@g...>
Subject: Re: [Caml-list] Camlp4 as a universal pre-processor ?
Excerpts from David Teller's message of Tue Oct 23 12:34:15 +0200 2007:
> I've read the Lambda example, but it looked to me like it was a syntax
> extension for OCaml and no other language, unless I completely
> misunderstand the meaning of, say, <:expr<...>> .

You're  right the lambda example is not adapted.

> Now, do you suggest I should write a full lexer and parser with Camlp4
> just in order to write simple macros ?

Hum,  in  fact  that's  because  ocpp  is  no  longer supported in Camlp4 3.10
(another (external) tool that can replace it is in preparation).

However  writing  a  small  lexer  that catch some quotation of yours is quite
simple;  but  since  you  where talking about menhir and dypgen they certainly
have  lexing  conventions  quite  close  to OCaml, so the default lexer should
suffice.

It's  mainly  about writing a parser that search for some QUOTATION tokens and
expand them, in fact it will be even simpler to directly use a stream parser.

(* pseudo untested code *)
let rec go = parse
  | [< '(QUOTATION q, _loc); strm >] -> expand q; go strm
  | [< '(token, _loc); strm >] -> Token.<some function> tok; go strm
  | [< >] -> ()

> On Tue, 2007-10-23 at 11:39 +0200, Nicolas Pouillard wrote:
> > A  way  to  start  this  is  to  just keep the lexer and provide a new grammar
> > including  quotations  [2] and antiquotations. On the wiki [1] there is also a
> > small  but  complete example of a grammar for the untyped lambda calculus with
> > antiquotations [3], and also a tutorial of making a full parser with Camlp4 [4].
> > 
> > [1]: http://brion.inria.fr/gallium/index.php/Camlp4
> > [2]: http://brion.inria.fr/gallium/index.php/Quotation
> > [3]: http://brion.inria.fr/gallium/index.php/Lambda_calculus_quotations
> > [4]: http://brion.inria.fr/gallium/index.php/Full_parser_tutorial

-- 
Nicolas Pouillard aka Ertai