Documentation

Grip.Combinators

Grip.Combinators: a megaparsec-style vocabulary over the grip core #

Ready-made byte parsers (ws, digit, oneOf, ...) and higher-order combinators (sepBy, between, choice, ...), each with a precise grade where the grade is stable, or at the Parser (fallible) face where it depends on runtime data. Batteries-only.

Byte parsers #

@[inline]

Match the byte of an ASCII Char literal: ch '{' matches {.

Equations
Instances For
    @[inline]

    Skip zero or more whitespace bytes; returns the count.

    Equations
    Instances For
      @[inline]

      Skip one or more whitespace bytes; returns the count.

      Equations
      Instances For
        @[inline]

        One byte from bs.

        Equations
        Instances For
          @[inline]

          One byte not in bs.

          Equations
          Instances For

            Higher-order combinators #

            @[inline]
            def Grip.GParser.between {α β γ : Type} {g g₁ g₂ : Grade} (open_ : GParser g₁ β) (close : GParser g₂ γ) (p : GParser g α) :
            GParser (g₁ * (g * g₂)) α

            p between open/close; grades multiply (megaparsec order: open, close, body).

            Equations
            Instances For
              @[inline]

              One or more p separated by sep; both must always consume.

              Equations
              Instances For
                @[inline]

                Zero or more p separated by sep.

                Equations
                Instances For
                  @[inline]

                  Zero or more p each followed by sep.

                  Equations
                  Instances For
                    @[inline]

                    One or more p each followed by sep.

                    Equations
                    Instances For
                      @[inline]
                      def Grip.GParser.many1 {α : Type} {ge : Modality} (p : GParser { errors := ge, consumes := always } α) :
                      GParser { errors := ge, consumes := always } (List α)

                      One or more p (always-consuming); the grade is the element parser's.

                      Equations
                      Instances For
                        @[inline]
                        def Grip.GParser.skipMany {α : Type} {ge : Modality} (p : GParser { errors := ge, consumes := always } α) :

                        Skip zero or more p (always-consuming); returns the count skipped.

                        Equations
                        Instances For
                          @[inline]

                          Skip one or more p (always-consuming); returns the count.

                          Equations
                          Instances For
                            @[inline]
                            def Grip.GParser.option {α : Type} {g : Grade} (x : α) (p : GParser g α) :
                            GParser (g.choice 1) α

                            p, or x if p fails. Never fails; consumption follows p's grade.

                            Equations
                            Instances For
                              @[inline]
                              def Grip.GParser.optional {α : Type} {g : Grade} (p : GParser g α) :
                              GParser (g.choice 1) (Option α)

                              some of p, or none. Never fails; consumption follows p's grade.

                              Equations
                              Instances For
                                @[inline]

                                Succeed (consuming nothing) exactly when p fails.

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

                                  Zero or more p until endp succeeds; endp's result is discarded and the p results are collected. Total via fix; both parsers must always consume.

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

                                    End of input: succeed (consuming nothing) exactly when no byte remains. Defined as notFollowedBy of the any-byte parser; used to reject trailing input after a top-level parse. Labelled, since a failure here always means the same thing: something followed what should have been the last byte.

                                    Equations
                                    Instances For
                                      @[inline]
                                      def Grip.GParser.chooseG {α : Type} {g : Grade} (x : GParser g α) (xs : List (GParser g α)) :
                                      GParser g α

                                      Ordered choice over a non-empty list at a single grade g. The grade is preserved via choice_self (choosing between two grade-g parsers is again grade g).

                                      Equations
                                      Instances For
                                        @[inline]
                                        def Grip.GParser.choice {α : Type} (ps : List (Parser α)) :

                                        Ordered choice at the ungraded Parser face; empty list fails.

                                        Equations
                                        • One or more equations did not get rendered due to their size.
                                        Instances For
                                          def Grip.GParser.count {α : Type} (n : Nat) (p : Parser α) :

                                          Exactly n copies of p, at the Parser face (grade is n-dependent).

                                          Equations
                                          Instances For

                                            Notation #

                                            The familiar parser-combinator operators, at the graded level (grades multiply/combine as the underlying combinator dictates). scoped, so they activate on open Grip. The Parser (ungraded) face additionally gets the standard Monad/Alternative operators for free; these graded versions coexist with those and are chosen when the operands are graded GParsers. The label operator <?> is global (declared with the core).

                                            Functor map: f <$> p.

                                            Equations
                                            Instances For

                                              Replace the result with a constant: x <$ p.

                                              Equations
                                              Instances For

                                                Applicative apply: pf <*> px; grades multiply.

                                                Equations
                                                Instances For

                                                  Sequence, keep the right result: p *> q; grades multiply.

                                                  Equations
                                                  Instances For

                                                    Sequence, keep the left result: p <* q; grades multiply.

                                                    Equations
                                                    Instances For

                                                      Ordered choice: p <|> q; grade follows Grade.choice.

                                                      Equations
                                                      Instances For

                                                        Sanity guards. #