Grip.Grade: the parser grade algebra #
structure Grade (tracking error and consumption Modality), the named grades,
Grade.mul/Grade.choice, and consumptionWitness with its composition lemmas.
No mathlib. Monoid/Lattice instances for Grade belong in grip-props.
Equations
- instReprGrade = { reprPrec := instReprGrade.repr }
Equations
- One or more equations did not get rendered due to their size.
Instances For
A parser that always consumes and possibly errors.
Instances For
A parser that never consumes and never errors.
Instances For
The impossible grade: always consumes, never errors. No parser can inhabit this grade on arbitrary input (it must accept empty input).
Instances For
Sequential composition: the grade of p >>= q is mul g1 g2,
with errors and consumption each being the join of the two grades.
Reducible for the same reason as Modality.sup: goals mentioning a grade product
have to stay type-correct at instances transparency.
Instances For
Equations
- Grade.instMul = { mul := Grade.mul }
Equations
- Grade.instOne = { one := Grade.one }
Relates the start offset n and end offset m of a successful parse, according to a
Modality grade:
alwaysrequiresn < m(at least one byte consumed)possiblyallowsn ≤ m(consumed some or none)neverrequiresn = m(no input consumed)
Equations
- consumptionWitness n m always = (n < m)
- consumptionWitness n m possibly = (n ≤ m)
- consumptionWitness n m never = (n = m)
Instances For
Every consumption witness is monotone in the absolute input offset.
A reflexive witness holds for any grade a ≤ possibly
(i.e. a ≠ always), since no input has been consumed.
Transitivity: chain two witnesses through a common midpoint.
If gc witnesses (n2, n1) and gc' witnesses (n3, n2),
then max gc gc' witnesses (n3, n1).
If the error grade ge' is at most possibly (i.e. ge' ≠ always),
a consumption witness for the second branch gc' lifts to a witness for
the ite-computed consumption ge'.ite gc gc'.
If the error grade ge' is at least possibly (i.e. ge' ≠ never),
a consumption witness for the first branch gc lifts to a witness for
the ite-computed consumption ge'.ite gc gc'.