Documentation

Parser.Stream

Parser Stream #

Parsers read input tokens from a stream. In contrast to the Std.Stream class, the stream itself does not change, but instead we keep track of the position inside the stream. This helps with error reporting and and allows for backtracking.

class Parser.Stream (σ : Type u_1) (τ : outParam (Type u_2)) :
Type (max (max (u + 1) u_1) u_2)

Parser stream class

This class implements streams based on a static stream with a moving position.

  • The type Position is used to record position data for the stream type.
  • start (s : σ) : Position returns starting position for the stream s
  • next? (s : σ) (pos : Position) : Option (τ × Position) returns the token at position pos in s together with the next position. It returns none if the end of the stream has been reached.

Implementations should try to make the Position type as lightweight as possible. Often Position is just a scalar type or another simple type. This may allow for parsers to use the stream state more efficiently.

  • Position : Type u

    Parser stream class

    This class implements streams based on a static stream with a moving position.

    • The type Position is used to record position data for the stream type.
    • start (s : σ) : Position returns starting position for the stream s
    • next? (s : σ) (pos : Position) : Option (τ × Position) returns the token at position pos in s together with the next position. It returns none if the end of the stream has been reached.

    Implementations should try to make the Position type as lightweight as possible. Often Position is just a scalar type or another simple type. This may allow for parsers to use the stream state more efficiently.

  • start : σPosition σ

    Parser stream class

    This class implements streams based on a static stream with a moving position.

    • The type Position is used to record position data for the stream type.
    • start (s : σ) : Position returns starting position for the stream s
    • next? (s : σ) (pos : Position) : Option (τ × Position) returns the token at position pos in s together with the next position. It returns none if the end of the stream has been reached.

    Implementations should try to make the Position type as lightweight as possible. Often Position is just a scalar type or another simple type. This may allow for parsers to use the stream state more efficiently.

  • next? : σPosition σOption (τ × Position σ)

    Parser stream class

    This class implements streams based on a static stream with a moving position.

    • The type Position is used to record position data for the stream type.
    • start (s : σ) : Position returns starting position for the stream s
    • next? (s : σ) (pos : Position) : Option (τ × Position) returns the token at position pos in s together with the next position. It returns none if the end of the stream has been reached.

    Implementations should try to make the Position type as lightweight as possible. Often Position is just a scalar type or another simple type. This may allow for parsers to use the stream state more efficiently.

Instances
    @[implicit_reducible]
    instance instInhabitedPosition {σ : Type u_1} {τ : Type u_2} [self : Parser.Stream σ τ] [Inhabited σ] :
    Equations
    def Parser.Stream.Segment (σ : Type u_1) {τ : Type u_2} [self : Parser.Stream σ τ] :
    Type u_3

    Stream segment type.

    Equations
    Instances For
      def Parser.Stream.mkDefault (σ : Type u_1) (τ : Type u_2) [Std.Stream σ τ] :
      Type u_1

      Default wrapper to make a Parser.Stream from a plain Stream.

      This wrapper uses the entire stream state as position information; this is not efficient. Always prefer tailored Parser.Stream instances to this default.

      Equations
      Instances For
        @[reducible]
        instance Parser.Stream.instMkDefault (σ : Type u_1) (τ : Type u_2) [self : Std.Stream σ τ] :
        Equations
        @[reducible]
        Equations
        • One or more equations did not get rendered due to their size.
        @[reducible]
        Equations
        • One or more equations did not get rendered due to their size.
        @[reducible]
        Equations
        • One or more equations did not get rendered due to their size.
        @[reducible]
        Equations
        @[reducible]
        Equations
        @[reducible]
        instance Parser.Stream.instList (τ : Type u_1) :
        Equations