ocaml-trace/ppxlib/Ppxlib/Ast_traverse/index.html
2025-12-12 13:56:43 +00:00

28 lines
9.9 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Ast_traverse (ppxlib.Ppxlib.Ast_traverse)</title><meta charset="utf-8"/><link rel="stylesheet" href="../../../_odoc-theme/odoc.css"/><meta name="generator" content="odoc 3.1.0"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../../highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body class="odoc"><nav class="odoc-nav"><a href="../index.html">Up</a> <a href="../../../index.html">Index</a> &#x00BB; <a href="../../index.html">ppxlib</a> &#x00BB; <a href="../index.html">Ppxlib</a> &#x00BB; Ast_traverse</nav><header class="odoc-preamble"><h1>Module <code><span>Ppxlib.Ast_traverse</span></code></h1><p>This module provides AST traversal classes, such as maps, iterations, folds, etc. on the <a href="../../Astlib/Ast_502/Parsetree/index.html"><code>Parsetree</code></a> types.</p></header><div class="odoc-tocs"><nav class="odoc-toc odoc-local-toc"><ul><li><a href="#link-to-the-tutorial">Link to the tutorial</a></li><li><a href="#api">API</a></li></ul></nav></div><div class="odoc-content"><h2 id="link-to-the-tutorial"><a href="#link-to-the-tutorial" class="anchor"></a>Link to the tutorial</h2><p>For a detailed explanation on this module, refer to the <a href="../../ast-traversal.html" title="ast-traversal">relevant</a> part of the manual.</p><h2 id="api"><a href="#api" class="anchor"></a>API</h2><p>To use these classes, inherit from them and override the methods corresponding to the types from <code>Parsetree</code> you want to process. For instance to collect all the string constants in a structure:</p><pre class="language-ocaml"><code> let string_constants_of =
object
inherit [string list] Ast_traverse.fold as super
method! expression e acc =
let acc = super#expression e acc in
match e.pexp_desc with
| Pexp_constant (Const_string (s, _)) -&gt; s :: acc
| _ -&gt; acc
method! pattern p acc =
let acc = super#pattern p acc in
match p.ppat_desc with
| Ppat_constant (Const_string (s, _)) -&gt; s :: acc
| _ -&gt; acc
end
let string_constants_of_structure = string_constants_of#structure</code></pre><div class="odoc-spec"><div class="spec class anchored" id="class-map"><a href="#class-map" class="anchor"></a><code><span><span class="keyword">class</span> </span><span><a href="class-map/index.html">map</a></span><span> : <span class="keyword">object</span> ... <span class="keyword">end</span></span></code></div></div><div class="odoc-spec"><div class="spec class anchored" id="class-iter"><a href="#class-iter" class="anchor"></a><code><span><span class="keyword">class</span> </span><span><a href="class-iter/index.html">iter</a></span><span> : <span class="keyword">object</span> ... <span class="keyword">end</span></span></code></div></div><div class="odoc-spec"><div class="spec class anchored" id="class-fold"><a href="#class-fold" class="anchor"></a><code><span><span class="keyword">class</span> 'acc </span><span><a href="class-fold/index.html">fold</a></span><span> : <span class="keyword">object</span> ... <span class="keyword">end</span></span></code></div></div><div class="odoc-spec"><div class="spec class anchored" id="class-fold_map"><a href="#class-fold_map" class="anchor"></a><code><span><span class="keyword">class</span> 'acc </span><span><a href="class-fold_map/index.html">fold_map</a></span><span> : <span class="keyword">object</span> ... <span class="keyword">end</span></span></code></div></div><div class="odoc-spec"><div class="spec class anchored" id="class-map_with_context"><a href="#class-map_with_context" class="anchor"></a><code><span><span class="keyword">class</span> 'ctx </span><span><a href="class-map_with_context/index.html">map_with_context</a></span><span> : <span class="keyword">object</span> ... <span class="keyword">end</span></span></code></div></div><div class="odoc-spec"><div class="spec class anchored" id="class-map_with_path"><a href="#class-map_with_path" class="anchor"></a><code><span><span class="keyword">class</span> </span><span><a href="class-map_with_path/index.html">map_with_path</a></span><span> : <span>string <a href="class-map_with_context/index.html">map_with_context</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-enter_value"><a href="#val-enter_value" class="anchor"></a><code><span><span class="keyword">val</span> enter_value :
<span><span>(<a href="../../Astlib/Ast_502/Parsetree/index.html#type-expression">Astlib.Ast_502.Parsetree.expression</a>, <span>string <a href="../../Astlib/Location/index.html#type-loc">Astlib.Location.loc</a></span>)</span> <a href="../Attribute/index.html#type-t">Attribute.t</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-enter_module"><a href="#val-enter_module" class="anchor"></a><code><span><span class="keyword">val</span> enter_module :
<span><span>(<a href="../../Astlib/Ast_502/Parsetree/index.html#type-module_expr">Astlib.Ast_502.Parsetree.module_expr</a>, <span>string <a href="../../Astlib/Location/index.html#type-loc">Astlib.Location.loc</a></span>)</span>
<a href="../Attribute/index.html#type-t">Attribute.t</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-do_not_enter_value_binding"><a href="#val-do_not_enter_value_binding" class="anchor"></a><code><span><span class="keyword">val</span> do_not_enter_value_binding :
<span><span>(<a href="../../Astlib/Ast_502/Parsetree/index.html#type-value_binding">Astlib.Ast_502.Parsetree.value_binding</a>, unit)</span> <a href="../Attribute/index.html#type-t">Attribute.t</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-do_not_enter_value_description"><a href="#val-do_not_enter_value_description" class="anchor"></a><code><span><span class="keyword">val</span> do_not_enter_value_description :
<span><span>(<a href="../../Astlib/Ast_502/Parsetree/index.html#type-value_description">Astlib.Ast_502.Parsetree.value_description</a>, unit)</span> <a href="../Attribute/index.html#type-t">Attribute.t</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-do_not_enter_module_binding"><a href="#val-do_not_enter_module_binding" class="anchor"></a><code><span><span class="keyword">val</span> do_not_enter_module_binding :
<span><span>(<a href="../../Astlib/Ast_502/Parsetree/index.html#type-module_binding">Astlib.Ast_502.Parsetree.module_binding</a>, unit)</span> <a href="../Attribute/index.html#type-t">Attribute.t</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-do_not_enter_module_declaration"><a href="#val-do_not_enter_module_declaration" class="anchor"></a><code><span><span class="keyword">val</span> do_not_enter_module_declaration :
<span><span>(<a href="../../Astlib/Ast_502/Parsetree/index.html#type-module_declaration">Astlib.Ast_502.Parsetree.module_declaration</a>, unit)</span> <a href="../Attribute/index.html#type-t">Attribute.t</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-do_not_enter_module_type_declaration"><a href="#val-do_not_enter_module_type_declaration" class="anchor"></a><code><span><span class="keyword">val</span> do_not_enter_module_type_declaration :
<span><span>(<a href="../../Astlib/Ast_502/Parsetree/index.html#type-module_type_declaration">Astlib.Ast_502.Parsetree.module_type_declaration</a>, unit)</span> <a href="../Attribute/index.html#type-t">Attribute.t</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-do_not_enter_let_module"><a href="#val-do_not_enter_let_module" class="anchor"></a><code><span><span class="keyword">val</span> do_not_enter_let_module :
<span><span>(<a href="../../Astlib/Ast_502/Parsetree/index.html#type-expression">Astlib.Ast_502.Parsetree.expression</a>, unit)</span> <a href="../Attribute/index.html#type-t">Attribute.t</a></span></span></code></div></div><div class="odoc-spec"><div class="spec class anchored" id="class-lift"><a href="#class-lift" class="anchor"></a><code><span><span class="keyword">class</span> <span class="keyword">virtual</span> 'res </span><span><a href="class-lift/index.html">lift</a></span><span> : <span class="keyword">object</span> ... <span class="keyword">end</span></span></code></div></div><div class="odoc-spec"><div class="spec class anchored" id="class-lift_map_with_context"><a href="#class-lift_map_with_context" class="anchor"></a><code><span><span class="keyword">class</span> <span class="keyword">virtual</span> ['ctx, 'res] </span><span><a href="class-lift_map_with_context/index.html">lift_map_with_context</a></span><span> : <span class="keyword">object</span> ... <span class="keyword">end</span></span></code></div></div><div class="odoc-spec"><div class="spec class anchored" id="class-map_with_expansion_context_and_errors"><a href="#class-map_with_expansion_context_and_errors" class="anchor"></a><code><span><span class="keyword">class</span> </span><span><a href="class-map_with_expansion_context_and_errors/index.html">map_with_expansion_context_and_errors</a></span><span> : <span class="keyword">object</span> ... <span class="keyword">end</span></span></code></div></div><div class="odoc-spec"><div class="spec class anchored" id="class-sexp_of"><a href="#class-sexp_of" class="anchor"></a><code><span><span class="keyword">class</span> </span><span><a href="class-sexp_of/index.html">sexp_of</a></span><span> : <span class="keyword">object</span> ... <span class="keyword">end</span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-sexp_of"><a href="#val-sexp_of" class="anchor"></a><code><span><span class="keyword">val</span> sexp_of : <a href="../../Ppxlib__Ast_traverse/class-sexp_of/index.html">sexp_of</a></span></code></div></div></div></body></html>