caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Stefano Zacchiroli <zack@bononia.it>
To: Inria Ocaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] [camlp4] how to parse/pretty print OCaml source files
Date: Wed, 7 Nov 2007 16:28:48 +0100	[thread overview]
Message-ID: <20071107152848.GA19628@takhisis.invalid> (raw)
In-Reply-To: <1194375800-sup-2076@ausone.local>

On Tue, Nov 06, 2007 at 08:09:28PM +0100, Nicolas Pouillard wrote:
> > - what's the corresponding camlp4 idiom for the old "Pcaml.parse_implem"
> >   (which used to parse str_items starting from a "char Stream.t")?
> >   [ Note that I need to parse the revised syntax, but I doubt this will
> >   make a sensible difference. ]

First things first :), so let's start with parsing ...

> Looking  for parse_implem in Camlp4/Sig.ml that some module have the signature
> Parser(Ast).S,  searching  for  occurences  of  this signature leads me to two
> signatures  Syntax and Camlp4Syntax. Then I go to Camlp4/PreCast.mli where all
> precasted  modules  lives.  Here  I  found that Camlp4.PreCast.Syntax have the
> Camlp4Syntax type.
> 
> So Camlp4.PreCast.Syntax.parse_implem is what you searched.

OK.

> However you perhaps need a function more precise that reading an implementation. You perhaps prefer just reading a toplevel phrase for this you can use:
> 
> open Camlp4.PreCast;;
> 
> let strm = ... in
> Syntax.Gram.parse loc Syntax.top_phrase strm

That's right, parsing one phrase at a time is definitely handier.
However the above does not work. (The argument are permuted, but that of
course is a non issue.) What does "loc" stands for? Given I'm parsing a
char stream I would have expected that the parser returns me a located
object, why should I give a location in advance? Is it some kind of
"current" location when parsing has been left last time?

In this case how should I build a location? The only way I've found is
Camlp4.PreCast.Loc.mk which takes as input a file name and returns a
location placed at the beginning of that file. I'm going for Loc.ml "",
but I don't know if I'll mess up something in the future ...

TIA, Cheers.

-- 
Stefano Zacchiroli -*- PhD in Computer Science ............... now what?
zack@{cs.unibo.it,debian.org,bononia.it} -%- http://www.bononia.it/zack/
(15:56:48)  Zack: e la demo dema ?    /\    All one has to do is hit the
(15:57:15)  Bac: no, la demo scema    \/    right keys at the right time


  reply	other threads:[~2007-11-07 15:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-06 18:14 Stefano Zacchiroli
2007-11-06 19:09 ` [Caml-list] " Nicolas Pouillard
2007-11-07 15:28   ` Stefano Zacchiroli [this message]
2007-11-06 20:31 ` Jon Harrop
2007-11-07  8:39   ` Andrej Bauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20071107152848.GA19628@takhisis.invalid \
    --to=zack@bononia.it \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).