<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Parser (baguette_sharp.Baguette_sharp.Parser)</title><link rel="stylesheet" href="../../../odoc.css"/><meta charset="utf-8"/><meta name="generator" content="odoc 2.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">baguette_sharp</a> &#x00BB; <a href="../index.html">Baguette_sharp</a> &#x00BB; Parser</nav><header class="odoc-preamble"><h1>Module <code><span>Baguette_sharp.Parser</span></code></h1><p>Parser module</p></header><div class="odoc-content"><p>Exceptions</p><div class="odoc-spec"><div class="spec class" id="class-bag_exception" class="anchored"><a href="#class-bag_exception" class="anchor"></a><code><span><span class="keyword">class</span>  </span><span><a href="class-bag_exception/index.html">bag_exception</a></span><span> : <span>string <span class="arrow">&#45;&gt;</span></span> <span class="keyword">object</span> ... <span class="keyword">end</span></span></code></div></div><div class="odoc-spec"><div class="spec class" id="class-outofbound" class="anchored"><a href="#class-outofbound" class="anchor"></a><code><span><span class="keyword">class</span>  </span><span><a href="class-outofbound/index.html">outofbound</a></span><span> : <span>string <span class="arrow">&#45;&gt;</span></span> <span class="keyword">object</span> ... <span class="keyword">end</span></span></code></div></div><div class="odoc-spec"><div class="spec class" id="class-arg" class="anchored"><a href="#class-arg" class="anchor"></a><code><span><span class="keyword">class</span>  </span><span><a href="class-arg/index.html">arg</a></span><span> : <span>string <span class="arrow">&#45;&gt;</span></span> <span class="keyword">object</span> ... <span class="keyword">end</span></span></code></div></div><div class="odoc-spec"><div class="spec class" id="class-type_error" class="anchored"><a href="#class-type_error" class="anchor"></a><code><span><span class="keyword">class</span>  </span><span><a href="class-type_error/index.html">type_error</a></span><span> : <span>string <span class="arrow">&#45;&gt;</span></span> <span class="keyword">object</span> ... <span class="keyword">end</span></span></code></div></div><div class="odoc-spec"><div class="spec class" id="class-syntax_error" class="anchored"><a href="#class-syntax_error" class="anchor"></a><code><span><span class="keyword">class</span>  </span><span><a href="class-syntax_error/index.html">syntax_error</a></span><span> : <span>string <span class="arrow">&#45;&gt;</span></span> <span class="keyword">object</span> ... <span class="keyword">end</span></span></code></div></div><div class="odoc-spec"><div class="spec type" id="type-arguments" class="anchored"><a href="#type-arguments" class="anchor"></a><code><span><span class="keyword">type</span> arguments</span><span> = </span></code><table><tr id="type-arguments.Str" class="anchored"><td class="def variant constructor"><a href="#type-arguments.Str" class="anchor"></a><code><span>| </span><span><span class="constructor">Str</span> <span class="keyword">of</span> string</span></code></td></tr><tr id="type-arguments.I" class="anchored"><td class="def variant constructor"><a href="#type-arguments.I" class="anchor"></a><code><span>| </span><span><span class="constructor">I</span> <span class="keyword">of</span> int</span></code></td></tr><tr id="type-arguments.Nul" class="anchored"><td class="def variant constructor"><a href="#type-arguments.Nul" class="anchor"></a><code><span>| </span><span><span class="constructor">Nul</span> <span class="keyword">of</span> unit</span></code></td></tr><tr id="type-arguments.D" class="anchored"><td class="def variant constructor"><a href="#type-arguments.D" class="anchor"></a><code><span>| </span><span><span class="constructor">D</span> <span class="keyword">of</span> float</span></code></td></tr><tr id="type-arguments.Bool" class="anchored"><td class="def variant constructor"><a href="#type-arguments.Bool" class="anchor"></a><code><span>| </span><span><span class="constructor">Bool</span> <span class="keyword">of</span> bool</span></code></td></tr></table></div><div class="spec-doc"><p>Type argument: every primitive type the language recognize</p></div></div><div class="odoc-spec"><div class="spec type" id="type-parameters" class="anchored"><a href="#type-parameters" class="anchor"></a><code><span><span class="keyword">type</span> parameters</span><span> = </span></code><table><tr id="type-parameters.CallExpression" class="anchored"><td class="def variant constructor"><a href="#type-parameters.CallExpression" class="anchor"></a><code><span>| </span><span><span class="constructor">CallExpression</span> <span class="keyword">of</span> string</span></code></td></tr><tr id="type-parameters.Argument" class="anchored"><td class="def variant constructor"><a href="#type-parameters.Argument" class="anchor"></a><code><span>| </span><span><span class="constructor">Argument</span> <span class="keyword">of</span> <a href="#type-arguments">arguments</a></span></code></td></tr><tr id="type-parameters.GOTO" class="anchored"><td class="def variant constructor"><a href="#type-parameters.GOTO" class="anchor"></a><code><span>| </span><span><span class="constructor">GOTO</span> <span class="keyword">of</span> string</span></code></td></tr><tr id="type-parameters.Exception" class="anchored"><td class="def variant constructor"><a href="#type-parameters.Exception" class="anchor"></a><code><span>| </span><span><span class="constructor">Exception</span> <span class="keyword">of</span> <a href="class-bag_exception/index.html">bag_exception</a></span></code></td></tr><tr id="type-parameters.Label" class="anchored"><td class="def variant constructor"><a href="#type-parameters.Label" class="anchor"></a><code><span>| </span><span><span class="constructor">Label</span> <span class="keyword">of</span> string</span></code></td></tr><tr id="type-parameters.IF" class="anchored"><td class="def variant constructor"><a href="#type-parameters.IF" class="anchor"></a><code><span>| </span><span><span class="constructor">IF</span></span></code></td></tr><tr id="type-parameters.COND" class="anchored"><td class="def variant constructor"><a href="#type-parameters.COND" class="anchor"></a><code><span>| </span><span><span class="constructor">COND</span></span></code></td></tr><tr id="type-parameters.Array" class="anchored"><td class="def variant constructor"><a href="#type-parameters.Array" class="anchor"></a><code><span>| </span><span><span class="constructor">Array</span></span></code></td></tr><tr id="type-parameters.TBL" class="anchored"><td class="def variant constructor"><a href="#type-parameters.TBL" class="anchor"></a><code><span>| </span><span><span class="constructor">TBL</span> <span class="keyword">of</span> <span><a href="#type-parameters">parameters</a> array</span></span></code></td></tr></table></div><div class="spec-doc"><p>Type parameters: every structure the language recognize</p></div></div><div class="odoc-spec"><div class="spec type" id="type-ast" class="anchored"><a href="#type-ast" class="anchor"></a><code><span><span class="keyword">type</span> <span>'a ast</span></span><span> = </span></code><table><tr id="type-ast.Nil" class="anchored"><td class="def variant constructor"><a href="#type-ast.Nil" class="anchor"></a><code><span>| </span><span><span class="constructor">Nil</span></span></code></td></tr><tr id="type-ast.Node" class="anchored"><td class="def variant constructor"><a href="#type-ast.Node" class="anchor"></a><code><span>| </span><span><span class="constructor">Node</span> <span class="keyword">of</span> <span class="type-var">'a</span> * <span><span><span class="type-var">'a</span> <a href="#type-ast">ast</a></span> list</span></span></code></td></tr></table></div><div class="spec-doc"><p>Type AST</p></div></div><p>Parsing methods</p><div class="odoc-spec"><div class="spec value" id="val-parse_string_rec" class="anchored"><a href="#val-parse_string_rec" class="anchor"></a><code><span><span class="keyword">val</span> parse_string_rec : <span><span><a href="../Token/index.html#type-token_type">Token.token_type</a> list</span> <span class="arrow">&#45;&gt;</span></span> string * <span><a href="../Token/index.html#type-token_type">Token.token_type</a> list</span></span></code></div><div class="spec-doc"><p>Parse a string recursively until it encounters a closing quote</p></div></div><div class="odoc-spec"><div class="spec value" id="val-parse_line" class="anchored"><a href="#val-parse_line" class="anchor"></a><code><span><span class="keyword">val</span> parse_line : 
  <span><span><a href="../Token/index.html#type-token_type">Token.token_type</a> list</span> <span class="arrow">&#45;&gt;</span></span>
  <span><a href="../Token/index.html#type-token_type">Token.token_type</a> list</span> * <span><span><a href="#type-parameters">parameters</a> <a href="#type-ast">ast</a></span> list</span></span></code></div><div class="spec-doc"><p>Parse a line (a list of tokens) into a a list of ASTs</p></div></div><div class="odoc-spec"><div class="spec value" id="val-parse_file" class="anchored"><a href="#val-parse_file" class="anchor"></a><code><span><span class="keyword">val</span> parse_file : <span><span><a href="../Token/index.html#type-token_type">Token.token_type</a> list</span> <span class="arrow">&#45;&gt;</span></span> <span><span><a href="#type-parameters">parameters</a> <a href="#type-ast">ast</a></span> list</span></span></code></div><div class="spec-doc"><p>Parse a file using parse line</p></div></div><p>Parameters/Arguments utility functions</p><div class="odoc-spec"><div class="spec value" id="val-create_int_argument" class="anchored"><a href="#val-create_int_argument" class="anchor"></a><code><span><span class="keyword">val</span> create_int_argument : <span>int <span class="arrow">&#45;&gt;</span></span> <a href="#type-parameters">parameters</a></span></code></div><div class="spec-doc"><p>Creates an integer argument and wraps it into a parameter</p></div></div><div class="odoc-spec"><div class="spec value" id="val-create_float_argument" class="anchored"><a href="#val-create_float_argument" class="anchor"></a><code><span><span class="keyword">val</span> create_float_argument : <span>float <span class="arrow">&#45;&gt;</span></span> <a href="#type-parameters">parameters</a></span></code></div><div class="spec-doc"><p>Creates a float argument and wraps it into a parameter</p></div></div><div class="odoc-spec"><div class="spec value" id="val-create_bool_argument" class="anchored"><a href="#val-create_bool_argument" class="anchor"></a><code><span><span class="keyword">val</span> create_bool_argument : <span>bool <span class="arrow">&#45;&gt;</span></span> <a href="#type-parameters">parameters</a></span></code></div><div class="spec-doc"><p>Creates a boolean argument and wraps it into a parameter</p></div></div><div class="odoc-spec"><div class="spec value" id="val-create_string_argument" class="anchored"><a href="#val-create_string_argument" class="anchor"></a><code><span><span class="keyword">val</span> create_string_argument : <span>string <span class="arrow">&#45;&gt;</span></span> <a href="#type-parameters">parameters</a></span></code></div><div class="spec-doc"><p>Creates a string argument and wraps it into a parameter</p></div></div><p>Parameters algebra function</p><div class="odoc-spec"><div class="spec value" id="val-add_numbers" class="anchored"><a href="#val-add_numbers" class="anchor"></a><code><span><span class="keyword">val</span> add_numbers : <span><a href="#type-parameters">parameters</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="#type-parameters">parameters</a> <span class="arrow">&#45;&gt;</span></span> <a href="#type-parameters">parameters</a></span></code></div><div class="spec-doc"><p>Adds two parameters</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <span class="value">a</span> <p>baguette exception if the type are non-summable</p></li></ul></div></div><div class="odoc-spec"><div class="spec value" id="val-equality" class="anchored"><a href="#val-equality" class="anchor"></a><code><span><span class="keyword">val</span> equality : <span><a href="#type-parameters">parameters</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="#type-parameters">parameters</a> <span class="arrow">&#45;&gt;</span></span> <a href="#type-parameters">parameters</a></span></code></div><div class="spec-doc"><p>Checks for equality between two parameters</p></div></div><div class="odoc-spec"><div class="spec value" id="val-inferior_large" class="anchored"><a href="#val-inferior_large" class="anchor"></a><code><span><span class="keyword">val</span> inferior_large : <span><a href="#type-parameters">parameters</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="#type-parameters">parameters</a> <span class="arrow">&#45;&gt;</span></span> <a href="#type-parameters">parameters</a></span></code></div><div class="spec-doc"><p>Checks for the &lt;= between two parameters</p></div></div><div class="odoc-spec"><div class="spec value" id="val-inferior" class="anchored"><a href="#val-inferior" class="anchor"></a><code><span><span class="keyword">val</span> inferior : <span><a href="#type-parameters">parameters</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="#type-parameters">parameters</a> <span class="arrow">&#45;&gt;</span></span> <a href="#type-parameters">parameters</a></span></code></div><div class="spec-doc"><p>Checks for the &lt; between two parameters</p></div></div><div class="odoc-spec"><div class="spec value" id="val-superior_large" class="anchored"><a href="#val-superior_large" class="anchor"></a><code><span><span class="keyword">val</span> superior_large : <span><a href="#type-parameters">parameters</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="#type-parameters">parameters</a> <span class="arrow">&#45;&gt;</span></span> <a href="#type-parameters">parameters</a></span></code></div><div class="spec-doc"><p>Checks for the &gt;= between two parameters</p></div></div><div class="odoc-spec"><div class="spec value" id="val-superior" class="anchored"><a href="#val-superior" class="anchor"></a><code><span><span class="keyword">val</span> superior : <span><a href="#type-parameters">parameters</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="#type-parameters">parameters</a> <span class="arrow">&#45;&gt;</span></span> <a href="#type-parameters">parameters</a></span></code></div><div class="spec-doc"><p>Checks for the &gt; between two parameters</p></div></div><div class="odoc-spec"><div class="spec value" id="val-mult_numbers" class="anchored"><a href="#val-mult_numbers" class="anchor"></a><code><span><span class="keyword">val</span> mult_numbers : <span><a href="#type-parameters">parameters</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="#type-parameters">parameters</a> <span class="arrow">&#45;&gt;</span></span> <a href="#type-parameters">parameters</a></span></code></div><div class="spec-doc"><p>Multiply two numbers</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <span class="value">a</span> <p>baguette sharp type error if the arguments are not numbers</p></li></ul></div></div><div class="odoc-spec"><div class="spec value" id="val-expn" class="anchored"><a href="#val-expn" class="anchor"></a><code><span><span class="keyword">val</span> expn : <span><a href="#type-parameters">parameters</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="#type-parameters">parameters</a> <span class="arrow">&#45;&gt;</span></span> <a href="#type-parameters">parameters</a></span></code></div><div class="spec-doc"><p>Exponentiate a^b</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <span class="value">a</span> <p>baguette sharp type error if the arguments are not numbers</p></li></ul></div></div><div class="odoc-spec"><div class="spec value" id="val-divide_numbers" class="anchored"><a href="#val-divide_numbers" class="anchor"></a><code><span><span class="keyword">val</span> divide_numbers : <span><a href="#type-parameters">parameters</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="#type-parameters">parameters</a> <span class="arrow">&#45;&gt;</span></span> <a href="#type-parameters">parameters</a></span></code></div><div class="spec-doc"><p>Divide a/b</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <span class="value">a</span> <p>baguette sharp type error if the arguments are not numbers</p></li></ul></div></div><div class="odoc-spec"><div class="spec value" id="val-substract_numbers" class="anchored"><a href="#val-substract_numbers" class="anchor"></a><code><span><span class="keyword">val</span> substract_numbers : <span><a href="#type-parameters">parameters</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="#type-parameters">parameters</a> <span class="arrow">&#45;&gt;</span></span> <a href="#type-parameters">parameters</a></span></code></div><div class="spec-doc"><p>Subtract two number</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <span class="value">a</span> <p>baguette sharp type error if the arguments are not numbers</p></li></ul></div></div><div class="odoc-spec"><div class="spec value" id="val-apply_binary_operator" class="anchored"><a href="#val-apply_binary_operator" class="anchor"></a><code><span><span class="keyword">val</span> apply_binary_operator : 
  <span><span>( <span>bool <span class="arrow">&#45;&gt;</span></span> <span>bool <span class="arrow">&#45;&gt;</span></span> bool )</span> <span class="arrow">&#45;&gt;</span></span>
  <span><a href="#type-parameters">parameters</a> <span class="arrow">&#45;&gt;</span></span>
  <span><a href="#type-parameters">parameters</a> <span class="arrow">&#45;&gt;</span></span>
  <a href="#type-parameters">parameters</a></span></code></div><div class="spec-doc"><p>Apply a binary operator for two booleans</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <span class="value">a</span> <p>baguette sharp type error if the arguments are not booleans</p></li></ul></div></div><div class="odoc-spec"><div class="spec value" id="val-apply_unary_operator" class="anchored"><a href="#val-apply_unary_operator" class="anchor"></a><code><span><span class="keyword">val</span> apply_unary_operator : <span><span>( <span>bool <span class="arrow">&#45;&gt;</span></span> bool )</span> <span class="arrow">&#45;&gt;</span></span> <span><a href="#type-parameters">parameters</a> <span class="arrow">&#45;&gt;</span></span> <a href="#type-parameters">parameters</a></span></code></div><div class="spec-doc"><p>Apply an unary operator on a boolean</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <span class="value">a</span> <p>baguette sharp type error if the argument is not a boolean</p></li></ul></div></div><p>Printing utility</p><div class="odoc-spec"><div class="spec value" id="val-print_argument" class="anchored"><a href="#val-print_argument" class="anchor"></a><code><span><span class="keyword">val</span> print_argument : <span><a href="#type-arguments">arguments</a> <span class="arrow">&#45;&gt;</span></span> string</span></code></div><div class="spec-doc"><p>Transforms an argument into a string <code>Type: value</code></p></div></div><div class="odoc-spec"><div class="spec value" id="val-print_lit_argument" class="anchored"><a href="#val-print_lit_argument" class="anchor"></a><code><span><span class="keyword">val</span> print_lit_argument : <span><a href="#type-arguments">arguments</a> <span class="arrow">&#45;&gt;</span></span> string</span></code></div><div class="spec-doc"><p>Transforms only the value of an argument</p></div></div><div class="odoc-spec"><div class="spec value" id="val-print_argument_for_repl" class="anchored"><a href="#val-print_argument_for_repl" class="anchor"></a><code><span><span class="keyword">val</span> print_argument_for_repl : <span><a href="#type-arguments">arguments</a> <span class="arrow">&#45;&gt;</span></span> string</span></code></div><div class="spec-doc"><p>Transform an argument into a string for the REPL</p></div></div><div class="odoc-spec"><div class="spec value" id="val-print_parameter" class="anchored"><a href="#val-print_parameter" class="anchor"></a><code><span><span class="keyword">val</span> print_parameter : <span>?fortbl:bool <span class="arrow">&#45;&gt;</span></span> <span><a href="#type-parameters">parameters</a> <span class="arrow">&#45;&gt;</span></span> string</span></code></div><div class="spec-doc"><p>Transforms a parameter into a string</p><ul class="at-tags"><li class="parameter"><span class="at-tag">parameter</span> <span class="value">fortbl</span> <p>specify if we are printing an array to simplify the output</p></li></ul></div></div><div class="odoc-spec"><div class="spec value" id="val-print_pretty_arguments" class="anchored"><a href="#val-print_pretty_arguments" class="anchor"></a><code><span><span class="keyword">val</span> print_pretty_arguments : <span><span><a href="#type-parameters">parameters</a> list</span> <span class="arrow">&#45;&gt;</span></span> string</span></code></div><div class="spec-doc"><p>Transform a list of parameters into a string representation</p></div></div><div class="odoc-spec"><div class="spec value" id="val-print_pretty_node" class="anchored"><a href="#val-print_pretty_node" class="anchor"></a><code><span><span class="keyword">val</span> print_pretty_node : <span><span><a href="#type-parameters">parameters</a> <a href="#type-ast">ast</a></span> <span class="arrow">&#45;&gt;</span></span> string</span></code></div><div class="spec-doc"><p>Pretty-print (transforms into a string) an AST</p></div></div></div></body></html>