From: Dmitry Bely <dmitry.bely@gmail.com>
To: Caml List <caml-list@inria.fr>
Subject: Chain Camlp4 syntax extensions?
Date: Tue, 28 Sep 2010 17:13:13 +0400 [thread overview]
Message-ID: <AANLkTi=E_O2gnY=rStjW_UOweTGGBfXO9f_j0VjUkX4B@mail.gmail.com> (raw)
I have two similar syntax extension that generate some functions for
each type in the module:
EXTEND Gram
str_item:
[ [ "type"; tdl = LIST1 type_declaration SEP "and" ->
...
END;
So I use them as usual:
ocamlc -c -pp "camlp4o pa_ext1.cmo" file.ml
or
ocamlc -c -pp "camlp4o pa_ext2.cmo" file.ml
Now I need to apply them both to the same source file in sequence
(without rewriting the extensions if possible). What is the right way
to do that? Of course, If I write
ocamlc -c -pp "camlp4o pa_ext1.cmo pa_ext2.cmo" file.ml
only pa_ext2 extension is actually applied. Calling camlp4o twice with
an intermediate text representation works but is actually unacceptable
(the error location info is lost etc.). Any advice?
And another question. For camlp5 it was possible to inject some code
into the beginning of the generated file (the code is taken from IoXML
syntax extension):
value first = ref True;
Pcaml.parse_implem.val :=
fun strm ->
let (sil, stopped) = Grammar.Entry.parse Pcaml.implem strm in
let sil =
if first.val then
let _ = do { first.val := False } in
let _loc =
Stdpp.dummy_loc
in
[(<:str_item< open IoXML >>, _loc) :: sil]
else sil
in
(sil, stopped)
;
How to do the same with camlp4?
- Dmitry Bely
next reply other threads:[~2010-09-28 13:13 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-28 13:13 Dmitry Bely [this message]
2010-09-28 16:07 ` [Caml-list] " Jake Donham
2010-09-28 16:55 ` Dmitry Bely
2010-09-29 8:27 ` Hendrik Tews
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='AANLkTi=E_O2gnY=rStjW_UOweTGGBfXO9f_j0VjUkX4B@mail.gmail.com' \
--to=dmitry.bely@gmail.com \
--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