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
Help with new camlp4
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-04-02 (12:40)
From: Joel Reymont <joelr1@g...>
Subject: Re: [Caml-list] Help with new camlp4
I'm stuck for good now.

I'm trying to make sure that translate has a proper signature. It  
needs a few arguments that weren't present in the original  
declaration (let translate xml = ...). I add the missing bits but xml  
in translate is of type Xml whereas Quotation.ExAst wants a string.


let translate (_: Quotation.Ast.Loc.t) (_:string option) (xml: string) =
   let (body,vars,sublist) = visit StringSet.empty xml in
     if sublist then
       failwith "Need exactly 1 root (condition/repeat/omit-tag  
       let vvars = (fun x -> <:patt< ~ $x$>>)  
(StringSet.elements vars) in
         List.fold_right (fun p e -> <:expr<fun $p$ -> $e$>>) vvars body

let expand_expr_file = chain translate Xml.parse_file ;;

let expand_expr_str = chain translate Xml.parse_string ;;

let expand_patt x =
(*  Stdpp.raise_with_loc loc *)
   Loc.raise x (Failure "Quotation not allowed in pattern")

Quotation.add "octalxml" (Quotation.ExAst  
(expand_expr_str,expand_patt)) ;;
Quotation.add "octalfile" (Quotation.ExAst  
(expand_expr_file,expand_patt)) ;;