From: Stefano Zacchiroli <zack@bononia.it>
To: Inria Ocaml Mailing List <caml-list@inria.fr>
Subject: [camlp4] how to parse/pretty print OCaml source files
Date: Tue, 6 Nov 2007 19:14:31 +0100 [thread overview]
Message-ID: <20071106181431.GA19764@takhisis.invalid> (raw)
I need to write a simple wrapper around the OCaml top-level. Besides
executing top-level phrases as usual, the wrapper should "patch" the
pretty-printing of both input phrases and of top-level output. The kind
of patching I would need ranges from substituting ascii arts like "->"
for suitable unicode symbols to reworking abstract syntax trees of OCaml
values.
I would have an idea of where to start with camlp5, but not the faintest
with (the new) camlp4. The stuff currently on the wiki does not help. So
here they go some questions (I'll be happy to write the corresponding
articles in the camlp4 wiki ... assuming I'll manage to find the needed
info here!)
- 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. ]
- what's the camlp4 idiom for the old "Pcaml.print_implem" (which used
to print str_items on a given formatter)
[ Same remark as above for the revised syntax. ]
- what's the camlp4 idiom for "Ast2pt.phrase" (which used to convert
str_items to "Parsetree.toplevel_phrase", the type required by the
Toploop module for executing phrases), assuming it is still needed of
course ...
- how can I install with camlp4 a custom printer for OCaml ASTs so that
Toploop.execute_phrase uses it to print on the given formatter?
Note that I would also be fine in using camlp5 for the task, but AFAIU
the code, overriding tiny bits of the default pretty printers for OCaml
ASTs is easier with the new camlp4 since it has OO printers. This way I
can override methods in derived classes and be done with that.
Many thanks in advance,
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
next reply other threads:[~2007-11-06 18:14 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-06 18:14 Stefano Zacchiroli [this message]
2007-11-06 19:09 ` [Caml-list] " Nicolas Pouillard
2007-11-07 15:28 ` Stefano Zacchiroli
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=20071106181431.GA19764@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