Token Functions #
tokenCore next? reads a token from the stream using next?.
This is a low-level parser to customize how the parser stream is used.
Equations
- One or more equations did not get rendered due to their size.
Instances For
tokenMap test accepts token t with result x if test t = some x, otherise 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 from the stream. Only fails on end of stream.
Equations
Instances For
tokenFilter test accepts and returns token t if test t = true, otherwise fails reporting
unexpected token.
Equations
- Parser.tokenFilter test = Parser.tokenMap fun (c : τ) => if test c = true then some c else none
Instances For
token tk accepts and returns tk, otherwise fails otherwise fails reporting unexpected token.
Equations
- Parser.token tk = Parser.tokenFilter fun (x : τ) => x == tk
Instances For
tokenArray tks accepts and returns tokens from tks in order, otherwise fails reporting the
first unexpected token.
Equations
- One or more equations did not get rendered due to their size.
Instances For
tokenArray tks accepts and returns tokens from tks in order, otherwise fails reporting the
first unexpected token.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Basic Combinators #
lookAhead p tries to parses p without consuming any input. If p fails then the stream is
backtracked with the same error.
Equations
- One or more equations did not get rendered due to their size.
Instances For
peek returns the next token, without consuming any input. Only fails on end of stream.
Equations
Instances For
notFollowedBy p succeeds only if p fails. Consumes no input regardless of outcome.
Equations
- One or more equations did not get rendered due to their size.
Instances For
endOfInput succeeds only on end of stream. Consumes no input.
Instances For
test p returns true if p succeeds and false otherwise. This parser never fails.
Equations
- Parser.test p = Parser.optionD (p *> pure true) false
Instances For
foldr f p q
take n p parses exactly n occurrences of p, and returns an array of the returned values
of p.
Equations
- Parser.take n p = Parser.withBacktracking (Parser.take.rest p n #[])
Instances For
Equations
- Parser.take.rest p 0 x✝ = pure x✝
- Parser.take.rest p n.succ x✝ = do let __do_lift ← p Parser.take.rest p n (x✝.push __do_lift)
Instances For
takeUpTo n p parses up to n occurrences of p, and returns an array of the returned values
of p. This parser never fails.
Equations
- Parser.takeUpTo n p = Parser.takeUpTo.rest p n #[]
Instances For
Equations
- Parser.takeUpTo.rest p 0 x✝ = pure x✝
- Parser.takeUpTo.rest p n.succ x✝ = do let __do_lift ← Parser.option? p match __do_lift with | some x => Parser.takeUpTo.rest p n (x✝.push x) | none => pure x✝
Instances For
takeMany p parses zero or more occurrences of p until it fails, and returns the array of
returned values of p. This parser never fails.
Equations
Instances For
takeMany1 p parses one or more occurrences of p until it fails, and returns the array of
returned values of p. Consumes no input on error.
Equations
- Parser.takeMany1 p = Parser.withBacktracking do let __do_lift ← p Parser.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
returned values of p. Consumes no input on error.
Equations
- Parser.takeManyN n p = Parser.withBacktracking do let __do_lift ← Parser.take n p Parser.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 returned values of p and the output of stop. If p fails before stop is encountered,
the error from p is reported and no input is consumed.
Equations
- Parser.takeUntil stop p = Parser.withBacktracking (Parser.takeUntil.rest stop p #[])
Instances For
drop n p parses exactly n occurrences of p (without backtracking), ignoring all outputs.
Equations
- Parser.drop 0 p = pure PUnit.unit
- Parser.drop n_2.succ p = p *> Parser.drop n_2 p
Instances For
dropUpTo n p parses up to n occurrences of p (with backtracking) ignoring all outputs. This
parser never fails.
Equations
- Parser.dropUpTo 0 p = pure PUnit.unit
- Parser.dropUpTo n_2.succ p = do let __do_lift ← Parser.option? p match __do_lift with | some val => Parser.drop n_2 p | none => pure PUnit.unit
Instances For
dropMany p parses zero or more occurrences of p (with backtracking) until it fails, ignoring
all outputs.
Equations
Instances For
dropMany1 p parses one or more occurrences of p (with backtracking) until it fails, ignoring
all outputs.
Equations
- Parser.dropMany1 p = Parser.withBacktracking p *> Parser.foldl (Function.const α) () p
Instances For
dropManyN n p parses n or more occurrences of p until it fails, ignoring all outputs.
Equations
- Parser.dropManyN n p = Parser.withBacktracking (Parser.drop n p *> Parser.foldl (Function.const α) () p)
Instances For
dropUntil stop p runs p until stop succeeds, returns the output of stop ignoring all
outputs from p. If p fails before encountering stop then the error from p is reported
and no input is consumed.
Equations
- Parser.dropUntil stop p = Parser.withBacktracking (Parser.dropUntil.loop stop p)
Instances For
count family
count p parses occurrences of p (with backtracking) until it fails and returns the count of
successes.
Equations
- Parser.count p = Parser.foldl (fun (n : Nat) (x : α) => n + 1) 0 p
Instances For
countUpTo n p parses up to n occurrences of p until it fails, and returns the count of
successes. This parser never fails.
Equations
- Parser.countUpTo n p = Parser.countUpTo.loop p n 0
Instances For
Equations
- Parser.countUpTo.loop p 0 x✝ = pure x✝
- Parser.countUpTo.loop p n.succ x✝ = do let __do_lift ← Parser.option? p match __do_lift with | some val => Parser.countUpTo.loop p n (x✝ + 1) | none => pure x✝
Instances For
countUntil stop p counts zero or more occurrences of p until stop succeeds, and returns
the count of successes and the output of stop. If p fails before encountering stop then the
error from p is reported and no input is consumed.
Equations
- Parser.countUntil stop p = Parser.withBacktracking (Parser.countUntil.loop stop p 0)
Instances For
endBy p sep parses zero or more occurrences of p, separated and ended by sep, returns
the array of values returned by 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 returns the longest possible array but fails if there is a final occurrence ofpwithout a trailingsep. Then the error ofsepis reported.
No input is consumed on error.
Equations
- Parser.endBy sep p strict = Parser.withBacktracking (Parser.endByCore✝ sep p #[] strict)
Instances For
endBy1 p sep parses one or more occurrences of p, separated and ended by sep, returns
the array of values returned by p.
The optional strict parameter controls error reporting after parsing the initial p and sep:
- If
strict = falsethen this parser never fails and returns the longest possible array. - If
strict = truethen this parser returns the longest possible array but fails if there is a final occurrence ofpwithout a trailingsep. Then the error ofsepis reported.
No input is consumed on error.
Equations
- Parser.endBy1 sep p strict = Parser.withBacktracking do let __do_lift ← p <* sep Parser.endByCore✝ sep p #[__do_lift] strict
Instances For
sepBy p sep parses zero or more occurrences of p, separated by sep, returns the array of
values returned by 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 returns the longest possible array but fails if there is a final occurrence ofsepwithout a trailingp. Then the error ofpis reported.
No input is consumed on error.
Equations
- Parser.sepBy sep p strict = Parser.withBacktracking do let __do_lift ← Parser.option? p match __do_lift with | some x => Parser.sepByCore✝ sep p #[x] strict | none => pure #[]
Instances For
sepBy1 p sep parses one or more occurrences of p, separated by sep, returns the array of
values returned by p.
The optional strict parameter controls error reporting after parsing the initial p:
- If
strict = falsethen this parser never fails and returns the longest possible array. - If
strict = truethen this parser returns the longest possible array but fails if there is a final occurrence ofsepwithout a trailingp. Then the error ofpis reported.
No input is consumed on error.
Equations
- Parser.sepBy1 sep p strict = Parser.withBacktracking do let __do_lift ← p Parser.sepByCore✝ sep p #[__do_lift] strict
Instances For
sepNoEndBy p sep parses zero or more occurrences of p, separated sep but without a trailing
sep, returns the array of values returned by p.
Equations
- Parser.sepNoEndBy sep p = Parser.sepBy sep p true
Instances For
sepNoEndBy1 p sep parses one or more occurrences of p, separated sep but without a trailing
sep, returns the array of values returned by p.
Equations
- Parser.sepNoEndBy1 sep p = Parser.sepBy1 sep p true
Instances For
sepEndBy p sep parses zero or more occurrences of p, separated by sep with an optional
trailing sep, returns the array of values returned by p. This parser never fails.
Equations
- Parser.sepEndBy sep p = Parser.sepBy sep p <* Parser.optional sep
Instances For
sepEndBy1 p sep parses one or more occurrences of p, separated by sep with an optional
trailing sep, returns the array of values returned by p. This parser never fails.
Equations
- Parser.sepEndBy1 sep p = Parser.sepBy1 sep p <* Parser.optional sep