PrimParser #
A parser combinator library with precise grades tracking error and consumption
behavior at the type level via Necessity.
Equations
- instReprGrade = { reprPrec := instReprGrade.repr }
Equations
- One or more equations did not get rendered due to their size.
Instances For
Instances For
Instances For
Instances For
Equations
- Grade.instMax = { max := Grade.max }
Equations
- One or more equations did not get rendered due to their size.
Equations
- Grade.instZero = { zero := empty }
Relates input size n and remaining size m according to a consumption grade:
always requires strict decrease, possibly allows ≤, never requires equality.
Equations
- Parser.consumptionWitness n m always = (n < m)
- Parser.consumptionWitness n m possibly = (n ≤ m)
- Parser.consumptionWitness n m never = (n = m)
Instances For
A successful parse result.
- result : α
- restSize : ℕ
- witness : consumptionWitness self.restSize n consumes
Instances For
Equations
- Parser.Outcome.Sound errors (Parser.failure f) = (possibly ≤ errors)
- Parser.Outcome.Sound errors (Parser.success r) = (errors ≤ possibly)
Instances For
A parser with error type ε, static grade g, and result type α.
The grade tracks error and consumption behavior at the type level.
Instances For
Equations
- (Parser.failure f).handle sound_2 onSuccess onError = onError sound_2 f
- (Parser.success r).handle sound_2 onSuccess onError = onSuccess sound_2 r
Instances For
Equations
- Parser.instGradedFunctorNecessitySuccess = { gmap := fun {i : Necessity} {α β : Type} => Functor.map }
Equations
- Parser.instParserErrorError = { endOfInput := Parser.Error.eof }
Equations
- Parser.Success.bindParser t x f = match (f x.result).run (t.dropTo x.restSize ⋯) with | Parser.failure e => Parser.failure (e.trans ⋯) | Parser.success y => Parser.success (x.seq y)
Instances For
Equations
- Parser.Outcome.throw e = Parser.failure { error := e, restSize := n, witness := ⋯ }
Instances For
Equations
Instances For
Lift a value into a parser that consumes nothing and never fails.
Equations
- Parser.pure a = { run := fun {n : ℕ} (x : Text n) => Parser.success { result := a, restSize := n, witness := ⋯ }, sound := ⋯ }
Instances For
Equations
- One or more equations did not get rendered due to their size.
Equations
- Parser.instGradedMonadGrade = { toGradedApplicative := Parser.instGradedApplicativeGrade, gbind := fun {i j : Grade} {α β : Type} => Parser.bind }
Build a recursive parser via a fixpoint. Termination is guaranteed by requiring the body to always consume input.
Equations
- Parser.fix f h = { run := fun {n : ℕ} (t : Text n) => ↑(Parser.fixGo✝ h f t), sound := ⋯ }
Instances For
Equations
- Parser.«term_<|>_» = Lean.ParserDescr.trailingNode `Parser.«term_<|>_» 20 20 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " <|> ") (Lean.ParserDescr.cat `term 21))
Instances For
try p1; if it fails without consuming, then try p2
Equations
- One or more equations did not get rendered due to their size.
Instances For
Try p1 first, if it fails with Failure f, run p2 on the input left at f.restSize
Equations
- One or more equations did not get rendered due to their size.
Instances For
Try each parser in the list in order, returning the first success.
Equations
- Parser.oneOf l = Parser.oneOf.go ↑l ⋯
Instances For
Equations
- p_2.relaxConsumes = p_2
- p_2.relaxConsumes = p_2
- p_2.relaxConsumes = { result := p_2.result, restSize := p_2.restSize, witness := ⋯ }
Instances For
Equations
- Parser.Except.Sound errors (Except.error a) = (possibly ≤ errors)
- Parser.Except.Sound errors (Except.ok a) = (errors ≤ possibly)
Instances For
Consume a single byte.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Consume a single UTF-8 character.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Consume a character and apply f; succeed with the result or fail if f returns none.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Consume a character that satisfies predicate f, or fail.
Instances For
Match a specific character.
Equations
- Parser.char c = Parser.skipSatisfy fun (x : Char) => x == c
Instances For
Equations
- Parser.string.go [] = Parser.throw Parser.Error.fail Parser.token._proof_1
- Parser.string.go [c] = Parser.skipSatisfy fun (x : Char) => x == c
- Parser.string.go (c :: cs) = (Parser.skipSatisfy fun (x : Char) => x == c) >>=ᵍ fun (x : PUnit.{1}) => Parser.string.go cs
Instances For
Apply p zero or more times, collecting results. Requires p to always consume.
Equations
- p.many = { run := fun {n : ℕ} (t : Text n) => Parser.success (Parser.many.go p t), sound := @Parser.many._proof_2 }
Instances For
Consume characters while f holds, returning the collected string.
Equations
Instances For
Consume one or more characters while f holds.
Equations
Instances For
Skip characters while f holds.
Equations
Instances For
Skip one or more characters while f holds.
Equations
Instances For
Skip zero or more whitespace characters.
Instances For
Skip one or more whitespace characters.
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
- Parser.dquote = Parser.char '\"'
Instances For
Equations
- Parser.comma = Parser.char ','
Instances For
Parse p surrounded by the delimiters l and r. Delimiters consume whitespace after them.
Equations
- l.bracket r p = l.lexeme.rawBracket r.lexeme p
Instances For
Parse a natural number (one or more digits).
Equations
- Parser.nat = Parser.digit >>=ᵍ fun (d : ℕ) => Parser.digit.many >>=ᵍ fun (ds : List ℕ) => gpure (List.foldl (fun (acc d : ℕ) => acc * 10 + d) d ds)
Instances For
Parse an integer (optional leading - followed by digits).
Equations
- Parser.int = gcast Parser.int._proof_1 ((Parser.char '-').optional >>=ᵍ fun (neg : Option PUnit.{1}) => Parser.nat >>=ᵍ fun (n : ℕ) => gpure (if neg.isSome = true then -↑n else ↑n))
Instances For
Equations
- Parser.space = Parser.skipSatisfy fun (x : Char) => x == ' '
Instances For
Equations
- Parser.tab = Parser.skipSatisfy fun (x : Char) => x == '\t'
Instances For
Equations
- Parser.ASCII.lf = Parser.skipSatisfy fun (x : Char) => x == '\n'
Instances For
Equations
- Parser.ASCII.cr = Parser.skipSatisfy fun (x : Char) => x == '\x0d'
Instances For
Match an ASCII uppercase letter.
Instances For
Match an ASCII lowercase letter.
Instances For
Match an ASCII letter.
Equations
Instances For
Match an ASCII letter or digit.
Instances For
Match an ASCII control character.
Equations
- Parser.ASCII.control = Parser.satisfy fun (c : Char) => decide (c.val < 32) || c.val == 127
Instances For
Match a binary digit.
Equations
- Parser.ASCII.binDigit = Parser.token fun (x : Char) => match x with | '0' => some false | '1' => some true | x => none
Instances For
Match an octal digit, returning its numeric value.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Match a hexadecimal digit, returning its numeric value.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Match a line terminator: LF or CRLF.
Equations
- Parser.eol = gcast Parser.eol._proof_1 (Parser.ASCII.cr.optional >>=ᵍ fun (x : Option PUnit.{1}) => Parser.ASCII.lf)
Instances For
Parse zero or more occurrences of p separated by sep.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Parse zero or more occurrences of p, each followed by sep.
Equations
- sep.endBy p h = (Parser.endItem✝ sep p h).many
Instances For
Parse one or more occurrences of p, each followed by sep.
Equations
- sep.endBy1 p h = (Parser.endItem✝ sep p h).many1
Instances For
Parse one or more occurrences of p separated by sep, with an optional
trailing sep.
Equations
Instances For
Parse zero or more occurrences of p separated by sep, with an optional
trailing sep.
Equations
Instances For
Parse exactly n + 1 occurrences of p.
Equations
- Parser.count1 0 p = (fun (x : α) => x ::ᵥ List.Vector.nil) <$>ᵍ p
- Parser.count1 n_2.succ p = gcast ⋯ (p >>=ᵍ fun (x : α) => Parser.count1 n_2 p >>=ᵍ fun (rest : List.Vector α (n_2 + 1)) => gpure (x ::ᵥ rest))
Instances For
Parse exactly n occurrences of p.
Equations
- Parser.count 0 p = Parser.ok List.Vector.nil ⋯ ⋯
- Parser.count n_2.succ p = (Parser.count1 n_2 p).relax
Instances For
Skip up to n occurrences of p; never fails.
Equations
- One or more equations did not get rendered due to their size.
- Parser.skipUpTo 0 x✝ = Parser.ok () Parser.token._proof_2 Parser.token._proof_1
Instances For
Skip n or more occurrences of p.
Equations
- Parser.skipManyN n p = gcast ⋯ (Parser.skip n p >>=ᵍ fun (x : PUnit.{1}) => p.skipMany)
Instances For
Parse exactly n occurrences of p separated by sep.
Equations
- sep.sepByN p 0 = Parser.ok List.Vector.nil Parser.token._proof_1 Parser.token._proof_1
- sep.sepByN p n_1.succ = (have sepP := gcast ⋯ (sep >>=ᵍ fun (x : β) => p); p >>=ᵍ fun (p1 : α) => Parser.count n_1 sepP >>=ᵍ fun (ps : List.Vector α n_1) => gpure (p1 ::ᵥ ps)).weaken
Instances For
Parse one or more occurrences of p separated by left-associative operator op.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Succeed only at end of input, consuming nothing.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Instances For
Run p; if it fails with error e, run recover e. If recovery also
fails, report p's original error.
Equations
- One or more equations did not get rendered due to their size.