Documentation

Parser_.Stream

structure TokenStream (τ : Type u_1) :
Type u_1

A token stream backed by an Array with a consumed-count cursor.

Replaces Parser.Stream.OfList as the concrete stream under both parsers. OfList stores its position as the length of a past : List it re-conses on every step, so getPosition — called on every withBacktracking, every choice alternative, twice per located — is O(n) in the number of consumed tokens. TokenStream holds the whole token array once and moves an index, so getPosition/setPosition are O(1) and located is array indexing.

  • toks : Array τ

    Every token, consumed and remaining. Never changes after construction.

  • idx : Nat

    Number of tokens consumed; the current position. Always ≤ toks.size.

Instances For
    def instReprTokenStream.repr {τ✝ : Type u_1} [Repr τ✝] :
    TokenStream τ✝NatStd.Format
    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      @[implicit_reducible]
      instance instReprTokenStream {τ✝ : Type u_1} [Repr τ✝] :
      Equations
      @[implicit_reducible]
      instance instInhabitedTokenStream {a✝ : Type u_1} :
      Equations
      @[inline]
      def TokenStream.ofArray {τ : Type u_1} (toks : Array τ) :

      A fresh stream over toks, positioned at the start.

      Equations
      Instances For
        @[inline]
        def TokenStream.atEnd {τ : Type u_1} (s : TokenStream τ) :

        Whether every token has been consumed.

        Equations
        Instances For
          @[inline]
          def TokenStream.get! {τ : Type u_1} [Inhabited τ] (s : TokenStream τ) (n : Nat) :
          τ

          The token at absolute index n, or panic — for located, which only ever asks for indices inside a span the parser has already crossed.

          Equations
          Instances For
            @[implicit_reducible]
            Equations
            • One or more equations did not get rendered due to their size.