mirror of
https://github.com/ocaml-tracing/ocaml-trace.git
synced 2026-03-09 12:23:32 -04:00
53 lines
16 KiB
HTML
53 lines
16 KiB
HTML
<!DOCTYPE html>
|
||
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Driver (ppxlib.Ppxlib.Driver)</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> » <a href="../../index.html">ppxlib</a> » <a href="../index.html">Ppxlib</a> » Driver</nav><header class="odoc-preamble"><h1>Module <code><span>Ppxlib.Driver</span></code></h1><p>Interaction with the driver, such as getting/seeting cookies, adding arguments.</p><p>The relevant part in the manual is <a href="../../driver.html#driver_execution" title="driver_execution">the section on its execution</a>.</p></header><div class="odoc-content"><div class="odoc-spec"><div class="spec value anchored" id="val-add_arg"><a href="#val-add_arg" class="anchor"></a><code><span><span class="keyword">val</span> add_arg : <span><a href="../../../ocaml/Stdlib/Arg/index.html#type-key">Stdlib.Arg.key</a> <span class="arrow">-></span></span> <span><a href="../../../ocaml/Stdlib/Arg/index.html#type-spec">Stdlib.Arg.spec</a> <span class="arrow">-></span></span> <span><span class="label">doc</span>:string <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p>Add one argument to the command line</p></div></div><div class="odoc-spec"><div class="spec module anchored" id="module-Lint_error"><a href="#module-Lint_error" class="anchor"></a><code><span><span class="keyword">module</span> <a href="Lint_error/index.html">Lint_error</a></span><span> : <span class="keyword">sig</span> ... <span class="keyword">end</span></span></code></div><div class="spec-doc"><p>Error reported by linters</p></div></div><div class="odoc-spec"><div class="spec module anchored" id="module-Cookies"><a href="#module-Cookies" class="anchor"></a><code><span><span class="keyword">module</span> <a href="Cookies/index.html">Cookies</a></span><span> : <span class="keyword">sig</span> ... <span class="keyword">end</span></span></code></div></div><div class="odoc-spec"><div class="spec module anchored" id="module-Instrument"><a href="#module-Instrument" class="anchor"></a><code><span><span class="keyword">module</span> <a href="Instrument/index.html">Instrument</a></span><span> : <span class="keyword">sig</span> ... <span class="keyword">end</span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-register_transformation"><a href="#val-register_transformation" class="anchor"></a><code><span><span class="keyword">val</span> register_transformation :
|
||
<span><span class="optlabel">?extensions</span>:<span><a href="../Extension/index.html#type-t">Extension.t</a> list</span> <span class="arrow">-></span></span>
|
||
<span><span class="optlabel">?rules</span>:<span><a href="../Context_free/Rule/index.html#type-t">Context_free.Rule.t</a> list</span> <span class="arrow">-></span></span>
|
||
<span><span class="optlabel">?enclose_impl</span>:
|
||
<span>(<span><span><a href="../Location/index.html#type-t">Location.t</a> option</span> <span class="arrow">-></span></span>
|
||
<span><a href="../../Astlib/Ast_502/Parsetree/index.html#type-structure_item">Astlib.Ast_502.Parsetree.structure_item</a> list</span>
|
||
* <span><a href="../../Astlib/Ast_502/Parsetree/index.html#type-structure_item">Astlib.Ast_502.Parsetree.structure_item</a> list</span>)</span> <span class="arrow">-></span></span>
|
||
<span><span class="optlabel">?enclose_intf</span>:
|
||
<span>(<span><span><a href="../Location/index.html#type-t">Location.t</a> option</span> <span class="arrow">-></span></span>
|
||
<span><a href="../../Astlib/Ast_502/Parsetree/index.html#type-signature_item">Astlib.Ast_502.Parsetree.signature_item</a> list</span>
|
||
* <span><a href="../../Astlib/Ast_502/Parsetree/index.html#type-signature_item">Astlib.Ast_502.Parsetree.signature_item</a> list</span>)</span> <span class="arrow">-></span></span>
|
||
<span><span class="optlabel">?impl</span>:
|
||
<span>(<span><span><a href="../../Astlib/Ast_502/Parsetree/index.html#type-structure_item">Astlib.Ast_502.Parsetree.structure_item</a> list</span> <span class="arrow">-></span></span>
|
||
<span><a href="../../Astlib/Ast_502/Parsetree/index.html#type-structure_item">Astlib.Ast_502.Parsetree.structure_item</a> list</span>)</span> <span class="arrow">-></span></span>
|
||
<span><span class="optlabel">?intf</span>:
|
||
<span>(<span><span><a href="../../Astlib/Ast_502/Parsetree/index.html#type-signature_item">Astlib.Ast_502.Parsetree.signature_item</a> list</span> <span class="arrow">-></span></span>
|
||
<span><a href="../../Astlib/Ast_502/Parsetree/index.html#type-signature_item">Astlib.Ast_502.Parsetree.signature_item</a> list</span>)</span> <span class="arrow">-></span></span>
|
||
<span><span class="optlabel">?lint_impl</span>:
|
||
<span>(<span><span><a href="../../Astlib/Ast_502/Parsetree/index.html#type-structure_item">Astlib.Ast_502.Parsetree.structure_item</a> list</span> <span class="arrow">-></span></span> <span><a href="Lint_error/index.html#type-t">Lint_error.t</a> list</span>)</span> <span class="arrow">-></span></span>
|
||
<span><span class="optlabel">?lint_intf</span>:
|
||
<span>(<span><span><a href="../../Astlib/Ast_502/Parsetree/index.html#type-signature_item">Astlib.Ast_502.Parsetree.signature_item</a> list</span> <span class="arrow">-></span></span> <span><a href="Lint_error/index.html#type-t">Lint_error.t</a> list</span>)</span> <span class="arrow">-></span></span>
|
||
<span><span class="optlabel">?preprocess_impl</span>:
|
||
<span>(<span><span><a href="../../Astlib/Ast_502/Parsetree/index.html#type-structure_item">Astlib.Ast_502.Parsetree.structure_item</a> list</span> <span class="arrow">-></span></span>
|
||
<span><a href="../../Astlib/Ast_502/Parsetree/index.html#type-structure_item">Astlib.Ast_502.Parsetree.structure_item</a> list</span>)</span> <span class="arrow">-></span></span>
|
||
<span><span class="optlabel">?preprocess_intf</span>:
|
||
<span>(<span><span><a href="../../Astlib/Ast_502/Parsetree/index.html#type-signature_item">Astlib.Ast_502.Parsetree.signature_item</a> list</span> <span class="arrow">-></span></span>
|
||
<span><a href="../../Astlib/Ast_502/Parsetree/index.html#type-signature_item">Astlib.Ast_502.Parsetree.signature_item</a> list</span>)</span> <span class="arrow">-></span></span>
|
||
<span><span class="optlabel">?instrument</span>:<a href="Instrument/index.html#type-t">Instrument.t</a> <span class="arrow">-></span></span>
|
||
<span><span class="optlabel">?aliases</span>:<span>string list</span> <span class="arrow">-></span></span>
|
||
<span>string <span class="arrow">-></span></span>
|
||
unit</span></code></div><div class="spec-doc"><p><code>register_transformation name</code> registers a code transformation.</p><p><code>name</code> is a logical name for the set of transformations (such as <code>sexp_conv</code> or <code>bin_prot</code>). It is mostly used for debugging purposes.</p><p><code>rules</code> is a list of context independent rewriting rules, such as extension point expanders. This is what most code transformation should use.</p><p><code>extensions</code> is a special cases of <code>rules</code> and is deprecated. It is only kept for backward compatibility.</p><p><code>enclose_impl</code> and <code>enclose_intf</code> produces a header and footer for implementation/interface files. They are a special case of <code>impl</code> and <code>intf</code>. The header is placed after any initial module-level attributes; the footer is placed after everything else. Both functions receive a location that denotes all of the items between header and footer, or <code>None</code> if the that list of items is empty.</p><p><code>impl</code> is an optional function that is applied on implementation files and <code>intf</code> is an optional function that is applied on interface files. These two functions are applied on the AST of the whole file. They should only be used when the other mechanism are not enough. For instance if the transformation expands extension points that depend on the context.</p><p><code>lint_impl</code> and <code>lint_intf</code> are applied to the unprocessed source. Errors they return will be reported to the user as preprocessor warnings.</p><p><code>instrument</code> can be used to instrument implementation files. Its transformation is applied to the AST of the whole file. The difference to <code>impl</code> is that you can specify if it should be applied before or after all rewriters defined through <code>rules</code>, <code>impl</code> or <code>intf</code> are applied.</p><p>More information on each phase, and their relative order, can be found in the <a href="../../driver.html#driver_execution" title="driver_execution">manual</a>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-register_transformation_using_ocaml_current_ast"><a href="#val-register_transformation_using_ocaml_current_ast" class="anchor"></a><code><span><span class="keyword">val</span> register_transformation_using_ocaml_current_ast :
|
||
<span><span class="optlabel">?impl</span>:
|
||
<span>(<span><a href="../../Astlib/Ast_501/Parsetree/index.html#type-structure">Ppxlib_ast.Compiler_version.Ast.Parsetree.structure</a> <span class="arrow">-></span></span>
|
||
<a href="../../Astlib/Ast_501/Parsetree/index.html#type-structure">Ppxlib_ast.Compiler_version.Ast.Parsetree.structure</a>)</span> <span class="arrow">-></span></span>
|
||
<span><span class="optlabel">?intf</span>:
|
||
<span>(<span><a href="../../Astlib/Ast_501/Parsetree/index.html#type-signature">Ppxlib_ast.Compiler_version.Ast.Parsetree.signature</a> <span class="arrow">-></span></span>
|
||
<a href="../../Astlib/Ast_501/Parsetree/index.html#type-signature">Ppxlib_ast.Compiler_version.Ast.Parsetree.signature</a>)</span> <span class="arrow">-></span></span>
|
||
<span><span class="optlabel">?aliases</span>:<span>string list</span> <span class="arrow">-></span></span>
|
||
<span>string <span class="arrow">-></span></span>
|
||
unit</span></code></div><div class="spec-doc"><p>Same as <code>register_transformation</code> except that it uses the same AST as the current ocaml compiler.</p><p>This is not the intended way of using driver. This is only for ppx rewriters that are not written using ppxlib but want to export a driver compatible library.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-register_code_transformation"><a href="#val-register_code_transformation" class="anchor"></a><code><span><span class="keyword">val</span> register_code_transformation :
|
||
<span><span class="label">name</span>:string <span class="arrow">-></span></span>
|
||
<span><span class="optlabel">?aliases</span>:<span>string list</span> <span class="arrow">-></span></span>
|
||
<span><span class="label">impl</span>:
|
||
<span>(<span><span><a href="../../Astlib/Ast_502/Parsetree/index.html#type-structure_item">Astlib.Ast_502.Parsetree.structure_item</a> list</span> <span class="arrow">-></span></span>
|
||
<span><a href="../../Astlib/Ast_502/Parsetree/index.html#type-structure_item">Astlib.Ast_502.Parsetree.structure_item</a> list</span>)</span> <span class="arrow">-></span></span>
|
||
<span><span class="label">intf</span>:
|
||
<span>(<span><span><a href="../../Astlib/Ast_502/Parsetree/index.html#type-signature_item">Astlib.Ast_502.Parsetree.signature_item</a> list</span> <span class="arrow">-></span></span>
|
||
<span><a href="../../Astlib/Ast_502/Parsetree/index.html#type-signature_item">Astlib.Ast_502.Parsetree.signature_item</a> list</span>)</span> <span class="arrow">-></span></span>
|
||
unit</span></code></div><div class="spec-doc"><p>Same as:</p><pre class="language-ocaml"><code> register_transformation ~name ~impl ~intf ()</code></pre><ul class="at-tags"><li class="deprecated"><span class="at-tag">deprecated</span> [since 2015-11] use register_transformation instead</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-register_correction"><a href="#val-register_correction" class="anchor"></a><code><span><span class="keyword">val</span> register_correction : <span><span class="label">loc</span>:<a href="../Location/index.html#type-t">Location.t</a> <span class="arrow">-></span></span> <span><span class="label">repl</span>:string <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p>Rewriters might call this function to suggest a correction to the code source. When they do this, the driver will generate a <code>file.ml.ppx-corrected</code> file with the suggested replacement. The build system will then show the diff to the user who is free to accept the correction or not.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-register_process_file_hook"><a href="#val-register_process_file_hook" class="anchor"></a><code><span><span class="keyword">val</span> register_process_file_hook : <span><span>(<span>unit <span class="arrow">-></span></span> unit)</span> <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p>Hook called before processing a file</p></div></div><div class="odoc-spec"><div class="spec module anchored" id="module-V2"><a href="#module-V2" class="anchor"></a><code><span><span class="keyword">module</span> <a href="V2/index.html">V2</a></span><span> : <span class="keyword">sig</span> ... <span class="keyword">end</span></span></code></div></div><div class="odoc-spec"><div class="spec module anchored" id="module-Create_file_property"><a href="#module-Create_file_property" class="anchor"></a><code><span><span class="keyword">module</span> <a href="Create_file_property/index.html">Create_file_property</a></span><span>
|
||
(<a href="Create_file_property/argument-1-Name/index.html">Name</a> : <span class="keyword">sig</span> ... <span class="keyword">end</span>)
|
||
(<a href="Create_file_property/argument-2-T/index.html">T</a> : <a href="../../../sexplib0/Sexplib0/Sexpable/module-type-S/index.html">Stdppx.Sexpable.S</a>) :
|
||
<span class="keyword">sig</span> ... <span class="keyword">end</span></span></code></div><div class="spec-doc"><p>Create a new file property.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-standalone"><a href="#val-standalone" class="anchor"></a><code><span><span class="keyword">val</span> standalone : <span>unit <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p>Suitable for -pp and also usable as a standalone command line tool.</p><p>If the first command line argument is <code>-as-ppx</code> then it will run as a ppx rewriter.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-run_as_ppx_rewriter"><a href="#val-run_as_ppx_rewriter" class="anchor"></a><code><span><span class="keyword">val</span> run_as_ppx_rewriter : <span>unit <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p>Suitable for -ppx. Used only for the public release.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-pretty"><a href="#val-pretty" class="anchor"></a><code><span><span class="keyword">val</span> pretty : <span>unit <span class="arrow">-></span></span> bool</span></code></div><div class="spec-doc"><p>If <code>true</code>, code transformations should avoid generating code that is not strictly necessary, such as extra type annotations.</p></div></div></div></body></html>
|