package jingoo

  1. Overview
  2. Docs

Jg_ast_mapper.jg_ast_mapper allows to implement AST rewriting.

A typical mapper would be based on Jg_ast_mapper.default_mapper, a deep identity mapper, and will fall back on it for handling the syntax it does not modify.

ast, statement and expression expect a first argument being the mapper currently used.

For example, Jg_interp.inline_include defines an ast mapper replacing {% include %} statements by actual code (statements) from these included files.

let open Jg_ast_mapper in
  let statement self = function
    | IncludeStatement (LiteralExpr (Tstr file), true) ->
      Statements (self.ast self @@ ast_from_file ~env file)
    | RawIncludeStatement (LiteralExpr (Tstr file)) ->
      Statements (self.ast self @@ ast_from_file ~env file)
    | e -> default_mapper.statement self e in
  { default_mapper with statement }
val default_mapper : jg_ast_mapper
OCaml

Innovation. Community. Security.