<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <title>Madin</title>
    <subtitle>Madin blog: Software and other things I don&#39;t understand</subtitle>
    <link rel="self" type="application/atom+xml" href="https://madin.dev/atom.xml"/>
    <link rel="alternate" type="text/html" href="https://madin.dev"/>
    <generator uri="https://www.getzola.org/">Zola</generator>
    <updated>2024-01-05T00:00:00+00:00</updated>
    <id>https://madin.dev/atom.xml</id>
    <entry xml:lang="en">
        <title>Favorite Books</title>
        <published>2024-01-05T00:00:00+00:00</published>
        <updated>2024-01-05T00:00:00+00:00</updated>
        
        <author>
          <name>Ibrahim Najjar</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://madin.dev/fav-books/"/>
        <id>https://madin.dev/fav-books/</id>
        
        <content type="html" xml:base="https://madin.dev/fav-books/"></content>
        
    </entry>
    <entry xml:lang="en">
        <title>Favorite Quotes</title>
        <published>2023-12-30T00:00:00+00:00</published>
        <updated>2023-12-30T00:00:00+00:00</updated>
        
        <author>
          <name>Ibrahim Najjar</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://madin.dev/fav-quotes/"/>
        <id>https://madin.dev/fav-quotes/</id>
        
        <content type="html" xml:base="https://madin.dev/fav-quotes/">&lt;blockquote&gt;
&lt;p&gt;“Computer Science is the continuation of logic by other means”&lt;/p&gt;
&lt;p&gt;– Georg Gottlob&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;“Young man, in mathematics you don’t understand things. You just get used to them”&lt;/p&gt;
&lt;p&gt;– John von Neumann&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;“God does not play dice with the universe”&lt;/p&gt;
&lt;p&gt;– Albert Einstein&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Algebra is the offer made by the devil to the mathematician. The devil says: “I will give you this powerful machine, it will answer any question you like. All you need to do is give me your soul: give up geometry and you will have this marvellous machine.”&lt;/p&gt;
&lt;p&gt;– Sir Michael Atiyah&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;“All good problem solvers occasionally admit defeat. An important part of the problem solver’s art is knowing when to give up.”&lt;/p&gt;
&lt;p&gt;– Paul Zeitz, &lt;em&gt;The Art and Craft of Problem Solving&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Code Generation</title>
        <published>2023-09-28T00:00:00+00:00</published>
        <updated>2023-09-28T00:00:00+00:00</updated>
        
        <author>
          <name>Ibrahim Najjar</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://madin.dev/ntlc/code-gen/"/>
        <id>https://madin.dev/ntlc/code-gen/</id>
        
        <content type="html" xml:base="https://madin.dev/ntlc/code-gen/">&lt;blockquote&gt;
&lt;p&gt;&lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://github.com/abjrcode/ntlc/blob/main/compiler/src/codegen.rs&quot;&gt;Just give me the codez&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h1 id=&quot;introduction&quot;&gt;Introduction&lt;a class=&quot;heading-anchor&quot; href=&quot;#introduction&quot; aria-label=&quot;Anchor link for: introduction&quot;&gt;#&lt;/a&gt;
&lt;/h1&gt;
&lt;p&gt;Welcome to the fourth and final step in our journey. This step is what differentiates a compiled language from an interpreted one&lt;sup&gt;&lt;a href=&quot;https://madin.dev/ntlc/code-gen/#compiled_vs_interpreted&quot;&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;In interpreted languages, the interpreter is responsible for executing the program. It does so by reading the source code, parsing it into an AST and executing the AST directly. JavaScript, Python and Ruby are examples of interpreted languages.&lt;/p&gt;
&lt;p&gt;In compiled languages, the compiler reads the source code, parses it into an AST then transforms&lt;sup&gt;&lt;a href=&quot;https://madin.dev/ntlc/code-gen/#visitor_pattern&quot;&gt;2&lt;/a&gt;&lt;/sup&gt; the AST into an &lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://en.wikipedia.org/wiki/Intermediate_representation&quot;&gt;Intermediate Representations (IR)&lt;/a&gt;, assembly code or directly into machine code. The end user can then run the resulting binary directly using their operating system. C, C++ and Rust are examples of compiled languages.&lt;/p&gt;
&lt;h2 id=&quot;low-level-virtual-machine-llvm&quot;&gt;Low Level Virtual Machine (LLVM)&lt;a class=&quot;heading-anchor&quot; href=&quot;#low-level-virtual-machine-llvm&quot; aria-label=&quot;Anchor link for: low-level-virtual-machine-llvm&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Most compilers used to implement code generation directly, but as the number of &lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://en.wikipedia.org/wiki/Computing_platform&quot;&gt;platforms&lt;/a&gt; &lt;em&gt;(Windows, OSx, *Nix)&lt;/em&gt; kept growing and the number of &lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://en.wikipedia.org/wiki/Comparison_of_instruction_set_architectures&quot;&gt;compute architectures&lt;/a&gt; became even larger &lt;em&gt;(think x86_64, arch64 etc…)&lt;/em&gt;, it became harder to maintain a single code generator that targets all platforms.&lt;/p&gt;
&lt;p&gt;LLVM&lt;sup&gt;&lt;a href=&quot;https://madin.dev/ntlc/code-gen/#cranelift&quot;&gt;3&lt;/a&gt;&lt;/sup&gt; was born out of the need to solve this problem&lt;sup&gt;&lt;a href=&quot;https://madin.dev/ntlc/code-gen/#lsp_similarity&quot;&gt;4&lt;/a&gt;&lt;/sup&gt;. It is a collection of tools and libraries that can be used to build compiler &lt;strong&gt;backend&lt;/strong&gt;s.&lt;/p&gt;
&lt;p&gt;Everything that we have worked on so far, i.e. the lexer, parser and type checker are part of the &lt;strong&gt;frontend&lt;/strong&gt; of a compiler.&lt;/p&gt;
&lt;p&gt;The frontend is distinct per programming language and implemented specifically for that language. The frontend is the thing that gives a language its “identity” and provides its unique features that separate it from other languages.&lt;/p&gt;
&lt;h2 id=&quot;llvm-high-level-overview&quot;&gt;LLVM – High Level Overview&lt;a class=&quot;heading-anchor&quot; href=&quot;#llvm-high-level-overview&quot; aria-label=&quot;Anchor link for: llvm-high-level-overview&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I would love to sit here and give you an introduction to LLVM, but I think &lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://mukulrathi.com/create-your-own-programming-language/llvm-ir-cpp-api-tutorial/&quot;&gt;this article&lt;/a&gt; does a an amazing job at that, so please read it before continuing. It is sufficient to read up to and including the &lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://mukulrathi.com/create-your-own-programming-language/llvm-ir-cpp-api-tutorial/#types-and-constants&quot;&gt;Types and Constants&lt;/a&gt; section.&lt;/p&gt;
&lt;h1 id=&quot;translating-ntlc-to-llvm-ir&quot;&gt;Translating NTLC to LLVM IR&lt;a class=&quot;heading-anchor&quot; href=&quot;#translating-ntlc-to-llvm-ir&quot; aria-label=&quot;Anchor link for: translating-ntlc-to-llvm-ir&quot;&gt;#&lt;/a&gt;
&lt;/h1&gt;
&lt;blockquote&gt;
&lt;p&gt;Read &lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://mukulrathi.com/create-your-own-programming-language/llvm-ir-cpp-api-tutorial/&quot;&gt;LLVM Tutorial&lt;/a&gt; before proceeding&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;NTLC is a very simple language, so translating it to LLVM IR is not that hard.&lt;/p&gt;
&lt;p&gt;We will translate an entire NTLC program into a function, conveniently named &lt;code&gt;main&lt;/code&gt; that takes no arguments and returns an integer. The return value of the function will be the result of evaluating the NTLC program. This is very similar to how &lt;code&gt;main&lt;/code&gt; works in most programming languages.&lt;/p&gt;
&lt;p&gt;The function’s body – implementation – will be the result of translating each NTLC construct to LLVM IR.&lt;/p&gt;
&lt;p&gt;Let’s go over each each construct in NTLC and see how it maps to LLVM IR.&lt;/p&gt;
&lt;h2 id=&quot;integer-boolean-constants&quot;&gt;Integer &amp;amp; Boolean Constants&lt;a class=&quot;heading-anchor&quot; href=&quot;#integer-boolean-constants&quot; aria-label=&quot;Anchor link for: integer-boolean-constants&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Integers and Booleans are the only two types in NTLC. In LLVM IR, integers are represented by the &lt;code&gt;i32&lt;/code&gt; type and booleans are represented by the &lt;code&gt;i1&lt;/code&gt; type. Very straightforward.&lt;/p&gt;
&lt;h2 id=&quot;successor-predecessor&quot;&gt;Successor &amp;amp; Predecessor&lt;a class=&quot;heading-anchor&quot; href=&quot;#successor-predecessor&quot; aria-label=&quot;Anchor link for: successor-predecessor&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;succ&lt;/code&gt; and &lt;code&gt;pred&lt;/code&gt; are both builtin functions in NTLC. They are used to increment and decrement integers respectively. We only need to define both of these functions once since they are kind of “global functions” that can invoked by NTLC code anywhere.&lt;/p&gt;
&lt;p&gt;In LLVM IR, we can implement them roughly as:&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;asm&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;define i32 @succ(i32 %x) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  %&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;1&lt;/span&gt;&lt;span&gt; = &lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;add&lt;/span&gt;&lt;span&gt; i32 %x, &lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;  ret&lt;/span&gt;&lt;span&gt; i32 %&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;asm&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;define i32 @pred(i32 %x) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  %&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;1&lt;/span&gt;&lt;span&gt; = &lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;sub&lt;/span&gt;&lt;span&gt; i32 %x, &lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;  ret&lt;/span&gt;&lt;span&gt; i32 %&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;iszero&quot;&gt;IsZero&lt;a class=&quot;heading-anchor&quot; href=&quot;#iszero&quot; aria-label=&quot;Anchor link for: iszero&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;iszero&lt;/code&gt; is another builtin function in NTLC. It is used to check if an integer is zero or not. In LLVM IR, we can implement it as follows:&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;asm&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;define i1 @izzero(i32 %x) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  %&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;1&lt;/span&gt;&lt;span&gt; = icmp eq i32 %x, &lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;  ret&lt;/span&gt;&lt;span&gt; i1 %&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now that &lt;code&gt;succ&lt;/code&gt;, &lt;code&gt;pred&lt;/code&gt; and &lt;code&gt;iszero&lt;/code&gt; are all defined, we can invoke (call) them in LLVM by using their name and the appropriate arguments.&lt;/p&gt;
&lt;p&gt;An example invocation of &lt;code&gt;succ&lt;/code&gt; would look like this:&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;asm&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;%&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;1&lt;/span&gt;&lt;span&gt; = &lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;call&lt;/span&gt;&lt;span&gt; i32 @succ(i32 &lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;0&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;conditionals&quot;&gt;Conditionals&lt;a class=&quot;heading-anchor&quot; href=&quot;#conditionals&quot; aria-label=&quot;Anchor link for: conditionals&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The final and most complex construct in NTLC is the conditional expression. It is used to alter the execution path of a program based on the value of a boolean expression. In LLVM IR, conditionals are implemented using &lt;em&gt;labels&lt;/em&gt; and &lt;em&gt;jumps&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Labels and jumps were very popular in the early days of programming, even when working with what was deemed “high level languages” back then. But, the code they can result in can be hard to read and thus not easy to maintain. So, most language introduced constructs such as for loops, while loops and if statements that abstract the developer from working with labels and jumps directly.&lt;/p&gt;
&lt;p&gt;I say “abstract” because under the hood, compilers are still converting those language features to labels and jumps.&lt;/p&gt;
&lt;p&gt;If you aren’t familiar with labels and jumps, here is a small example to illustrate the concept in pseudo code:&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;main() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    // A label is just a name for a sequence of statements&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    // Indented statements are &amp;quot;part of the label&amp;quot;: they are executed&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    // when the program &amp;quot;jumps&amp;quot; to execute the label&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    // In that sense, a label is similar to a function&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    // except that it doesn&amp;#39;t take any arguments and doesn&amp;#39;t return anything&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    here: // &amp;lt;------- `here` is a label&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        print(&amp;quot;Hello World&amp;quot;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    // This is another label&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    there:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        print(&amp;quot;Goodbye World&amp;quot;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    if (true) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        // This is a jump&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        goto here&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        // It causes the program to go and execute the label statements&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        // The program then continues executing the statements after the label one by one&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        // WE NEVER REACH THIS LINE&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    } else {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        // This is another jump&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        goto there&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If the previous code snippet was actual code, it would cause an infinite loop. The program would print “Hello World” forever.&lt;/p&gt;
&lt;h3 id=&quot;conditionals-in-llvm-ir&quot;&gt;Conditionals in LLVM IR&lt;a class=&quot;heading-anchor&quot; href=&quot;#conditionals-in-llvm-ir&quot; aria-label=&quot;Anchor link for: conditionals-in-llvm-ir&quot;&gt;#&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;Even with my understanding of labels and jumps, I had a hard time implementing them initially for NTLC. Why you might ask?&lt;/p&gt;
&lt;p&gt;Because I could not see how would nested conditionals work! Let me illustrate with an example:&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;ntlc&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; true&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; then if&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; false&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; then&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; true&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; else&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; true&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; else&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; false&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here is the problem:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Label names must be unique&lt;/li&gt;
&lt;li&gt;You cannot nest labels&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;You might be thinking: “Why not just generate a unique name for each label?”&lt;/p&gt;
&lt;p&gt;The short answer is: You are right. I just got confused with the LLVM API.&lt;/p&gt;
&lt;p&gt;When you translate source code to LLVM IR, you don’t simple map your source language constructs to LLVM IR. That would be too error prone and would require a lot of boilerplate code.&lt;/p&gt;
&lt;p&gt;You use the LLVM API to create constructs that represent your code. So, I thought that I would have to maintain a lookup table for label names I have generated within a function, create a label, check if it exists in the table and if it does then create a new unique name for it. I would have to do so recursively as conditionals can be nested infinitely – at least in theory.&lt;/p&gt;
&lt;p&gt;The solution turned out to be way simpler than I thought. When using the LLVM API to create a label, if the label doesn’t exist, LLVM will create it for you. If it does exist, LLVM will generate a new unique name for you and everything will work as expected.&lt;/p&gt;
&lt;p&gt;That’s why the LLVM API gives you the &lt;code&gt;context&lt;/code&gt; and &lt;code&gt;IRBuilder&lt;/code&gt; types. They are used internally by LLVM to keep track of things like label names and other state.&lt;/p&gt;
&lt;p&gt;If this still doesn’t make sense, don’t worry. It will become clearer when we look at the code.&lt;/p&gt;
&lt;h2 id=&quot;llvm-optimizations&quot;&gt;LLVM Optimizations&lt;a class=&quot;heading-anchor&quot; href=&quot;#llvm-optimizations&quot; aria-label=&quot;Anchor link for: llvm-optimizations&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;LLVM can be configured to perform optimizations on the generated IR. This is a very powerful feature that can result in significant performance improvements.&lt;/p&gt;
&lt;p&gt;Those optimizations tend to “rewrite” your generated IR into a functionally equivalent but more efficient IR.&lt;/p&gt;
&lt;p&gt;I have deliberately chosen to disable those optimizations, because:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;NTLC is not really meant for any real world usage&lt;/li&gt;
&lt;li&gt;And, this allows you &lt;em&gt;(and me)&lt;/em&gt; to see how the generated LLVM instructions map to their corresponding NTLC constructs.&lt;/li&gt;
&lt;/ol&gt;
&lt;h1 id=&quot;putting-it-all-together&quot;&gt;Putting it all together&lt;a class=&quot;heading-anchor&quot; href=&quot;#putting-it-all-together&quot; aria-label=&quot;Anchor link for: putting-it-all-together&quot;&gt;#&lt;/a&gt;
&lt;/h1&gt;
&lt;p&gt;If you have cloned the &lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://github.com/abjrcode/ntlc&quot;&gt;ntlc repository&lt;/a&gt; and followed the instructions mentioned in the readme to install all the required dependencies, then running the compiler via &lt;code&gt;cargo run&lt;/code&gt; would:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Compile the example file &lt;code&gt;/example/good.ntlc&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;It would print the output of the lexer, parser and type checker and code generator to the console&lt;/li&gt;
&lt;li&gt;Generate a binary called &lt;code&gt;good&lt;/code&gt; in the &lt;code&gt;/bin&lt;/code&gt; directory.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Try executing that binary on your operating system by running &lt;code&gt;./bin/good&lt;/code&gt; in your favorite shell. If everything went well you should not see any output. That’s because our NTLC programs do not have the capability to print to the console.&lt;/p&gt;
&lt;p&gt;But in Bash, Zsh, PowerShell and other shells, one can check the exit code of the last executed command/program by running &lt;code&gt;echo $?&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Go ahead and do so and you will see the return value of the NTLC program. Try changing the NTLC program in &lt;code&gt;/example/good.ntlc&lt;/code&gt; and see how the return value changes.&lt;/p&gt;
&lt;p&gt;Congratulations! You have just written your first compiler!&lt;/p&gt;
&lt;h1 id=&quot;closing-thoughts&quot;&gt;Closing Thoughts&lt;a class=&quot;heading-anchor&quot; href=&quot;#closing-thoughts&quot; aria-label=&quot;Anchor link for: closing-thoughts&quot;&gt;#&lt;/a&gt;
&lt;/h1&gt;
&lt;p&gt;That’s it. You have made it to the end of the journey. I hope you enjoyed it as much as I did and you actually learned something useful from it.&lt;/p&gt;
&lt;p&gt;Where to go from here?
If you want to learn more, then I would refer you to some of the resources I mentioned in the &lt;a href=&quot;https://madin.dev/ntlc/intro/#why-another-programming-language&quot;&gt;introduction&lt;/a&gt; article.&lt;/p&gt;
&lt;p&gt;If you feel like you have a good grasp of most concepts and would like to challenge yourself a bit more, here are some ideas:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Add support for more types such as floating point numbers, strings, characters etc…&lt;/li&gt;
&lt;li&gt;Add support for user defined functions&lt;/li&gt;
&lt;li&gt;Add support for user defined types&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The possibilities are endless really. Have fun and happy hacking!&lt;/p&gt;
&lt;ol id=&quot;footnotes&quot;&gt;
  &lt;li id=&quot;compiled_vs_interpreted&quot;&gt;Some interpreted languages perform some compilation to speed things up at execution time, and some even support both interpretation and compilation which makes it hard to draw a distinction&lt;/li&gt;
  &lt;li id=&quot;visitor_pattern&quot;&gt;&lt;a target=&quot;_blank&quot; href=&quot;https://en.wikipedia.org/wiki/Visitor_pattern&quot;&gt;Visitor pattern&lt;/a&gt; is a common OOP pattern that is used to implement both interpretation and transformation of AST&lt;/li&gt;
  &lt;li id=&quot;cranelift&quot;&gt;&lt;a href=&quot;https://cranelift.dev/&quot;&gt;Cranelift&lt;/a&gt; seems to be another option. It is written in Rust, but it was/is still new and not as well documented as LLVM at the time I looked into it&lt;/li&gt;
  &lt;li id=&quot;lsp_similarity&quot;&gt;This is the same as the idea behind &lt;a href=&quot;/ntlc/lsp/#intro&quot;&gt;LSPs&lt;/a&gt; whereby a single Language Server can be used by multiple &quot;frontend&quot; client editors&lt;/li&gt;
&lt;/ol&gt;
&lt;h1 id=&quot;code&quot;&gt;Code&lt;a class=&quot;heading-anchor&quot; href=&quot;#code&quot; aria-label=&quot;Anchor link for: code&quot;&gt;#&lt;/a&gt;
&lt;/h1&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;use&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;inkwell&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;builder&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Builder&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;use&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;inkwell&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Context&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;use&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;inkwell&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;module&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span&gt;{&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Linkage&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Module&lt;/span&gt;&lt;span&gt;};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;use crate::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;parser&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;/**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * `MainFunc` represents how our NTLC program&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * looks like after it&amp;#39;s compiled to LLVM IR.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * It is a function that takes no arguments&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * and returns an integer.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * You might think, hey where the the boolean&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * return value?&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * Well, on the OS level there is no such thing&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * Everything is represented as numbers.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * So we will map boolean values like true and false to 0 and 1 respectively.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * That does make it hard to distinguish between booleans and integers&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * such as when the program returns an integer 1 but since&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * our language is simple we don&amp;#39;t need to worry about that.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * I mean after all this is just a shortcut not to link with libc&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * or provide a way to print to the console.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;pub&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt; type&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;MainFunc&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; = unsafe&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt; extern&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;C&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; fn&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;i32&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[derive(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Debug&lt;/span&gt;&lt;span&gt;)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;pub&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt; enum&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;CodegenError&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;    LlvmNative&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;String&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;/**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * This module contains the internals of the code generator.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * I chose to wrap things in an isolated module because the code generator&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * needs to keep track of some state as part of translation process.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * This way consumers of the &amp;quot;codegen&amp;quot; module don&amp;#39;t need to worry about&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;mod&lt;/span&gt;&lt;span&gt; internals {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    use&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;inkwell&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;values&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;IntValue&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    use crate::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;parser&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    use&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; super&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::*&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;    /**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;     * `context`, `module` and `builder` are the state that the code generator&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;     * needs to keep track of.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;     *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;     * These are constructs provided by the LLVM library.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;     */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    pub&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt; struct&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;CodeGenerator&lt;/span&gt;&lt;span&gt;&amp;lt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;ctx&lt;/span&gt;&lt;span&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;        pub&lt;/span&gt;&lt;span&gt; context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;: &amp;amp;&lt;/span&gt;&lt;span&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;ctx&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Context&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;        pub&lt;/span&gt;&lt;span&gt; module&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Module&lt;/span&gt;&lt;span&gt;&amp;lt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;ctx&lt;/span&gt;&lt;span&gt;&amp;gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;        pub&lt;/span&gt;&lt;span&gt; builder&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Builder&lt;/span&gt;&lt;span&gt;&amp;lt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;ctx&lt;/span&gt;&lt;span&gt;&amp;gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;    /**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;     * Here we are implementing the actual&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;     * functionality of the code generator&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;     *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;     * These functions appear in an impl block&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;     * which makes them methods of the CodeGenerator struct&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;     * defined above.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;     */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    impl&lt;/span&gt;&lt;span&gt;&amp;lt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;ctx&lt;/span&gt;&lt;span&gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;CodeGenerator&lt;/span&gt;&lt;span&gt;&amp;lt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;ctx&lt;/span&gt;&lt;span&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;        /**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;         * This function adds the builtin `izzero` function to the module.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;         */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;        fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; add_builtin_izzero&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt;self&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Result&lt;/span&gt;&lt;span&gt;&amp;lt;(), &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;CodegenError&lt;/span&gt;&lt;span&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;            // This is a representation of the integer type in LLVM IR&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; i32_type&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;i32_type&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;            // This is a representation of the boolean type in LLVM IR&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; bool_type&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;bool_type&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;            // This is the type of the `izzero` function&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;            // It takes an integer and returns a boolean&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; iz_zero_fn_type&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; bool_type&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;fn_type&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;[i32_type&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;into&lt;/span&gt;&lt;span&gt;()],&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; false&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;            // Now we add the function declaration to the module&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;            // We give it the name &amp;quot;izzero&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; iz_zero_fn&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-14&quot;&gt;                self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;module&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                    .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;add_function&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;quot;izzero&amp;quot;&lt;/span&gt;&lt;span&gt;, iz_zero_fn_type, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Linkage&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Internal&lt;/span&gt;&lt;span&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;            // Now we add a basic block to the function&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;            // A basic block is a sequence of instructions&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;            // that execute sequentially&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;            // This is where we implement our function&amp;#39;s body&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; basic_block&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;append_basic_block&lt;/span&gt;&lt;span&gt;(iz_zero_fn,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;entry&amp;quot;&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-14&quot;&gt;            self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;builder&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;position_at_end&lt;/span&gt;&lt;span&gt;(basic_block);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;            // Now we get the value of the first parameter of the function&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;            // which is the integer we want to check if it&amp;#39;s zero&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; x&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; iz_zero_fn&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;get_nth_param&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;0&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;ok_or&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;CodegenError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;LlvmNative&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-11&quot;&gt;                    &amp;quot;Failed to get nth param&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;to_string&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                ))&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;into_int_value&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;            // Now we create a constant integer with the value 0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; zero&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; i32_type&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;const_int&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;0&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; false&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;            // Now we compare the value of the parameter with the constant zero&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; iz_zero&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-14&quot;&gt;                self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;builder&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                    .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;build_int_compare&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;inkwell&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;IntPredicate&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;EQ&lt;/span&gt;&lt;span&gt;, x, zero,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;iz_zero_cmp&amp;quot;&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;            // Now we return the result of the comparison&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-14&quot;&gt;            self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;builder&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;build_return&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;iz_zero));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Ok&lt;/span&gt;&lt;span&gt;(())&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;        /**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;         * This function adds the builtin `pred` function to the module.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;         *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;         * It follows a similar construction to the `izzero` function.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;         */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;        fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; add_builtin_pred&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt;self&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Result&lt;/span&gt;&lt;span&gt;&amp;lt;(), &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;CodegenError&lt;/span&gt;&lt;span&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; i32_type&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;i32_type&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; pred_fn_type&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; i32_type&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;fn_type&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;[i32_type&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;into&lt;/span&gt;&lt;span&gt;()],&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; false&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; pred_fn&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                .&lt;/span&gt;&lt;span&gt;module&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;add_function&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;quot;pred&amp;quot;&lt;/span&gt;&lt;span&gt;, pred_fn_type, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Linkage&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Internal&lt;/span&gt;&lt;span&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; basic_block&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;append_basic_block&lt;/span&gt;&lt;span&gt;(pred_fn,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;entry&amp;quot;&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-14&quot;&gt;            self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;builder&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;position_at_end&lt;/span&gt;&lt;span&gt;(basic_block);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; x&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; pred_fn&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;get_nth_param&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;0&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;ok_or&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;CodegenError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;LlvmNative&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-11&quot;&gt;                    &amp;quot;Failed to get nth param&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;to_string&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                ))&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;into_int_value&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; constant_one&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; i32_type&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;const_int&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;1&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; false&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; pred_value&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;builder&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;build_int_sub&lt;/span&gt;&lt;span&gt;(x, constant_one,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;minus_one&amp;quot;&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-14&quot;&gt;            self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;builder&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;build_return&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;pred_value));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Ok&lt;/span&gt;&lt;span&gt;(())&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;        /**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;         * This function adds the builtin `succ` function to the module.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;         *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;         * It follows a similar construction to the `izzero` function.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;         */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;        fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; add_builtin_succ&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt;self&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Result&lt;/span&gt;&lt;span&gt;&amp;lt;(), &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;CodegenError&lt;/span&gt;&lt;span&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; i32_type&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;i32_type&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; succ_fn_type&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; i32_type&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;fn_type&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;[i32_type&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;into&lt;/span&gt;&lt;span&gt;()],&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; false&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; succ_fn&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                .&lt;/span&gt;&lt;span&gt;module&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;add_function&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;quot;succ&amp;quot;&lt;/span&gt;&lt;span&gt;, succ_fn_type, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Linkage&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Internal&lt;/span&gt;&lt;span&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; basic_block&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;append_basic_block&lt;/span&gt;&lt;span&gt;(succ_fn,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;entry&amp;quot;&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-14&quot;&gt;            self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;builder&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;position_at_end&lt;/span&gt;&lt;span&gt;(basic_block);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; x&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; succ_fn&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;get_nth_param&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;0&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;ok_or&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;CodegenError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;LlvmNative&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-11&quot;&gt;                    &amp;quot;Failed to get nth param&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;to_string&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                ))&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;into_int_value&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; constant_one&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; i32_type&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;const_int&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;1&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; false&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; succ_value&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;builder&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;build_int_add&lt;/span&gt;&lt;span&gt;(x, constant_one,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;plus_one&amp;quot;&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-14&quot;&gt;            self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;builder&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;build_return&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;succ_value));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Ok&lt;/span&gt;&lt;span&gt;(())&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;        /**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;         * new is similar to constructors in Object Oriented Languages&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;         * It initializes a new LLVM module and injects our builtin&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;         * functions and constants into it.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;         *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;         * LLVM modules are the smallest unit of compilation.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;         * You can think of them as a single source file in C or Rust.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;         */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;        pub fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; new&lt;/span&gt;&lt;span&gt;(ctx&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;: &amp;amp;&lt;/span&gt;&lt;span&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;ctx&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Context&lt;/span&gt;&lt;span&gt;, module_name&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;: &amp;amp;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;str&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Result&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt;Self&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;CodegenError&lt;/span&gt;&lt;span&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; module&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; ctx&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;create_module&lt;/span&gt;&lt;span&gt;(module_name);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; code_generator&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;CodeGenerator&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; ctx,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                module,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                builder&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; ctx&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;create_builder&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            code_generator&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;add_builtin_izzero&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            code_generator&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;add_builtin_pred&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            code_generator&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;add_builtin_succ&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Ok&lt;/span&gt;&lt;span&gt;(code_generator)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;        /**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;         * This is the main function of the code generator.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;         * It takes an AST and compiles it to LLVM IR.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;         *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;         * It does it the same way as we did we the type checker&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;         * by recursively traversing the AST and compiling each node&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;         */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;        fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; compile_internal&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt;self&lt;/span&gt;&lt;span&gt;, ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;IntValue&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            match&lt;/span&gt;&lt;span&gt; ast {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;                /*&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;                 * Terminal nodes map to simple constants in LLVM&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;                 */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;                    let&lt;/span&gt;&lt;span&gt; bool_type&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;bool_type&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    bool_type&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;const_int&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;1&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; false&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;                    let&lt;/span&gt;&lt;span&gt; bool_type&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;bool_type&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    bool_type&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;const_zero&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Zero&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;                    let&lt;/span&gt;&lt;span&gt; int_type&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;i32_type&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    int_type&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;const_zero&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;                /*&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;                 * Here we are not building the `succ` function&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;                 * Remember, we already added it as a builtin function&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;                 *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;                 * This is how we call a function in LLVM IR&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;                 */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Successor&lt;/span&gt;&lt;span&gt;(inner_term)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;                    // First we get the function from the module&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;                    let&lt;/span&gt;&lt;span&gt; succ_fn&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                        .&lt;/span&gt;&lt;span&gt;module&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                        .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;get_function&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;quot;succ&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                        .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;ok_or&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;CodegenError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;LlvmNative&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-11&quot;&gt;                            &amp;quot;Failed to get succ function&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;to_string&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                        ))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                        .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;                    // Then we compile the inner term&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;                    // which could be any valid NTLC term&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;                    let&lt;/span&gt;&lt;span&gt; succ_value&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;compile_internal&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;*&lt;/span&gt;&lt;span&gt;inner_term);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;                    // Then we call the function with the value of the inner term&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;                    let&lt;/span&gt;&lt;span&gt; succ_call&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-14&quot;&gt;                        self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;builder&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;build_call&lt;/span&gt;&lt;span&gt;(succ_fn,&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; &amp;amp;&lt;/span&gt;&lt;span&gt;[succ_value&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;into&lt;/span&gt;&lt;span&gt;()],&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;succ_call&amp;quot;&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;                    // Then we get the return value of the function call&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;                    let&lt;/span&gt;&lt;span&gt; succ_call_value&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; succ_call&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;try_as_basic_value&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;left&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;                    // Then we return the value&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    succ_call_value&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;into_int_value&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;                // Same as above&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Predecessor&lt;/span&gt;&lt;span&gt;(inner_term)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;                    let&lt;/span&gt;&lt;span&gt; pred_fn&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                        .&lt;/span&gt;&lt;span&gt;module&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                        .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;get_function&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;quot;pred&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                        .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;ok_or&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;CodegenError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;LlvmNative&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-11&quot;&gt;                            &amp;quot;Failed to get pred function&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;to_string&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                        ))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                        .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;                    let&lt;/span&gt;&lt;span&gt; pred_value&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;compile_internal&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;*&lt;/span&gt;&lt;span&gt;inner_term);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;                    let&lt;/span&gt;&lt;span&gt; pred_call&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-14&quot;&gt;                        self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;builder&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;build_call&lt;/span&gt;&lt;span&gt;(pred_fn,&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; &amp;amp;&lt;/span&gt;&lt;span&gt;[pred_value&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;into&lt;/span&gt;&lt;span&gt;()],&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;pred_call&amp;quot;&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;                    let&lt;/span&gt;&lt;span&gt; pred_call_value&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; pred_call&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;try_as_basic_value&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;left&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    pred_call_value&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;into_int_value&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;                // Same as above&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;IsZero&lt;/span&gt;&lt;span&gt;(inner_term)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;                    let&lt;/span&gt;&lt;span&gt; iz_zero_fn&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                        .&lt;/span&gt;&lt;span&gt;module&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                        .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;get_function&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;quot;izzero&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                        .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;ok_or&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;CodegenError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;LlvmNative&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-11&quot;&gt;                            &amp;quot;Failed to get izzero function&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;to_string&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                        ))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                        .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;                    let&lt;/span&gt;&lt;span&gt; iz_zero_value&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;compile_internal&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;*&lt;/span&gt;&lt;span&gt;inner_term);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;                    let&lt;/span&gt;&lt;span&gt; iz_zero_call&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;builder&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;build_call&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                        iz_zero_fn,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                        &amp;amp;&lt;/span&gt;&lt;span&gt;[iz_zero_value&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;into&lt;/span&gt;&lt;span&gt;()],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-11&quot;&gt;                        &amp;quot;iz_zero_call&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;                    let&lt;/span&gt;&lt;span&gt; iz_zero_call_value&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; iz_zero_call&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;try_as_basic_value&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;left&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    iz_zero_call_value&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;into_int_value&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;                /*&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;                 * Conditionals are a bit more involved&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;                 * If you have seen goto statements before they might seem familiar&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;                 *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;                 * Essentially we are creating a &amp;quot;label&amp;quot; for each possible&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;                 * branch of the conditional.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;                 *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;                 * And then we use jump instructions to execute one or the other&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;                 * depending on the value of the condition.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;                 */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Conditional&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    condition,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    consequence,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    alternative,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                }&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;                    let&lt;/span&gt;&lt;span&gt; condition_value&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;compile_internal&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;*&lt;/span&gt;&lt;span&gt;condition);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;                    let&lt;/span&gt;&lt;span&gt; bool_type&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;bool_type&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;                    let&lt;/span&gt;&lt;span&gt; true_value&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; bool_type&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;const_int&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;1&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; false&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;                    let&lt;/span&gt;&lt;span&gt; condition_cmp&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;builder&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;build_int_compare&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                        &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;inkwell&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;IntPredicate&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;EQ&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                        condition_value,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                        true_value,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-11&quot;&gt;                        &amp;quot;condition_cmp&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;                    let&lt;/span&gt;&lt;span&gt; then_block&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;append_basic_block&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-14&quot;&gt;                        self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;builder&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;get_insert_block&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;get_parent&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-11&quot;&gt;                        &amp;quot;then&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;                    let&lt;/span&gt;&lt;span&gt; else_block&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;append_basic_block&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-14&quot;&gt;                        self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;builder&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;get_insert_block&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;get_parent&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-11&quot;&gt;                        &amp;quot;else&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;                    let&lt;/span&gt;&lt;span&gt; merge_block&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;append_basic_block&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-14&quot;&gt;                        self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;builder&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;get_insert_block&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;get_parent&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-11&quot;&gt;                        &amp;quot;merge&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-14&quot;&gt;                    self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;builder&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                        .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;build_conditional_branch&lt;/span&gt;&lt;span&gt;(condition_cmp, then_block, else_block);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-14&quot;&gt;                    self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;builder&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;position_at_end&lt;/span&gt;&lt;span&gt;(then_block);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;                    let&lt;/span&gt;&lt;span&gt; consequence_value&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;compile_internal&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;*&lt;/span&gt;&lt;span&gt;consequence);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-14&quot;&gt;                    self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;builder&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;build_unconditional_branch&lt;/span&gt;&lt;span&gt;(merge_block);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;                    let&lt;/span&gt;&lt;span&gt; then_block&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;builder&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;get_insert_block&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-14&quot;&gt;                    self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;builder&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;position_at_end&lt;/span&gt;&lt;span&gt;(else_block);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;                    let&lt;/span&gt;&lt;span&gt; alternative_value&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;compile_internal&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;*&lt;/span&gt;&lt;span&gt;alternative);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-14&quot;&gt;                    self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;builder&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;build_unconditional_branch&lt;/span&gt;&lt;span&gt;(merge_block);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;                    let&lt;/span&gt;&lt;span&gt; else_block&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;builder&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;get_insert_block&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-14&quot;&gt;                    self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;builder&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;position_at_end&lt;/span&gt;&lt;span&gt;(merge_block);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;                    /*&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;                       phi is a special construction in LLVM&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;                       that tells us which branch of the conditional&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;                       was executed to get us to this point&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;                    */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;                    let&lt;/span&gt;&lt;span&gt; phi&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;builder&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;build_phi&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;i32_type&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;phi&amp;quot;&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    phi&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;add_incoming&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                        (&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;consequence_value, then_block),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                        (&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;alternative_value, else_block),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    ]);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    phi&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;as_basic_value&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;into_int_value&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                _&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;                    let&lt;/span&gt;&lt;span&gt; int_type&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;i32_type&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    int_type&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;const_int&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;0&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; false&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;        /*&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;         * This is the public interface of the code generator.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;         * It takes an AST and compiles it to LLVM IR.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;         *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;         * We basically we just create a main function&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;         * and we put compile our NTLC program to be the body&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;         * of that function&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;         *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;         * The result of evaluating the NTLC program is the return value&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;         * of the main function&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;         */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;        pub fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; compile&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt;self&lt;/span&gt;&lt;span&gt;, ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Result&lt;/span&gt;&lt;span&gt;&amp;lt;(), &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;CodegenError&lt;/span&gt;&lt;span&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; i32_type&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;i32_type&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; main_fn_type&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; i32_type&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;fn_type&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;[],&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; false&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; main_fn&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                .&lt;/span&gt;&lt;span&gt;module&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;add_function&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;quot;main&amp;quot;&lt;/span&gt;&lt;span&gt;, main_fn_type, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Linkage&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;External&lt;/span&gt;&lt;span&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; basic_block&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;append_basic_block&lt;/span&gt;&lt;span&gt;(main_fn,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;entry&amp;quot;&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-14&quot;&gt;            self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;builder&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;position_at_end&lt;/span&gt;&lt;span&gt;(basic_block);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; return_value&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;compile_internal&lt;/span&gt;&lt;span&gt;(ast);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-14&quot;&gt;            self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;builder&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;build_return&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;return_value));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Ok&lt;/span&gt;&lt;span&gt;(())&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;/**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * This is the only function exported from the code generator&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * Check `main.rs` to see how it&amp;#39;s used.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * As you can see, it delegates all of its work to the code generator module&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * defined above.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;pub fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; generate&lt;/span&gt;&lt;span&gt;(context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;: &amp;amp;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Context&lt;/span&gt;&lt;span&gt;, ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Result&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Module&lt;/span&gt;&lt;span&gt;&amp;lt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;_&lt;/span&gt;&lt;span&gt;&amp;gt;, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;CodegenError&lt;/span&gt;&lt;span&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;    let&lt;/span&gt;&lt;span&gt; codegen&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;internals&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;CodeGenerator&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;new&lt;/span&gt;&lt;span&gt;(context,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;main&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    codegen&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;compile&lt;/span&gt;&lt;span&gt;(ast)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Ok&lt;/span&gt;&lt;span&gt;(codegen&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;module)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[cfg(test)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;mod&lt;/span&gt;&lt;span&gt; code_generator_tests {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    use&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;inkwell&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span&gt;{&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;execution_engine&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;JitFunction&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;OptimizationLevel&lt;/span&gt;&lt;span&gt;};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    use crate::&lt;/span&gt;&lt;span&gt;{&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;lexer&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span&gt;scan, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;parser&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span&gt;parse};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    use&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; super&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::*&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_codegen_true&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;true&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;create&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; codegen&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;internals&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;CodeGenerator&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;new&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;context,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;test_codegen_true&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        codegen&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;compile&lt;/span&gt;&lt;span&gt;(ast)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; execution_engine&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; codegen&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span&gt;module&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;create_jit_execution_engine&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;OptimizationLevel&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;None&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; main&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            unsafe&lt;/span&gt;&lt;span&gt; { execution_engine&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;get_function&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;quot;main&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; as&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;JitFunction&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;MainFunc&lt;/span&gt;&lt;span&gt;&amp;gt; };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;        unsafe&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;            assert_eq!&lt;/span&gt;&lt;span&gt;(main&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;call&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 1&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_codegen_false&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;false&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;create&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; codegen&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;internals&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;CodeGenerator&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;new&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;context,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;test_codegen_false&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        codegen&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;compile&lt;/span&gt;&lt;span&gt;(ast)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; execution_engine&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; codegen&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span&gt;module&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;create_jit_execution_engine&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;OptimizationLevel&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;None&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; main&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            unsafe&lt;/span&gt;&lt;span&gt; { execution_engine&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;get_function&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;quot;main&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; as&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;JitFunction&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;MainFunc&lt;/span&gt;&lt;span&gt;&amp;gt; };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;        unsafe&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;            assert_eq!&lt;/span&gt;&lt;span&gt;(main&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;call&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 0&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_codegen_zero&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;0&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;create&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; codegen&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;internals&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;CodeGenerator&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;new&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;context,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;test_codegen_zero&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        codegen&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;compile&lt;/span&gt;&lt;span&gt;(ast)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; execution_engine&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; codegen&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span&gt;module&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;create_jit_execution_engine&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;OptimizationLevel&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;None&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; main&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            unsafe&lt;/span&gt;&lt;span&gt; { execution_engine&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;get_function&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;quot;main&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; as&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;JitFunction&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;MainFunc&lt;/span&gt;&lt;span&gt;&amp;gt; };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;        unsafe&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;            assert_eq!&lt;/span&gt;&lt;span&gt;(main&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;call&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 0&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_codegen_succ&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;succ 0&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;create&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; codegen&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;internals&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;CodeGenerator&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;new&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;context,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;test_codegen_succ&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        codegen&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;compile&lt;/span&gt;&lt;span&gt;(ast)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; execution_engine&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; codegen&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span&gt;module&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;create_jit_execution_engine&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;OptimizationLevel&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;None&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; main&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            unsafe&lt;/span&gt;&lt;span&gt; { execution_engine&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;get_function&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;quot;main&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; as&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;JitFunction&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;MainFunc&lt;/span&gt;&lt;span&gt;&amp;gt; };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;        unsafe&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;            assert_eq!&lt;/span&gt;&lt;span&gt;(main&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;call&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 1&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_codegen_pred&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;pred 0&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;create&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; codegen&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;internals&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;CodeGenerator&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;new&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;context,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;test_codegen_pred&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        codegen&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;compile&lt;/span&gt;&lt;span&gt;(ast)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; execution_engine&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; codegen&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span&gt;module&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;create_jit_execution_engine&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;OptimizationLevel&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;None&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; main&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            unsafe&lt;/span&gt;&lt;span&gt; { execution_engine&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;get_function&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;quot;main&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; as&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;JitFunction&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;MainFunc&lt;/span&gt;&lt;span&gt;&amp;gt; };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;        unsafe&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;            assert_eq!&lt;/span&gt;&lt;span&gt;(main&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;call&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;1&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_codegen_izzero&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;iszero 0&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;create&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; codegen&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;internals&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;CodeGenerator&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;new&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;context,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;test_codegen_izzero&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        codegen&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;compile&lt;/span&gt;&lt;span&gt;(ast)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; execution_engine&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; codegen&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span&gt;module&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;create_jit_execution_engine&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;OptimizationLevel&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;None&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; main&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            unsafe&lt;/span&gt;&lt;span&gt; { execution_engine&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;get_function&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;quot;main&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; as&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;JitFunction&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;MainFunc&lt;/span&gt;&lt;span&gt;&amp;gt; };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;        unsafe&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;            assert_eq!&lt;/span&gt;&lt;span&gt;(main&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;call&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 1&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_codegen_if_then_branch&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;if true then true else false&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;create&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; codegen&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;internals&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;CodeGenerator&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;new&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;context,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;test_codegen_if&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        codegen&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;compile&lt;/span&gt;&lt;span&gt;(ast)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; execution_engine&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; codegen&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span&gt;module&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;create_jit_execution_engine&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;OptimizationLevel&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;None&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; main&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            unsafe&lt;/span&gt;&lt;span&gt; { execution_engine&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;get_function&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;quot;main&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; as&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;JitFunction&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;MainFunc&lt;/span&gt;&lt;span&gt;&amp;gt; };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;        unsafe&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;            assert_eq!&lt;/span&gt;&lt;span&gt;(main&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;call&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 1&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_codegen_if_else_branch&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;if false then true else false&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;create&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; codegen&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;internals&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;CodeGenerator&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;new&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;context,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;test_codegen_if&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        codegen&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;compile&lt;/span&gt;&lt;span&gt;(ast)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; execution_engine&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; codegen&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span&gt;module&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;create_jit_execution_engine&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;OptimizationLevel&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;None&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; main&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            unsafe&lt;/span&gt;&lt;span&gt; { execution_engine&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;get_function&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;quot;main&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; as&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;JitFunction&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;MainFunc&lt;/span&gt;&lt;span&gt;&amp;gt; };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;        unsafe&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;            assert_eq!&lt;/span&gt;&lt;span&gt;(main&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;call&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 0&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_codegen_nested_successors&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;succ(succ(0))&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;create&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; codegen&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;internals&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;CodeGenerator&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;new&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;context,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;test_codegen_nested_succ&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        codegen&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;compile&lt;/span&gt;&lt;span&gt;(ast)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; execution_engine&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; codegen&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span&gt;module&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;create_jit_execution_engine&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;OptimizationLevel&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;None&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; main&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            unsafe&lt;/span&gt;&lt;span&gt; { execution_engine&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;get_function&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;quot;main&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; as&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;JitFunction&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;MainFunc&lt;/span&gt;&lt;span&gt;&amp;gt; };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;        unsafe&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;            assert_eq!&lt;/span&gt;&lt;span&gt;(main&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;call&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 2&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_codegen_nested_predecessors&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;pred(pred(0))&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;create&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; codegen&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;internals&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;CodeGenerator&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;new&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;context,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;test_codegen_nested_pred&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        codegen&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;compile&lt;/span&gt;&lt;span&gt;(ast)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; execution_engine&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; codegen&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span&gt;module&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;create_jit_execution_engine&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;OptimizationLevel&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;None&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; main&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            unsafe&lt;/span&gt;&lt;span&gt; { execution_engine&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;get_function&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;quot;main&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; as&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;JitFunction&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;MainFunc&lt;/span&gt;&lt;span&gt;&amp;gt; };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;        unsafe&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;            assert_eq!&lt;/span&gt;&lt;span&gt;(main&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;call&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;2&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_nested_if&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;if true then if false then false else true else false&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;create&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; codegen&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;internals&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;CodeGenerator&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;new&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;context,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;test_codegen_nested_if&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        codegen&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;compile&lt;/span&gt;&lt;span&gt;(ast)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; execution_engine&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; codegen&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span&gt;module&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;create_jit_execution_engine&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;OptimizationLevel&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;None&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; main&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            unsafe&lt;/span&gt;&lt;span&gt; { execution_engine&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;get_function&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;quot;main&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; as&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;JitFunction&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;MainFunc&lt;/span&gt;&lt;span&gt;&amp;gt; };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;        unsafe&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;            assert_eq!&lt;/span&gt;&lt;span&gt;(main&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;call&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 1&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_complex_nesting&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;if iszero(pred(succ(0))) then succ(succ(0)) else pred(pred(0))&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;create&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; codegen&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;internals&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;CodeGenerator&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;new&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;context,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;test_codegen_complex_nesting&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        codegen&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;compile&lt;/span&gt;&lt;span&gt;(ast)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; execution_engine&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; codegen&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span&gt;module&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;create_jit_execution_engine&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;OptimizationLevel&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;None&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; main&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            unsafe&lt;/span&gt;&lt;span&gt; { execution_engine&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;get_function&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;quot;main&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; as&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;JitFunction&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;MainFunc&lt;/span&gt;&lt;span&gt;&amp;gt; };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;        unsafe&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;            assert_eq!&lt;/span&gt;&lt;span&gt;(main&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;call&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 2&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_most_complex_example&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;if iszero(pred(succ(0))) then if iszero(pred(0)) then succ(succ(0)) else pred(pred(pred(0))) else succ(pred(pred(0)))&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;create&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; codegen&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;internals&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;CodeGenerator&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;new&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;context,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;test_codegen_complex_nesting&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        codegen&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;compile&lt;/span&gt;&lt;span&gt;(ast)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; execution_engine&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; codegen&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span&gt;module&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;create_jit_execution_engine&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;OptimizationLevel&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;None&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; main&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            unsafe&lt;/span&gt;&lt;span&gt; { execution_engine&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;get_function&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;quot;main&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; as&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;JitFunction&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;MainFunc&lt;/span&gt;&lt;span&gt;&amp;gt; };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;        unsafe&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;            assert_eq!&lt;/span&gt;&lt;span&gt;(main&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;call&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;3&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[cfg(test)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;mod&lt;/span&gt;&lt;span&gt; code_generator_builtins_tests {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    use&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;inkwell&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span&gt;{&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;execution_engine&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;JitFunction&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;OptimizationLevel&lt;/span&gt;&lt;span&gt;};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    use&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; super&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::*&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;    type&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;IzZeroFunc&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; = unsafe&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt; extern&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;C&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; fn&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;i32&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;bool&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;    type&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;SuccFunc&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; = unsafe&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt; extern&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;C&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; fn&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;i32&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;i32&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;    type&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;PredFunc&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; = unsafe&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt; extern&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;C&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; fn&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;i32&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;i32&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_builtin_izzero&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;create&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; codegen&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;internals&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;CodeGenerator&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;new&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;context,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;test_builtin_izzero&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; execution_engine&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; codegen&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span&gt;module&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;create_jit_execution_engine&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;OptimizationLevel&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;None&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; iszero&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            unsafe&lt;/span&gt;&lt;span&gt; { execution_engine&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;get_function&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;quot;izzero&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; as&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;JitFunction&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;IzZeroFunc&lt;/span&gt;&lt;span&gt;&amp;gt; };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;        unsafe&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;            assert!&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;!&lt;/span&gt;&lt;span&gt;(iszero&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;call&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;1&lt;/span&gt;&lt;span&gt;)));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;            assert!&lt;/span&gt;&lt;span&gt;(iszero&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;call&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;0&lt;/span&gt;&lt;span&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_builtin_succ&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;create&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; codegen&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;internals&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;CodeGenerator&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;new&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;context,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;test_builtin_succ&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; execution_engine&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; codegen&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span&gt;module&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;create_jit_execution_engine&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;OptimizationLevel&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;None&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; succ&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            unsafe&lt;/span&gt;&lt;span&gt; { execution_engine&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;get_function&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;quot;succ&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; as&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;JitFunction&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;SuccFunc&lt;/span&gt;&lt;span&gt;&amp;gt; };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;        unsafe&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;            assert_eq!&lt;/span&gt;&lt;span&gt;(succ&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;call&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;0&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 1&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_builtin_pred&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Context&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;create&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; codegen&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;internals&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;CodeGenerator&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;new&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;context,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;test_builtin_pred&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; execution_engine&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; codegen&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span&gt;module&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;create_jit_execution_engine&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;OptimizationLevel&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;None&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; pred&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            unsafe&lt;/span&gt;&lt;span&gt; { execution_engine&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;get_function&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;quot;pred&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; as&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;JitFunction&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;PredFunc&lt;/span&gt;&lt;span&gt;&amp;gt; };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;        unsafe&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;            assert_eq!&lt;/span&gt;&lt;span&gt;(pred&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;call&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;0&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;1&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Language Server Protocol</title>
        <published>2023-09-24T00:00:00+00:00</published>
        <updated>2023-09-24T00:00:00+00:00</updated>
        
        <author>
          <name>Ibrahim Najjar</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://madin.dev/ntlc/lsp/"/>
        <id>https://madin.dev/ntlc/lsp/</id>
        
        <content type="html" xml:base="https://madin.dev/ntlc/lsp/">&lt;blockquote&gt;
&lt;p&gt;Just give me the codez: &lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://github.com/abjrcode/ntlc/tree/main/lsp-extension&quot;&gt;VSCode Client Side&lt;/a&gt; and &lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://github.com/abjrcode/ntlc/blob/main/lsp-server/src/main.rs&quot;&gt;Server&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h1 id=&quot;intro&quot;&gt;Intro&lt;a class=&quot;heading-anchor&quot; href=&quot;#intro&quot; aria-label=&quot;Anchor link for: intro&quot;&gt;#&lt;/a&gt;
&lt;/h1&gt;
&lt;p&gt;I assume you’ve probably worked before in an IDE environment or a “smart” editor such as VSCode, Vim, Emacs or IntelliJ just to name a few.&lt;/p&gt;
&lt;p&gt;All of these editors provide you with smart programming language features such as syntax highlighting &lt;em&gt;(coloring)&lt;/em&gt;, auto-completion, go to definition, find all references, rename symbol, etc.&lt;/p&gt;
&lt;p&gt;Back in the day, each editor had to implement these features for each programming language. This was a lot of work and it was hard to keep up with the latest features of each language.&lt;/p&gt;
&lt;p&gt;So, one day, a group of people got together and decided to create a protocol that would allow editors to support many languages without having to implement support for each of them over and over again for each editor.&lt;/p&gt;
&lt;p&gt;That protocol is the &lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://microsoft.github.io/language-server-protocol/overviews/lsp/overview/&quot;&gt;Language Server Protocol (LSP)&lt;/a&gt;.&lt;/p&gt;
&lt;h1 id=&quot;overview&quot;&gt;Overview&lt;a class=&quot;heading-anchor&quot; href=&quot;#overview&quot; aria-label=&quot;Anchor link for: overview&quot;&gt;#&lt;/a&gt;
&lt;/h1&gt;
&lt;p&gt;The way one decouples an editor from a language is by:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Having a server that implements the LSP for the language
&lt;ul&gt;
&lt;li&gt;The server is written once using whatever language the author desires&lt;/li&gt;
&lt;li&gt;The server is responsible for providing the language features. It has intimate knowledge of the language&lt;/li&gt;
&lt;li&gt;The different editors can use the same server because all parties agree on the protocol&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Each editor or IDE provides a mechanism to implement a client. Most IDEs do this by providing a plugin mechanism
&lt;ul&gt;
&lt;li&gt;The client is usually responsible for starting the server&lt;/li&gt;
&lt;li&gt;The client is responsible for communicating with the server&lt;/li&gt;
&lt;li&gt;The client is usually written per editor&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;the-protocol&quot;&gt;The Protocol&lt;a class=&quot;heading-anchor&quot; href=&quot;#the-protocol&quot; aria-label=&quot;Anchor link for: the-protocol&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;&lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/&quot;&gt;LSP&lt;/a&gt; is a &lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://www.jsonrpc.org/&quot;&gt;JSON-RPC&lt;/a&gt; based protocol:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;JSON because the messages exchanged back and forth between the client and server are formatted as JSON text&lt;/li&gt;
&lt;li&gt;RPC stands for &lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://en.wikipedia.org/wiki/Remote_procedure_call&quot;&gt;Remote Procedure Call&lt;/a&gt; which means the client and server communicate by calling functions on each other.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The editor typically sends a request to the server, e.g. user opened a file, and the server responds with something that is appropriate for that particular message, e.g. the the server might choose to analyze the file and return a list of grammatical errors to the editor.&lt;/p&gt;
&lt;p&gt;The protocol essentially defines all sorts of supported messages, what kind of fields each message has and other features of the protocol.&lt;/p&gt;
&lt;h2 id=&quot;implementing-the-protocol&quot;&gt;Implementing the Protocol&lt;a class=&quot;heading-anchor&quot; href=&quot;#implementing-the-protocol&quot; aria-label=&quot;Anchor link for: implementing-the-protocol&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Implementing the protocol, at least the server side of it, means you have to be able to parse the messages sent from the editor: basically deserializing the JSON payload and converting it to a &lt;em&gt;class&lt;/em&gt;, &lt;em&gt;struct&lt;/em&gt; or whatever in-memory representation that is suitable for your language – the one you’re writing the LSP server &lt;em&gt;in&lt;/em&gt;, not the one you’re writing the server &lt;em&gt;for&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;The same has to happen when you’re sending the response back to client - editor.&lt;/p&gt;
&lt;p&gt;As you can imagine, this is repetitive and people don’t implement it everyday because the protocol does not change much. Also, that’s not really the interesting part of the server. You want to spend your time providing language features, not implementing the protocol details.&lt;/p&gt;
&lt;p&gt;So, typically there are libraries that implement the protocol for you. You just have to provide the actual language features. For my use case and since I used Rust to implement the compiler, I decided ot use &lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://github.com/ebkalderon/tower-lsp&quot;&gt;Tower LSP&lt;/a&gt; to write the server so that I can reuse part of the compiler code.&lt;/p&gt;
&lt;h2 id=&quot;tower-lsp&quot;&gt;Tower LSP&lt;a class=&quot;heading-anchor&quot; href=&quot;#tower-lsp&quot; aria-label=&quot;Anchor link for: tower-lsp&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;&lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://github.com/ebkalderon/tower-lsp&quot;&gt;Tower LSP&lt;/a&gt; is a Rust library that implements the LSP protocol. It basically gives you an interface and you have to fill in the methods that implement the relevant language features for &lt;em&gt;your language&lt;/em&gt;, NTLC in our case.&lt;/p&gt;
&lt;p&gt;For example, if the user hovers over a variable, the editor will send a request to the server asking for the type of the variable.&lt;/p&gt;
&lt;p&gt;Tower LSP will receive that message, validate it, deserialize it and then call the method you implemented to handle that specific request. You job is to focus on implementing the logic that retrieves the type of said variable.&lt;/p&gt;
&lt;h3 id=&quot;syntax-highlighting&quot;&gt;Syntax Highlighting&lt;a class=&quot;heading-anchor&quot; href=&quot;#syntax-highlighting&quot; aria-label=&quot;Anchor link for: syntax-highlighting&quot;&gt;#&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;Syntax highlighting is something that is usually also implemented by the server, but some editors like VSCode allow you to supply your syntax highlighting rules in &lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide&quot;&gt;another form&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;For NTLC, &lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://github.com/abjrcode/ntlc/blob/main/lsp-extension/syntaxes/ntlc.tmLanguage.json&quot;&gt;this is implemented here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The reason editors offer this alternative mechanism in addition to language servers is mainly performance.
When the user opens a file, the editor can highlight &lt;em&gt;(color)&lt;/em&gt; almost instantly without having to wait for the the extension/plugin to activate the language server and for the language server to analyze the file and send the results back.&lt;/p&gt;
&lt;p&gt;When the server does finally start and analyzes the file, it can contribute more “accurate” &lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide&quot;&gt;semantic syntax highlighting&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;NTLC is very simple and so there is no need for the server to provide any “semantic” highlighting.&lt;/p&gt;
&lt;h1 id=&quot;the-hard-parts&quot;&gt;The Hard Parts&lt;a class=&quot;heading-anchor&quot; href=&quot;#the-hard-parts&quot; aria-label=&quot;Anchor link for: the-hard-parts&quot;&gt;#&lt;/a&gt;
&lt;/h1&gt;
&lt;p&gt;Two things:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;You want the server to be super fast and have as little latency as possible: as you can imagine, when working in a project with many files &lt;em&gt;(some which might be thousands of lines)&lt;/em&gt; where you are constantly switching between them, inserting, editing and deleting text; the editor will be sending the server a message about each of those events and the server has to, in many cases, re-scan the source code, re-parse and type check it and maybe even more.&lt;/li&gt;
&lt;li&gt;You optimally want the server to be able to do all of that incrementally, i.e. without having to read the entire file. You can opt-in and tell VSCode to send only information about exactly what had changed in the file. This is called incremental synchronization. But that also means the server has to be able to figure out what to re-analyze. So servers need to keep state and cache intelligently.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In our implementation we do neither of those things:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;NTLC is a small language that I used to learn all of the stuff I have been writing about in this series&lt;/li&gt;
&lt;li&gt;NTLC programs are single line programs. There is barely any performance overhead&lt;/li&gt;
&lt;li&gt;Implementing incremental lexing, parsing and type checking is something you have to consider when you start out. Adding them later is not easy. I did not know of them when I started and so I didn’t implement them.&lt;/li&gt;
&lt;/ol&gt;
&lt;h1 id=&quot;code&quot;&gt;Code&lt;a class=&quot;heading-anchor&quot; href=&quot;#code&quot; aria-label=&quot;Anchor link for: code&quot;&gt;#&lt;/a&gt;
&lt;/h1&gt;
&lt;p&gt;The code is made out of two parts:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The client side: essentially a VSCode extension. NTLC is super simple. The only thing the extension does is start the corresponding server when the user is working on a file that has an &lt;code&gt;.ntlc&lt;/code&gt; extension.&lt;/li&gt;
&lt;li&gt;The server side: a Rust tower-lsp server. I chose to support only two features:
&lt;ul&gt;
&lt;li&gt;Inlay hints: show the type of the entire program
&lt;img src=&quot;https://madin.dev/ntlc/lsp/./inlay_hint.png&quot; alt=&quot;Inlay Type Hints&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; /&gt;&lt;/li&gt;
&lt;li&gt;Diagnostics: show errors (lexing, parsing or type checking errors) in the code
&lt;img src=&quot;https://madin.dev/ntlc/lsp/./diagnostics.png&quot; alt=&quot;Diagnostics&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; /&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Notice that in the server implementation we reuse bits of the compiler code, namely the lexer, parser and type-checker. This is the main reason I decided to use Rust to implement the language server.&lt;/p&gt;
&lt;h2 id=&quot;vscode-typescript-client&quot;&gt;VSCode TypeScript Client&lt;a class=&quot;heading-anchor&quot; href=&quot;#vscode-typescript-client&quot; aria-label=&quot;Anchor link for: vscode-typescript-client&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;typescript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;/* --------------------------------------------------------------------------------------------&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * Copyright (c) Microsoft Corporation. All rights reserved.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * Licensed under the MIT License. See License.txt in the project root for license information.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * ------------------------------------------------------------------------------------------ */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;import&lt;/span&gt;&lt;span&gt; { workspace, window }&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; from&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;vscode&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;import&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  Executable,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  LanguageClient,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  LanguageClientOptions,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  ServerOptions,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; from&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;vscode-languageclient/node&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;let&lt;/span&gt;&lt;span&gt; client&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LanguageClient&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;export async&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt; function&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; activate&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;  const&lt;/span&gt;&lt;span&gt; traceOutputChannel&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; window.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;createOutputChannel&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-11&quot;&gt;    &amp;quot;NTLC Language Server trace&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;  const&lt;/span&gt;&lt;span&gt; command&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; process.env.SERVER_PATH&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; ||&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;ntlc_lsp&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;  const&lt;/span&gt;&lt;span&gt; run&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Executable&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    command,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    options: {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      env: {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;        ...&lt;/span&gt;&lt;span&gt;process.env,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        RUST_LOG:&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;debug&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;  const&lt;/span&gt;&lt;span&gt; serverOptions&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;ServerOptions&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    run,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    debug: run,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;  // If the extension is launched in debug mode then the debug server options are used&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;  // Otherwise the run options are used&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;  // Options to control the language client&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;  let&lt;/span&gt;&lt;span&gt; clientOptions&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LanguageClientOptions&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;    // Register the server for plain text documents&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    documentSelector: [{ scheme:&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;file&amp;quot;&lt;/span&gt;&lt;span&gt;, language:&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;ntlc&amp;quot;&lt;/span&gt;&lt;span&gt; }],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    synchronize: {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;      // Notify the server about file changes to &amp;#39;.clientrc files contained in the workspace&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      fileEvents: workspace.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;createFileSystemWatcher&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;quot;**/.ntlc&amp;quot;&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    traceOutputChannel,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  traceOutputChannel.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;appendLine&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-11&quot;&gt;    `Starting NTLC Language Server: [&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;${&lt;/span&gt;&lt;span&gt;process.env.SERVER_PATH&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;]`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;  // Create the language client and start the client.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  client&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; = new&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; LanguageClient&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-11&quot;&gt;    &amp;quot;ntlc_lsp&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-11&quot;&gt;    &amp;quot;NTLC language server&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    serverOptions,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    clientOptions&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  client.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;start&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;export&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt; function&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; deactivate&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Thenable&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;void&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; |&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt; undefined&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;  if&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;!&lt;/span&gt;&lt;span&gt;client) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    return&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; undefined&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;  return&lt;/span&gt;&lt;span&gt; client.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;stop&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;server&quot;&gt;Server&lt;a class=&quot;heading-anchor&quot; href=&quot;#server&quot; aria-label=&quot;Anchor link for: server&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;/**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * This code was adopted from example code from the tower-lsp crate.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * https://github.com/ebkalderon/tower-lsp&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;use&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;dashmap&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;DashMap&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;use&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;ntlcc&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;parser&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span&gt;parse;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;use&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;ntlcc&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;type_checker&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;use&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;serde&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span&gt;{&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Deserialize&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Serialize&lt;/span&gt;&lt;span&gt;};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;use&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;tower_lsp&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;jsonrpc&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Result&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;use&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;tower_lsp&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;lsp_types&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;notification&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Notification&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;use&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;tower_lsp&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;lsp_types&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::*&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;use&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;tower_lsp&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span&gt;{&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Client&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LanguageServer&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LspService&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Server&lt;/span&gt;&lt;span&gt;};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;/**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * There is many Rust constructs that are new in this file.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * Ignore them. I didn&amp;#39;t understand every bit when I started&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * Essentially Rust doesn&amp;#39;t support async/await completely on its own&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * You need a runtime and that runtime is provided by Tokio (https://tokio.rs/)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * in this project&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * TowerLSP is a Rust library that depends on Tokio&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * What does it do you might ask?&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * Essentially language server protocol is a client-server protocol&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * that allows you to write a language server that can be used by&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * any editor that supports the protocol&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * The protocol is defined here: https://microsoft.github.io/language-server-protocol/specifications/specification-current/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * It uses JSON RPC to exchange messages between the client and the server&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * Just like how the web uses HTTP to exchange messages between the browser and the server&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * So instead of us worrying about implementing the protocol and its details&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * we can just use TowerLSP to do that for us&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * TowerLSP leaves &amp;quot;blanks&amp;quot; for us to fill in.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * Like what to do when the code editor sends us a message&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * saying the user hovered over a piece of code&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * Or what to do when the code editor sends us a message&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * saying user opened a file&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * You can see the list of all supported messages that the code editor can send&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * in the protocol documentation&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[derive(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Debug&lt;/span&gt;&lt;span&gt;)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;struct&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Backend&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;    // We use the client to talk back to the editor/IDE&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    client&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Client&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;    // This is a map that maps a file path to its AST&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;    // We use this to get the AST of a file when the editor&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;    // asks us for inlay or diagnostics&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    ast_map&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;DashMap&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;String&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span&gt;&amp;gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[tower_lsp&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span&gt;async_trait]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;impl&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LanguageServer&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; for&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Backend&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;    /*&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;        Here we initialize the language server&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;        We tell the editor what features the language server supports&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;    */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    async fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; initialize&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt;self&lt;/span&gt;&lt;span&gt;, _&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;InitializeParams&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Result&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;InitializeResult&lt;/span&gt;&lt;span&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Ok&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;InitializeResult&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            server_info&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;ServerInfo&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                name&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;NTLC-LSP&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;to_string&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                version&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;quot;0.0.1&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;to_string&lt;/span&gt;&lt;span&gt;()),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            }),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            offset_encoding&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;None&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            capabilities&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;ServerCapabilities&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                inlay_hint_provider&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;OneOf&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Left&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;true&lt;/span&gt;&lt;span&gt;)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                text_document_sync&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TextDocumentSyncCapability&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Kind&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TextDocumentSyncKind&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;FULL&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                )),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                workspace&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;WorkspaceServerCapabilities&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    workspace_folders&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;WorkspaceFoldersServerCapabilities&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                        supported&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;true&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                        change_notifications&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;OneOf&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Left&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;true&lt;/span&gt;&lt;span&gt;)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    }),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    file_operations&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;None&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                }),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                ..&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;ServerCapabilities&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;default&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        })&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    async fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; initialized&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt;self&lt;/span&gt;&lt;span&gt;, _&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;InitializedParams&lt;/span&gt;&lt;span&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-14&quot;&gt;        self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;client&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;log_message&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;MessageType&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;INFO&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;initialized!&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .await&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    async fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; shutdown&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt;self&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Result&lt;/span&gt;&lt;span&gt;&amp;lt;()&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Ok&lt;/span&gt;&lt;span&gt;(())&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    async fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; did_open&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt;self&lt;/span&gt;&lt;span&gt;, params&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;DidOpenTextDocumentParams&lt;/span&gt;&lt;span&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-14&quot;&gt;        self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;client&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;log_message&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;MessageType&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;INFO&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;file opened!&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .await&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-14&quot;&gt;        self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;on_change&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TextDocumentItem&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            uri&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; params&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;text_document&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;uri,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            text&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; params&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;text_document&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;text,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            version&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; params&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;text_document&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;version,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        })&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;        .await&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    async fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; did_change&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt;self&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; mut&lt;/span&gt;&lt;span&gt; params&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;DidChangeTextDocumentParams&lt;/span&gt;&lt;span&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-14&quot;&gt;        self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;on_change&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TextDocumentItem&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            uri&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; params&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;text_document&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;uri,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            text&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;mem&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;take&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;mut&lt;/span&gt;&lt;span&gt; params&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;content_changes[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;0&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;text),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            version&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; params&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;text_document&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;version,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        })&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;        .await&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    async fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; did_save&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt;self&lt;/span&gt;&lt;span&gt;, _&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;DidSaveTextDocumentParams&lt;/span&gt;&lt;span&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-14&quot;&gt;        self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;client&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;log_message&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;MessageType&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;INFO&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;file saved!&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .await&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    async fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; did_close&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt;self&lt;/span&gt;&lt;span&gt;, _&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;DidCloseTextDocumentParams&lt;/span&gt;&lt;span&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-14&quot;&gt;        self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;client&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;log_message&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;MessageType&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;INFO&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;file closed!&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .await&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;    /**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;     * We are using inlay hints to show the type of our entire&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;     * NTLC program&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;     */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    async fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; inlay_hint&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;        &amp;amp;&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt;self&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        params&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;tower_lsp&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;lsp_types&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;InlayHintParams&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    )&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Result&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Option&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Vec&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;InlayHint&lt;/span&gt;&lt;span&gt;&amp;gt;&amp;gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-14&quot;&gt;        self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;client&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;log_message&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;MessageType&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;INFO&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;inlay hint&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .await&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; uri&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; = &amp;amp;&lt;/span&gt;&lt;span&gt;params&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;text_document&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;uri;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;        if&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt; let&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(ast)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;ast_map&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;get&lt;/span&gt;&lt;span&gt;(uri&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;as_str&lt;/span&gt;&lt;span&gt;()) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; [ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;value&lt;/span&gt;&lt;span&gt;()];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; inlay_hint_list&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; term&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;iter&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;map&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;|&lt;/span&gt;&lt;span&gt;v&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;|&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-6&quot;&gt;                        0&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                        &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;u32&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;MAX&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                        match&lt;/span&gt;&lt;span&gt; v {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;ntlcc&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;type_checker&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Boolean&lt;/span&gt;&lt;span&gt;(_)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;BOOL&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;to_string&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;ntlcc&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;type_checker&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Integer&lt;/span&gt;&lt;span&gt;(_)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;INT&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;to_string&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;ntlcc&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;type_checker&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Void&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;VOID&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;to_string&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                        },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                })&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;map&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;|&lt;/span&gt;&lt;span&gt;item&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;|&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;InlayHint&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    text_edits&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;None&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    tooltip&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;None&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    kind&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;InlayHintKind&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;TYPE&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    padding_left&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;None&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    padding_right&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;None&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    data&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;None&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    position&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Position&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                        line&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 0&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                        character&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; item&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;1&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    label&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;InlayHintLabel&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;LabelParts&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;vec!&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;InlayHintLabelPart&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                        value&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; item&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;2&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                        tooltip&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;None&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                        location&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Location&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                            uri&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; params&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;text_document&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;uri&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;clone&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                            range&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Range&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                                start&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Position&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;new&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;0&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 0&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                                end&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Position&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;new&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;0&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;u32&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;MAX&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                            },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                        }),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                        command&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;None&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    }]),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                })&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;collect&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Vec&lt;/span&gt;&lt;span&gt;&amp;lt;_&amp;gt;&amp;gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            return&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Ok&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(inlay_hint_list));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Ok&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;None&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    async fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; did_change_configuration&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt;self&lt;/span&gt;&lt;span&gt;, _&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;DidChangeConfigurationParams&lt;/span&gt;&lt;span&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-14&quot;&gt;        self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;client&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;log_message&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;MessageType&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;INFO&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;configuration changed!&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .await&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    async fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; did_change_workspace_folders&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt;self&lt;/span&gt;&lt;span&gt;, _&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;DidChangeWorkspaceFoldersParams&lt;/span&gt;&lt;span&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-14&quot;&gt;        self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;client&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;log_message&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;MessageType&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;INFO&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;workspace folders changed!&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .await&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    async fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; did_change_watched_files&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt;self&lt;/span&gt;&lt;span&gt;, _&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;DidChangeWatchedFilesParams&lt;/span&gt;&lt;span&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-14&quot;&gt;        self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;client&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;log_message&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;MessageType&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;INFO&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;watched files have changed!&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .await&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[derive(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Debug&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Deserialize&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Serialize&lt;/span&gt;&lt;span&gt;)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;struct&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;InlayHintParams&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    path&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;String&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;enum&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;CustomNotification&lt;/span&gt;&lt;span&gt; {}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;impl&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Notification&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; for&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;CustomNotification&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;    type&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Params&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;InlayHintParams&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;    const&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; METHOD&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;: &amp;amp;&lt;/span&gt;&lt;span&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;static&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;custom/notification&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;struct&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TextDocumentItem&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    uri&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Url&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    text&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;String&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    version&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;i32&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;impl&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Backend&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;    /**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;     * Whenever a file is opened, changed, saved, etc by the user&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;     * the editor sends us a message&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;     *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;     * We use this message to to lex, parse, and type check the program&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;     * and then publish the diagnostics to the editor&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;     *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;     * We also store the AST of the program in the ast_map&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;     * This is a performance optimization&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;     *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;     * We don&amp;#39;t really need this in NTLC because our programs are small&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;     */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    async fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; on_change&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt;self&lt;/span&gt;&lt;span&gt;, params&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TextDocumentItem&lt;/span&gt;&lt;span&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; program_source&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; params&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;text&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;trim&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; lex_result&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;ntlcc&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;lexer&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;scan&lt;/span&gt;&lt;span&gt;(program_source)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;map_err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;|&lt;/span&gt;&lt;span&gt;e&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;|&lt;/span&gt;&lt;span&gt; e&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;to_string&lt;/span&gt;&lt;span&gt;());&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; parse_result&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; lex_result&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;and_then&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;|&lt;/span&gt;&lt;span&gt;tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;map_err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;|&lt;/span&gt;&lt;span&gt;e&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;|&lt;/span&gt;&lt;span&gt; e&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;to_string&lt;/span&gt;&lt;span&gt;()));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; type_checker_result&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; parse_result&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;and_then&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;|&lt;/span&gt;&lt;span&gt;ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;|&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;ntlcc&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;type_checker&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;infer&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;ast)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;map_err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;|&lt;/span&gt;&lt;span&gt;e&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;|&lt;/span&gt;&lt;span&gt; e&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;to_string&lt;/span&gt;&lt;span&gt;()));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; (ast, errors)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; = match&lt;/span&gt;&lt;span&gt; type_checker_result {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Ok&lt;/span&gt;&lt;span&gt;(ast)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(ast),&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; vec!&lt;/span&gt;&lt;span&gt;[]),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Err&lt;/span&gt;&lt;span&gt;(e)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;None&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; vec!&lt;/span&gt;&lt;span&gt;[e]),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; diagnostics&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; errors&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;into_iter&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;map&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;|&lt;/span&gt;&lt;span&gt;item&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;|&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;                let&lt;/span&gt;&lt;span&gt; start_position&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Position&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    line&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 0&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    character&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 0&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;                let&lt;/span&gt;&lt;span&gt; end_position&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Position&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    line&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 0&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    character&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;u32&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;MAX&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Diagnostic&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;new_simple&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Range&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;new&lt;/span&gt;&lt;span&gt;(start_position, end_position), item)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            })&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;collect&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-14&quot;&gt;        self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;client&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;log_message&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;MessageType&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;INFO&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;before publishing diagnostics&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .await&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-14&quot;&gt;        self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;client&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;publish_diagnostics&lt;/span&gt;&lt;span&gt;(params&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;uri&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;clone&lt;/span&gt;&lt;span&gt;(), diagnostics, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(params&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;version))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            .await&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;        if&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt; let&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(ast)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; ast {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-14&quot;&gt;            self&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;ast_map&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;insert&lt;/span&gt;&lt;span&gt;(params&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span&gt;uri&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;to_string&lt;/span&gt;&lt;span&gt;(), ast);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[tokio&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span&gt;main]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;async fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; main&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;env_logger&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;init&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;    let&lt;/span&gt;&lt;span&gt; stdin&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;tokio&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;io&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;stdin&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;    let&lt;/span&gt;&lt;span&gt; stdout&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;tokio&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;io&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;stdout&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;    let&lt;/span&gt;&lt;span&gt; (service, socket)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LspService&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;build&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;|&lt;/span&gt;&lt;span&gt;client&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;|&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Backend&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        client,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        ast_map&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;DashMap&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;new&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    })&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;finish&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Server&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;new&lt;/span&gt;&lt;span&gt;(stdin, stdout, socket)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;serve&lt;/span&gt;&lt;span&gt;(service)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.await&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Type Checker</title>
        <published>2023-09-23T00:00:00+00:00</published>
        <updated>2023-09-23T00:00:00+00:00</updated>
        
        <author>
          <name>Ibrahim Najjar</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://madin.dev/ntlc/type-checker/"/>
        <id>https://madin.dev/ntlc/type-checker/</id>
        
        <content type="html" xml:base="https://madin.dev/ntlc/type-checker/">&lt;blockquote&gt;
&lt;p&gt;&lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://github.com/abjrcode/ntlc/blob/main/compiler/src/type_checker.rs&quot;&gt;Just give me the codez&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h1 id=&quot;expectation-vs-reality&quot;&gt;Expectation vs Reality&lt;a class=&quot;heading-anchor&quot; href=&quot;#expectation-vs-reality&quot; aria-label=&quot;Anchor link for: expectation-vs-reality&quot;&gt;#&lt;/a&gt;
&lt;/h1&gt;
&lt;p&gt;The type checker was the part I was mostly excited about when I decided to start this project.&lt;/p&gt;
&lt;p&gt;Why you might ask? there are a couple of reasons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Every time I sat off to write a compiler, I stopped at the parsing phase.&lt;/li&gt;
&lt;li&gt;Most courses on compilers usually stop here and instead implement an &lt;em&gt;interpreter&lt;/em&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Spoiler alert though: our type checker is very basic. I did not realize that when I started off but for a type checker to do any meaningful work the language needs to, at the least, have variables. NTLC does not, and so there is barely any work for the type checker to do.&lt;/p&gt;
&lt;p&gt;Before we start though, let’s clear up some terminology.&lt;/p&gt;
&lt;h2 id=&quot;type-checking-vs-type-inference&quot;&gt;Type Checking vs Type Inference&lt;a class=&quot;heading-anchor&quot; href=&quot;#type-checking-vs-type-inference&quot; aria-label=&quot;Anchor link for: type-checking-vs-type-inference&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The difference is actually quite easy to explain. Let’s do that with a JavaScript example and pretend as if JavaScript had type inference built in.&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;const&lt;/span&gt;&lt;span&gt; x&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 1&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;const&lt;/span&gt;&lt;span&gt; y&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; x&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; +&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 3&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Notice that in the previous example, we did not have to specify the type of &lt;code&gt;x&lt;/code&gt; nor &lt;code&gt;y&lt;/code&gt;. The compiler would &lt;strong&gt;infer&lt;/strong&gt; that &lt;code&gt;x&lt;/code&gt; is an integer because it is assigned the value &lt;code&gt;1&lt;/code&gt;, and so &lt;code&gt;y&lt;/code&gt; is also an integer since it is equal to &lt;code&gt;INTEGER + INTEGER&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Notice that JavaScript does not have type inference and the previous example would still have ran even if you did something like:&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;const&lt;/span&gt;&lt;span&gt; x&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 1&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;const&lt;/span&gt;&lt;span&gt; y&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;hello&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; +&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 3&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is not about type inference but about static vs dynamic typing, which we will get to in a bit.&lt;/p&gt;
&lt;p&gt;You might think all of this is very obvious, and it is in this silly example, but this can get &lt;em&gt;really tricky&lt;/em&gt; as you add functions and more complex types to a language&lt;sup&gt;&lt;a href=&quot;#type_inference&quot;&gt;1&lt;/a&gt;&lt;/sup&gt;.&lt;/p&gt;
&lt;p&gt;If JavaScript was statically typed, then we would have to specify the types of &lt;code&gt;x&lt;/code&gt; and &lt;code&gt;y&lt;/code&gt; explicitly.&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;// Fictitious JavaScript with static typing&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;const&lt;/span&gt;&lt;span&gt; x&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt; number&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 1&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;const&lt;/span&gt;&lt;span&gt; y&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt; number&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; x&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; +&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 3&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now, the compiler would not have to do any sort of inference. It just checks that the types are correct.&lt;/p&gt;
&lt;p&gt;For example, since &lt;code&gt;y = x + 3&lt;/code&gt;, &lt;code&gt;y&lt;/code&gt; must be a number because we can only do addition with numbers. So, if the developer would have declared &lt;code&gt;y&lt;/code&gt; as a &lt;code&gt;string&lt;/code&gt; for example, the compiler would have errored.&lt;/p&gt;
&lt;p&gt;It is not uncommon to see languages that have a mixture of both, where they infer the types of some expressions and require the developer to specify the types of others.&lt;/p&gt;
&lt;h2 id=&quot;static-vs-dynamic-typing&quot;&gt;Static vs Dynamic Typing&lt;a class=&quot;heading-anchor&quot; href=&quot;#static-vs-dynamic-typing&quot; aria-label=&quot;Anchor link for: static-vs-dynamic-typing&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Type inference algorithms in some languages are pretty powerful that you might have mistaken those languages for being dynamically typed, OCaml is one example.&lt;/p&gt;
&lt;p&gt;JavaScript is a dynamically typed language. This means that the type of a variable is not known until runtime, or at least not checked until then. This is why you can do things like:&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;const&lt;/span&gt;&lt;span&gt; x&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 1&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;const&lt;/span&gt;&lt;span&gt; y&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;hello&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; +&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 3&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And the compiler would not complain. It is only &lt;em&gt;at runtime&lt;/em&gt; that the interpreter would realize that you are trying to add a string to a number and throw an error.&lt;/p&gt;
&lt;p&gt;Contrast this to a statically typed language like Rust where the compiler would not even compile the program, let alone let you run it.&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;// This will not compile in Rust&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;let&lt;/span&gt;&lt;span&gt; x&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;i32&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 1&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;let&lt;/span&gt;&lt;span&gt; y&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;i32&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;hello&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; +&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 3&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;//           ^^^^^^^^^^^ expected integer, found `&amp;amp;str`&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h1 id=&quot;type-checking-ntlc&quot;&gt;Type Checking NTLC&lt;a class=&quot;heading-anchor&quot; href=&quot;#type-checking-ntlc&quot; aria-label=&quot;Anchor link for: type-checking-ntlc&quot;&gt;#&lt;/a&gt;
&lt;/h1&gt;
&lt;p&gt;As I mentioned earlier, NTLC is a very simple language. It does not have variables, so there is no room for type inference.&lt;/p&gt;
&lt;p&gt;But, we can still do type checking to prevent nonsensical programs such as:&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;ntlc&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;z-1&quot;&gt; succ&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;true&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; then&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 0&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; else&lt;/span&gt;&lt;span class=&quot;z-1&quot;&gt; succ&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;0&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;How are we supposed to evaluate &lt;code&gt;succ(true)&lt;/code&gt;?
We could potentially do an implicit cast from &lt;code&gt;true&lt;/code&gt; to &lt;code&gt;1&lt;/code&gt; and pretend as if the previous expression is &lt;code&gt;succ(1)&lt;/code&gt; but that sounds weird, at least to me.&lt;/p&gt;
&lt;p&gt;Notice that if we don’t add type checking to NTLC, that would make a dynamic language and the previous program would be valid, and you would be able to compile and run it - only to have the program crash at runtime.&lt;/p&gt;
&lt;h2 id=&quot;type-checking-algorithm&quot;&gt;Type Checking Algorithm&lt;a class=&quot;heading-anchor&quot; href=&quot;#type-checking-algorithm&quot; aria-label=&quot;Anchor link for: type-checking-algorithm&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Having NTLC grammar at hand:&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;TERM ::=&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    true&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    false&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    if TERM then TERM else TERM&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    succ TERM&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    pred TERM&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    iszero TERM&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The idea is very simple:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;We already know the types of &lt;code&gt;true&lt;/code&gt;, &lt;code&gt;false&lt;/code&gt; and &lt;code&gt;0&lt;/code&gt;, they are &lt;code&gt;Boolean&lt;/code&gt;, &lt;code&gt;Boolean&lt;/code&gt; and &lt;code&gt;Integer&lt;/code&gt;, respectively.&lt;/li&gt;
&lt;li&gt;We know that &lt;code&gt;succ&lt;/code&gt; and &lt;code&gt;pred&lt;/code&gt; take an &lt;code&gt;Integer&lt;/code&gt; and return an &lt;code&gt;Integer&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;We know that &lt;code&gt;iszero&lt;/code&gt; takes an &lt;code&gt;Integer&lt;/code&gt; and returns a &lt;code&gt;Boolean&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;We know that an &lt;code&gt;if&lt;/code&gt; expression must have something that evaluates to a &lt;code&gt;Boolean&lt;/code&gt; as a condition and the &lt;code&gt;consequence&lt;/code&gt; and &lt;code&gt;alternative&lt;/code&gt; terms must be of the same type.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;These will form the base cases of our type checking algorithm.&lt;/p&gt;
&lt;p&gt;The algorithm is very similar to the recursive descent algorithm we used to parse the AST. We will traverse the AST and check that the types of the nodes match what we expect them to be.&lt;/p&gt;
&lt;p&gt;Recursion would always stop at terminal nodes since those are always going to be either &lt;code&gt;0&lt;/code&gt;, &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt; which types we know.&lt;/p&gt;
&lt;p&gt;Again, have a look at the code and I hope all of this would make perfect sense.&lt;/p&gt;
&lt;ol id=&quot;footnotes&quot;&gt;
  &lt;li id=&quot;type_inference&quot;&gt;&lt;a target=&quot;_blank&quot; href=&quot;https://en.wikipedia.org/wiki/Hindley%E2%80%93Milner_type_system&quot;&gt;Hindley-Milner&lt;/a&gt; seems to be the most widely used type-inference algorithm. &lt;a target=&quot;_blank&quot; href=&quot;https://medium.com/@dhruvrajvanshi/type-inference-for-beginners-part-1-3e0a5be98a4b&quot;&gt;Type Inference for Beginners&lt;/a&gt; and &lt;a target=&quot;_blank&quot; href=&quot;https://mukulrathi.com/create-your-own-programming-language/intro-to-type-checking/&quot;&gt;Intro to Type Checking&lt;/a&gt; do a great job of explaining the concepts&lt;/li&gt;
&lt;/ol&gt;
&lt;h1 id=&quot;code&quot;&gt;Code&lt;a class=&quot;heading-anchor&quot; href=&quot;#code&quot; aria-label=&quot;Anchor link for: code&quot;&gt;#&lt;/a&gt;
&lt;/h1&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;/*&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *    t ::= // terms&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *        true  // constant true&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *        false // constant false&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *        if t then t else t // conditional&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *        0 // constant zero&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *        succ t // successor&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *        pred t // predecessor&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *        iszero t // zero test&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *        */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;use&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Display&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;use crate::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;parser&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[derive(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Debug&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Clone&lt;/span&gt;&lt;span&gt;)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;/**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * This is like a Typed AST.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * There are two real possibilities for an NTLC program.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * The whole program either evaluates to a boolean or an integer.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * Check the grammar above to see why this is the case.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * `Void` is just a convenience to represent an empty program.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;pub&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt; enum&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;    Boolean&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;    Integer&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Void&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;/**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * We implement equality manually for `TypedTerm` because we want to&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * ignore the inner term when comparing.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * If two expressions are of the same type, then they are equal.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * We don&amp;#39;t care about the inner term.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;impl&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;PartialEq&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; for&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; eq&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt;self&lt;/span&gt;&lt;span&gt;, other&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;: &amp;amp;&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt;Self&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;bool&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;        matches!&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            (&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt;self&lt;/span&gt;&lt;span&gt;, other),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            (&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Boolean&lt;/span&gt;&lt;span&gt;(_), &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Boolean&lt;/span&gt;&lt;span&gt;(_))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                |&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Integer&lt;/span&gt;&lt;span&gt;(_), &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Integer&lt;/span&gt;&lt;span&gt;(_))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                |&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Void&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Void&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;impl&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Display&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; for&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; fmt&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt;self&lt;/span&gt;&lt;span&gt;, f&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;: &amp;amp;mut&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Formatter&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Result&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;        match&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Boolean&lt;/span&gt;&lt;span&gt;(_)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; write!&lt;/span&gt;&lt;span&gt;(f,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;BOOLEAN&amp;quot;&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Integer&lt;/span&gt;&lt;span&gt;(_)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; write!&lt;/span&gt;&lt;span&gt;(f,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;INTEGER&amp;quot;&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Void&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; write!&lt;/span&gt;&lt;span&gt;(f,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;&amp;lt;VOID - EMPTY PROGRAM&amp;gt;&amp;quot;&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[derive(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Debug&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;PartialEq&lt;/span&gt;&lt;span&gt;)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;pub&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt; enum&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypeError&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypeMismatch&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Vec&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span&gt;&amp;gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        found&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;impl&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Display&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; for&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypeError&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; fmt&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt;self&lt;/span&gt;&lt;span&gt;, f&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;: &amp;amp;mut&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Formatter&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Result&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;        match&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypeError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypeMismatch&lt;/span&gt;&lt;span&gt; { expected, found }&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;                write!&lt;/span&gt;&lt;span&gt;(f,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;Type error! Expected one of: &amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                for&lt;/span&gt;&lt;span&gt; (i, t)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; in&lt;/span&gt;&lt;span&gt; expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;iter&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;enumerate&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                    if&lt;/span&gt;&lt;span&gt; i&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; ==&lt;/span&gt;&lt;span&gt; expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;len&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 1&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;                        write!&lt;/span&gt;&lt;span&gt;(f,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;{}&amp;quot;&lt;/span&gt;&lt;span&gt;, t)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    }&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; else&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;                        write!&lt;/span&gt;&lt;span&gt;(f,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;{}, &amp;quot;&lt;/span&gt;&lt;span&gt;, t)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;                write!&lt;/span&gt;&lt;span&gt;(f,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot; but found: {}&amp;quot;&lt;/span&gt;&lt;span&gt;, found)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;/**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * This is the entry point of the type checker.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * Although I called it `infer` it doesn&amp;#39;t really do any inference.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * The reason being that type inference is actually not needed&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * For our grammar since we know the type of everything.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * There is no inference needed.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * It just checks if the program is &amp;quot;well typed&amp;quot;.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * &amp;quot;Well typed&amp;quot;: means you are not doing things like&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * iszero true or if 0 then true else false.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * It uses the same algorithm as recursive descent&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * traversing the AST and checking the types of the nodes.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;pub fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; infer&lt;/span&gt;&lt;span&gt;(ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;: &amp;amp;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Result&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypeError&lt;/span&gt;&lt;span&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    match&lt;/span&gt;&lt;span&gt; ast {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;        // The terminals which are also the base cases of the recursion&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;        // are the easiest to type check.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Ok&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Boolean&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;True&lt;/span&gt;&lt;span&gt;)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Ok&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Boolean&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;False&lt;/span&gt;&lt;span&gt;)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Zero&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Ok&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Integer&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Zero&lt;/span&gt;&lt;span&gt;)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;        /*&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;           We need to make sure that the inner term of the successor&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;           is an integer.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;        */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Successor&lt;/span&gt;&lt;span&gt;(t)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; t&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; infer&lt;/span&gt;&lt;span&gt;(t)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            match&lt;/span&gt;&lt;span&gt; t {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Integer&lt;/span&gt;&lt;span&gt;(inner_term)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Ok&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Integer&lt;/span&gt;&lt;span&gt;(inner_term)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                _&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypeError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypeMismatch&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; vec!&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Integer&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Empty&lt;/span&gt;&lt;span&gt;)],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    found&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; t,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                }),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Predecessor&lt;/span&gt;&lt;span&gt;(t)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; t&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; infer&lt;/span&gt;&lt;span&gt;(t)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            match&lt;/span&gt;&lt;span&gt; t {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Integer&lt;/span&gt;&lt;span&gt;(inner_term)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Ok&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Integer&lt;/span&gt;&lt;span&gt;(inner_term)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                _&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypeError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypeMismatch&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; vec!&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Integer&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Empty&lt;/span&gt;&lt;span&gt;)],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    found&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; t,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                }),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;IsZero&lt;/span&gt;&lt;span&gt;(t)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; t&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; infer&lt;/span&gt;&lt;span&gt;(t)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            match&lt;/span&gt;&lt;span&gt; t {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Integer&lt;/span&gt;&lt;span&gt;(inner_term)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Ok&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Boolean&lt;/span&gt;&lt;span&gt;(inner_term)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                _&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypeError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypeMismatch&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; vec!&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Integer&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Empty&lt;/span&gt;&lt;span&gt;)],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    found&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; t,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                }),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Conditional&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            condition,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            consequence,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            alternative,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; condition_type&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; infer&lt;/span&gt;&lt;span&gt;(condition)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; conseq_type&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; infer&lt;/span&gt;&lt;span&gt;(consequence)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; alt_type&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; infer&lt;/span&gt;&lt;span&gt;(alternative)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;            /*&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;             * For the conditional we need to make sure that the condition&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;             * is a boolean and that the consequence and alternative are of the same type.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;             *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;             * This is to avoid things like:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;             * if true then 0 else false&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;             *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;             * While there is nothing wrong with the above program&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;             * We don&amp;#39;t have a way to represent it in our grammar&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;             * or in our type system.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;             *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;             * The resulting type would be what is typically known&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;             * as a union type.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;             *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;             * So we simply disallow it in our case&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;             */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            match&lt;/span&gt;&lt;span&gt; condition_type {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Boolean&lt;/span&gt;&lt;span&gt;(_)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;                    if&lt;/span&gt;&lt;span&gt; conseq_type&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; ==&lt;/span&gt;&lt;span&gt; alt_type {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                        &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Ok&lt;/span&gt;&lt;span&gt;(conseq_type)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    }&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; else&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;                        let&lt;/span&gt;&lt;span&gt; expected_type&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; = match&lt;/span&gt;&lt;span&gt; conseq_type {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Boolean&lt;/span&gt;&lt;span&gt;(_)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Boolean&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Empty&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Integer&lt;/span&gt;&lt;span&gt;(_)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Integer&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Empty&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Void&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Void&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                        };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                        &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypeError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypeMismatch&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                            expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; vec!&lt;/span&gt;&lt;span&gt;[expected_type],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                            found&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; alt_type,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                        })&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                _&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypeError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypeMismatch&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; vec!&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Boolean&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Empty&lt;/span&gt;&lt;span&gt;)],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    found&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; condition_type,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                }),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Empty&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Ok&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Void&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[cfg(test)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;mod&lt;/span&gt;&lt;span&gt; test_type_checker_happy_path {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    use&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; super&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::*&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    use crate::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;lexer&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span&gt;scan;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    use crate::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;parser&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span&gt;parse;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_empty_program&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; typed_ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; infer&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;ast)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(typed_ast, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Void&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_true&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;true&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; typed_ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; infer&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;ast)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(typed_ast, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Boolean&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;True&lt;/span&gt;&lt;span&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_false&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;false&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; typed_ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; infer&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;ast)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(typed_ast, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Boolean&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;False&lt;/span&gt;&lt;span&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_zero&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;0&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; typed_ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; infer&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;ast)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(typed_ast, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Integer&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Zero&lt;/span&gt;&lt;span&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_successor&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;succ 0&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; typed_ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; infer&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;ast)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(typed_ast, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Integer&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Zero&lt;/span&gt;&lt;span&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_predecessor&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;pred 0&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; typed_ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; infer&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;ast)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(typed_ast, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Integer&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Zero&lt;/span&gt;&lt;span&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_is_zero&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;iszero 0&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; typed_ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; infer&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;ast)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(typed_ast, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Boolean&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Zero&lt;/span&gt;&lt;span&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_conditional&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;if true then 0 else 0&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; typed_ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; infer&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;ast)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(typed_ast, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Integer&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Zero&lt;/span&gt;&lt;span&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_boolean_conditional&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;if true then false else true&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; typed_ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; infer&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;ast)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(typed_ast, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Boolean&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;True&lt;/span&gt;&lt;span&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_nested_conditional&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;if true then if true then 0 else 0 else 0&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; typed_ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; infer&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;ast)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(typed_ast, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Integer&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Zero&lt;/span&gt;&lt;span&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_condition_with_function_calls&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;if iszero 0 then succ 0 else pred 0&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; typed_ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; infer&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;ast)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(typed_ast, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Integer&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Zero&lt;/span&gt;&lt;span&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[cfg(test)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;mod&lt;/span&gt;&lt;span&gt; test_type_checker_unhappy_path {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    use&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; super&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::*&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    use crate::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;lexer&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span&gt;scan;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    use crate::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;parser&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span&gt;parse;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_successor&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;succ true&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; typed_ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; infer&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;ast);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            typed_ast,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypeError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypeMismatch&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; vec!&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Integer&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Empty&lt;/span&gt;&lt;span&gt;)],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                found&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Boolean&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;True&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            })&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_predecessor&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;pred true&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; typed_ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; infer&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;ast);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            typed_ast,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypeError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypeMismatch&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; vec!&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Integer&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Empty&lt;/span&gt;&lt;span&gt;)],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                found&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Boolean&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;True&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            })&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_is_zero&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;iszero true&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; typed_ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; infer&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;ast);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            typed_ast,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypeError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypeMismatch&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; vec!&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Integer&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Empty&lt;/span&gt;&lt;span&gt;)],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                found&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Boolean&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;True&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            })&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_conditional&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;if true then true else 0&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; typed_ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; infer&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;ast);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            typed_ast,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypeError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypeMismatch&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; vec!&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Boolean&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Empty&lt;/span&gt;&lt;span&gt;)],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                found&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Integer&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Zero&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            })&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_nested_conditional&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;if true then if true then true else 0 else 0&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; typed_ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; infer&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;ast);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            typed_ast,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypeError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypeMismatch&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; vec!&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Boolean&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Empty&lt;/span&gt;&lt;span&gt;)],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                found&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;TypedTerm&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Integer&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Zero&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            })&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Parser</title>
        <published>2023-09-22T00:00:00+00:00</published>
        <updated>2023-09-22T00:00:00+00:00</updated>
        
        <author>
          <name>Ibrahim Najjar</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://madin.dev/ntlc/parser/"/>
        <id>https://madin.dev/ntlc/parser/</id>
        
        <content type="html" xml:base="https://madin.dev/ntlc/parser/">&lt;blockquote&gt;
&lt;p&gt;&lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://github.com/abjrcode/ntlc/blob/main/compiler/src/parser.rs&quot;&gt;Just give me the codez&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h1 id=&quot;intro&quot;&gt;Intro&lt;a class=&quot;heading-anchor&quot; href=&quot;#intro&quot; aria-label=&quot;Anchor link for: intro&quot;&gt;#&lt;/a&gt;
&lt;/h1&gt;
&lt;p&gt;Parsing – for me – was the most mysterious, &lt;em&gt;and to a certain extent the most scary&lt;/em&gt;, part of compilers when I started.&lt;/p&gt;
&lt;p&gt;Coming across names and acronyms like Shift-Reduce Parsers, Recursive Descent Parsers, LL(1), LR(1), LALR(1) and more made it feel like an intimidating topic.&lt;/p&gt;
&lt;p&gt;But, let’s take a step back and consider what a parser is and why we need one.&lt;/p&gt;
&lt;h1 id=&quot;parsing&quot;&gt;Parsing&lt;a class=&quot;heading-anchor&quot; href=&quot;#parsing&quot; aria-label=&quot;Anchor link for: parsing&quot;&gt;#&lt;/a&gt;
&lt;/h1&gt;
&lt;p&gt;In the &lt;a href=&quot;https://madin.dev/ntlc/lexer/&quot;&gt;previous post&lt;/a&gt;, we talked about lexing and how it takes a stream of characters and converts it into a stream of tokens.&lt;/p&gt;
&lt;p&gt;The concrete example we used was:&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;ntlc&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;z-1&quot;&gt; iszero&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-1&quot;&gt;succ&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;0&lt;/span&gt;&lt;span&gt;))&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; then&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; true&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; else&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; false&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;which resulted in the following list of tokens:&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;If&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;IsZero&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LeftParenthesis&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Succ&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LeftParenthesis&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Zero&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;RightParenthesis&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;RightParenthesis&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Then&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;True&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Else&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;False&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;]&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now, what do we want to do with these tokens?&lt;/p&gt;
&lt;p&gt;Well, these tokens are a representation of our program’s source code. That source code is something we want to eventually execute.&lt;/p&gt;
&lt;p&gt;Now, how would we go about executing – &lt;em&gt;evaluating&lt;/em&gt; – this source code to get the correct result?&lt;/p&gt;
&lt;p&gt;We need to somehow extract “meaning” from the source code, and the way we extract meaning is by extracting structure.&lt;/p&gt;
&lt;h2 id=&quot;language-and-grammar&quot;&gt;Language and Grammar&lt;a class=&quot;heading-anchor&quot; href=&quot;#language-and-grammar&quot; aria-label=&quot;Anchor link for: language-and-grammar&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The source code is written in a language, and we need to understand that language. The best solution that we “humans” came up with so far to “understand” &lt;sup&gt;&lt;a href=&quot;#large_language_models&quot;&gt;1&lt;/a&gt;&lt;/sup&gt; language was to extract structure from it, and the way we extract structure is through following a systematic grammar.&lt;/p&gt;
&lt;p&gt;For example, in the case of natural languages such as English, we have a grammar rule that tells us that a sentence is composed of a subject, a verb, and an object.&lt;/p&gt;
&lt;p&gt;Computer scientists adopted the same approach to allow computers to “understand” programs written in a programming language. They define grammars for said languages.&lt;/p&gt;
&lt;p&gt;The parser is the machinery that carries out the task of extracting structure from source code by following the rules of the grammar.&lt;/p&gt;
&lt;h2 id=&quot;theory-and-practice&quot;&gt;Theory and Practice&lt;a class=&quot;heading-anchor&quot; href=&quot;#theory-and-practice&quot; aria-label=&quot;Anchor link for: theory-and-practice&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;As far as I have seen, parsing theory which lends itself to the study of grammars and languages seems to be one of the most studied topics in compilers and computer science in general. There is so much literature and academic work on the topic&lt;sup&gt;&lt;a href=&quot;#parsing_theory&quot;&gt;2&lt;/a&gt;&lt;/sup&gt; that it is impossible to give it justice in a single blog post&lt;sup&gt;&lt;a href=&quot;#recommendation_grammar_book&quot;&gt;3&lt;/a&gt;&lt;/sup&gt;.&lt;/p&gt;
&lt;p&gt;For our purposes, I am going to make a very gross simplification and say that grammar is just a bunch of substitution rules. For our language, NTLC, the grammar is:&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;TERM ::=&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    true&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    false&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    if TERM then TERM else TERM&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    succ TERM&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    pred TERM&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    iszero TERM&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;How would you read this?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Every word that is made of capital letters – technically known as a &lt;strong&gt;non-terminal&lt;/strong&gt; – is something that can be replaced by what it equates to on the right-hand side.
&lt;ul&gt;
&lt;li&gt;In our case, we only have one non-terminal called &lt;code&gt;TERM&lt;/code&gt;, and it can be replaced by any of the values on the right-hand side.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;::=&lt;/code&gt; is just a notation for saying “can be replaced by”&lt;/li&gt;
&lt;li&gt;To generate a program in NTLC, you start with &lt;code&gt;TERM&lt;/code&gt; and keep replacing non-terminals until you have only non-capital words left – technically those are called &lt;strong&gt;terminals&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;example&quot;&gt;Example&lt;a class=&quot;heading-anchor&quot; href=&quot;#example&quot; aria-label=&quot;Anchor link for: example&quot;&gt;#&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;Following the previous grammar we can make sentences &lt;em&gt;(NTLC programs)&lt;/em&gt; such as:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;true&lt;/code&gt;: It is just a program that evaluates to &lt;code&gt;true&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;0&lt;/code&gt;: It is just a program that evaluates to &lt;code&gt;0&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;succ(TERM)&lt;/code&gt;: in this case we have one non-terminal that we still need to replace. We can choose anything that is a valid TERM. Notice that we can essentially repeat this almost indefinitely. For example, we can have &lt;code&gt;succ(succ(succ(0)))&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Another observation, the grammar allows us to construct nonsensical sentences such as:&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;ntlc&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1&quot;&gt;succ&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;true&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Not all hope is lost though. You see, you can do the same in English with “just” the grammar:&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;The cat   is the table&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;^^^^^^^   ^^ ^^^^^^^&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;SUBJECT   VERB OBJECT&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Evidently, this is also nonsensical.&lt;/p&gt;
&lt;h2 id=&quot;semantic-analysis&quot;&gt;Semantic Analysis&lt;a class=&quot;heading-anchor&quot; href=&quot;#semantic-analysis&quot; aria-label=&quot;Anchor link for: semantic-analysis&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The way we typically prevent such nonsensical programs is through another stage in the compiler pipeline called “Semantic Analysis”. This is usually where type-checkers – a topic we cover in the next post – live.&lt;/p&gt;
&lt;p&gt;“Semantic Analysis” is where most compiler engineers seem to spend most of their time. It is the place where the compiler &lt;em&gt;(at least in statically typed languages)&lt;/em&gt; can help the end user, developers, the most.&lt;/p&gt;
&lt;p&gt;You may have seen such messages when programming:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;“You are trying to add a number to a string”&lt;/li&gt;
&lt;li&gt;“You are trying to call a function with the wrong number of arguments”&lt;/li&gt;
&lt;li&gt;“You are trying to access an undefined variable”&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These and many others are the workings of the Semantic Analyzer.&lt;/p&gt;
&lt;p&gt;I digress, let’s get back to parsing.&lt;/p&gt;
&lt;h1 id=&quot;parsing-techniques&quot;&gt;Parsing Techniques&lt;a class=&quot;heading-anchor&quot; href=&quot;#parsing-techniques&quot; aria-label=&quot;Anchor link for: parsing-techniques&quot;&gt;#&lt;/a&gt;
&lt;/h1&gt;
&lt;p&gt;As I said earlier, there is a lot of theory on parsing and so many techniques, but we are going to use one technique known as &lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://en.wikipedia.org/wiki/Recursive_descent_parser&quot;&gt;&lt;strong&gt;Recursive Descent Parsing&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Why did I choose this technique?&lt;/p&gt;
&lt;p&gt;Honestly, it is the only kind of parsing technique that people actually implement by hand&lt;sup&gt;&lt;a href=&quot;#parsing_techniques&quot;&gt;4&lt;/a&gt;&lt;/sup&gt;. Every other technique is typically implemented by Parser Generators&lt;sup&gt;&lt;a href=&quot;#tree_sitter&quot;&gt;5&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;h2 id=&quot;recursive-descent-parsing&quot;&gt;Recursive Descent Parsing&lt;a class=&quot;heading-anchor&quot; href=&quot;#recursive-descent-parsing&quot; aria-label=&quot;Anchor link for: recursive-descent-parsing&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Recursive Descent Parsing works by following the rules of the grammar in a recursive fashion, hence the name. And it does it from top to bottom, hence the “Descent” part.&lt;/p&gt;
&lt;p&gt;What does that really mean?
It is actually very simple, but, it is one of those things that seem to click only when you actually implement them.&lt;/p&gt;
&lt;p&gt;Before that though, it might help if we actually see what the parser output looks like.&lt;/p&gt;
&lt;h3 id=&quot;abstract-syntax-tree-ast&quot;&gt;Abstract Syntax Tree (AST)&lt;a class=&quot;heading-anchor&quot; href=&quot;#abstract-syntax-tree-ast&quot; aria-label=&quot;Anchor link for: abstract-syntax-tree-ast&quot;&gt;#&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;Abstract Syntax Trees are so famous that people rarely refer to them by their full name. They are usually referred to as ASTs.&lt;/p&gt;
&lt;p&gt;The reason being, my guess, is that once you have an AST representation of your source code, you can do so many things with it:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;You can evaluate it&lt;/li&gt;
&lt;li&gt;You can compile it to another language&lt;/li&gt;
&lt;li&gt;You can optimize it&lt;/li&gt;
&lt;li&gt;You can pretty print it&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;And the list goes on. They are pretty much a canonical representation of your source code.&lt;/p&gt;
&lt;p&gt;So what would the AST for our NTLC program look like if it was parsed?&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;ntlc&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;z-1&quot;&gt; iszero&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-1&quot;&gt;succ&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;0&lt;/span&gt;&lt;span&gt;))&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; then&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; true&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; else&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; false&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Would produce the following AST:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://madin.dev/ntlc/parser/ast.svg&quot; alt=&quot;ast&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; /&gt;&lt;/p&gt;
&lt;p&gt;So the goal of the parser is to take the stream of tokens and convert it into such AST.&lt;/p&gt;
&lt;h3 id=&quot;step-by-step&quot;&gt;Step by step&lt;a class=&quot;heading-anchor&quot; href=&quot;#step-by-step&quot; aria-label=&quot;Anchor link for: step-by-step&quot;&gt;#&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;Let’s go through an example step by step. First the grammar for reference:&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;TERM ::=&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    true&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    false&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    if TERM then TERM else TERM&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    succ TERM&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    pred TERM&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    iszero TERM&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and let’s say we have the following source code:&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;ntlc&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; true&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; then&lt;/span&gt;&lt;span class=&quot;z-1&quot;&gt; succ&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;0&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; else&lt;/span&gt;&lt;span class=&quot;z-1&quot;&gt; pred&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;0&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The corresponding tokens would be:&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;If&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;True&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Then&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Succ&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LeftParenthesis&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Zero&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;RightParenthesis&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Else&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Pred&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LeftParenthesis&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Zero&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;RightParenthesis&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;]&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The way recursive descent would work on the preceding list of tokens is by following the grammar rules from top to bottom:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;We start with &lt;code&gt;TERM&lt;/code&gt;, and we see that the first token is &lt;code&gt;Token::If&lt;/code&gt;, so we can use the rule &lt;code&gt;if TERM then TERM else TERM&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;Notice that once the parser goes down this path, it kinda “remembers” that it is in the middle of parsing an &lt;code&gt;if&lt;/code&gt; expression and so &lt;code&gt;then TERM else TERM&lt;/code&gt; must follow. Otherwise, the parser would either have to &lt;em&gt;backtrack&lt;/em&gt; (try another possible path) or fail.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;We see that the next token is &lt;code&gt;Token::True&lt;/code&gt;, so we can use the rule &lt;code&gt;true&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;We see that the next token is &lt;code&gt;Token::Then&lt;/code&gt;, which matches our expectation so continue parsing the &lt;code&gt;if&lt;/code&gt; expression.&lt;/li&gt;
&lt;li&gt;We see that the next token is &lt;code&gt;Token::Succ&lt;/code&gt;, so we can use the rule &lt;code&gt;succ TERM&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;We see that the next token is &lt;code&gt;Token::LeftParenthesis&lt;/code&gt;, so we can use the rule &lt;code&gt;succ (TERM)&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;We did not mention parenthesis &lt;code&gt;(&lt;/code&gt; and &lt;code&gt;)&lt;/code&gt; in our grammar explicitly. They are optional and help make the code clearer in some cases.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;We see that the next token is &lt;code&gt;Token::Zero&lt;/code&gt;, so we can use the rule &lt;code&gt;0&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;We see that the next token is &lt;code&gt;Token::RightParenthesis&lt;/code&gt;, which matches our expectation.&lt;/li&gt;
&lt;li&gt;We see that the next token is &lt;code&gt;Token::Else&lt;/code&gt;, again, it matches our expectation.&lt;/li&gt;
&lt;li&gt;Likewise, we see that the next token is &lt;code&gt;Token::Pred&lt;/code&gt;, so we can use the rule &lt;code&gt;pred TERM&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;We see that the next token is &lt;code&gt;Token::LeftParenthesis&lt;/code&gt;, so we can use the rule &lt;code&gt;pred (TERM)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;We see that the next token is &lt;code&gt;Token::Zero&lt;/code&gt;, so we can use the rule &lt;code&gt;0&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;We see that the next token is &lt;code&gt;Token::RightParenthesis&lt;/code&gt;, so we can use the rule &lt;code&gt;pred (0)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Finally, we see that we have no more tokens, so we are done&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;problems-and-solutions&quot;&gt;Problems and solutions&lt;a class=&quot;heading-anchor&quot; href=&quot;#problems-and-solutions&quot; aria-label=&quot;Anchor link for: problems-and-solutions&quot;&gt;#&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;Now our grammar is simple, but in some cases there could be multiple possible paths (choices) that are possible and so recursive descent would have to &lt;em&gt;backtrack&lt;/em&gt; and try different alternatives.&lt;/p&gt;
&lt;p&gt;I also did not mention two possible problems that could rise in different grammars:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Ambiguity&lt;/strong&gt;: There are multiple possible correct paths to parse a given input, but usually only one of them is “semantically” correct. For example, &lt;code&gt;1 + 2 * 3&lt;/code&gt; could be parsed as &lt;code&gt;(1 + 2) * 3&lt;/code&gt; or &lt;code&gt;1 + (2 * 3)&lt;/code&gt;. The latter one is the correct one.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Left Recursion&lt;/strong&gt;: A non-terminal can be replaced by itself. Imagine if the grammar had a rule like &lt;code&gt;TERM ::= TERM + TERM&lt;/code&gt;. This would result in infinite recursion. People usually solve this by rewriting the grammar rule into a “semantically equivalent” rule without the recursion on the left.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For a better understanding on both issues and their solutions, I refer you to &lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://journal.stuffwithstuff.com/2011/03/19/pratt-parsers-expression-parsing-made-easy/&quot;&gt;Pratt Parsers: Expression Parsing Made Easy&lt;/a&gt; and &lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://matklad.github.io/2020/04/13/simple-but-powerful-pratt-parsing.html&quot;&gt;Simple but Powerful Pratt Parsing&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Okay, with all this talk you might think the implementation is pretty complex&lt;sup&gt;&lt;a href=&quot;#error_recovery&quot;&gt;6&lt;/a&gt;&lt;/sup&gt;, but actually it almost &lt;em&gt;rolls off the tongue&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;So, without further ado, I leave you with the code.&lt;/p&gt;
&lt;ol id=&quot;footnotes&quot;&gt;
  &lt;li id=&quot;large_language_models&quot;&gt;Recent advances in AI and specifially &lt;a target=&quot;_blank&quot; href=&quot;https://www.elastic.co/what-is/large-language-models&quot;&gt;Largage Language Models (LLMs)&lt;/a&gt; might present a different approach to understanding language. After all, many people communicate and understand others although they have never taken a single grammar class&lt;/li&gt;
  &lt;li id=&quot;parsing_theory&quot;&gt;There does not seem to be much recent research on the topic though. I think it&#39;s mainly because there aren&#39;t any stones which has not been turned. i.e., it is a solved problem&lt;/li&gt;
  &lt;li id=&quot;recommendation_grammar_book&quot;&gt;I highly recommend &lt;a target=&quot;_blank&quot; href=&quot;https://dickgrune.com/Books/PTAPG_2nd_Edition/&quot;&gt;Parsing Techniques - A Practical Guide&lt;/a&gt; for a very good understanding of both grammar and parsing techniques. It is an easy read even if you don&#39;t have a technical background&lt;/li&gt;
  &lt;li id=&quot;parsing_techniques&quot;&gt;Funny enough, it is also the least studied theoratically. Most research covers the other techniques that are implemented by Parser Generators. Read &lt;a target=&quot;_blank&quot; href=&quot;https://tratt.net/laurie/blog/2020/which_parsing_approach.html&quot;&gt;Which Parsing Approach&lt;/a&gt; for a recap&lt;/li&gt;
  &lt;li id=&quot;tree_sitter&quot;&gt;&lt;a target=&quot;_blank&quot; href=&quot;https://tree-sitter.github.io/tree-sitter/&quot;&gt;Tree Sitter&lt;/a&gt; seems to be one of the most powerful and recent Parser Generators&lt;/li&gt;
  &lt;li id=&quot;error_recovery&quot;&gt;The implementation of recursive descent is simple. What turned out to be difficult when implementing parsers in general is two topics that we don&#39;t cover in this post: error recovery and error reporting, also incremental parsing&lt;/li&gt;
&lt;/ol&gt;
&lt;h1 id=&quot;code&quot;&gt;Code&lt;a class=&quot;heading-anchor&quot; href=&quot;#code&quot; aria-label=&quot;Anchor link for: code&quot;&gt;#&lt;/a&gt;
&lt;/h1&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;use&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;iter&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Peekable&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;/*&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *    t ::= // terms&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *        true  // constant true&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *        false // constant false&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *        if t then t else t // conditional&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *        0 // constant zero&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *        succ t // successor&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *        pred t // predecessor&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *        iszero t // zero test&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *        */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;use crate::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;lexer&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[derive(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;PartialEq&lt;/span&gt;&lt;span&gt;)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;pub&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt; enum&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;SyntaxError&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnexpectedToken&lt;/span&gt;&lt;span&gt; { expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Vec&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span&gt;&amp;gt;, found&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span&gt; },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnexpectedEndOfInput&lt;/span&gt;&lt;span&gt; { expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Vec&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span&gt;&amp;gt; },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;impl&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Debug&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; for&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;SyntaxError&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; fmt&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt;self&lt;/span&gt;&lt;span&gt;, f&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;: &amp;amp;mut&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Formatter&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Result&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;        match&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;SyntaxError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnexpectedToken&lt;/span&gt;&lt;span&gt; { expected, found }&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;                write!&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    f,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-11&quot;&gt;                    &amp;quot;Unexpected &amp;#39;{:?}&amp;#39;. expected one of: {:?}&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    found, expected&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;SyntaxError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnexpectedEndOfInput&lt;/span&gt;&lt;span&gt; { expected }&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;                write!&lt;/span&gt;&lt;span&gt;(f,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;Unexpected &amp;lt;EOF&amp;gt;. expected one of: {:?}&amp;quot;&lt;/span&gt;&lt;span&gt;, expected)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;impl&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Display&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; for&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;SyntaxError&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; fmt&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt;self&lt;/span&gt;&lt;span&gt;, f&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;: &amp;amp;mut&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Formatter&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Result&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;        match&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;SyntaxError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnexpectedToken&lt;/span&gt;&lt;span&gt; { expected, found }&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;                write!&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    f,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-11&quot;&gt;                    &amp;quot;Unexpected &amp;#39;{:?}&amp;#39;. expected one of {:?}&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    found, expected&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;SyntaxError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnexpectedEndOfInput&lt;/span&gt;&lt;span&gt; { expected }&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;                write!&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    f,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-11&quot;&gt;                    &amp;quot;Unexpected end of stream. expected one of {:?}&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    expected&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;impl&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Error&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; for&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;SyntaxError&lt;/span&gt;&lt;span&gt; {}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[derive(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Debug&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;PartialEq&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Eq&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Hash&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Clone&lt;/span&gt;&lt;span&gt;)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;/**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * This is our Abstract Syntax Tree (AST)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * It is a recursive data structure that represents the program&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * Ignore those `Box&amp;lt;&amp;gt;` for now, they are just there to make the&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * Rust borrow checker happy.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * This should be self explanatory as it literally&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * follows the structure of our grammar.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;*/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;pub&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt; enum&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Conditional&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        condition&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Box&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span&gt;&amp;gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        consequence&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Box&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span&gt;&amp;gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        alternative&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Box&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span&gt;&amp;gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;    Successor&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Box&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span&gt;&amp;gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;    Predecessor&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Box&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span&gt;&amp;gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;    IsZero&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Box&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span&gt;&amp;gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;True&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;False&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Zero&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Empty&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;impl&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Display&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; for&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; fmt&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt;self&lt;/span&gt;&lt;span&gt;, f&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;: &amp;amp;mut&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Formatter&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Result&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;        match&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Conditional&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                condition,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                consequence,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                alternative,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            }&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; write!&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                f,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-11&quot;&gt;                &amp;quot;COND[{}] -&amp;gt; CONSEQUENCE[{}] ;; ALT[{}]&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                condition, consequence, alternative&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            ),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Successor&lt;/span&gt;&lt;span&gt;(expr)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; write!&lt;/span&gt;&lt;span&gt;(f,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;Successor[{}]&amp;quot;&lt;/span&gt;&lt;span&gt;, expr),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Predecessor&lt;/span&gt;&lt;span&gt;(expr)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; write!&lt;/span&gt;&lt;span&gt;(f,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;Predcessor[{}]&amp;quot;&lt;/span&gt;&lt;span&gt;, expr),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;IsZero&lt;/span&gt;&lt;span&gt;(expr)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; write!&lt;/span&gt;&lt;span&gt;(f,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;ZeroAssertion[{}]&amp;quot;&lt;/span&gt;&lt;span&gt;, expr),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; write!&lt;/span&gt;&lt;span&gt;(f,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;T&amp;quot;&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; write!&lt;/span&gt;&lt;span&gt;(f,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;F&amp;quot;&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Zero&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; write!&lt;/span&gt;&lt;span&gt;(f,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;ZERO&amp;quot;&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Empty&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; write!&lt;/span&gt;&lt;span&gt;(f,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;&amp;lt;EMPTY&amp;gt;&amp;quot;&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; match_left_parantheses&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;T&lt;/span&gt;&lt;span&gt;&amp;gt;(tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;: &amp;amp;mut&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Peekable&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;T&lt;/span&gt;&lt;span&gt;&amp;gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Result&lt;/span&gt;&lt;span&gt;&amp;lt;(), &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;SyntaxError&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;where&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Iterator&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Item&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span&gt;&amp;gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    match&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;next&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LeftParenthesis&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Ok&lt;/span&gt;&lt;span&gt;(()),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(token)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;SyntaxError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnexpectedToken&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; vec!&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LeftParenthesis&lt;/span&gt;&lt;span&gt;],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            found&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; token,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;None&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;SyntaxError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnexpectedEndOfInput&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; vec!&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LeftParenthesis&lt;/span&gt;&lt;span&gt;],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; match_right_parenthesis&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;T&lt;/span&gt;&lt;span&gt;&amp;gt;(tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;: &amp;amp;mut&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Peekable&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;T&lt;/span&gt;&lt;span&gt;&amp;gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Result&lt;/span&gt;&lt;span&gt;&amp;lt;(), &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;SyntaxError&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;where&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Iterator&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Item&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span&gt;&amp;gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    match&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;next&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;RightParenthesis&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Ok&lt;/span&gt;&lt;span&gt;(()),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(token)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;SyntaxError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnexpectedToken&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; vec!&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;RightParenthesis&lt;/span&gt;&lt;span&gt;],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            found&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; token,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;None&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;SyntaxError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnexpectedEndOfInput&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; vec!&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;RightParenthesis&lt;/span&gt;&lt;span&gt;],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; match_then&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;T&lt;/span&gt;&lt;span&gt;&amp;gt;(tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;: &amp;amp;mut&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Peekable&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;T&lt;/span&gt;&lt;span&gt;&amp;gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Result&lt;/span&gt;&lt;span&gt;&amp;lt;(), &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;SyntaxError&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;where&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Iterator&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Item&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span&gt;&amp;gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    match&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;next&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Then&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Ok&lt;/span&gt;&lt;span&gt;(()),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(token)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;SyntaxError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnexpectedToken&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; vec!&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Then&lt;/span&gt;&lt;span&gt;],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            found&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; token,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;None&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;SyntaxError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnexpectedEndOfInput&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; vec!&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Then&lt;/span&gt;&lt;span&gt;],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; match_else&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;T&lt;/span&gt;&lt;span&gt;&amp;gt;(tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;: &amp;amp;mut&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Peekable&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;T&lt;/span&gt;&lt;span&gt;&amp;gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Result&lt;/span&gt;&lt;span&gt;&amp;lt;(), &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;SyntaxError&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;where&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Iterator&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Item&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span&gt;&amp;gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    match&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;next&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Else&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Ok&lt;/span&gt;&lt;span&gt;(()),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(token)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;SyntaxError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnexpectedToken&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; vec!&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Else&lt;/span&gt;&lt;span&gt;],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            found&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; token,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;None&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;SyntaxError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnexpectedEndOfInput&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; vec!&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Else&lt;/span&gt;&lt;span&gt;],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;/**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * This is the recursive function that does most of the work&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * It essentially follows the structure of our grammar&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse_term&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;T&lt;/span&gt;&lt;span&gt;&amp;gt;(tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;: &amp;amp;mut&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Peekable&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;T&lt;/span&gt;&lt;span&gt;&amp;gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Result&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;SyntaxError&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;where&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Iterator&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Item&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span&gt;&amp;gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;    // Get the next token&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    match&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;next&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;        // If it is `true` then our AST contains a single node `Term::True`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;True&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Ok&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;True&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;        // If it is `false` then our AST contains a single node `Term::False`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;False&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Ok&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;False&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Zero&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Ok&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Zero&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;        /*&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;         * If it is `iszero` then we need to check if there is a left parenthesis&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;         * as our grammar allows both `iszero 0` and `iszero(TERM)`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;         *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;         * The same applies for other builtin functions&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;         */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;IsZero&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; match_right&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; = match&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;peek&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LeftParenthesis&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;                    match_left_parantheses&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-6&quot;&gt;                    true&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                _&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; false&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;            /*&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;               This is the heart of how recursive descent works&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;               We call `parse_term()` again to parse the inner expression&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;            */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; inner_expr&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse_term&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;            // If we matched a left parenthesis, we need to match a right parenthesis&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            if&lt;/span&gt;&lt;span&gt; match_right {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;                match_right_parenthesis&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Ok&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;IsZero&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Box&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;new&lt;/span&gt;&lt;span&gt;(inner_expr)))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Succ&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; match_right&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; = match&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;peek&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LeftParenthesis&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;                    match_left_parantheses&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-6&quot;&gt;                    true&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                _&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; false&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; inner_expr&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse_term&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            if&lt;/span&gt;&lt;span&gt; match_right {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;                match_right_parenthesis&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Ok&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Successor&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Box&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;new&lt;/span&gt;&lt;span&gt;(inner_expr)))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Pred&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; match_right&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; = match&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;peek&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LeftParenthesis&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;                    match_left_parantheses&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-6&quot;&gt;                    true&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                _&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; false&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; inner_expr&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse_term&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            if&lt;/span&gt;&lt;span&gt; match_right {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;                match_right_parenthesis&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Ok&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Predecessor&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Box&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;new&lt;/span&gt;&lt;span&gt;(inner_expr)))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;        /*&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;           If terms might seem more complex but they follow the same&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;           pattern of invoking `parse_term()` recursively&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;        */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;If&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; match_right&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; = match&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;peek&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LeftParenthesis&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;                    match_left_parantheses&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-6&quot;&gt;                    true&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                _&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; false&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; condition&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse_term&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            if&lt;/span&gt;&lt;span&gt; match_right {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;                match_right_parenthesis&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;            match_then&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; match_right&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; = match&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;peek&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LeftParenthesis&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;                    match_left_parantheses&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-6&quot;&gt;                    true&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                _&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; false&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; consequence&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse_term&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            if&lt;/span&gt;&lt;span&gt; match_right {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;                match_right_parenthesis&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;            match_else&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; match_right&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; = match&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;peek&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LeftParenthesis&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;                    match_left_parantheses&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-6&quot;&gt;                    true&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                _&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; false&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; alternative&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse_term&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            if&lt;/span&gt;&lt;span&gt; match_right {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;                match_right_parenthesis&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Ok&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Conditional&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                condition&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Box&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;new&lt;/span&gt;&lt;span&gt;(condition),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                consequence&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Box&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;new&lt;/span&gt;&lt;span&gt;(consequence),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                alternative&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Box&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;new&lt;/span&gt;&lt;span&gt;(alternative),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            })&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;EOF&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Ok&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Empty&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(token)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;SyntaxError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnexpectedToken&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; vec!&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;If&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;True&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;False&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Zero&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Pred&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Succ&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;IsZero&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            ],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            found&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; token,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;None&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Ok&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Empty&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;/**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * Entry point of our parser&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * This is the implementation of the Recursive Descent algorithm&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * It takes a vector of tokens and returns a Term (AST) or a SyntaxError&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * if the program is not valid.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * It delegates most of the work to `parse_term()` which is a recursive function&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * After `parse_term()` returns, we check if there are any tokens left in the stream&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * At this stage, there must be none left otherwise the program is not valid.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; * For example, succ(0) 0 is not valid because there is a 0 at the end of the program&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt; */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;pub fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse&lt;/span&gt;&lt;span&gt;(tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Vec&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span&gt;&amp;gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Result&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;SyntaxError&lt;/span&gt;&lt;span&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;    let&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; mut&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;into_iter&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;peekable&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;    let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse_term&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;mut&lt;/span&gt;&lt;span&gt; tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    match&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;next&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;EOF&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; (),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(token)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;            return&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;SyntaxError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnexpectedToken&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; vec!&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;EOF&lt;/span&gt;&lt;span&gt;],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                found&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; token,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            })&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;None&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; (),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Ok&lt;/span&gt;&lt;span&gt;(ast)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[cfg(test)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;mod&lt;/span&gt;&lt;span&gt; tests_parser_happy_path {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    use&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; super&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::*&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    use crate::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;lexer&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span&gt;scan;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_parse_empty_program&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(ast, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Empty&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_parse_literal_true&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;true&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(ast, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;True&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_parse_literal_false&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;false&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(ast, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;False&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_parse_literal_zero&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;0&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(ast, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Zero&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_parse_conditional&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;if true then false else true&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            ast,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Conditional&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                condition&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Box&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;new&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;True&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                consequence&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Box&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;new&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;False&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                alternative&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Box&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;new&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;True&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_parse_successor&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;succ 0&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(ast, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Successor&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Box&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;new&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Zero&lt;/span&gt;&lt;span&gt;),));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_parse_predecessor&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;pred 0&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(ast, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Predecessor&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Box&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;new&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Zero&lt;/span&gt;&lt;span&gt;),));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_parse_iszero&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;iszero 0&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(ast, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;IsZero&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Box&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;new&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Zero&lt;/span&gt;&lt;span&gt;),));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_parse_nested&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;if true then succ   (0) else pred( 0 )&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            ast,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Conditional&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                condition&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Box&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;new&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;True&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                consequence&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Box&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;new&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Successor&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Box&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;new&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Zero&lt;/span&gt;&lt;span&gt;))),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                alternative&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Box&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;new&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;Predecessor&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Box&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;new&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Zero&lt;/span&gt;&lt;span&gt;)))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[cfg(test)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;mod&lt;/span&gt;&lt;span&gt; tests_sad_path {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    use&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; super&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::*&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    use crate::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;lexer&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span&gt;scan;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_parse_unexpected_true&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;true true&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse&lt;/span&gt;&lt;span&gt;(tokens);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            ast,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;SyntaxError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnexpectedToken&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; vec!&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;EOF&lt;/span&gt;&lt;span&gt;],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                found&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;True&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            })&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_parse_unexpected_false&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;true false&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse&lt;/span&gt;&lt;span&gt;(tokens);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            ast,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;SyntaxError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnexpectedToken&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; vec!&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;EOF&lt;/span&gt;&lt;span&gt;],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                found&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;False&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            })&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_parse_unbalanced_parenthesis&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;iszero(true&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; parse&lt;/span&gt;&lt;span&gt;(tokens);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            ast,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;SyntaxError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnexpectedToken&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; vec!&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;RightParenthesis&lt;/span&gt;&lt;span&gt;],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                found&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;EOF&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            })&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_unbalanced_if&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;if true then false iszero 0&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; super&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;parse&lt;/span&gt;&lt;span&gt;(tokens);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            ast,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;SyntaxError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnexpectedToken&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; vec!&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Else&lt;/span&gt;&lt;span&gt;],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                found&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;IsZero&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            })&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_invalid_syntax_starting_with_else&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;else 0 if true&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; super&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;parse&lt;/span&gt;&lt;span&gt;(tokens);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            ast,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;SyntaxError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnexpectedToken&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; vec!&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;If&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;True&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;False&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Zero&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Pred&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Succ&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;IsZero&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                ],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                found&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Else&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            })&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_parse_unexpected_token&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;if true then false else true 0&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; ast&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; super&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;parse&lt;/span&gt;&lt;span&gt;(tokens);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            ast,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;SyntaxError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnexpectedToken&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; vec!&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;EOF&lt;/span&gt;&lt;span&gt;],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                found&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Zero&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            })&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Introduction</title>
        <published>2023-09-20T00:00:00+00:00</published>
        <updated>2023-09-20T00:00:00+00:00</updated>
        
        <author>
          <name>Ibrahim Najjar</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://madin.dev/ntlc/intro/"/>
        <id>https://madin.dev/ntlc/intro/</id>
        
        <content type="html" xml:base="https://madin.dev/ntlc/intro/">&lt;h1 id=&quot;intro&quot;&gt;Intro&lt;a class=&quot;heading-anchor&quot; href=&quot;#intro&quot; aria-label=&quot;Anchor link for: intro&quot;&gt;#&lt;/a&gt;
&lt;/h1&gt;
&lt;p&gt;We are going to build a super tiny programming language called NTLC, and, we will do it from scratch in &lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://www.rust-lang.org/&quot;&gt;Rust&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;why-another-programming-language&quot;&gt;Why another programming language?&lt;a class=&quot;heading-anchor&quot; href=&quot;#why-another-programming-language&quot; aria-label=&quot;Anchor link for: why-another-programming-language&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;It’s not a &lt;em&gt;real&lt;/em&gt; programming language. It’s just a toy language that will we will use for fun and learning. It’s not meant to be used for anything except learning and exploring.&lt;/p&gt;
&lt;p&gt;If you do end up falling in love with programming languages, or you wish to learn more about them, or, perhaps you would like to create your own &lt;em&gt;real&lt;/em&gt; language then then I highly recommend:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://craftinginterpreters.com/&quot;&gt;Crafting Interpreters&lt;/a&gt; by Bob Nystrom&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://interpreterbook.com/&quot;&gt;Writing an Interpreter in Go&lt;/a&gt; by Thorsten Ball&lt;/li&gt;
&lt;li&gt;Or if you are up for some adventures in OCaml and C++, &lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://mukulrathi.com/create-your-own-programming-language/intro-to-compiler/&quot;&gt;the amazing Bolt language series by Mukul Rathi&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;why-from-scratch-and-why-rust&quot;&gt;Why from scratch, and, why Rust?&lt;a class=&quot;heading-anchor&quot; href=&quot;#why-from-scratch-and-why-rust&quot; aria-label=&quot;Anchor link for: why-from-scratch-and-why-rust&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Well, that’s how one really learns in my opinion – by doing.&lt;/p&gt;
&lt;p&gt;As for Rust, it’s a language that I have been wanting to explore for a while now – &lt;em&gt;the hype you know&lt;/em&gt; – and this seemed like a good opportunity to do so &lt;em&gt;(spoiler alert: it might not have been the wisest choice)&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;In my opinion, Rust is not a beginner friendly language. It’s a very powerful one, but, it’s also a complex one, especially if you haven’t done any C or C++ before. Nevertheless, I will do my best to explain things as we go.&lt;/p&gt;
&lt;p&gt;Having already planned to write about NTLC; I should’ve perhaps chosen a language that is more beginner friendly or one that I am really proficient with but where is the challenge in that!&lt;/p&gt;
&lt;h1 id=&quot;the-language&quot;&gt;The Language&lt;a class=&quot;heading-anchor&quot; href=&quot;#the-language&quot; aria-label=&quot;Anchor link for: the-language&quot;&gt;#&lt;/a&gt;
&lt;/h1&gt;
&lt;p&gt;&lt;strong&gt;NTLC&lt;/strong&gt; stands for “Neo Typed Lambda Calculus”. The name was inspired from the book &lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://www.cis.upenn.edu/~bcpierce/tapl/&quot;&gt;“Types and Programming Languages”&lt;/a&gt; by Benjamin C. Pierce, which is a great book on type theory and programming languages in general.&lt;/p&gt;
&lt;p&gt;The book uses a language called “Simply Typed Lambda Calculus” to demonstrate the concepts of type theory, and, we are building a typed version of a simpler precursor to it known as “Untyped Arithmetic Expressions”. It is just that for some reason my mind was already fixated on the name “Neo Typed Lambda Calculus” so I stuck with it.&lt;/p&gt;
&lt;h2 id=&quot;end-to-end&quot;&gt;End to End&lt;a class=&quot;heading-anchor&quot; href=&quot;#end-to-end&quot; aria-label=&quot;Anchor link for: end-to-end&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The language itself is so simple that one might not even call it a language, but that also makes for a great learning playground.&lt;/p&gt;
&lt;p&gt;Also, I have never built a language before so this felt like a great place to start, and, it will allow us to build the full compiler pipeline&lt;sup&gt;&lt;a href=&quot;#full_compiler_pipeline&quot;&gt;1&lt;/a&gt;&lt;/sup&gt;: including a type checker, simple IDE integration and native code generation from start to finish.&lt;/p&gt;
&lt;h3 id=&quot;small-interlude&quot;&gt;Small Interlude&lt;a class=&quot;heading-anchor&quot; href=&quot;#small-interlude&quot; aria-label=&quot;Anchor link for: small-interlude&quot;&gt;#&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;I recommend this approach for anything you wish to build or learn:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Get a feeling for the landscape you’re about to enter&lt;/li&gt;
&lt;li&gt;Build a fully functioning thing. It doesn’t have to be perfect or even good. It just has to work&lt;/li&gt;
&lt;li&gt;Now, iterate and refine. You will have a much better understanding of the problem space and will be able to make better decisions&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;what-does-it-look-like&quot;&gt;What does it look like?&lt;a class=&quot;heading-anchor&quot; href=&quot;#what-does-it-look-like&quot; aria-label=&quot;Anchor link for: what-does-it-look-like&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Here is a program/snippet written in NTLC:&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;ntlc&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;z-1&quot;&gt; iszero&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-1&quot;&gt;succ&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;0&lt;/span&gt;&lt;span&gt;))&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; then&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; true&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; else&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; false&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;which evaluates, you guessed it, to &lt;code&gt;false&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;iszero()&lt;/code&gt; is a builtin function that checks if the given argument is zero. &lt;code&gt;succ()&lt;/code&gt; &lt;em&gt;(successor)&lt;/em&gt; is a function that increments its argument by one. &lt;code&gt;true&lt;/code&gt;, &lt;code&gt;false&lt;/code&gt; and &lt;code&gt;0&lt;/code&gt; are predefined constants.&lt;/p&gt;
&lt;p&gt;There is one more builtin function called &lt;code&gt;pred()&lt;/code&gt; &lt;em&gt;(predecessor)&lt;/em&gt; that decrements its argument by one.&lt;/p&gt;
&lt;p&gt;You can also nest things, here is another contrived example:&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;ntlc&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;z-1&quot;&gt; iszero&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-1&quot;&gt;succ&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-1&quot;&gt;pred&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;0&lt;/span&gt;&lt;span&gt;)))&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; then if&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; true&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; then&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; false&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; else&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; true&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; else&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; false&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Yikes! And, that’s it. That’s the whole language.&lt;/p&gt;
&lt;p&gt;There are no user defined types &lt;em&gt;(think classes, structs, or even variables)&lt;/em&gt; or functions. There are no loops. There are no strings. There aren’t even any other numbers beside the predefined &lt;code&gt;0&lt;/code&gt; constant. The language doesn’t even allow empty lines. The whole program must be typed in one single line.&lt;/p&gt;
&lt;p&gt;Again, this keeps things simple and allows us to build things end to end. Also, adding those – &lt;em&gt;albeit tricky for some and near impossible for other&lt;/em&gt; – constructs can be done iteratively and incrementally.&lt;/p&gt;
&lt;h1 id=&quot;what-s-next&quot;&gt;What’s next?&lt;a class=&quot;heading-anchor&quot; href=&quot;#what-s-next&quot; aria-label=&quot;Anchor link for: what-s-next&quot;&gt;#&lt;/a&gt;
&lt;/h1&gt;
&lt;p&gt;In the next chapter, we will build the first stage of our language compiler – the lexer.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://madin.dev/ntlc/lexer/&quot;&gt;See you there!&lt;/a&gt;&lt;/p&gt;
&lt;ol id=&quot;footnotes&quot;&gt; 
 &lt;li id=&quot;full_compiler_pipeline&quot;&gt;It is as full of a pipeline as possible with such simple language that doesn&#39;t have many constructs but it is more than enough for a start.&lt;/li&gt;
&lt;/ol&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Lexer</title>
        <published>2023-09-20T00:00:00+00:00</published>
        <updated>2023-09-20T00:00:00+00:00</updated>
        
        <author>
          <name>Ibrahim Najjar</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://madin.dev/ntlc/lexer/"/>
        <id>https://madin.dev/ntlc/lexer/</id>
        
        <content type="html" xml:base="https://madin.dev/ntlc/lexer/">&lt;blockquote&gt;
&lt;p&gt;&lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://github.com/abjrcode/ntlc/blob/main/compiler/src/lexer.rs&quot;&gt;Just give me the codez&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h1 id=&quot;what-is-a-lexer&quot;&gt;What is a lexer?&lt;a class=&quot;heading-anchor&quot; href=&quot;#what-is-a-lexer&quot; aria-label=&quot;Anchor link for: what-is-a-lexer&quot;&gt;#&lt;/a&gt;
&lt;/h1&gt;
&lt;p&gt;The &lt;strong&gt;lexer&lt;/strong&gt;&lt;sup&gt;&lt;a href=&quot;#lexer_derivation&quot;&gt;1&lt;/a&gt;&lt;/sup&gt;, also known as the &lt;strong&gt;tokenizer&lt;/strong&gt; or the &lt;strong&gt;scanner&lt;/strong&gt;, is the first stage in the compilation process. It takes source code &lt;em&gt;(NTLC source code in our case)&lt;/em&gt; and converts it into a stream of “tokens”.&lt;/p&gt;
&lt;p&gt;First stage you say, are there more? Definitely!&lt;/p&gt;
&lt;p&gt;Actually, the compiler is more like a pipeline. Each stage takes the output of the previous one and transforms it into something that is ready for the next stage to consume. The output of the lexer is the input of the parser, and so on.&lt;/p&gt;
&lt;p&gt;Here is a very typical compiler pipeline&lt;sup&gt;&lt;a href=&quot;#compiler_pipeline&quot;&gt;2&lt;/a&gt;&lt;/sup&gt;:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://madin.dev/ntlc/lexer/compiler_pipeline.svg&quot; alt=&quot;Compiler Pipeline&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; /&gt;&lt;/p&gt;
&lt;h2 id=&quot;why-do-we-need-a-lexer&quot;&gt;Why do we need a lexer?&lt;a class=&quot;heading-anchor&quot; href=&quot;#why-do-we-need-a-lexer&quot; aria-label=&quot;Anchor link for: why-do-we-need-a-lexer&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Strictly speaking, we don’t. It just allows us to work with the source code on a higher conceptual level. Later stages, namely the parser, will have way easier time reasoning about the structure of the source code if it doesn’t have to worry about string indices, whitespace characters, and/or the nuances of character sets and text encoding.&lt;/p&gt;
&lt;p&gt;Actually this is true of every stage in the pipeline. If the source language was so simple, you probably would not even need a compiler. You could get away with a few regular expressions and a bunch of string manipulation functions.&lt;/p&gt;
&lt;p&gt;The compiler is essentially a systematic and deterministic way to convert a program written in one language to another. Remember the good old divide and conquer technique: it advises you to break a big problem into smaller manageable ones! Well, that’s what the compiler really does with all its stages.&lt;/p&gt;
&lt;h1 id=&quot;lexer-output&quot;&gt;Lexer output&lt;a class=&quot;heading-anchor&quot; href=&quot;#lexer-output&quot; aria-label=&quot;Anchor link for: lexer-output&quot;&gt;#&lt;/a&gt;
&lt;/h1&gt;
&lt;p&gt;Remember when we said earlier that the lexer converts source code to tokens. It is time we talk about those tokens.&lt;/p&gt;
&lt;p&gt;The lexer typically outputs an array/vector/list of tokens &lt;em&gt;(technically speaking, that’s if it is not a streaming lexer but let’s ignore that for now)&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Now, most of the time a token&lt;sup&gt;&lt;a href=&quot;#token&quot;&gt;3&lt;/a&gt;&lt;/sup&gt; is a structure that has a type and a value. Here is an example to illustrate how our NTLC snippet from the &lt;a href=&quot;https://madin.dev/ntlc/intro/&quot;&gt;previous post&lt;/a&gt; would map to a list of tokens:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://madin.dev/ntlc/lexer/lexer_at_work.svg&quot; alt=&quot;Lexer Output&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Notice that because our language is very simple, things almost map one-to-one without any additional data.&lt;/p&gt;
&lt;p&gt;But, say for example our language was to support arbitrary numbers or strings, then we would probably extend our token type to include a value field that would hold the actual value of the token.&lt;/p&gt;
&lt;p&gt;For instance, a string token might look like this:&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;pub&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt; enum&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-5&quot;&gt;    StringLiteral&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;String&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;    //            ^^^^^^&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;    //            This is the value field&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;    //&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;    //&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;    // More token types ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;or in TypeScript:&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;typescript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;class&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;StringLiteral&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;  constructor&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;public readonly&lt;/span&gt;&lt;span class=&quot;z-14 z-i&quot;&gt; value&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt; string&lt;/span&gt;&lt;span&gt;) {}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;type&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;StringLiteral&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; |&lt;/span&gt;&lt;span&gt; ...&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When the lexer scans an input that has a string literal like “Hello World”, it would emit a token of type &lt;code&gt;StringLiteral&lt;/code&gt; with a value of “Hello World” like so:&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Token::StringLiteral(&amp;quot;Hello World&amp;quot;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;One final thing, you might be thinking: wait, where did we get our token types from? Did we just make them up?&lt;/p&gt;
&lt;p&gt;Actually, sort of. Remember, this is &lt;em&gt;our&lt;/em&gt; language and we get to define the rules, but, we won’t get into those until the next article on &lt;a href=&quot;https://madin.dev/ntlc/parser/&quot;&gt;parsers&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;how-do-lexers-work&quot;&gt;How do lexers work?&lt;a class=&quot;heading-anchor&quot; href=&quot;#how-do-lexers-work&quot; aria-label=&quot;Anchor link for: how-do-lexers-work&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Before we describe the workings of the lexer, and parser for that matter, it is worth mentioning that there exists tools known as Parser Generators &lt;em&gt;(&lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://en.wikipedia.org/wiki/Yacc&quot;&gt;yacc&lt;/a&gt; and &lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://tree-sitter.github.io/tree-sitter/&quot;&gt;Tree Sitter&lt;/a&gt; are such tools)&lt;/em&gt; that can actually generate code that implements the lexer and parser for your given you provide them with your programming language definition in some form or another, but hey, where is the fun in that!&lt;/p&gt;
&lt;p&gt;Okay, getting back to how lexers work. They basically scan the input character by character&lt;sup&gt;&lt;a href=&quot;#lexer_regex&quot;&gt;4&lt;/a&gt;&lt;/sup&gt; &lt;em&gt;(and most of the time, they take a sneak peek ahead at the next character or characters)&lt;/em&gt; and try to match those characters against a set of rules. If a rule matches, the lexer would emit a token and move on to the next character. If it comes across an unexpected character, it would throw an error.&lt;/p&gt;
&lt;p&gt;It’s good to know that in NTLC we have the following token types:&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-13&quot;&gt;pub&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt; enum&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;True&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; // Literal true&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;False&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; // Literal false&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;If&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; // Keyword if&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Then&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; // Keyword then&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Else&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; // Keyword else&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Zero&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; // Literal zero&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Succ&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; // builtin function succ()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Pred&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; // builtin function pred()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;IsZero&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; // builtin function iszero()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LeftParenthesis&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; // (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;RightParenthesis&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; // )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-6&quot;&gt;    EOF&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; // End of file (this is not something that ones types in but it&amp;#39;s a handy way to represent&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;         // the end of the input)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Okay, enough with words. I feel that describing the workings of a compiler makes things sound more complicated than they actually are. So, let’s just look at the code. I have left comments all over the place to explain what is going on.&lt;/p&gt;
&lt;ol id=&quot;footnotes&quot;&gt;
  &lt;li id=&quot;lexer_derivation&quot;&gt;The word &quot;lexer&quot; is derived from the Latin word &quot;lexicon&quot; which refers to the vocabulary of a language, including its words and their meanings.&lt;/li&gt;
  &lt;li id=&quot;compiler_pipeline&quot;&gt;Actually, there is something quite satisfying about compilers: they are as &quot;pure&quot; as they can be. The compiler is essentially a function that takes a string and returns an alternative representation of that string -- no network calls, no database transactions, no file storage etc.&lt;/li&gt;
  &lt;li id=&quot;token&quot;&gt;Sometimes the token encodes additional information such as the line number and column of the corresponding source code. Choosing what to store in a token depends on your application and requirements&lt;/li&gt;
  &lt;li id=&quot;lexer_regex&quot;&gt;Most of the time, lexers are defined in terms of one or more more regular expressions and you will see why soon!&lt;/li&gt;
&lt;/ol&gt;
&lt;h1 id=&quot;full-lexer-code-listing&quot;&gt;Full Lexer code listing&lt;a class=&quot;heading-anchor&quot; href=&quot;#full-lexer-code-listing&quot; aria-label=&quot;Anchor link for: full-lexer-code-listing&quot;&gt;#&lt;/a&gt;
&lt;/h1&gt;
&lt;blockquote&gt;
&lt;p&gt;HINT: check the tests at the bottom of the file for more examples on how the lexer works&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Again, the full source code for the project is available &lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://github.com/abjrcode/ntlc/blob/main/compiler/src/lexer.rs&quot;&gt;here&lt;/a&gt;!&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;scan()&lt;/code&gt;function at line &lt;strong&gt;271&lt;/strong&gt; is the entry point of the lexer module and the place where the main logic resides, so, make sure you start there first as everything else is more or less helper utilities.&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;  1&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;use&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Error&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;  2&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;use&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Debug&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;  3&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;use&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;vec&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Vec&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;  4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;  5&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;// I keep a copy of the grammar here for reference&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;  6&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;/*&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;  7&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; *    t ::= // terms&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;  8&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; *        true  // constant true&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;  9&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; *        false // constant false&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 10&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; *        if t then t else t // conditional&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 11&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; *        0 // constant zero&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 12&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; *        succ t // successor&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 13&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; *        pred t // predecessor&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 14&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; *        iszero t // zero test&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 15&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; *        */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 16&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 17&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;static&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; KEYWORD_TRUE&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;: &amp;amp;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;true&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 18&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;static&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; KEYWORD_FALSE&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;: &amp;amp;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;false&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 19&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;static&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; KEYWORD_IF&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;: &amp;amp;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;if&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 20&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;static&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; KEYWORD_THEN&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;: &amp;amp;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;then&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 21&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;static&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; KEYWORD_ELSE&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;: &amp;amp;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;else&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 22&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;static&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; KEYWORD_IS_ZERO&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;: &amp;amp;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;iszero&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 23&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;static&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; KEYWORD_ZERO&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;: &amp;amp;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;0&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 24&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;static&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; KEYWORD_SUCC&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;: &amp;amp;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;succ&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 25&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;static&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; KEYWORD_PRED&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;: &amp;amp;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;pred&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 26&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 27&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;// These are directives. Similar to annotations or decorators in other programming languages&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 28&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;// clippy is Rust&amp;#39;s linter and we are just telling it to be quite about EOF casing&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 29&lt;/span&gt;&lt;span&gt;#[allow(clippy&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span&gt;upper_case_acronyms)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 30&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;// In Rust one can ask the compiler to implement certain interfaces for&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 31&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;// a type by using the `derive` keyword. In this case we are asking the&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 32&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;// compiler to implement the `PartialEq` (Partial Equality) interface for the `Token` type&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 33&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;// which is needed/used when we compare two values of the same type for equality using ==.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 34&lt;/span&gt;&lt;span&gt;#[derive(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;PartialEq&lt;/span&gt;&lt;span&gt;)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 35&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;/*&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 36&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; `enum` is, roughly speaking, similar to how unions work in TypeScript where you can say:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 37&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; `type Token = True | False`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 38&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; And so token can either be True or False&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 39&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; Notice that `True` and `False` are not the literal boolean values `true` and `false`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 40&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; but rather the names of the variants of the enum. They are types in their own right.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 41&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; Tokens are the output of the lexer and are the input of the parser.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 42&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;*/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 43&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;pub&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt; enum&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 44&lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;True&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 45&lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;False&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 46&lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;If&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 47&lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Then&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 48&lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Else&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 49&lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Zero&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 50&lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Succ&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 51&lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Pred&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 52&lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;IsZero&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 53&lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LeftParenthesis&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 54&lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;RightParenthesis&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 55&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;    EOF&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 56&lt;/span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 57&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 58&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;/**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 59&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; * Rust doesn&amp;#39;t have classes but structs which are similar to classes in other languages, just without &amp;quot;inline&amp;quot; methods.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 60&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; * This is how one implements &amp;quot;traits&amp;quot; (which roughly correspond to interfaces in other languages)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 61&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; * for a struct.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 62&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; * Essentially we are saying the Token type implements the Debug trait.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 63&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; * The Debug trait allows us to print the value of a Token when used in a format string (akin to string interpolation).&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 64&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 65&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;impl&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Debug&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; for&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 66&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; fmt&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 67&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;        &amp;amp;&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt;self&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; /* similar to `this` in object oriented languages */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 68&lt;/span&gt;&lt;span&gt;        f&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;: &amp;amp;mut&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Formatter&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 69&lt;/span&gt;&lt;span&gt;    )&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Result&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 70&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;        /*&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 71&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;         * I hope this very readable and self explanatory&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 72&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;         */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 73&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;        match&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 74&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; write!&lt;/span&gt;&lt;span&gt;(f,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;TRUE&amp;quot;&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 75&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; write!&lt;/span&gt;&lt;span&gt;(f,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;FALSE&amp;quot;&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 76&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;If&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; write!&lt;/span&gt;&lt;span&gt;(f,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;IF&amp;quot;&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 77&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Then&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; write!&lt;/span&gt;&lt;span&gt;(f,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;THEN&amp;quot;&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 78&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Else&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; write!&lt;/span&gt;&lt;span&gt;(f,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;ELSE&amp;quot;&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 79&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Zero&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; write!&lt;/span&gt;&lt;span&gt;(f,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;0&amp;quot;&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 80&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Succ&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; write!&lt;/span&gt;&lt;span&gt;(f,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;SUCC&amp;quot;&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 81&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Pred&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; write!&lt;/span&gt;&lt;span&gt;(f,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;PRED&amp;quot;&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 82&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;IsZero&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; write!&lt;/span&gt;&lt;span&gt;(f,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;IS_ZERO&amp;quot;&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 83&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LeftParenthesis&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; write!&lt;/span&gt;&lt;span&gt;(f,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;(&amp;quot;&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 84&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;RightParenthesis&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; write!&lt;/span&gt;&lt;span&gt;(f,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;)&amp;quot;&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 85&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;EOF&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; write!&lt;/span&gt;&lt;span&gt;(f,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;&amp;lt;EOF&amp;gt;&amp;quot;&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 86&lt;/span&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 87&lt;/span&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 88&lt;/span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 89&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 90&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;/**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 91&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; * While the `Debug` trait is used for debugging purposes, the `Display` trait is used for printing&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 92&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; * a human readable or nice string representation of a value.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 93&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; * It is similar in that regard to how one might override `toString()` in Java.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 94&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 95&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;impl&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Display&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; for&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 96&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; fmt&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt;self&lt;/span&gt;&lt;span&gt;, f&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;: &amp;amp;mut&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Formatter&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Result&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 97&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;        match&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 98&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; write!&lt;/span&gt;&lt;span&gt;(f,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;TRUE&amp;quot;&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt; 99&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; write!&lt;/span&gt;&lt;span&gt;(f,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;FALSE&amp;quot;&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;100&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;If&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; write!&lt;/span&gt;&lt;span&gt;(f,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;IF&amp;quot;&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;101&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Then&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; write!&lt;/span&gt;&lt;span&gt;(f,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;THEN&amp;quot;&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;102&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Else&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; write!&lt;/span&gt;&lt;span&gt;(f,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;ELSE&amp;quot;&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;103&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Zero&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; write!&lt;/span&gt;&lt;span&gt;(f,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;0&amp;quot;&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;104&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Succ&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; write!&lt;/span&gt;&lt;span&gt;(f,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;SUCC&amp;quot;&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;105&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Pred&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; write!&lt;/span&gt;&lt;span&gt;(f,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;PRED&amp;quot;&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;106&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;IsZero&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; write!&lt;/span&gt;&lt;span&gt;(f,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;IS_ZERO&amp;quot;&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;107&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LeftParenthesis&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; write!&lt;/span&gt;&lt;span&gt;(f,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;(&amp;quot;&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;108&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;RightParenthesis&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; write!&lt;/span&gt;&lt;span&gt;(f,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;)&amp;quot;&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;109&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;EOF&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; write!&lt;/span&gt;&lt;span&gt;(f,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;&amp;lt;EOF&amp;gt;&amp;quot;&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;110&lt;/span&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;111&lt;/span&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;112&lt;/span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;113&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;114&lt;/span&gt;&lt;span&gt;#[derive(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;PartialEq&lt;/span&gt;&lt;span&gt;)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;115&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;/*&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;116&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;* We use an enum to represent the different kind of errors the lexer could run into&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;117&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;*/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;118&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;pub&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt; enum&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LexingError&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;119&lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnrecognizedToken&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;120&lt;/span&gt;&lt;span&gt;        found&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;String&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;121&lt;/span&gt;&lt;span&gt;        column&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;usize&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;122&lt;/span&gt;&lt;span&gt;        line&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;usize&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;123&lt;/span&gt;&lt;span&gt;    },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;124&lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnexpectedCharacter&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;125&lt;/span&gt;&lt;span&gt;        found&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;char&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;126&lt;/span&gt;&lt;span&gt;        expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Vec&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;String&lt;/span&gt;&lt;span&gt;&amp;gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;127&lt;/span&gt;&lt;span&gt;        column&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;usize&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;128&lt;/span&gt;&lt;span&gt;        line&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;usize&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;129&lt;/span&gt;&lt;span&gt;    },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;130&lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnexpectedEOF&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;131&lt;/span&gt;&lt;span&gt;        expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Vec&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;String&lt;/span&gt;&lt;span&gt;&amp;gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;132&lt;/span&gt;&lt;span&gt;        column&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;usize&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;133&lt;/span&gt;&lt;span&gt;        line&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;usize&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;134&lt;/span&gt;&lt;span&gt;    },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;135&lt;/span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;136&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;137&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;/**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;138&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; * This is a helper function that is used to format Lexer error message&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;139&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;140&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; format_expectation_error&lt;/span&gt;&lt;span&gt;(expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;: &amp;amp;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Vec&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;String&lt;/span&gt;&lt;span&gt;&amp;gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;String&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;141&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;    let&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; mut&lt;/span&gt;&lt;span&gt; result&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Vec&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;String&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Vec&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;new&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;142&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;143&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;    for&lt;/span&gt;&lt;span&gt; e&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; in&lt;/span&gt;&lt;span&gt; expected {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;144&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;        match&lt;/span&gt;&lt;span&gt; e {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;145&lt;/span&gt;&lt;span&gt;            s&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; if&lt;/span&gt;&lt;span&gt; s&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; ==&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; result&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;push&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;quot;&amp;lt;SPACE&amp;gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;to_string&lt;/span&gt;&lt;span&gt;()),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;146&lt;/span&gt;&lt;span&gt;            s&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; if&lt;/span&gt;&lt;span&gt; s&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; ==&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;\t&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; result&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;push&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;quot;&amp;lt;TAB&amp;gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;to_string&lt;/span&gt;&lt;span&gt;()),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;147&lt;/span&gt;&lt;span&gt;            s&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; if&lt;/span&gt;&lt;span&gt; s&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; ==&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;\0&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; result&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;push&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;quot;&amp;lt;EOF&amp;gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;to_string&lt;/span&gt;&lt;span&gt;()),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;148&lt;/span&gt;&lt;span&gt;            s&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; result&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;push&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;format!&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;quot;&amp;#39;{}&amp;#39;&amp;quot;&lt;/span&gt;&lt;span&gt;, s)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;149&lt;/span&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;150&lt;/span&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;151&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;152&lt;/span&gt;&lt;span&gt;    result&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;join&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;quot;, &amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;153&lt;/span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;154&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;155&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;impl&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Display&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; for&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LexingError&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;156&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; fmt&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt;self&lt;/span&gt;&lt;span&gt;, f&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;: &amp;amp;mut&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Formatter&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Result&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;157&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;        match&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;158&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LexingError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnrecognizedToken&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;159&lt;/span&gt;&lt;span&gt;                found,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;160&lt;/span&gt;&lt;span&gt;                column,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;161&lt;/span&gt;&lt;span&gt;                line,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;162&lt;/span&gt;&lt;span&gt;            }&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;163&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;                write!&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;164&lt;/span&gt;&lt;span&gt;                    f,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;165&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;                    &amp;quot;Unrecognized token &amp;#39;{}&amp;#39; at line {}, column {}&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;166&lt;/span&gt;&lt;span&gt;                    found,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;167&lt;/span&gt;&lt;span&gt;                    line&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; +&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 1&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;168&lt;/span&gt;&lt;span&gt;                    column&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;169&lt;/span&gt;&lt;span&gt;                )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;170&lt;/span&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;171&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LexingError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnexpectedCharacter&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;172&lt;/span&gt;&lt;span&gt;                found,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;173&lt;/span&gt;&lt;span&gt;                expected,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;174&lt;/span&gt;&lt;span&gt;                column,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;175&lt;/span&gt;&lt;span&gt;                line,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;176&lt;/span&gt;&lt;span&gt;            }&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;177&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;                write!&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;178&lt;/span&gt;&lt;span&gt;                    f,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;179&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;                    &amp;quot;Found &amp;#39;{}&amp;#39; at line {}, column {} when perhaphs you meant &amp;#39;{}&amp;#39;?&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;180&lt;/span&gt;&lt;span&gt;                    found,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;181&lt;/span&gt;&lt;span&gt;                    line,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;182&lt;/span&gt;&lt;span&gt;                    column&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; +&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 1&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;183&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;                    format_expectation_error&lt;/span&gt;&lt;span&gt;(expected)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;184&lt;/span&gt;&lt;span&gt;                )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;185&lt;/span&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;186&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LexingError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnexpectedEOF&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;187&lt;/span&gt;&lt;span&gt;                expected,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;188&lt;/span&gt;&lt;span&gt;                column,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;189&lt;/span&gt;&lt;span&gt;                line,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;190&lt;/span&gt;&lt;span&gt;            }&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;191&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;                write!&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;192&lt;/span&gt;&lt;span&gt;                    f,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;193&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;                    &amp;quot;Unexpected end of file at line {}, column {} when you perhaps meant &amp;#39;{}&amp;#39;?&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;194&lt;/span&gt;&lt;span&gt;                    line,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;195&lt;/span&gt;&lt;span&gt;                    column&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; +&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 1&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;196&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;                    format_expectation_error&lt;/span&gt;&lt;span&gt;(expected)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;197&lt;/span&gt;&lt;span&gt;                )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;198&lt;/span&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;199&lt;/span&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;200&lt;/span&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;201&lt;/span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;202&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;203&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;impl&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Debug&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; for&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LexingError&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;204&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; fmt&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt;self&lt;/span&gt;&lt;span&gt;, f&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;: &amp;amp;mut&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Formatter&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Result&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;205&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;        match&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; self&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;206&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LexingError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnrecognizedToken&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;207&lt;/span&gt;&lt;span&gt;                found,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;208&lt;/span&gt;&lt;span&gt;                column,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;209&lt;/span&gt;&lt;span&gt;                line,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;210&lt;/span&gt;&lt;span&gt;            }&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;211&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;                write!&lt;/span&gt;&lt;span&gt;(f,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;Unknown token &amp;#39;{}&amp;#39; at ({}, {})&amp;quot;&lt;/span&gt;&lt;span&gt;, found, line, column)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;212&lt;/span&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;213&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LexingError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnexpectedCharacter&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;214&lt;/span&gt;&lt;span&gt;                found,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;215&lt;/span&gt;&lt;span&gt;                expected,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;216&lt;/span&gt;&lt;span&gt;                column,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;217&lt;/span&gt;&lt;span&gt;                line,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;218&lt;/span&gt;&lt;span&gt;            }&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;219&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;                write!&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;220&lt;/span&gt;&lt;span&gt;                    f,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;221&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;                    &amp;quot;Unexpected token &amp;#39;{}&amp;#39; at ({}, {}). Expectation context {}&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;222&lt;/span&gt;&lt;span&gt;                    found,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;223&lt;/span&gt;&lt;span&gt;                    line,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;224&lt;/span&gt;&lt;span&gt;                    column,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;225&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;                    format_expectation_error&lt;/span&gt;&lt;span&gt;(expected)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;226&lt;/span&gt;&lt;span&gt;                )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;227&lt;/span&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;228&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LexingError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnexpectedEOF&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;229&lt;/span&gt;&lt;span&gt;                expected,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;230&lt;/span&gt;&lt;span&gt;                column,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;231&lt;/span&gt;&lt;span&gt;                line,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;232&lt;/span&gt;&lt;span&gt;            }&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;233&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;                write!&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;234&lt;/span&gt;&lt;span&gt;                    f,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;235&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;                    &amp;quot;Unexpected EOF looking for lexeme &amp;#39;{}&amp;#39; at ({}, {})&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;236&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;                    format_expectation_error&lt;/span&gt;&lt;span&gt;(expected),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;237&lt;/span&gt;&lt;span&gt;                    line,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;238&lt;/span&gt;&lt;span&gt;                    column&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;239&lt;/span&gt;&lt;span&gt;                )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;240&lt;/span&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;241&lt;/span&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;242&lt;/span&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;243&lt;/span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;244&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;245&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;/**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;246&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; * The `Error` trait is like a marker interface&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;247&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; * It is just tells the compiler that `LexingError` is, well, kinda of an error&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;248&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;249&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;impl&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Error&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; for&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LexingError&lt;/span&gt;&lt;span&gt; {}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;250&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;251&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;/**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;252&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; * This is the heart of the lexer. It basically takes NTLC program source code&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;253&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; * as input and returns a vector/list of tokens of type `Token` as output.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;254&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;255&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; * It iterates the input string character by character from left to right and tries to match them&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;256&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; * against the known tokens of the language.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;257&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;258&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; * Most of the time, the lexer is actually made part of the parser module and is implemented&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;259&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; * as a streaming lexer. That is, it is implemented as a function that returns the next&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;260&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; * token only when asked for explicitly by the parser and not all at once.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;261&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; * This is done to avoid having to read the entire input into memory at once.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;262&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; * Also, when working within a text editor or IDE, those tools can send you incomplete&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;263&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; * pieces of code to avoid resending the entire source file over and over again.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;264&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; * We will see this when we are working on the language server.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;265&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;266&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;267&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; * You might see the `&amp;amp;str` type and wonder what it is. It is just a reference to a string.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;268&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; * Or to be more technically correct, a readonly reference to a string slice (what a mouthful).&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;269&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; * This avoids copying the string around in memory. Don&amp;#39;t worry about it too much.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;270&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;271&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; * The `Result&amp;lt;&amp;gt;` type is a probably implemented as an `enum` under te hood. It says this function&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;272&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; * either returns a vector of tokens or an error&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;273&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; * This is a concept from functional programming and it&amp;#39;s very idiomatic to see the Result&amp;lt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;274&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; * type all over the place in Rust code.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;275&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; * If you worked with a language that uses exceptions, this might be feel strange at first&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;276&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; * but, I personally think it is way cleaner to explicitly state that your function might&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;277&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; * return an error. This reminds me to some extent of checked exceptions in Java (at least last time I used it).&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;278&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;279&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;pub fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;: &amp;amp;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;str&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Result&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Vec&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span&gt;&amp;gt;, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LexingError&lt;/span&gt;&lt;span&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;280&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;    let&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; mut&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Vec&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Vec&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;new&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;281&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;282&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;    /*&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;283&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;    This line might seem to be doing a bit of magic but essentially it is just a convenient&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;284&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;    way to line up the input with itself shifted by one character, essentially giving us each character&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;285&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;    and the one following it as a pair (char, next_char). Let me demonstrate:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;286&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;287&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;    let&amp;#39;s say that the input is &amp;quot;succ(0)&amp;quot; this will give us the following:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;288&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;    s u c c ( 0 )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;289&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;    u c c ( 0 ) \0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;290&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;291&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;    and as pairs comes out as:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;292&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;    [(&amp;#39;s&amp;#39;, &amp;#39;u&amp;#39;), (&amp;#39;u&amp;#39;, &amp;#39;c&amp;#39;), (&amp;#39;c&amp;#39;, &amp;#39;c&amp;#39;), (&amp;#39;c&amp;#39;, &amp;#39;(&amp;#39;), (&amp;#39;(&amp;#39;, &amp;#39;0&amp;#39;), (&amp;#39;0&amp;#39;, &amp;#39;)&amp;#39;), (&amp;#39;)&amp;#39;, &amp;#39;\0&amp;#39;)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;293&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;294&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;    This is handy because a lot of the time we need to &amp;quot;lookahead&amp;quot; when we are scanning the input&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;295&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;    to decide what the next token is. Keep reading.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;296&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;    */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;297&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;    let&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; mut&lt;/span&gt;&lt;span&gt; chars&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;298&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;        .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;chars&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;299&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;        .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;zip&lt;/span&gt;&lt;span&gt;(input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;chars&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;skip&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;1&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;chain&lt;/span&gt;&lt;span&gt;([&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;\0&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;]))&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; // we are adding a null character at the end of the shifted string so both strings have the same length, this prevents the iterator from stopping prematurely&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;300&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;        .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;peekable&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;301&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;302&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;    // We are tracking the line number although our lexer doesn&amp;#39;t support multiple lines of input&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;303&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;    // This is useful for error reporting if we were to support new lines.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;304&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;    // The same with the `index` which is the column number within the input string&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;305&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;    let&lt;/span&gt;&lt;span&gt; line&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 1&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;usize&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;306&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;    let&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; mut&lt;/span&gt;&lt;span&gt; index&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 0&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;usize&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;307&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;308&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;    // This is the main loop of the lexer. It iterates over the input characters&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;309&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;    // and tries to match them against known tokens of the language&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;310&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;    // The `let Some(&amp;amp;(c, next)) = chars.peek()` is known as a pattern match expression&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;311&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;    // It is also something that is very common in functional languages&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;312&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;    // It is similar to destructuring in JavaScript or Python but more powerful&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;313&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;    // Here we are saying, if there is a next character in the input, assign it to `c`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;314&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;    // and assign the character after it to `next`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;315&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;    while&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt; let&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;(c, next))&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; chars&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;peek&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;316&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;        // This is the main match statement. It is similar to a switch statement in other languages&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;317&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;        // but more powerful because of pattern matching&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;318&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;        // Now, the code basically and does the following:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;319&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;        match&lt;/span&gt;&lt;span&gt; c {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;320&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;            // if the current character is &amp;#39;t&amp;#39; then check the next character&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;321&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;            // because in our grammar, there are two tokens that start with &amp;#39;t&amp;#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;322&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;            // `true` and `then` and we need to know which one it is&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;323&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;            // if the `t` is followed by an `r` then it is `true` otherwise it is `then`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;324&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;            // and we can move on to the next token&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;325&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;            // the reset of the rules work in a similar fashion&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;326&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;            // now you see why lexers typically use regular expressions to match tokens&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;327&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;            &amp;#39;t&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt; match&lt;/span&gt;&lt;span&gt; next {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;328&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;                &amp;#39;r&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;329&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;                    /*&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;330&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;                    We use the consume function to &amp;quot;consume&amp;quot; the rest of the keyword&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;331&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;                    and advance the iterator to the next character&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;332&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;                     */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;333&lt;/span&gt;&lt;span&gt;                    index&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; +=&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; consume&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;mut&lt;/span&gt;&lt;span&gt; chars,&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; KEYWORD_TRUE&lt;/span&gt;&lt;span&gt;, line, index)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;334&lt;/span&gt;&lt;span&gt;                    tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;push&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;True&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;335&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;                    /*&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;336&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;                    We use the match_one_of function to check if the next character is&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;337&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;                    one of the characters we expect to see after the keyword&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;338&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;                    Imagine that the input might be the invalid program `truefalse`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;339&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;                    This is incorrect and we we use match_one_of to detect that&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;340&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;                    Here we are saying we expect to see either a space, a tab, a right parenthesis&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;341&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;                    Notice that this would accept the input `true)` which is also incorrect&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;342&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;                    but that would be detected by the parser&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;343&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;                    Choosing which errors to catch where is a matter of taste and maybe&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;344&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;                    a bit of performance&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;345&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;                    */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;346&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;                    match_one_of&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;347&lt;/span&gt;&lt;span&gt;                        chars&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;peek&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;map&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;|&amp;amp;&lt;/span&gt;&lt;span&gt;(x, _)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;|&lt;/span&gt;&lt;span&gt; x),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;348&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;                        &amp;amp;&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;#39; &amp;#39;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;\t&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;#39;)&amp;#39;&lt;/span&gt;&lt;span&gt;],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;349&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;                        true&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;350&lt;/span&gt;&lt;span&gt;                        line,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;351&lt;/span&gt;&lt;span&gt;                        index,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;352&lt;/span&gt;&lt;span&gt;                    )&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;353&lt;/span&gt;&lt;span&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;354&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;                &amp;#39;h&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;355&lt;/span&gt;&lt;span&gt;                    index&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; +=&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; consume&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;mut&lt;/span&gt;&lt;span&gt; chars,&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; KEYWORD_THEN&lt;/span&gt;&lt;span&gt;, line, index)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;356&lt;/span&gt;&lt;span&gt;                    tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;push&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Then&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;357&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;                    match_one_of&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;358&lt;/span&gt;&lt;span&gt;                        chars&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;peek&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;map&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;|&amp;amp;&lt;/span&gt;&lt;span&gt;(x, _)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;|&lt;/span&gt;&lt;span&gt; x),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;359&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;                        &amp;amp;&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;#39; &amp;#39;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;\t&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;360&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;                        false&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;361&lt;/span&gt;&lt;span&gt;                        line,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;362&lt;/span&gt;&lt;span&gt;                        index,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;363&lt;/span&gt;&lt;span&gt;                    )&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;364&lt;/span&gt;&lt;span&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;365&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;                &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;\0&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;366&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;                    return&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LexingError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnexpectedEOF&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;367&lt;/span&gt;&lt;span&gt;                        expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; vec!&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;quot;true&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;to_string&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;then&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;to_string&lt;/span&gt;&lt;span&gt;()],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;368&lt;/span&gt;&lt;span&gt;                        column&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; index,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;369&lt;/span&gt;&lt;span&gt;                        line,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;370&lt;/span&gt;&lt;span&gt;                    })&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;371&lt;/span&gt;&lt;span&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;372&lt;/span&gt;&lt;span&gt;                c&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;373&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;                    return&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LexingError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnexpectedCharacter&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;374&lt;/span&gt;&lt;span&gt;                        found&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; c,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;375&lt;/span&gt;&lt;span&gt;                        expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; vec!&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;quot;true&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;to_string&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;then&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;to_string&lt;/span&gt;&lt;span&gt;()],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;376&lt;/span&gt;&lt;span&gt;                        column&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; index,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;377&lt;/span&gt;&lt;span&gt;                        line,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;378&lt;/span&gt;&lt;span&gt;                    })&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;379&lt;/span&gt;&lt;span&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;380&lt;/span&gt;&lt;span&gt;            },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;381&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;            &amp;#39;f&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;382&lt;/span&gt;&lt;span&gt;                index&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; +=&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; consume&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;mut&lt;/span&gt;&lt;span&gt; chars,&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; KEYWORD_FALSE&lt;/span&gt;&lt;span&gt;, line, index)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;383&lt;/span&gt;&lt;span&gt;                tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;push&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;False&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;384&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;                match_one_of&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;385&lt;/span&gt;&lt;span&gt;                    chars&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;peek&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;map&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;|&amp;amp;&lt;/span&gt;&lt;span&gt;(x, _)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;|&lt;/span&gt;&lt;span&gt; x),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;386&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;                    &amp;amp;&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;#39; &amp;#39;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;\t&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;#39;)&amp;#39;&lt;/span&gt;&lt;span&gt;],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;387&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;                    true&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;388&lt;/span&gt;&lt;span&gt;                    line,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;389&lt;/span&gt;&lt;span&gt;                    index,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;390&lt;/span&gt;&lt;span&gt;                )&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;391&lt;/span&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;392&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;            &amp;#39;i&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt; match&lt;/span&gt;&lt;span&gt; next {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;393&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;                &amp;#39;f&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;394&lt;/span&gt;&lt;span&gt;                    index&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; +=&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; consume&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;mut&lt;/span&gt;&lt;span&gt; chars,&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; KEYWORD_IF&lt;/span&gt;&lt;span&gt;, line, index)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;395&lt;/span&gt;&lt;span&gt;                    tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;push&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;If&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;396&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;                    match_one_of&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;397&lt;/span&gt;&lt;span&gt;                        chars&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;peek&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;map&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;|&amp;amp;&lt;/span&gt;&lt;span&gt;(x, _)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;|&lt;/span&gt;&lt;span&gt; x),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;398&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;                        &amp;amp;&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;#39; &amp;#39;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;\t&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;399&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;                        false&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;400&lt;/span&gt;&lt;span&gt;                        line,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;401&lt;/span&gt;&lt;span&gt;                        index,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;402&lt;/span&gt;&lt;span&gt;                    )&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;403&lt;/span&gt;&lt;span&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;404&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;                &amp;#39;s&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;405&lt;/span&gt;&lt;span&gt;                    index&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; +=&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; consume&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;mut&lt;/span&gt;&lt;span&gt; chars,&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; KEYWORD_IS_ZERO&lt;/span&gt;&lt;span&gt;, line, index)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;406&lt;/span&gt;&lt;span&gt;                    tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;push&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;IsZero&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;407&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;                    match_one_of&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;408&lt;/span&gt;&lt;span&gt;                        chars&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;peek&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;map&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;|&amp;amp;&lt;/span&gt;&lt;span&gt;(x, _)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;|&lt;/span&gt;&lt;span&gt; x),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;409&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;                        &amp;amp;&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;#39; &amp;#39;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;\t&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;#39;(&amp;#39;&lt;/span&gt;&lt;span&gt;],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;410&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;                        false&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;411&lt;/span&gt;&lt;span&gt;                        line,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;412&lt;/span&gt;&lt;span&gt;                        index,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;413&lt;/span&gt;&lt;span&gt;                    )&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;414&lt;/span&gt;&lt;span&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;415&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;                &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;\0&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;416&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;                    return&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LexingError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnexpectedEOF&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;417&lt;/span&gt;&lt;span&gt;                        expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; vec!&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;quot;if&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;to_string&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;iszero&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;to_string&lt;/span&gt;&lt;span&gt;()],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;418&lt;/span&gt;&lt;span&gt;                        column&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; index,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;419&lt;/span&gt;&lt;span&gt;                        line,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;420&lt;/span&gt;&lt;span&gt;                    })&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;421&lt;/span&gt;&lt;span&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;422&lt;/span&gt;&lt;span&gt;                c&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;423&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;                    return&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LexingError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnexpectedCharacter&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;424&lt;/span&gt;&lt;span&gt;                        found&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; c,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;425&lt;/span&gt;&lt;span&gt;                        expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; vec!&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;quot;if&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;to_string&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;iszero&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;to_string&lt;/span&gt;&lt;span&gt;()],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;426&lt;/span&gt;&lt;span&gt;                        column&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; index,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;427&lt;/span&gt;&lt;span&gt;                        line,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;428&lt;/span&gt;&lt;span&gt;                    })&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;429&lt;/span&gt;&lt;span&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;430&lt;/span&gt;&lt;span&gt;            },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;431&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;            &amp;#39;e&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;432&lt;/span&gt;&lt;span&gt;                index&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; +=&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; consume&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;mut&lt;/span&gt;&lt;span&gt; chars,&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; KEYWORD_ELSE&lt;/span&gt;&lt;span&gt;, line, index)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;433&lt;/span&gt;&lt;span&gt;                tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;push&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Else&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;434&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;                match_one_of&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;435&lt;/span&gt;&lt;span&gt;                    chars&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;peek&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;map&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;|&amp;amp;&lt;/span&gt;&lt;span&gt;(x, _)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;|&lt;/span&gt;&lt;span&gt; x),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;436&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;                    &amp;amp;&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;#39; &amp;#39;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;\t&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;437&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;                    false&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;438&lt;/span&gt;&lt;span&gt;                    line,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;439&lt;/span&gt;&lt;span&gt;                    index,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;440&lt;/span&gt;&lt;span&gt;                )&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;441&lt;/span&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;442&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;            &amp;#39;0&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;443&lt;/span&gt;&lt;span&gt;                index&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; +=&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; consume&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;mut&lt;/span&gt;&lt;span&gt; chars,&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; KEYWORD_ZERO&lt;/span&gt;&lt;span&gt;, line, index)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;444&lt;/span&gt;&lt;span&gt;                tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;push&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Zero&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;445&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;                match_one_of&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;446&lt;/span&gt;&lt;span&gt;                    chars&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;peek&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;map&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;|&amp;amp;&lt;/span&gt;&lt;span&gt;(x, _)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;|&lt;/span&gt;&lt;span&gt; x),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;447&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;                    &amp;amp;&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;#39; &amp;#39;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;\t&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;#39;)&amp;#39;&lt;/span&gt;&lt;span&gt;],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;448&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;                    true&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;449&lt;/span&gt;&lt;span&gt;                    line,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;450&lt;/span&gt;&lt;span&gt;                    index,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;451&lt;/span&gt;&lt;span&gt;                )&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;452&lt;/span&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;453&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;            &amp;#39;s&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;454&lt;/span&gt;&lt;span&gt;                index&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; +=&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; consume&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;mut&lt;/span&gt;&lt;span&gt; chars,&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; KEYWORD_SUCC&lt;/span&gt;&lt;span&gt;, line, index)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;455&lt;/span&gt;&lt;span&gt;                tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;push&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Succ&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;456&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;                match_one_of&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;457&lt;/span&gt;&lt;span&gt;                    chars&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;peek&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;map&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;|&amp;amp;&lt;/span&gt;&lt;span&gt;(x, _)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;|&lt;/span&gt;&lt;span&gt; x),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;458&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;                    &amp;amp;&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;#39; &amp;#39;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;\t&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;#39;(&amp;#39;&lt;/span&gt;&lt;span&gt;],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;459&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;                    false&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;460&lt;/span&gt;&lt;span&gt;                    line,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;461&lt;/span&gt;&lt;span&gt;                    index,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;462&lt;/span&gt;&lt;span&gt;                )&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;463&lt;/span&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;464&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;            &amp;#39;p&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;465&lt;/span&gt;&lt;span&gt;                index&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; +=&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; consume&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;mut&lt;/span&gt;&lt;span&gt; chars,&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; KEYWORD_PRED&lt;/span&gt;&lt;span&gt;, line, index)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;466&lt;/span&gt;&lt;span&gt;                tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;push&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Pred&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;467&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;                match_one_of&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;468&lt;/span&gt;&lt;span&gt;                    chars&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;peek&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;map&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;|&amp;amp;&lt;/span&gt;&lt;span&gt;(x, _)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;|&lt;/span&gt;&lt;span&gt; x),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;469&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;                    &amp;amp;&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;#39; &amp;#39;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;\t&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;#39;(&amp;#39;&lt;/span&gt;&lt;span&gt;],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;470&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;                    false&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;471&lt;/span&gt;&lt;span&gt;                    line,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;472&lt;/span&gt;&lt;span&gt;                    index,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;473&lt;/span&gt;&lt;span&gt;                )&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;?&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;474&lt;/span&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;475&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;            &amp;#39;(&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;476&lt;/span&gt;&lt;span&gt;                chars&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;next&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;477&lt;/span&gt;&lt;span&gt;                index&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; +=&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 1&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;478&lt;/span&gt;&lt;span&gt;                tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;push&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LeftParenthesis&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;479&lt;/span&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;480&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;            &amp;#39;)&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;481&lt;/span&gt;&lt;span&gt;                chars&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;next&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;482&lt;/span&gt;&lt;span&gt;                index&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; +=&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 1&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;483&lt;/span&gt;&lt;span&gt;                tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;push&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;RightParenthesis&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;484&lt;/span&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;485&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;            /*&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;486&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;            We don&amp;#39;t care about whitespace characters so we just skip them&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;487&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;            */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;488&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;            &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;\t&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; |&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;#39; &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;489&lt;/span&gt;&lt;span&gt;                chars&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;next&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;490&lt;/span&gt;&lt;span&gt;                index&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; +=&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 1&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;491&lt;/span&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;492&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;            /*&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;493&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;            This is the case where we don&amp;#39;t recognize the current character&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;494&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;            as part of the language so we just error&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;495&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;            */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;496&lt;/span&gt;&lt;span&gt;            ut&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;497&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;                return&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LexingError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnrecognizedToken&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;498&lt;/span&gt;&lt;span&gt;                    found&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; ut&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;to_string&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;499&lt;/span&gt;&lt;span&gt;                    column&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; index,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;500&lt;/span&gt;&lt;span&gt;                    line,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;501&lt;/span&gt;&lt;span&gt;                })&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;502&lt;/span&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;503&lt;/span&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;504&lt;/span&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;505&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;506&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;    // We add an EOF token at the end of the token stream to indicate we are done&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;507&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;    // This is used later by the parser to know when to stop or error&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;508&lt;/span&gt;&lt;span&gt;    tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;push&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;EOF&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;509&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;510&lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Ok&lt;/span&gt;&lt;span&gt;(tokens)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;511&lt;/span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;512&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;513&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;/*&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;514&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;This is a helper function that consumes a literal from the input&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;515&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;It is used to match keywords and other literals in the language&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;516&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;517&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; consume&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;T&lt;/span&gt;&lt;span&gt;&amp;gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;518&lt;/span&gt;&lt;span&gt;    input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;: &amp;amp;mut&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;T&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;519&lt;/span&gt;&lt;span&gt;    literal&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;: &amp;amp;&lt;/span&gt;&lt;span&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;static&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;str&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;520&lt;/span&gt;&lt;span&gt;    line&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;usize&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;521&lt;/span&gt;&lt;span&gt;    index&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;usize&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;522&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Result&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;usize&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LexingError&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;523&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;where&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;524&lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;iter&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Iterator&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Item&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;char&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;char&lt;/span&gt;&lt;span&gt;)&amp;gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;525&lt;/span&gt;&lt;span&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;526&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;    let&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; mut&lt;/span&gt;&lt;span&gt; i&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span&gt; index;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;527&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;528&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;    for&lt;/span&gt;&lt;span&gt; expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; in&lt;/span&gt;&lt;span&gt; literal&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;chars&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;529&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;        match&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;next&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;530&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;((c, _))&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;531&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;                if&lt;/span&gt;&lt;span&gt; c&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; !=&lt;/span&gt;&lt;span&gt; expected {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;532&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;                    return&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LexingError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnexpectedCharacter&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;533&lt;/span&gt;&lt;span&gt;                        found&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; c,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;534&lt;/span&gt;&lt;span&gt;                        expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; vec!&lt;/span&gt;&lt;span&gt;[literal&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;to_string&lt;/span&gt;&lt;span&gt;()],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;535&lt;/span&gt;&lt;span&gt;                        column&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; i,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;536&lt;/span&gt;&lt;span&gt;                        line,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;537&lt;/span&gt;&lt;span&gt;                    });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;538&lt;/span&gt;&lt;span&gt;                }&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; else&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;539&lt;/span&gt;&lt;span&gt;                    i&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; +=&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 1&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;540&lt;/span&gt;&lt;span&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;541&lt;/span&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;542&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;None&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;543&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;                return&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LexingError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnexpectedEOF&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;544&lt;/span&gt;&lt;span&gt;                    expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; vec!&lt;/span&gt;&lt;span&gt;[literal&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;to_string&lt;/span&gt;&lt;span&gt;()],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;545&lt;/span&gt;&lt;span&gt;                    column&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; i,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;546&lt;/span&gt;&lt;span&gt;                    line,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;547&lt;/span&gt;&lt;span&gt;                });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;548&lt;/span&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;549&lt;/span&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;550&lt;/span&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;551&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;552&lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Ok&lt;/span&gt;&lt;span&gt;(literal&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;len&lt;/span&gt;&lt;span&gt;())&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;553&lt;/span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;554&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;555&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;/**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;556&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; * This is another helper function that is used to match a character against a list of characters&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;557&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; * Sometimes we might expecting one character or another so this function tries to do that&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;558&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; * and if it cannot it errors&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;559&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; * For example, let&amp;#39;s say our input program is `pre(0)`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;560&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; * The `scan` function sees a `p` and tries to match it against the `pred` keyword&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;561&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; * but when it reaches `e` it cannot find `d` so it errors&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;562&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt; */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;563&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; match_one_of&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;564&lt;/span&gt;&lt;span&gt;    input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Option&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;char&lt;/span&gt;&lt;span&gt;&amp;gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;565&lt;/span&gt;&lt;span&gt;    literals&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;: &amp;amp;&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;char&lt;/span&gt;&lt;span&gt;],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;566&lt;/span&gt;&lt;span&gt;    allow_eof&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;bool&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;567&lt;/span&gt;&lt;span&gt;    line&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;usize&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;568&lt;/span&gt;&lt;span&gt;    index&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;usize&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;569&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Result&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;usize&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LexingError&lt;/span&gt;&lt;span&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;570&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;    match&lt;/span&gt;&lt;span&gt; input {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;571&lt;/span&gt;&lt;span&gt;        &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(next_next)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;572&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;            let&lt;/span&gt;&lt;span&gt; eof_expectation&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; = if&lt;/span&gt;&lt;span&gt; allow_eof {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;573&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;                vec!&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;quot;&amp;lt;EOF&amp;gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;to_string&lt;/span&gt;&lt;span&gt;()]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;574&lt;/span&gt;&lt;span&gt;            }&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; else&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;575&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;                vec!&lt;/span&gt;&lt;span&gt;[]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;576&lt;/span&gt;&lt;span&gt;            };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;577&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;578&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;            if !&lt;/span&gt;&lt;span&gt;literals&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;contains&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;next_next) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;579&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;                return&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LexingError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnexpectedCharacter&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;580&lt;/span&gt;&lt;span&gt;                    found&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; next_next,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;581&lt;/span&gt;&lt;span&gt;                    expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; literals&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;582&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;                        .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;iter&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;583&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;                        .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;map&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;|&lt;/span&gt;&lt;span&gt;c&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; format!&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;quot;{}&amp;quot;&lt;/span&gt;&lt;span&gt;, c))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;584&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;                        .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;chain&lt;/span&gt;&lt;span&gt;(eof_expectation)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;585&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;                        .&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;collect&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;586&lt;/span&gt;&lt;span&gt;                    column&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; index,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;587&lt;/span&gt;&lt;span&gt;                    line,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;588&lt;/span&gt;&lt;span&gt;                });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;589&lt;/span&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;590&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;591&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Ok&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;1&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;592&lt;/span&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;593&lt;/span&gt;&lt;span&gt;        &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;None&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;594&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;            if !&lt;/span&gt;&lt;span&gt;allow_eof {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;595&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;                return&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LexingError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnexpectedEOF&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;596&lt;/span&gt;&lt;span&gt;                    expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; literals&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;iter&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;map&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;|&lt;/span&gt;&lt;span&gt;c&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; format!&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;quot;{}&amp;quot;&lt;/span&gt;&lt;span&gt;, c))&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;collect&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;597&lt;/span&gt;&lt;span&gt;                    column&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; index,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;598&lt;/span&gt;&lt;span&gt;                    line,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;599&lt;/span&gt;&lt;span&gt;                });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;600&lt;/span&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;601&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;602&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Ok&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;0&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;603&lt;/span&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;604&lt;/span&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;605&lt;/span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;606&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;607&lt;/span&gt;&lt;span&gt;#[cfg(test)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;608&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;mod&lt;/span&gt;&lt;span&gt; lexer_tests_happy_path {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;609&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;    use&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; super&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::*&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;610&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;611&lt;/span&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;612&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_scan_empty_string&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;613&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;614&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;615&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;616&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;617&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;0&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;EOF&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;618&lt;/span&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;619&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;620&lt;/span&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;621&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_scan_basic&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;622&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;true false if then else 0 succ pred iszero ()&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;623&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;624&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;625&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;626&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;0&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;True&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;627&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;1&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;False&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;628&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;2&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;If&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;629&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;3&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Then&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;630&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;4&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Else&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;631&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;5&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Zero&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;632&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;6&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Succ&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;633&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;7&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Pred&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;634&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;8&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;IsZero&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;635&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;9&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LeftParenthesis&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;636&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;10&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;RightParenthesis&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;637&lt;/span&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;638&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;639&lt;/span&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;640&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_scan_mixture_of_whitespaces&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;641&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;if&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;\t&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;\t\t&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; then         0 else        succ&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;\t&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;0&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;642&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;643&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;644&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;645&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;0&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;If&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;646&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;1&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;True&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;647&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;2&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Then&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;648&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;3&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Zero&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;649&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;4&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Else&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;650&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;5&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Succ&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;651&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;6&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Zero&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;652&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;7&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;EOF&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;653&lt;/span&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;654&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;655&lt;/span&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;656&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_scan_parantheses&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;657&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;if (true) then 0 else (succ (pred(0))&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;658&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;659&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;660&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;661&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;0&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;If&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;662&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;1&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LeftParenthesis&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;663&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;2&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;True&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;664&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;3&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;RightParenthesis&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;665&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;4&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Then&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;666&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;5&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Zero&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;667&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;6&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Else&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;668&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;7&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LeftParenthesis&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;669&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;8&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Succ&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;670&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;9&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LeftParenthesis&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;671&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;10&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Pred&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;672&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;11&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LeftParenthesis&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;673&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;12&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Zero&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;674&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;13&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;RightParenthesis&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;675&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;14&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;RightParenthesis&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;676&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;15&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;EOF&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;677&lt;/span&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;678&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;679&lt;/span&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;680&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_scan_valid_tokens_bad_syntax&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;681&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;true)false)if then 0&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;682&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;683&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input)&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;684&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;685&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;0&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;True&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;686&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;1&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;RightParenthesis&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;687&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;2&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;False&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;688&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;3&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;RightParenthesis&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;689&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;4&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;If&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;690&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;5&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Then&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;691&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;6&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Zero&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;692&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(tokens[&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;7&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;EOF&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;693&lt;/span&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;694&lt;/span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;695&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;696&lt;/span&gt;&lt;span&gt;#[cfg(test)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;697&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;mod&lt;/span&gt;&lt;span&gt; lexer_tests_sad_path {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;698&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;    use&lt;/span&gt;&lt;span class=&quot;z-14&quot;&gt; super&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::*&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;699&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;700&lt;/span&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;701&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_scan_unrecognized_token_error&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;702&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;if    true then 0   else succ    0 1&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;703&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;704&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;705&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;706&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;707&lt;/span&gt;&lt;span&gt;            tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;err&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;708&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LexingError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnrecognizedToken&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;709&lt;/span&gt;&lt;span&gt;                found&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;from&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;quot;1&amp;quot;&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;710&lt;/span&gt;&lt;span&gt;                column&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 35&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;711&lt;/span&gt;&lt;span&gt;                line&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 1&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;712&lt;/span&gt;&lt;span&gt;            })&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;713&lt;/span&gt;&lt;span&gt;        );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;714&lt;/span&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;715&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;716&lt;/span&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;717&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_scan_unexpected_token_error&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;718&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;succ( suc ( 0 ) )&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;719&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;720&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;721&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;722&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;723&lt;/span&gt;&lt;span&gt;            tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;err&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;724&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LexingError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnexpectedCharacter&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;725&lt;/span&gt;&lt;span&gt;                found&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;#39; &amp;#39;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;726&lt;/span&gt;&lt;span&gt;                expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; vec!&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;quot;succ&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;to_string&lt;/span&gt;&lt;span&gt;()],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;727&lt;/span&gt;&lt;span&gt;                column&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 9&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;728&lt;/span&gt;&lt;span&gt;                line&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 1&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;729&lt;/span&gt;&lt;span&gt;            })&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;730&lt;/span&gt;&lt;span&gt;        );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;731&lt;/span&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;732&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;733&lt;/span&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;734&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_scan_unexpected_eof_error&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;735&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;tr&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;736&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;737&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;738&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;739&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;740&lt;/span&gt;&lt;span&gt;            tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;err&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;741&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LexingError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnexpectedEOF&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;742&lt;/span&gt;&lt;span&gt;                expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; vec!&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;quot;true&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;to_string&lt;/span&gt;&lt;span&gt;()],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;743&lt;/span&gt;&lt;span&gt;                column&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 2&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;744&lt;/span&gt;&lt;span&gt;                line&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 1&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;745&lt;/span&gt;&lt;span&gt;            })&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;746&lt;/span&gt;&lt;span&gt;        );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;747&lt;/span&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;748&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;749&lt;/span&gt;&lt;span&gt;    #[test]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;750&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;    fn&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; test_scan_literals_no_spaces_unexpected_token_error&lt;/span&gt;&lt;span&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;751&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; input&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;quot;truefalse&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;752&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;753&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;        let&lt;/span&gt;&lt;span&gt; tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; scan&lt;/span&gt;&lt;span&gt;(input);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;754&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;755&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;        assert_eq!&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;756&lt;/span&gt;&lt;span&gt;            tokens&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;err&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;757&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;LexingError&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;z-5 z-u&quot;&gt;UnexpectedCharacter&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;758&lt;/span&gt;&lt;span&gt;                found&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt; &amp;#39;f&amp;#39;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;759&lt;/span&gt;&lt;span&gt;                expected&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt; vec!&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;760&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;                    &amp;quot; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;to_string&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;761&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;                    &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt;\t&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;to_string&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;762&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;                    &amp;quot;)&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;to_string&lt;/span&gt;&lt;span&gt;(),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;763&lt;/span&gt;&lt;span class=&quot;z-11&quot;&gt;                    &amp;quot;&amp;lt;EOF&amp;gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-5&quot;&gt;to_string&lt;/span&gt;&lt;span&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;764&lt;/span&gt;&lt;span&gt;                ],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;765&lt;/span&gt;&lt;span&gt;                column&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 4&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;766&lt;/span&gt;&lt;span&gt;                line&lt;/span&gt;&lt;span class=&quot;z-13&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-6&quot;&gt; 1&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;767&lt;/span&gt;&lt;span&gt;            })&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;768&lt;/span&gt;&lt;span&gt;        );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;769&lt;/span&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;770&lt;/span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;</content>
        
    </entry>
    <entry xml:lang="en">
        <title>About Me</title>
        <published>2023-09-17T00:00:00+00:00</published>
        <updated>2023-09-17T00:00:00+00:00</updated>
        
        <author>
          <name>Ibrahim Najjar</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://madin.dev/about-me/"/>
        <id>https://madin.dev/about-me/</id>
        
        <content type="html" xml:base="https://madin.dev/about-me/">&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I love learning new things and building interesting stuff&lt;/p&gt;
&lt;p&gt;If you are keen, &lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://abjrcode.github.io/&quot;&gt;here is my Résumé&lt;/a&gt;&lt;/p&gt;
</content>
        
    </entry>
</feed>
