Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Chain Camlp4 syntax extensions?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Dmitry Bely <dmitry.bely@g...>
Subject: Chain Camlp4 syntax extensions?
I have two similar syntax extension that generate some functions for
each type in the module:

    [ [ "type"; tdl = LIST1 type_declaration SEP "and" ->

So I use them as usual:

ocamlc -c -pp "camlp4o pa_ext1.cmo"


ocamlc -c -pp "camlp4o pa_ext2.cmo"

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"

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 =
        [(<:str_item< open IoXML >>, _loc) :: sil]
      else sil
    (sil, stopped)

How to do the same with camlp4?

- Dmitry Bely