Token functions #
tokenMap f accepts token t with result x if f t = some x, otherwise fails reporting the
unexpected token.
Equations
- One or more equations did not get rendered due to their size.
Instances For
anyToken consumes and returns one token. Only fails at the end of the input.
Equations
Instances For
tokenFilter test accepts and returns token t if test t = true.
Equations
- ParseIt.tokenFilter test = ParseIt.tokenMap fun (t : τ) => if test t = true then some t else none
Instances For
token tk accepts and returns tk.
Equations
- ParseIt.token tk = ParseIt.tokenFilter fun (x : τ) => x == tk
Instances For
tokenArray tks accepts the tokens of tks in order and returns the tokens read. Fails, reporting
the first unexpected token, if any token does not match.
Equations
- One or more equations did not get rendered due to their size.
Instances For
tokenList tks accepts the tokens of tks in order and returns the tokens read. Fails, reporting
the first unexpected token, if any token does not match.
Equations
Instances For
endOfInput succeeds only at the end of the input. Consumes no input.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Folding #
foldlP f init p folds the parser function f from left to right using init as an initial value
and the parser p to generate inputs of type α. Folding ends as soon as the update parser
p >>= f y fails, or right after it succeeds without consuming input. This parser never fails.
Equations
- ParseIt.foldlP f init p = Prod.fst <$> ParseIt.efoldlP✝ f init p
Instances For
foldlM f init p folds the monadic function f from left to right using init as an initial
value and the parser p to generate inputs of type α. Folding ends as soon as p fails, or
right after p succeeds without consuming input. This parser never fails.
Equations
- ParseIt.foldlM f init p = ParseIt.foldlP (fun (y : β) (x : α) => monadLift (f y x)) init p
Instances For
foldl f init p folds the function f from left to right using init as an initial value and the
parser p to generate inputs of type α. Folding ends as soon as p fails, or right after p
succeeds without consuming input. This parser never fails.
Equations
- ParseIt.foldl f init p = ParseIt.foldlP (fun (y : β) (x : α) => pure (f y x)) init p
Instances For
foldr f p q parses p repeatedly until it fails and then parses q, folding f from right to
left over the results, starting from the result of q. Repetition also ends right after p
succeeds without consuming input. If q fails after some occurrences of p then the parse is
retried with fewer occurrences.
Equations
- One or more equations did not get rendered due to their size.
Instances For
foldlN n f init p folds the function f from left to right using init as an initial value over
the results of exactly n occurrences of p. Fails if any occurrence of p fails.
Equations
- ParseIt.foldlN 0 f init p = pure init
- ParseIt.foldlN n_2.succ f init p = do let __do_lift ← p ParseIt.foldlN n_2 f (f init __do_lift) p
Instances For
foldlUpTo n f init p folds the function f from left to right using init as an initial value
over the results of up to n occurrences of p. Folding ends early when p fails. This parser
never fails.
Equations
- ParseIt.foldlUpTo 0 f init p = pure init
- ParseIt.foldlUpTo n_2.succ f init p = do let __do_lift ← ParseIt.option? p match __do_lift with | some x => ParseIt.foldlUpTo n_2 f (f init x) p | none => pure init
Instances For
foldlUntil f init stop p folds the function f from left to right using init as an initial
value over the results of zero or more occurrences of p until stop succeeds, and returns the
result of folding with the result of stop. If p fails before stop succeeds then the error from
p is reported. If p succeeds without consuming input then the error from stop is reported.
Equations
- ParseIt.foldlUntil f init stop p it = ParseIt.foldlUntil.loop✝ f stop p it init it (ParseIt.Progress.refl it)
Instances For
take n p parses exactly n occurrences of p and returns the array of results.
Equations
- ParseIt.take n p = ParseIt.foldlN n Array.push (Array.emptyWithCapacity n) p
Instances For
takeUpTo n p parses up to n occurrences of p and returns the array of results. This parser
never fails.
Equations
- ParseIt.takeUpTo n p = ParseIt.foldlUpTo n Array.push #[] p
Instances For
takeMany p parses zero or more occurrences of p until it fails and returns the array of results.
This parser never fails.
Equations
Instances For
takeMany1 p parses one or more occurrences of p until it fails and returns the array of
results.
Equations
- ParseIt.takeMany1 p = do let __do_lift ← p ParseIt.foldl Array.push #[__do_lift] p
Instances For
takeManyN n p parses n or more occurrences of p until it fails and returns the array of
results.
Equations
- ParseIt.takeManyN n p = do let __do_lift ← ParseIt.take n p ParseIt.foldl Array.push __do_lift p
Instances For
takeUntil stop p parses zero or more occurrences of p until stop succeeds, and returns the
array of results of p and the result of stop. If p fails before stop succeeds then the error
from p is reported. If p succeeds without consuming input then the error from stop is
reported.
Equations
- ParseIt.takeUntil stop p = ParseIt.foldlUntil Array.push #[] stop p
Instances For
drop n p parses exactly n occurrences of p, ignoring the results.
Equations
- ParseIt.drop n p = ParseIt.foldlN n (fun (x : ParseIt.Unitᵤ) (x_1 : α) => PUnit.unit) PUnit.unit p
Instances For
dropUpTo n p parses up to n occurrences of p, ignoring the results. Never fails.
Equations
- ParseIt.dropUpTo n p = ParseIt.foldlUpTo n (fun (x : ParseIt.Unitᵤ) (x_1 : α) => PUnit.unit) PUnit.unit p
Instances For
dropMany p parses zero or more occurrences of p until it fails, ignoring the results. This
parser never fails.
Equations
- ParseIt.dropMany p = ParseIt.foldl (fun (x : ParseIt.Unitᵤ) (x_1 : α) => PUnit.unit) PUnit.unit p
Instances For
dropMany1 p parses one or more occurrences of p until it fails, ignoring the results.
Equations
- ParseIt.dropMany1 p = p *> ParseIt.dropMany p
Instances For
dropManyN n p parses n or more occurrences of p until it fails, ignoring the results.
Equations
- ParseIt.dropManyN n p = ParseIt.drop n p *> ParseIt.dropMany p
Instances For
dropUntil stop p parses zero or more occurrences of p until stop succeeds, and returns the
result of stop, ignoring the results of p. Errors are reported as for takeUntil.
Equations
- ParseIt.dropUntil stop p = Prod.snd <$> ParseIt.foldlUntil (fun (x : ParseIt.Unitᵤ) (x_1 : α) => PUnit.unit) PUnit.unit stop p
Instances For
count p parses zero or more occurrences of p until it fails and returns the number of
successes. This parser never fails.
Equations
- ParseIt.count p = ParseIt.foldl (fun (n : ParseIt.Natᵤ) (x : α) => { val := ↑n + 1 }) 0 p
Instances For
countUpTo n p parses up to n occurrences of p and returns the number of successes. This
parser never fails.
Equations
- ParseIt.countUpTo n p = ParseIt.foldlUpTo n (fun (n : ParseIt.Natᵤ) (x : α) => { val := ↑n + 1 }) 0 p
Instances For
countUntil stop p parses zero or more occurrences of p until stop succeeds, and returns the
number of occurrences of p and the result of stop. Errors are reported as for takeUntil.
Equations
- ParseIt.countUntil stop p = ParseIt.foldlUntil (fun (n : ParseIt.Natᵤ) (x : α) => { val := ↑n + 1 }) 0 stop p
Instances For
endBy sep p parses zero or more occurrences of p, each followed by sep, and returns the array
of results of p.
The optional strict parameter controls error reporting:
- If
strict = falsethen this parser never fails and returns the longest possible array. - If
strict = truethen this parser fails if there is a final occurrence ofpwithout a trailingsep. Then the error ofsepis reported.
Equations
- ParseIt.endBy sep p strict = ParseIt.endByCore✝ sep p #[] strict
Instances For
endBy1 sep p parses one or more occurrences of p, each followed by sep, and returns the array
of results of p. The optional strict parameter controls error reporting after the first
occurrence, as for endBy.
Equations
- ParseIt.endBy1 sep p strict = do let __do_lift ← p <* sep ParseIt.endByCore✝ sep p #[__do_lift] strict
Instances For
sepBy sep p parses zero or more occurrences of p separated by sep, and returns the array of
results of p.
The optional strict parameter controls error reporting:
- If
strict = falsethen this parser never fails and returns the longest possible array. - If
strict = truethen this parser fails if there is a finalsepwithout a followingp. Then the error ofpis reported.
Equations
- ParseIt.sepBy sep p strict = do let __do_lift ← ParseIt.option? p match __do_lift with | some x => ParseIt.sepByCore✝ sep p #[x] strict | none => pure #[]
Instances For
sepBy1 sep p parses one or more occurrences of p separated by sep, and returns the array of
results of p. The optional strict parameter controls error reporting after the first
occurrence, as for sepBy.
Equations
- ParseIt.sepBy1 sep p strict = do let __do_lift ← p ParseIt.sepByCore✝ sep p #[__do_lift] strict
Instances For
sepNoEndBy sep p parses zero or more occurrences of p separated by sep without a trailing
sep, and returns the array of results of p.
Equations
- ParseIt.sepNoEndBy sep p = ParseIt.sepBy sep p true
Instances For
sepNoEndBy1 sep p parses one or more occurrences of p separated by sep without a trailing
sep, and returns the array of results of p.
Equations
- ParseIt.sepNoEndBy1 sep p = ParseIt.sepBy1 sep p true
Instances For
sepEndBy sep p parses zero or more occurrences of p separated by sep with an optional
trailing sep, and returns the array of results of p. This parser never fails.
Equations
- ParseIt.sepEndBy sep p = ParseIt.sepBy sep p <* ParseIt.optional sep
Instances For
sepEndBy1 sep p parses one or more occurrences of p separated by sep with an optional
trailing sep, and returns the array of results of p.
Equations
- ParseIt.sepEndBy1 sep p = ParseIt.sepBy1 sep p <* ParseIt.optional sep