Version française
Home     About     Download     Resources     Contact us    
Browse thread
Question on camlp4 3.10
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Benedikt Grundmann <benedikt@c...>
Subject: Re: [Caml-list] Question on camlp4 3.10
Where can I find more documentation on camlp4 filter?  I assumed that
I should be able to use Camlp4FoldGenerator, but I already failed at
importing it into the toplevel, to interactively explore it:

bene@discworld:trunk$ rlwrap ocaml
        Objective Caml version 3.10.0

# #load "camlp4orf.cma";;
	Camlp4 Parsing version 3.10.0

# #load "camlp4lib.cma";;
# open Camlp4.PreCast;;
# class fold = Camlp4Filters.GenerateFold.generated;;
[tons of #load camlp4*.cma which all didn't get me Camlp4Filters into
the toplevel]


And another question, how should one handle errors in a syntax
extension?  One of my syntax extension handles only part of the full
ocaml type language, but instead of rewriting the type parser, I use
the original parser and apply a function on the Camlp4.Ast, so
sometimes I encounter a node in the ast that I cannot handle, what
should I do then?

Currently I do:

match t with
  | <:ctyp< ... > -> ...
  | _ ->
       let _loc = Ast.loc_of_ctyp t in
        Printf.eprintf "pa_message: Don't know how to handle the type
at %s\n%!"
          (Loc.to_string _loc);
        exit 1

But I'm sure that there is a better builtin way?!  (For example it
would be nice if I could
include a textual representation of t in the error message)


Thanks in advance,

Bene


2007/7/26, Nicolas Pouillard <nicolas.pouillard@gmail.com>:
> Ah,  sorry  I didn't read the second part. It's a lot harder to have it correct
> unless  you  completely ignore "open". You should do that with a Camlp4 filter,
> that  store  the  module  path while traversing module declaration in a topdown
> way.
>
> >
> > 2007/7/26, Nicolas Pouillard <nicolas.pouillard@gmail.com>:
> > > Look at the Camlp4MacroParser extension, there is __FILE__.
> > >
> > > Excerpts from Benedikt Grundmann's message of Thu Jul 26 15:46:26 +0200 2007:
> > > > How can I get the name of the module where my syntax extension is
> > > > applied?  For simplicity assume that I would like to write a MODULE
> > > > macro similar to __FILE__ in c.
> > > >
> > > > shell> cat > test.ml
> > > > let _ = print_endline MODULE
> > > >
> > > > shell> ./test
> > > > Test
> > > > shell> cat > test2.ml
> > > > module M =
> > > > struct
> > > >   let _ = print_endline MODULE
> > > > end
> > > >
> > > > shell> ./test2
> > > > Test.M
> > > >
> > > >
> > > > Cheers,
> > > >
> > > > Bene
> > > >
> > >
> > > --
> > > Nicolas Pouillard aka Ertai
> > >
> >
>
> --
> Nicolas Pouillard aka Ertai
>


-- 
Calvin: I try to make everyone's day a little more
surreal.

(From Calvin & Hobbes)