mirror of
https://github.com/ocaml-tracing/ocaml-trace.git
synced 2026-03-09 12:23:32 -04:00
104 lines
No EOL
21 KiB
HTML
104 lines
No EOL
21 KiB
HTML
<!DOCTYPE html>
|
||
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Rule (ppxlib.Ppxlib.Context_free.Rule)</title><link rel="stylesheet" href="../../../../_odoc-theme/odoc.css"/><meta charset="utf-8"/><meta name="generator" content="odoc 2.2.2"/><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">ppxlib</a> » <a href="../../index.html">Ppxlib</a> » <a href="../index.html">Context_free</a> » Rule</nav><header class="odoc-preamble"><h1>Module <code><span>Context_free.Rule</span></code></h1><p>Local rewriting rules.</p><p>This module lets you define local rewriting rules, such as extension point expanders. It is not completely generic and you cannot define any kind of rewriting, it currently focuses on what is commonly used. New scheme can be added on demand.</p><p>We have some ideas to make this fully generic, but this hasn't been a priority so far.</p></header><div class="odoc-content"><div class="odoc-spec"><div class="spec type anchored" id="type-t"><a href="#type-t" class="anchor"></a><code><span><span class="keyword">type</span> t</span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-extension"><a href="#val-extension" class="anchor"></a><code><span><span class="keyword">val</span> extension : <span><a href="../../Extension/index.html#type-t">Extension.t</a> <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>Rewrite an extension point</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-special_function"><a href="#val-special_function" class="anchor"></a><code><span><span class="keyword">val</span> special_function :
|
||
<span>string <span class="arrow">-></span></span>
|
||
<span><span>(<span><a href="../../../Astlib/Ast_500/Parsetree/index.html#type-expression">Astlib.Ast_500.Parsetree.expression</a> <span class="arrow">-></span></span>
|
||
<span><a href="../../../Astlib/Ast_500/Parsetree/index.html#type-expression">Astlib.Ast_500.Parsetree.expression</a> option</span>)</span> <span class="arrow">-></span></span>
|
||
<a href="#type-t">t</a></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-special_function'"><a href="#val-special_function'" class="anchor"></a><code><span><span class="keyword">val</span> special_function' :
|
||
<span><a href="../../Longident/index.html#type-t">Longident.t</a> <span class="arrow">-></span></span>
|
||
<span><span>(<span><a href="../../../Astlib/Ast_500/Parsetree/index.html#type-expression">Astlib.Ast_500.Parsetree.expression</a> <span class="arrow">-></span></span>
|
||
<span><a href="../../../Astlib/Ast_500/Parsetree/index.html#type-expression">Astlib.Ast_500.Parsetree.expression</a> option</span>)</span> <span class="arrow">-></span></span>
|
||
<a href="#type-t">t</a></span></code></div><div class="spec-doc"><p><code>special_function id expand</code> is a rule to rewrite a function call at parsing time. <code>id</code> is the identifier to match on and <code>expand</code> is used to expand the full function application (it gets the Pexp_apply node). If the function is found in the tree without being applied, <code>expand</code> gets only the identifier (Pexp_ident node) so you should handle both cases.</p><p>If <code>id</code> is an operator identifier and contains dots, it should be parenthesized (e.g. <code>"(+.+)"</code>). Another option is to use the <code>special_function'</code> variant which takes directly a <a href="../../Longident/index.html#type-t"><code>Longident.t</code></a> argument.</p><p><code>expand</code> must decide whether the expression it receive can be rewritten or not. Especially ppxlib makes the assumption that <code>expand</code> is idempotent. It will loop if it is not.</p></div></div><div class="odoc-spec"><div class="spec module anchored" id="module-Constant_kind"><a href="#module-Constant_kind" class="anchor"></a><code><span><span class="keyword">module</span> <a href="Constant_kind/index.html">Constant_kind</a></span><span> : <span class="keyword">sig</span> ... <span class="keyword">end</span></span></code></div><div class="spec-doc"><p>Used for the <code>constant</code> function.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-constant"><a href="#val-constant" class="anchor"></a><code><span><span class="keyword">val</span> constant :
|
||
<span><a href="Constant_kind/index.html#type-t">Constant_kind.t</a> <span class="arrow">-></span></span>
|
||
<span>char <span class="arrow">-></span></span>
|
||
<span><span>(<span><a href="../../Location/index.html#type-t">Location.t</a> <span class="arrow">-></span></span> <span>string <span class="arrow">-></span></span> <a href="../../../Astlib/Ast_500/Parsetree/index.html#type-expression">Ppxlib_ast.Parsetree.expression</a>)</span> <span class="arrow">-></span></span>
|
||
<a href="#type-t">t</a></span></code></div><div class="spec-doc"><p><code>constant kind suffix expander</code> Registers an extension for transforming constants literals, based on the suffix character.</p></div></div><p>The rest of this API is for rewriting rules that apply when a certain attribute is present. The API is not complete and is currently only enough to implement deriving.</p><div class="odoc-spec"><div class="spec type anchored" id="type-attr_group_inline"><a href="#type-attr_group_inline" class="anchor"></a><code><span><span class="keyword">type</span> <span>('a, 'b, 'c) attr_group_inline</span></span><span> =
|
||
<span><span><span>(<span class="type-var">'b</span>, <span class="type-var">'c</span>)</span> <a href="../../Attribute/index.html#type-t">Attribute.t</a></span> <span class="arrow">-></span></span>
|
||
<span><span>(<span>ctxt:<a href="../../Expansion_context/Deriver/index.html#type-t">Expansion_context.Deriver.t</a> <span class="arrow">-></span></span>
|
||
<span><a href="../../../Astlib/Ast_500/Asttypes/index.html#type-rec_flag">Ppxlib_ast.Asttypes.rec_flag</a> <span class="arrow">-></span></span>
|
||
<span><span><span class="type-var">'b</span> list</span> <span class="arrow">-></span></span>
|
||
<span><span><span><span class="type-var">'c</span> option</span> list</span> <span class="arrow">-></span></span>
|
||
<span><span class="type-var">'a</span> list</span>)</span> <span class="arrow">-></span></span>
|
||
<a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>Match the attribute on a group of items, such as a group of recursive type definitions (Pstr_type, Psig_type). The expander will be triggered if any of the item has the attribute. The expander is called as follow:</p><p><code>expand ~loc ~path rec_flag items values</code></p><p>where <code>values</code> is the list of values associated to the attribute for each item in <code>items</code>. <code>expand</code> must return a list of element to add after the group. For instance a list of structure item to add after a group of type definitions.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-attr_str_type_decl"><a href="#val-attr_str_type_decl" class="anchor"></a><code><span><span class="keyword">val</span> attr_str_type_decl :
|
||
<span><span>(<a href="../../../Astlib/Ast_500/Parsetree/index.html#type-structure_item">Astlib.Ast_500.Parsetree.structure_item</a>,
|
||
<a href="../../../Astlib/Ast_500/Parsetree/index.html#type-type_declaration">Astlib.Ast_500.Parsetree.type_declaration</a>,
|
||
<span class="type-var">_</span>)</span>
|
||
<a href="#type-attr_group_inline">attr_group_inline</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-attr_sig_type_decl"><a href="#val-attr_sig_type_decl" class="anchor"></a><code><span><span class="keyword">val</span> attr_sig_type_decl :
|
||
<span><span>(<a href="../../../Astlib/Ast_500/Parsetree/index.html#type-signature_item">Astlib.Ast_500.Parsetree.signature_item</a>,
|
||
<a href="../../../Astlib/Ast_500/Parsetree/index.html#type-type_declaration">Astlib.Ast_500.Parsetree.type_declaration</a>,
|
||
<span class="type-var">_</span>)</span>
|
||
<a href="#type-attr_group_inline">attr_group_inline</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-attr_str_type_decl_expect"><a href="#val-attr_str_type_decl_expect" class="anchor"></a><code><span><span class="keyword">val</span> attr_str_type_decl_expect :
|
||
<span><span>(<a href="../../../Astlib/Ast_500/Parsetree/index.html#type-structure_item">Astlib.Ast_500.Parsetree.structure_item</a>,
|
||
<a href="../../../Astlib/Ast_500/Parsetree/index.html#type-type_declaration">Astlib.Ast_500.Parsetree.type_declaration</a>,
|
||
<span class="type-var">_</span>)</span>
|
||
<a href="#type-attr_group_inline">attr_group_inline</a></span></span></code></div><div class="spec-doc"><p>The _expect variants are for producing code that is compared to what the user wrote in the source code.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-attr_sig_type_decl_expect"><a href="#val-attr_sig_type_decl_expect" class="anchor"></a><code><span><span class="keyword">val</span> attr_sig_type_decl_expect :
|
||
<span><span>(<a href="../../../Astlib/Ast_500/Parsetree/index.html#type-signature_item">Astlib.Ast_500.Parsetree.signature_item</a>,
|
||
<a href="../../../Astlib/Ast_500/Parsetree/index.html#type-type_declaration">Astlib.Ast_500.Parsetree.type_declaration</a>,
|
||
<span class="type-var">_</span>)</span>
|
||
<a href="#type-attr_group_inline">attr_group_inline</a></span></span></code></div></div><div class="odoc-spec"><div class="spec type anchored" id="type-attr_inline"><a href="#type-attr_inline" class="anchor"></a><code><span><span class="keyword">type</span> <span>('a, 'b, 'c) attr_inline</span></span><span> =
|
||
<span><span><span>(<span class="type-var">'b</span>, <span class="type-var">'c</span>)</span> <a href="../../Attribute/index.html#type-t">Attribute.t</a></span> <span class="arrow">-></span></span>
|
||
<span><span>(<span>ctxt:<a href="../../Expansion_context/Deriver/index.html#type-t">Expansion_context.Deriver.t</a> <span class="arrow">-></span></span> <span><span class="type-var">'b</span> <span class="arrow">-></span></span> <span><span class="type-var">'c</span> <span class="arrow">-></span></span> <span><span class="type-var">'a</span> list</span>)</span> <span class="arrow">-></span></span>
|
||
<a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>Same as <code>attr_group_inline</code> but for elements that are not part of a group, such as exceptions and type extensions</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-attr_str_module_type_decl"><a href="#val-attr_str_module_type_decl" class="anchor"></a><code><span><span class="keyword">val</span> attr_str_module_type_decl :
|
||
<span><span>(<a href="../../../Astlib/Ast_500/Parsetree/index.html#type-structure_item">Astlib.Ast_500.Parsetree.structure_item</a>,
|
||
<a href="../../../Astlib/Ast_500/Parsetree/index.html#type-module_type_declaration">Astlib.Ast_500.Parsetree.module_type_declaration</a>,
|
||
<span class="type-var">_</span>)</span>
|
||
<a href="#type-attr_inline">attr_inline</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-attr_sig_module_type_decl"><a href="#val-attr_sig_module_type_decl" class="anchor"></a><code><span><span class="keyword">val</span> attr_sig_module_type_decl :
|
||
<span><span>(<a href="../../../Astlib/Ast_500/Parsetree/index.html#type-signature_item">Astlib.Ast_500.Parsetree.signature_item</a>,
|
||
<a href="../../../Astlib/Ast_500/Parsetree/index.html#type-module_type_declaration">Astlib.Ast_500.Parsetree.module_type_declaration</a>,
|
||
<span class="type-var">_</span>)</span>
|
||
<a href="#type-attr_inline">attr_inline</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-attr_str_module_type_decl_expect"><a href="#val-attr_str_module_type_decl_expect" class="anchor"></a><code><span><span class="keyword">val</span> attr_str_module_type_decl_expect :
|
||
<span><span>(<a href="../../../Astlib/Ast_500/Parsetree/index.html#type-structure_item">Astlib.Ast_500.Parsetree.structure_item</a>,
|
||
<a href="../../../Astlib/Ast_500/Parsetree/index.html#type-module_type_declaration">Astlib.Ast_500.Parsetree.module_type_declaration</a>,
|
||
<span class="type-var">_</span>)</span>
|
||
<a href="#type-attr_inline">attr_inline</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-attr_sig_module_type_decl_expect"><a href="#val-attr_sig_module_type_decl_expect" class="anchor"></a><code><span><span class="keyword">val</span> attr_sig_module_type_decl_expect :
|
||
<span><span>(<a href="../../../Astlib/Ast_500/Parsetree/index.html#type-signature_item">Astlib.Ast_500.Parsetree.signature_item</a>,
|
||
<a href="../../../Astlib/Ast_500/Parsetree/index.html#type-module_type_declaration">Astlib.Ast_500.Parsetree.module_type_declaration</a>,
|
||
<span class="type-var">_</span>)</span>
|
||
<a href="#type-attr_inline">attr_inline</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-attr_str_type_ext"><a href="#val-attr_str_type_ext" class="anchor"></a><code><span><span class="keyword">val</span> attr_str_type_ext :
|
||
<span><span>(<a href="../../../Astlib/Ast_500/Parsetree/index.html#type-structure_item">Astlib.Ast_500.Parsetree.structure_item</a>,
|
||
<a href="../../../Astlib/Ast_500/Parsetree/index.html#type-type_extension">Astlib.Ast_500.Parsetree.type_extension</a>,
|
||
<span class="type-var">_</span>)</span>
|
||
<a href="#type-attr_inline">attr_inline</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-attr_sig_type_ext"><a href="#val-attr_sig_type_ext" class="anchor"></a><code><span><span class="keyword">val</span> attr_sig_type_ext :
|
||
<span><span>(<a href="../../../Astlib/Ast_500/Parsetree/index.html#type-signature_item">Astlib.Ast_500.Parsetree.signature_item</a>,
|
||
<a href="../../../Astlib/Ast_500/Parsetree/index.html#type-type_extension">Astlib.Ast_500.Parsetree.type_extension</a>,
|
||
<span class="type-var">_</span>)</span>
|
||
<a href="#type-attr_inline">attr_inline</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-attr_str_type_ext_expect"><a href="#val-attr_str_type_ext_expect" class="anchor"></a><code><span><span class="keyword">val</span> attr_str_type_ext_expect :
|
||
<span><span>(<a href="../../../Astlib/Ast_500/Parsetree/index.html#type-structure_item">Astlib.Ast_500.Parsetree.structure_item</a>,
|
||
<a href="../../../Astlib/Ast_500/Parsetree/index.html#type-type_extension">Astlib.Ast_500.Parsetree.type_extension</a>,
|
||
<span class="type-var">_</span>)</span>
|
||
<a href="#type-attr_inline">attr_inline</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-attr_sig_type_ext_expect"><a href="#val-attr_sig_type_ext_expect" class="anchor"></a><code><span><span class="keyword">val</span> attr_sig_type_ext_expect :
|
||
<span><span>(<a href="../../../Astlib/Ast_500/Parsetree/index.html#type-signature_item">Astlib.Ast_500.Parsetree.signature_item</a>,
|
||
<a href="../../../Astlib/Ast_500/Parsetree/index.html#type-type_extension">Astlib.Ast_500.Parsetree.type_extension</a>,
|
||
<span class="type-var">_</span>)</span>
|
||
<a href="#type-attr_inline">attr_inline</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-attr_str_exception"><a href="#val-attr_str_exception" class="anchor"></a><code><span><span class="keyword">val</span> attr_str_exception :
|
||
<span><span>(<a href="../../../Astlib/Ast_500/Parsetree/index.html#type-structure_item">Astlib.Ast_500.Parsetree.structure_item</a>,
|
||
<a href="../../../Astlib/Ast_500/Parsetree/index.html#type-type_exception">Astlib.Ast_500.Parsetree.type_exception</a>,
|
||
<span class="type-var">_</span>)</span>
|
||
<a href="#type-attr_inline">attr_inline</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-attr_sig_exception"><a href="#val-attr_sig_exception" class="anchor"></a><code><span><span class="keyword">val</span> attr_sig_exception :
|
||
<span><span>(<a href="../../../Astlib/Ast_500/Parsetree/index.html#type-signature_item">Astlib.Ast_500.Parsetree.signature_item</a>,
|
||
<a href="../../../Astlib/Ast_500/Parsetree/index.html#type-type_exception">Astlib.Ast_500.Parsetree.type_exception</a>,
|
||
<span class="type-var">_</span>)</span>
|
||
<a href="#type-attr_inline">attr_inline</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-attr_str_exception_expect"><a href="#val-attr_str_exception_expect" class="anchor"></a><code><span><span class="keyword">val</span> attr_str_exception_expect :
|
||
<span><span>(<a href="../../../Astlib/Ast_500/Parsetree/index.html#type-structure_item">Astlib.Ast_500.Parsetree.structure_item</a>,
|
||
<a href="../../../Astlib/Ast_500/Parsetree/index.html#type-type_exception">Astlib.Ast_500.Parsetree.type_exception</a>,
|
||
<span class="type-var">_</span>)</span>
|
||
<a href="#type-attr_inline">attr_inline</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-attr_sig_exception_expect"><a href="#val-attr_sig_exception_expect" class="anchor"></a><code><span><span class="keyword">val</span> attr_sig_exception_expect :
|
||
<span><span>(<a href="../../../Astlib/Ast_500/Parsetree/index.html#type-signature_item">Astlib.Ast_500.Parsetree.signature_item</a>,
|
||
<a href="../../../Astlib/Ast_500/Parsetree/index.html#type-type_exception">Astlib.Ast_500.Parsetree.type_exception</a>,
|
||
<span class="type-var">_</span>)</span>
|
||
<a href="#type-attr_inline">attr_inline</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-attr_str_class_type_decl"><a href="#val-attr_str_class_type_decl" class="anchor"></a><code><span><span class="keyword">val</span> attr_str_class_type_decl :
|
||
<span><span>(<a href="../../../Astlib/Ast_500/Parsetree/index.html#type-structure_item">Astlib.Ast_500.Parsetree.structure_item</a>,
|
||
<span><a href="../../../Astlib/Ast_500/Parsetree/index.html#type-class_type">Astlib.Ast_500.Parsetree.class_type</a> <a href="../../../Astlib/Ast_500/Parsetree/index.html#type-class_infos">Astlib.Ast_500.Parsetree.class_infos</a></span>,
|
||
<span class="type-var">_</span>)</span>
|
||
<a href="#type-attr_group_inline">attr_group_inline</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-attr_sig_class_type_decl"><a href="#val-attr_sig_class_type_decl" class="anchor"></a><code><span><span class="keyword">val</span> attr_sig_class_type_decl :
|
||
<span><span>(<a href="../../../Astlib/Ast_500/Parsetree/index.html#type-signature_item">Astlib.Ast_500.Parsetree.signature_item</a>,
|
||
<span><a href="../../../Astlib/Ast_500/Parsetree/index.html#type-class_type">Astlib.Ast_500.Parsetree.class_type</a> <a href="../../../Astlib/Ast_500/Parsetree/index.html#type-class_infos">Astlib.Ast_500.Parsetree.class_infos</a></span>,
|
||
<span class="type-var">_</span>)</span>
|
||
<a href="#type-attr_group_inline">attr_group_inline</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-attr_str_class_type_decl_expect"><a href="#val-attr_str_class_type_decl_expect" class="anchor"></a><code><span><span class="keyword">val</span> attr_str_class_type_decl_expect :
|
||
<span><span>(<a href="../../../Astlib/Ast_500/Parsetree/index.html#type-structure_item">Astlib.Ast_500.Parsetree.structure_item</a>,
|
||
<span><a href="../../../Astlib/Ast_500/Parsetree/index.html#type-class_type">Astlib.Ast_500.Parsetree.class_type</a> <a href="../../../Astlib/Ast_500/Parsetree/index.html#type-class_infos">Astlib.Ast_500.Parsetree.class_infos</a></span>,
|
||
<span class="type-var">_</span>)</span>
|
||
<a href="#type-attr_group_inline">attr_group_inline</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-attr_sig_class_type_decl_expect"><a href="#val-attr_sig_class_type_decl_expect" class="anchor"></a><code><span><span class="keyword">val</span> attr_sig_class_type_decl_expect :
|
||
<span><span>(<a href="../../../Astlib/Ast_500/Parsetree/index.html#type-signature_item">Astlib.Ast_500.Parsetree.signature_item</a>,
|
||
<span><a href="../../../Astlib/Ast_500/Parsetree/index.html#type-class_type">Astlib.Ast_500.Parsetree.class_type</a> <a href="../../../Astlib/Ast_500/Parsetree/index.html#type-class_infos">Astlib.Ast_500.Parsetree.class_infos</a></span>,
|
||
<span class="type-var">_</span>)</span>
|
||
<a href="#type-attr_group_inline">attr_group_inline</a></span></span></code></div></div></div></body></html> |