Documentation

Grip.Error

Grip.Error: the parser result type and parse errors #

ParseResult α is the result of running a parser at an offset: ok value newOffset or error e. One constructor holds the value and offset inline, so a successful step allocates a single object.

Err is the error value carried by ParseResult.error. GParser proves that its byte offset lies between the parser's starting offset and the end of the input. Built-in choice additionally uses it to report the furthest failure and the labels expected there; that stronger diagnostic convention is not part of the parser contract.

ParseError is the user-facing error produced by GParser.parse; it adds 1-based line and col computed from the source bytes.

Nothing in this file imports from Grip; only core Lean / Batteries.

structure Grip.Err :

The error value carried by ParseResult.error.

For every GParser run started in bounds, pos lies between that starting offset and the end of the input. Built-in combinators use pos for the furthest byte offset reached during parsing and expected for labels attached by label/<?>; the type does not prove that either diagnostic is maximal or complete.

  • pos : Nat

    Diagnostic offset used by built-in failure merging.

  • expected : List String

    Labels expected at pos in built-in diagnostics.

Instances For
    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      @[instance_reducible]
      Equations
      def Grip.instDecidableEqErr.decEq (x✝ x✝¹ : Err) :
      Decidable (x✝ = x✝¹)
      Equations
      Instances For
        @[instance_reducible]
        Equations
        Equations
        Instances For
          inductive Grip.ParseResult (α : Type) :

          The result of running a parser at an offset: ok value newOffset or error with a diagnostic. One constructor holds the value and the new offset inline, so a successful step allocates a single object rather than an Except.ok wrapping a Prod (the representation Except Err (α × Nat) used before).

          • ok {α : Type} (value : α) (newOffset : Nat) : ParseResult α

            Success: the parsed value and the newOffset reached.

          • error {α : Type} : ErrParseResult α

            Failure carrying an Err; built-in combinators retain the furthest one they observe.

          Instances For

            User-facing positioned parse error, produced by GParser.parse.

            • pos : Nat

              Byte offset of the failure.

            • line : Nat

              1-based line number (newline = 0x0a).

            • col : Nat

              1-based byte column (not grapheme column).

            • expected : List String

              Labels collected at the failure position.

            Instances For
              Equations
              • One or more equations did not get rendered due to their size.
              Instances For
                def Grip.instDecidableEqParseError.decEq (x✝ x✝¹ : ParseError) :
                Decidable (x✝ = x✝¹)
                Equations
                • One or more equations did not get rendered due to their size.
                Instances For
                  Equations
                  Instances For
                    Equations
                    Instances For

                      Build a ParseError from a raw Err and the source ByteArray.

                      Equations
                      Instances For

                        Render a dependency-free plain fallback as line:col: message, followed by the offending source line and a caret (^). Rich terminal presentation belongs to grip-diagnostics.

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