Skip to content
Yotam Barnoy edited this page Apr 22, 2015 · 3 revisions

The Parsing Driver (driver/pparse.ml) is called by both the Bytecode and Native Compiler. It's job is to convert an OCaml file into AST, either Parsing.structure or Parsing.signature. For an implementation parse, Parse.implementation is called. For an interface parse, Parse.interface is called instead.

Steps

  • Location.input_name is set to the current source file.
  • Any preprocessor such as ocamlpp is first run on the source.
  • The PParse.file function is called. This function can parse either an interface or an implementation, in either OCaml source or AST format.
  • The source file is opened and checked for a Magic string specifying that it is AST. If such a string is found, the file is composed of AST and is read via the Marshal module. Otherwise, it is source code, and Lexing.from_channel is called to lex the file, followed by parsing of the file via Parse.implementation or Parse.interface.
  • The source file is closed
  • PPX Rewriters are now applied to the untyped AST via PParse.apply_rewriters. Each ppx rewriter is a standalone program, so the AST needs to be serialized, fed to the rewriter, and then deserialized, for each rewriter.
  • The AST is returned to the calling function.
Clone this wiki locally