English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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: 2002-09-12 (14:36)
From: Daniel de Rauglaudre <daniel.de_rauglaudre@i...>
Subject: Re: [Caml-list] camlp4 -- troubles with printer

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
> : 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
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.

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