1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link rel="stylesheet" href="style.css" type="text/css">
<meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="Start" href="index.html">
<link rel="previous" href="Ast_iterator.html">
<link rel="next" href="Asttypes.html">
<link rel="Up" href="index.html">
<link title="Index of types" rel=Appendix href="index_types.html">
<link title="Index of exceptions" rel=Appendix href="index_exceptions.html">
<link title="Index of values" rel=Appendix href="index_values.html">
<link title="Index of modules" rel=Appendix href="index_modules.html">
<link title="Index of module types" rel=Appendix href="index_module_types.html">
<link title="Arg_helper" rel="Chapter" href="Arg_helper.html">
<link title="Ast_helper" rel="Chapter" href="Ast_helper.html">
<link title="Ast_invariants" rel="Chapter" href="Ast_invariants.html">
<link title="Ast_iterator" rel="Chapter" href="Ast_iterator.html">
<link title="Ast_mapper" rel="Chapter" href="Ast_mapper.html">
<link title="Asttypes" rel="Chapter" href="Asttypes.html">
<link title="Attr_helper" rel="Chapter" href="Attr_helper.html">
<link title="Build_path_prefix_map" rel="Chapter" href="Build_path_prefix_map.html">
<link title="Builtin_attributes" rel="Chapter" href="Builtin_attributes.html">
<link title="CamlinternalMenhirLib" rel="Chapter" href="CamlinternalMenhirLib.html">
<link title="Ccomp" rel="Chapter" href="Ccomp.html">
<link title="Clflags" rel="Chapter" href="Clflags.html">
<link title="Compiler_libs" rel="Chapter" href="Compiler_libs.html">
<link title="Config" rel="Chapter" href="Config.html">
<link title="Consistbl" rel="Chapter" href="Consistbl.html">
<link title="Depend" rel="Chapter" href="Depend.html">
<link title="Docstrings" rel="Chapter" href="Docstrings.html">
<link title="Domainstate" rel="Chapter" href="Domainstate.html">
<link title="Identifiable" rel="Chapter" href="Identifiable.html">
<link title="Int_replace_polymorphic_compare" rel="Chapter" href="Int_replace_polymorphic_compare.html">
<link title="Lexer" rel="Chapter" href="Lexer.html">
<link title="Load_path" rel="Chapter" href="Load_path.html">
<link title="Location" rel="Chapter" href="Location.html">
<link title="Longident" rel="Chapter" href="Longident.html">
<link title="Misc" rel="Chapter" href="Misc.html">
<link title="Numbers" rel="Chapter" href="Numbers.html">
<link title="Parse" rel="Chapter" href="Parse.html">
<link title="Parser" rel="Chapter" href="Parser.html">
<link title="Parsetree" rel="Chapter" href="Parsetree.html">
<link title="Pparse" rel="Chapter" href="Pparse.html">
<link title="Pprintast" rel="Chapter" href="Pprintast.html">
<link title="Printast" rel="Chapter" href="Printast.html">
<link title="Profile" rel="Chapter" href="Profile.html">
<link title="Strongly_connected_components" rel="Chapter" href="Strongly_connected_components.html">
<link title="Syntaxerr" rel="Chapter" href="Syntaxerr.html">
<link title="Targetint" rel="Chapter" href="Targetint.html">
<link title="Terminfo" rel="Chapter" href="Terminfo.html">
<link title="Warnings" rel="Chapter" href="Warnings.html"><link title="A generic Parsetree mapper" rel="Section" href="#1_AgenericParsetreemapper">
<link title="Apply mappers to compilation units" rel="Section" href="#1_Applymapperstocompilationunits">
<link title="Registration API" rel="Section" href="#1_RegistrationAPI">
<link title="Convenience functions to write mappers" rel="Section" href="#1_Conveniencefunctionstowritemappers">
<link title="Helper functions to call external mappers" rel="Section" href="#1_Helperfunctionstocallexternalmappers">
<link title="Cookies" rel="Section" href="#1_Cookies">
<title>Ast_mapper</title>
</head>
<body>
<div class="navbar"><a class="pre" href="Ast_iterator.html" title="Ast_iterator">Previous</a>
<a class="up" href="index.html" title="Index">Up</a>
<a class="post" href="Asttypes.html" title="Asttypes">Next</a>
</div>
<h1>Module <a href="type_Ast_mapper.html">Ast_mapper</a></h1>
<pre><span id="MODULEAst_mapper"><span class="keyword">module</span> Ast_mapper</span>: <code class="code"><span class="keyword">sig</span></code> <a href="Ast_mapper.html">..</a> <code class="code"><span class="keyword">end</span></code></pre><div class="info module top">
<div class="info-desc">
<p>The interface of a -ppx rewriter</p>
<p>A -ppx rewriter is a program that accepts a serialized abstract syntax
tree and outputs another, possibly modified, abstract syntax tree.
This module encapsulates the interface between the compiler and
the -ppx rewriters, handling such details as the serialization format,
forwarding of command-line flags, and storing state.</p>
<p><a href="Ast_mapper.html#TYPEmapper"><code class="code"><span class="constructor">Ast_mapper</span>.mapper</code></a> enables AST rewriting using open recursion.
A typical mapper would be based on <a href="Ast_mapper.html#VALdefault_mapper"><code class="code"><span class="constructor">Ast_mapper</span>.default_mapper</code></a>, a deep
identity mapper, and will fall back on it for handling the syntax it
does not modify. For example:</p>
<pre class="codepre"><code class="code"><span class="keyword">open</span> <span class="constructor">Asttypes</span>
<span class="keyword">open</span> <span class="constructor">Parsetree</span>
<span class="keyword">open</span> <span class="constructor">Ast_mapper</span>
<span class="keyword">let</span> test_mapper argv =
{ default_mapper <span class="keyword">with</span>
expr = <span class="keyword">fun</span> mapper expr <span class="keywordsign">-></span>
<span class="keyword">match</span> expr <span class="keyword">with</span>
<span class="keywordsign">|</span> { pexp_desc = <span class="constructor">Pexp_extension</span> ({ txt = <span class="string">"test"</span> }, <span class="constructor">PStr</span> [])} <span class="keywordsign">-></span>
<span class="constructor">Ast_helper</span>.<span class="constructor">Exp</span>.constant (<span class="constructor">Const_int</span> 42)
<span class="keywordsign">|</span> other <span class="keywordsign">-></span> default_mapper.expr mapper other; }
<span class="keyword">let</span> () =
register <span class="string">"ppx_test"</span> test_mapper</code></pre>
<p>This -ppx rewriter, which replaces <code class="code">[%test]</code> in expressions with
the constant <code class="code">42</code>, can be compiled using
<code class="code">ocamlc -o ppx_test -<span class="constructor">I</span> +compiler-libs ocamlcommon.cma ppx_test.ml</code>.</p>
<p><b>Warning:</b> this module is unstable and part of
<a href="Compiler_libs.html">compiler-libs</a>.</p>
</div>
</div>
<hr width="100%">
<h2 id="1_AgenericParsetreemapper">A generic Parsetree mapper</h2>
<pre><code><span id="TYPEmapper"><span class="keyword">type</span> <code class="type"></code>mapper</span> = {</code></pre><table class="typetable">
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.attribute">attribute</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEattribute">Parsetree.attribute</a> -> <a href="Parsetree.html#TYPEattribute">Parsetree.attribute</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.attributes">attributes</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEattribute">Parsetree.attribute</a> list -> <a href="Parsetree.html#TYPEattribute">Parsetree.attribute</a> list</code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.binding_op">binding_op</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEbinding_op">Parsetree.binding_op</a> -> <a href="Parsetree.html#TYPEbinding_op">Parsetree.binding_op</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.case">case</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEcase">Parsetree.case</a> -> <a href="Parsetree.html#TYPEcase">Parsetree.case</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.cases">cases</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEcase">Parsetree.case</a> list -> <a href="Parsetree.html#TYPEcase">Parsetree.case</a> list</code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.class_declaration">class_declaration</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -><br> <a href="Parsetree.html#TYPEclass_declaration">Parsetree.class_declaration</a> -> <a href="Parsetree.html#TYPEclass_declaration">Parsetree.class_declaration</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.class_description">class_description</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -><br> <a href="Parsetree.html#TYPEclass_description">Parsetree.class_description</a> -> <a href="Parsetree.html#TYPEclass_description">Parsetree.class_description</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.class_expr">class_expr</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEclass_expr">Parsetree.class_expr</a> -> <a href="Parsetree.html#TYPEclass_expr">Parsetree.class_expr</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.class_field">class_field</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEclass_field">Parsetree.class_field</a> -> <a href="Parsetree.html#TYPEclass_field">Parsetree.class_field</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.class_signature">class_signature</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEclass_signature">Parsetree.class_signature</a> -> <a href="Parsetree.html#TYPEclass_signature">Parsetree.class_signature</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.class_structure">class_structure</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEclass_structure">Parsetree.class_structure</a> -> <a href="Parsetree.html#TYPEclass_structure">Parsetree.class_structure</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.class_type">class_type</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEclass_type">Parsetree.class_type</a> -> <a href="Parsetree.html#TYPEclass_type">Parsetree.class_type</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.class_type_declaration">class_type_declaration</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -><br> <a href="Parsetree.html#TYPEclass_type_declaration">Parsetree.class_type_declaration</a> -> <a href="Parsetree.html#TYPEclass_type_declaration">Parsetree.class_type_declaration</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.class_type_field">class_type_field</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEclass_type_field">Parsetree.class_type_field</a> -> <a href="Parsetree.html#TYPEclass_type_field">Parsetree.class_type_field</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.constant">constant</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEconstant">Parsetree.constant</a> -> <a href="Parsetree.html#TYPEconstant">Parsetree.constant</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.constructor_declaration">constructor_declaration</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -><br> <a href="Parsetree.html#TYPEconstructor_declaration">Parsetree.constructor_declaration</a> -> <a href="Parsetree.html#TYPEconstructor_declaration">Parsetree.constructor_declaration</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.expr">expr</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEexpression">Parsetree.expression</a> -> <a href="Parsetree.html#TYPEexpression">Parsetree.expression</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.extension">extension</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEextension">Parsetree.extension</a> -> <a href="Parsetree.html#TYPEextension">Parsetree.extension</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.extension_constructor">extension_constructor</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -><br> <a href="Parsetree.html#TYPEextension_constructor">Parsetree.extension_constructor</a> -> <a href="Parsetree.html#TYPEextension_constructor">Parsetree.extension_constructor</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.include_declaration">include_declaration</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -><br> <a href="Parsetree.html#TYPEinclude_declaration">Parsetree.include_declaration</a> -> <a href="Parsetree.html#TYPEinclude_declaration">Parsetree.include_declaration</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.include_description">include_description</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -><br> <a href="Parsetree.html#TYPEinclude_description">Parsetree.include_description</a> -> <a href="Parsetree.html#TYPEinclude_description">Parsetree.include_description</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.label_declaration">label_declaration</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -><br> <a href="Parsetree.html#TYPElabel_declaration">Parsetree.label_declaration</a> -> <a href="Parsetree.html#TYPElabel_declaration">Parsetree.label_declaration</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.location">location</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Location.html#TYPEt">Location.t</a> -> <a href="Location.html#TYPEt">Location.t</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.module_binding">module_binding</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEmodule_binding">Parsetree.module_binding</a> -> <a href="Parsetree.html#TYPEmodule_binding">Parsetree.module_binding</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.module_declaration">module_declaration</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -><br> <a href="Parsetree.html#TYPEmodule_declaration">Parsetree.module_declaration</a> -> <a href="Parsetree.html#TYPEmodule_declaration">Parsetree.module_declaration</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.module_substitution">module_substitution</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -><br> <a href="Parsetree.html#TYPEmodule_substitution">Parsetree.module_substitution</a> -> <a href="Parsetree.html#TYPEmodule_substitution">Parsetree.module_substitution</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.module_expr">module_expr</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEmodule_expr">Parsetree.module_expr</a> -> <a href="Parsetree.html#TYPEmodule_expr">Parsetree.module_expr</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.module_type">module_type</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEmodule_type">Parsetree.module_type</a> -> <a href="Parsetree.html#TYPEmodule_type">Parsetree.module_type</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.module_type_declaration">module_type_declaration</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -><br> <a href="Parsetree.html#TYPEmodule_type_declaration">Parsetree.module_type_declaration</a> -> <a href="Parsetree.html#TYPEmodule_type_declaration">Parsetree.module_type_declaration</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.open_declaration">open_declaration</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEopen_declaration">Parsetree.open_declaration</a> -> <a href="Parsetree.html#TYPEopen_declaration">Parsetree.open_declaration</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.open_description">open_description</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEopen_description">Parsetree.open_description</a> -> <a href="Parsetree.html#TYPEopen_description">Parsetree.open_description</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.pat">pat</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEpattern">Parsetree.pattern</a> -> <a href="Parsetree.html#TYPEpattern">Parsetree.pattern</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.payload">payload</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEpayload">Parsetree.payload</a> -> <a href="Parsetree.html#TYPEpayload">Parsetree.payload</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.signature">signature</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEsignature">Parsetree.signature</a> -> <a href="Parsetree.html#TYPEsignature">Parsetree.signature</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.signature_item">signature_item</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEsignature_item">Parsetree.signature_item</a> -> <a href="Parsetree.html#TYPEsignature_item">Parsetree.signature_item</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.structure">structure</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEstructure">Parsetree.structure</a> -> <a href="Parsetree.html#TYPEstructure">Parsetree.structure</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.structure_item">structure_item</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEstructure_item">Parsetree.structure_item</a> -> <a href="Parsetree.html#TYPEstructure_item">Parsetree.structure_item</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.typ">typ</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEcore_type">Parsetree.core_type</a> -> <a href="Parsetree.html#TYPEcore_type">Parsetree.core_type</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.type_declaration">type_declaration</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEtype_declaration">Parsetree.type_declaration</a> -> <a href="Parsetree.html#TYPEtype_declaration">Parsetree.type_declaration</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.type_extension">type_extension</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEtype_extension">Parsetree.type_extension</a> -> <a href="Parsetree.html#TYPEtype_extension">Parsetree.type_extension</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.type_exception">type_exception</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEtype_exception">Parsetree.type_exception</a> -> <a href="Parsetree.html#TYPEtype_exception">Parsetree.type_exception</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.type_kind">type_kind</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEtype_kind">Parsetree.type_kind</a> -> <a href="Parsetree.html#TYPEtype_kind">Parsetree.type_kind</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.value_binding">value_binding</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEvalue_binding">Parsetree.value_binding</a> -> <a href="Parsetree.html#TYPEvalue_binding">Parsetree.value_binding</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.value_description">value_description</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -><br> <a href="Parsetree.html#TYPEvalue_description">Parsetree.value_description</a> -> <a href="Parsetree.html#TYPEvalue_description">Parsetree.value_description</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.with_constraint">with_constraint</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEwith_constraint">Parsetree.with_constraint</a> -> <a href="Parsetree.html#TYPEwith_constraint">Parsetree.with_constraint</a></code>;</code></td>
</tr></table>
<code>}</code>
<div class="info ">
<div class="info-desc">
<p>A mapper record implements one "method" per syntactic category,
using an open recursion style: each method takes as its first
argument the mapper to be applied to children in the syntax
tree.</p>
</div>
</div>
<pre><span id="VALdefault_mapper"><span class="keyword">val</span> default_mapper</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a></code></pre><div class="info ">
<div class="info-desc">
<p>A default mapper, which implements a "deep identity" mapping.</p>
</div>
</div>
<h2 id="1_Applymapperstocompilationunits">Apply mappers to compilation units</h2>
<pre><span id="VALtool_name"><span class="keyword">val</span> tool_name</span> : <code class="type">unit -> string</code></pre><div class="info ">
<div class="info-desc">
<p>Can be used within a ppx preprocessor to know which tool is
calling it <code class="code"><span class="string">"ocamlc"</span></code>, <code class="code"><span class="string">"ocamlopt"</span></code>, <code class="code"><span class="string">"ocamldoc"</span></code>, <code class="code"><span class="string">"ocamldep"</span></code>,
<code class="code"><span class="string">"ocaml"</span></code>, ... Some global variables that reflect command-line
options are automatically synchronized between the calling tool
and the ppx preprocessor: <a href="Clflags.html#VALinclude_dirs"><code class="code"><span class="constructor">Clflags</span>.include_dirs</code></a>,
<a href="Load_path.html"><code class="code"><span class="constructor">Load_path</span></code></a>, <a href="Clflags.html#VALopen_modules"><code class="code"><span class="constructor">Clflags</span>.open_modules</code></a>, <a href="Clflags.html#VALfor_package"><code class="code"><span class="constructor">Clflags</span>.for_package</code></a>,
<a href="Clflags.html#VALdebug"><code class="code"><span class="constructor">Clflags</span>.debug</code></a>.</p>
</div>
</div>
<pre><span id="VALapply"><span class="keyword">val</span> apply</span> : <code class="type">source:string -> target:string -> <a href="Ast_mapper.html#TYPEmapper">mapper</a> -> unit</code></pre><div class="info ">
<div class="info-desc">
<p>Apply a mapper (parametrized by the unit name) to a dumped
parsetree found in the <code class="code">source</code> file and put the result in the
<code class="code">target</code> file. The <code class="code">structure</code> or <code class="code">signature</code> field of the mapper
is applied to the implementation or interface.</p>
</div>
</div>
<pre><span id="VALrun_main"><span class="keyword">val</span> run_main</span> : <code class="type">(string list -> <a href="Ast_mapper.html#TYPEmapper">mapper</a>) -> unit</code></pre><div class="info ">
<div class="info-desc">
<p>Entry point to call to implement a standalone -ppx rewriter from a
mapper, parametrized by the command line arguments. The current
unit name can be obtained from <a href="Location.html#VALinput_name"><code class="code"><span class="constructor">Location</span>.input_name</code></a>. This
function implements proper error reporting for uncaught
exceptions.</p>
</div>
</div>
<h2 id="1_RegistrationAPI">Registration API</h2>
<pre><span id="VALregister_function"><span class="keyword">val</span> register_function</span> : <code class="type">(string -> (string list -> <a href="Ast_mapper.html#TYPEmapper">mapper</a>) -> unit) ref</code></pre>
<pre><span id="VALregister"><span class="keyword">val</span> register</span> : <code class="type">string -> (string list -> <a href="Ast_mapper.html#TYPEmapper">mapper</a>) -> unit</code></pre><div class="info ">
<div class="info-desc">
<p>Apply the <code class="code">register_function</code>. The default behavior is to run the
mapper immediately, taking arguments from the process command
line. This is to support a scenario where a mapper is linked as a
stand-alone executable.</p>
<p>It is possible to overwrite the <code class="code">register_function</code> to define
"-ppx drivers", which combine several mappers in a single process.
Typically, a driver starts by defining <code class="code">register_function</code> to a
custom implementation, then lets ppx rewriters (linked statically
or dynamically) register themselves, and then run all or some of
them. It is also possible to have -ppx drivers apply rewriters to
only specific parts of an AST.</p>
<p>The first argument to <code class="code">register</code> is a symbolic name to be used by
the ppx driver.</p>
</div>
</div>
<h2 id="1_Conveniencefunctionstowritemappers">Convenience functions to write mappers</h2>
<pre><span id="VALmap_opt"><span class="keyword">val</span> map_opt</span> : <code class="type">('a -> 'b) -> 'a option -> 'b option</code></pre>
<pre><span id="VALextension_of_error"><span class="keyword">val</span> extension_of_error</span> : <code class="type"><a href="Location.html#TYPEerror">Location.error</a> -> <a href="Parsetree.html#TYPEextension">Parsetree.extension</a></code></pre><div class="info ">
<div class="info-desc">
<p>Encode an error into an 'ocaml.error' extension node which can be
inserted in a generated Parsetree. The compiler will be
responsible for reporting the error.</p>
</div>
</div>
<pre><span id="VALattribute_of_warning"><span class="keyword">val</span> attribute_of_warning</span> : <code class="type"><a href="Location.html#TYPEt">Location.t</a> -> string -> <a href="Parsetree.html#TYPEattribute">Parsetree.attribute</a></code></pre><div class="info ">
<div class="info-desc">
<p>Encode a warning message into an 'ocaml.ppwarning' attribute which can be
inserted in a generated Parsetree. The compiler will be
responsible for reporting the warning.</p>
</div>
</div>
<h2 id="1_Helperfunctionstocallexternalmappers">Helper functions to call external mappers</h2>
<pre><span id="VALadd_ppx_context_str"><span class="keyword">val</span> add_ppx_context_str</span> : <code class="type">tool_name:string -> <a href="Parsetree.html#TYPEstructure">Parsetree.structure</a> -> <a href="Parsetree.html#TYPEstructure">Parsetree.structure</a></code></pre><div class="info ">
<div class="info-desc">
<p>Extract information from the current environment and encode it
into an attribute which is prepended to the list of structure
items in order to pass the information to an external
processor.</p>
</div>
</div>
<pre><span id="VALadd_ppx_context_sig"><span class="keyword">val</span> add_ppx_context_sig</span> : <code class="type">tool_name:string -> <a href="Parsetree.html#TYPEsignature">Parsetree.signature</a> -> <a href="Parsetree.html#TYPEsignature">Parsetree.signature</a></code></pre><div class="info ">
<div class="info-desc">
<p>Same as <code class="code">add_ppx_context_str</code>, but for signatures.</p>
</div>
</div>
<pre><span id="VALdrop_ppx_context_str"><span class="keyword">val</span> drop_ppx_context_str</span> : <code class="type">restore:bool -> <a href="Parsetree.html#TYPEstructure">Parsetree.structure</a> -> <a href="Parsetree.html#TYPEstructure">Parsetree.structure</a></code></pre><div class="info ">
<div class="info-desc">
<p>Drop the ocaml.ppx.context attribute from a structure. If
<code class="code">restore</code> is true, also restore the associated data in the current
process.</p>
</div>
</div>
<pre><span id="VALdrop_ppx_context_sig"><span class="keyword">val</span> drop_ppx_context_sig</span> : <code class="type">restore:bool -> <a href="Parsetree.html#TYPEsignature">Parsetree.signature</a> -> <a href="Parsetree.html#TYPEsignature">Parsetree.signature</a></code></pre><div class="info ">
<div class="info-desc">
<p>Same as <code class="code">drop_ppx_context_str</code>, but for signatures.</p>
</div>
</div>
<h2 id="1_Cookies">Cookies</h2><p>Cookies are used to pass information from a ppx processor to
a further invocation of itself, when called from the OCaml
toplevel (or other tools that support cookies).</p>
<pre><span id="VALset_cookie"><span class="keyword">val</span> set_cookie</span> : <code class="type">string -> <a href="Parsetree.html#TYPEexpression">Parsetree.expression</a> -> unit</code></pre>
<pre><span id="VALget_cookie"><span class="keyword">val</span> get_cookie</span> : <code class="type">string -> <a href="Parsetree.html#TYPEexpression">Parsetree.expression</a> option</code></pre></body></html>
|