[wg-camlp4] parse_with_ppx [was: My no-use of camlp4 syntax extensions for Otags]

Hendrik Tews tews at os.inf.tu-dresden.de
Thu Aug 22 13:21:29 BST 2013


Hi,

a long time ago I asked about function parse_with_ppx, that takes
a file name, applies -pp preprocessors, parses the result,
applies -ppx preprocessors and returns the syntax tree.

Is such a function available in 4.01 beta? Or, could somebody
point me to the relevant code in ocamlc/ocamlopt that does that?

(I need this functionality to port otags from camlp4 to -ppx.)


Here is some background from the "my no-use ..." thread:

I wrote:

   > ... it would be nice, if the compilerlibs could
   > provide a function parse_with_ppx, or everything that is needed
   > for writing it. parse_with_ppx takes a filename and a list of
   > preprocessor names, parses the file, runs all preprocessors and
   > returns the ast.

Alain ansered:

   This is already the case, you can do something like:

     let inputfile = Pparse.preprocess sourcefile in
     let ast =
      Pparse.file ppf inputfile Parse.implementation ast_impl_magic_number
     in
     ...
     Pparse.remove_preprocessed inputfile

   Maybe we should encapsulate the code above as a single function (with
   proper support for errors, i.e. removing the temporary file produced
   by the -pp preprocessor in case of error).

I answered again:

   I would prefer something that automatically deals with temporary
   files but raises errors as exceptions together with a function
   that converts these exceptions into proper error messages. 


Bye,

Hendrik


More information about the wg-camlp4 mailing list