Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] camlp4 -- troubles with printer
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Daniel de Rauglaudre <daniel.de_rauglaudre@i...>
Subject: Re: [Caml-list] camlp4 -- troubles with printer
Hi,

On Wed, Sep 11, 2002 at 11:59:22PM +0700, Max Kirillov wrote:

> Let's consider the attached file. It splits a file at words
> "WHERE", reverses the order of the pieces, and concat them
> back.
> [...]
> : $camlp4o ./syntax1.cmo pr_o.cmo test.ml                                 
> : let _ = print_string "1\n"; flush stdout
> : WHERE
> : let _ = print_string "2\n"; flush stdoutUncaught exception: End_of_file

The problem is indeed due to the locations in your resulting syntax tree
which are not (no more) in order.

By default pr_o.cmo considers that the locations of the phrases of the
resulting syntax tree are in increasing order. It uses them to print
the comments and/or the empty lines between the phrases (and in the
beginning and the end of the file).

The first two lines of your printed result:
   let _ = print_string "1\n"; flush stdout
   WHERE
corresponds for pr_o.cmo to the "comments" of the beginning of the file,
since your first phrase is actually the one with print_string "2\n".

If your resulting syntax tree does not respect the order of locations,
the solution is to use the option -sep added by pr_o.cmo:

   camlp4o ./syntax1.cmo pr_o.cmo -sep "\n\n" test.ml

This options tells pr_o.cmo not to read the source file to print the
comments between phrases, but print an empty line ("\n\n") instead.

-- 
Daniel de RAUGLAUDRE
daniel.de_rauglaudre@inria.fr
http://cristal.inria.fr/~ddr/
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners