List Info

Thread: "ocaml_beginners"::[] camlp4 3.10 follow up question




"ocaml_beginners"::[] camlp4 3.10 follow up question
country flaguser name
United States
2008-03-25 21:12:55

Thanks to Jon's suggestions a week ago, I have gotten a camlp4 3.10
extension mostly working. What I would like to do next is
automatically, have a bunch of declarations defined at the top level
at the top of the file I am processing. This differs from much
tutorial material on camlp4 in that tutorials deal mainly with 1-1
transformations of existing code rather than mixing in spontaneous
bits of extra code.

Does anyone have suggestions or know of samples I can peek at? I've
actually gotten this very thing working in Camlp5, but it was painful
to figure out without tips ;)

Thanks,

Andy

On Sunday 16 March 2008 19:30:09 andrew_schein wrote:
> Hi -
>
> I'd like to start playing around with the 3.10 version of Camlp4.
> Getting started is difficult because the amount of
> information/examples out there is still in its infancy.
>
>; In the 3.09 version of Camlp4 I like to visualize the grammar and
> figure out which point to extend by typing in:
>
> Grammar.Entry.print Pcaml.expr;;
>
> Is there something similar I can do with Camlp4 3.10? Otherwise, what
>; methods are people using to figure out the structure of the original
> OCaml grammar?

According to the article about camlp4 3.10 in the OCaml Journal, you do:

# Gram.Entry.print Format.std_formatter Syntax.expr;;

According to the article about camlp4 3.10 in the OCaml Journal, you do:

# Gram.Entry.print Format.std_formatter Syntax.expr;;

--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/products/?e

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] camlp4 3.10 follow up question
country flaguser name
United Kingdom
2008-03-26 06:43:01

On Wed, Mar 26, 2008 at 02:12:55AM -0000, andrew_schein wrote:
> Thanks to Jon's suggestions a week ago, I have gotten a camlp4 3.10
>; extension mostly working. What I would like to do next is
> automatically, have a bunch of declarations defined at the top level
> at the top of the file I am processing. This differs from much
>; tutorial material on camlp4 in that tutorials deal mainly with 1-1
> transformations of existing code rather than mixing in spontaneous
> bits of extra code.

Do you mean inserting code at the beginning of the file? Have a look
at Martin Jambon's FAQ (for OCaml < 3.10) here:

http://martin.jambon.free.fr/extend-ocaml-syntax.html#inserting-bof

IIRC this is a lot harder to do than it should be.

In PG'OCaml I restructured the code so that there didn't need to be
any initializer code at all. Instead I had a global hash table
(stored in another module), and each rewritten statement consults the
global hash table to find out if the initializer code has already been
performed.

Rich.

--
Richard Jones
Red Hat

__._,_.___
.

__,_._,___
"ocaml_beginners"::[] Re: camlp4 3.10 follow up question
country flaguser name
United States
2008-03-30 09:36:52

A question that came up in this thread is how to insert statements at
the beginning of a file using camlp4 3.10. Thanks to Nicolas
Pouillard who provided a solution. For future reference:

(* initial declarations are generated using AstFilters module *)

let gen_initial_exceptions str_item =
( let loc =
Ast.loc_of_str_item str_item in
<:str_itemloc<
exception Pa_BreakCont_Break
exception Pa_BreakCont_Continue
$str_item$
>>);;

AstFilters.register_str_item_filter gen_initial_exceptions;;

__._,_.___
.

__,_._,___
[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )