Grip.Byte: point combinators over the graded byte backend #
The non-looping combinators. Atomic byte readers (satisfy, byte, takeN), the
functor / sequence / choice / monad algebra (map, seqR, seqL, alt, bind,
map2), the capture/captureWith/captureWith? slice readers, first-byte
dispatch, and the <?> label. The total scanning loops are in Grip.Scan; the
graded type, weakening, run?, and fix are in Grip.Graded.
Consume nothing, never fail.
Equations
- Grip.GParser.pure a = { run := fun (x : ByteArray) (p : Nat) => Grip.ParseResult.ok a p, cwit := ⋯, ewit := ⋯, swit := ⋯, bwit := ⋯, fwit := ⋯ }
Instances For
Always fail, recording the current position as the furthest offset reached.
Equations
Instances For
Consume one byte satisfying f, or fail without consuming.
On failure the furthest offset is the current position p.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Match a specific byte.
On failure the furthest offset is the current position p.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Return the input slice a parser consumed, decoded as text (grade preserved). Lets
combinator parsers build real syntax trees (atom names, identifiers, header fields)
instead of only structural counts. Invalid UTF-8 in the slice decodes to "".
Equations
- One or more equations did not get rendered due to their size.
Instances For
Like capture, but hand the consumed byte range (arr, start, stop) to f instead
of decoding it to a String. Lets a value parser fold over the raw input bytes directly,
with no extract/fromUTF8?/String round-trip.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Like captureWith, but f may reject the consumed range by returning none, in which
case the parse fails at the entry offset. The result grade keeps p's consumption but sets
errors := possibly (the extra failure path), so a conditional p yields a conditional
parser. Lets a value decoder veto a syntactically-valid but semantically-out-of-range slice
(e.g. a JSON exponent so large that folding it would blow up).
Equations
- One or more equations did not get rendered due to their size.
Instances For
First-byte dispatch: read the current byte and run the parser select chooses for
it, without an intermediate allocation. Fails without consuming at end-of-input. This is
peek-then-branch fused into one step, so a keyword/number/string/array/object choice
costs a single byte read and a jump rather than an alt chain of failed attempts.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Sequence, keeping the right value; grades multiply.
Furthest offset from either x or y propagates on failure.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Ordered choice; grade follows Grade.choice.
On failure, the two errors are merged furthest-wins: if one branch reached a
farther offset, that error wins; on a tie the expected-label sets are unioned.
This is the megaparsec-style furthest-failure merge.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Apply a binary function across two parses; grades multiply. Furthest offset propagates on failure.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Replace the expected-label set of p's failure with [name].
Mirrors megaparsec's <?> operator: on success the result is unchanged; on
failure the expected field is overwritten so error messages read
"expected name" rather than a raw position.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Attach an expected label to a parser (megaparsec-style <?>).
p <?> "name" produces "expected name" on failure at the same position.
Equations
- Grip.«term_<?>_» = Lean.ParserDescr.trailingNode `Grip.«term_<?>_» 10 10 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " <?> ") (Lean.ParserDescr.cat `term 11))