Documentation

Parser.Error

Parser Error #

The class Parser.Error is used throughout the library for the purpose of reporting parser errors. Users are encouraged to provide their own instances tailored to their applications.

Three general purpose instances are provided:

These are intended for use in parser development and as building blocks (or inspiration) for tailored instances.

class Parser.Error (ε : Type u_1) (σ : Type u_2) (τ : outParam (Type u_3)) [Parser.Stream σ τ] :
Type (max (max u_1 u_3) u_4)

Parser error class

This class declares an error type for a given parser stream.

Given Parser.Stream σ τ, Parser.Error ε σ τ provides two basic mechanisms for reporting parsing errors:

  • unexpected (p : Stream.Position σ) (t : Option τ) : ε is used to report an unexpected input at a given position, optionally with the offending token.
  • addMessage (e : ε) (p : Stream.Position σ) (info : String) is used to add additional error information at a given position.

This class can be extended to provide additional error reporting and processing functonality, but only these two mechanisms are used within the library.

  • unexpected : Stream.Position σOption τε

    Parser error class

    This class declares an error type for a given parser stream.

    Given Parser.Stream σ τ, Parser.Error ε σ τ provides two basic mechanisms for reporting parsing errors:

    • unexpected (p : Stream.Position σ) (t : Option τ) : ε is used to report an unexpected input at a given position, optionally with the offending token.
    • addMessage (e : ε) (p : Stream.Position σ) (info : String) is used to add additional error information at a given position.

    This class can be extended to provide additional error reporting and processing functonality, but only these two mechanisms are used within the library.

  • addMessage : εStream.Position σStringε

    Parser error class

    This class declares an error type for a given parser stream.

    Given Parser.Stream σ τ, Parser.Error ε σ τ provides two basic mechanisms for reporting parsing errors:

    • unexpected (p : Stream.Position σ) (t : Option τ) : ε is used to report an unexpected input at a given position, optionally with the offending token.
    • addMessage (e : ε) (p : Stream.Position σ) (info : String) is used to add additional error information at a given position.

    This class can be extended to provide additional error reporting and processing functonality, but only these two mechanisms are used within the library.

Instances
    @[reducible, inline]

    Trivial error type

    This error type simply discards all error information. This is useful for parsers that cannot fail, or where parsing errors are intended to be handled by other means.

    Equations
    Instances For
      instance Parser.Error.instTrivial (σ : Type u_1) (τ : Type u_2) [Parser.Stream σ τ] :
      Equations
      • One or more equations did not get rendered due to their size.
      @[reducible, inline]
      abbrev Parser.Error.Basic (σ : Type u_1) (τ : Type u_2) [Parser.Stream σ τ] :
      Type (max u_3 u_2)

      Basic error type

      This error type records the position and, optionally, the offending token where a parsing error occurred; any additional information is discarded. This is useful for parsers where the cause of parsing errors is predictable and only the position of the error is needed for processing.

      Equations
      Instances For
        instance Parser.Error.instBasic (σ : Type u_1) (τ : Type u_2) [Parser.Stream σ τ] :
        Parser.Error (Basic σ τ) σ τ
        Equations
        • One or more equations did not get rendered due to their size.
        instance Parser.Error.instToStringBasicOfReprPosition (σ : Type u_1) (τ : Type u_2) [Repr τ] [Parser.Stream σ τ] [Repr (Stream.Position σ)] :
        ToString (Basic σ τ)
        Equations
        • One or more equations did not get rendered due to their size.
        inductive Parser.Error.Simple (σ : Type u_1) (τ : Type u_2) [Parser.Stream σ τ] :
        Type (max u_2 u_3)

        Simple error type

        This error type simply records all the error information provided, without additional processing. Users are expected to provide any necessary post-processing. This is useful for parser development.

        Instances For
          instance Parser.Error.instSimple (σ : Type u_1) (τ : Type u_2) [Parser.Stream σ τ] :
          Parser.Error (Simple σ τ) σ τ
          Equations