Legend:
Library
Module
Module type
Parameter
Class
Class type
Library
Module
Module type
Parameter
Class
Class type
type jg_ast_mapper = {
ast : jg_ast_mapper -> Jg_types.ast -> Jg_types.ast;
statement : jg_ast_mapper -> Jg_types.statement -> Jg_types.statement;
expression : jg_ast_mapper -> Jg_types.expression -> Jg_types.expression;
}
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