A megaparsec-shape parse error, ε for every Parser_ lexer/parser: the token that failed to
match (none at end of input) and every spelling that would have matched there instead.
ErrorCombine unions two same-position errors' expected; Parser_.withErrorMessage replaces
one outright, only when its own parser failed without consuming (megaparsec's <?>/label) —
never appends, which is what made the old chain-of-messages design repeat "expected expression" once per level of parseExpression's recursive descent.
posOverride, unset in the ordinary case, is for a sub-parser running over a stream this
error's own Stream.Position σ cannot describe on its own (Annotations.tryParseAnnotations',
over the flat concatenated comment text): it resolves its own position eagerly, against comment
boundaries only it has in scope, and hands the result over pre-resolved.
- pos : Parser.Stream.Position σ
- unexpected : Option τ
- posOverride : Option SourceSpan
Instances For
Equations
- One or more equations did not get rendered due to their size.
Equations
- instInhabitedParseErrorOfPosition = { default := { pos := Inhabited.default, unexpected := none } }
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- instErrorCombineSimple = { combine := fun (x e₂ : Parser.Error.Simple σ τ) => e₂ }
Render a ParseError's expected as the Unexpected hint it becomes: nothing when empty;
several spellings become "expected one of: …"; one spelling gets "expected " prepended if it
reads as a bare noun phrase (token's toString tk, "identifier", …, all lowercase-led), or is
shown verbatim if it already reads as a full sentence — either the library's own char/chars/
Unicode.* (withErrorMessage s!"expected {repr tk}", already "expected "-led) or fugue's own
direct, capitalized messages ("Operator conflict …", checkConflicts) — the one place these
three uses of the same expected : List String field are told apart.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Fail with tok unexpected and items (bare noun phrases) as the full expected set — a
peek-dispatch catch-all's way to name every alternative a match itself cannot state, since
Parser.Error.addMessage only ever replaces expected with one string at a time.
Equations
- throwExpected tok items s = pure (Parser.Result.error s { pos := Parser.Stream.getPosition s, unexpected := tok, expected := items })
Instances For
Run a parser written against one token type inside a parser over another. f maps an outer
token to an inner one (returning none at the first token the inner parser has no business
seeing); g maps back. The inner parser sees the maximal f-mapped prefix of the tokens not
yet consumed, indexed from 0, so mapError shifts its reported positions back by the number
of tokens already consumed. Only the cursor moves in the outer stream — its token array is
untouched, so the outer tokens g would have reconstructed are the originals.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- (Parser.Result.ok a a_1).isOk = true
- (Parser.Result.error a a_1).isOk = false
Instances For
Equations
Equations
- instLTPositionedSlice = { lt := Function.onFun (fun (x1 x2 : Cursor) => x1 < x2) PositionedSlice.position }
Equations
- instLEPositionedSlice = { le := Function.onFun (fun (x1 x2 : Cursor) => x1 ≤ x2) PositionedSlice.position }
Equations
- instBEqPositionedSlice = { beq := Function.onFun (fun (x1 x2 : Cursor) => x1 == x2) PositionedSlice.position }
Equations
Equations
Equations
- One or more equations did not get rendered due to their size.
Equations
- instBEqPositionPositionedSliceChar = { beq := Function.onFun (fun (x1 x2 : Cursor) => x1 == x2) PositionedSlice.position }
Equations
- instLTPositionPositionedSliceChar = { lt := Function.onFun (fun (x1 x2 : Cursor) => x1 < x2) PositionedSlice.position }
Equations
- instLEPositionPositionedSliceChar = { le := Function.onFun (fun (x1 x2 : Cursor) => x1 ≤ x2) PositionedSlice.position }
Equations
- segment : Parser.Stream.Segment PositionedSlice
- data : α
Instances For
Equations
- One or more equations did not get rendered due to their size.
Equations
- instInhabitedLocated = { default := { segment := (Inhabited.default, Inhabited.default), data := Inhabited.default } }
A piece of data is located if its span in the stream is fully known.
- segment : SourceSpan
- data : α
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- instReprLocated' = { reprPrec := instReprLocated'.repr }
Equations
- instInhabitedLocated' = { default := instInhabitedLocated'.default }
Equations
Instances For
Equations
- instBEqLocated' = { beq := instBEqLocated'.beq }
Describes the payload, position dropped — a located value reads the same as its data
wherever only a human-facing description is wanted (Parser_.token's "expected" hints).
- token : Option α
- pos : SourceSpan
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- instReprUnexpected = { reprPrec := instReprUnexpected.repr }
Equations
- instInhabitedUnexpected = { default := instInhabitedUnexpected.default }
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Warnings raised by the parser itself, as opposed to hard errors (Unexpected). Collected
out-of-band during parsing (ParserWarningM, below) rather than emitted immediately, and
filtered/printed by the compiler driver once parsing returns.
- fairIgnored
(pos : SourceSpan)
: ParserWarning
fair process/fair+was parsed and round-tripped, but is never acted on. - unusedAnnotation
(pos : SourceSpan)
: ParserWarning
A comment parses as a well-formed annotation (
@type/@mailbox/@parameter) but sits where no call site consumes it, so it is silently ignored. Distinct from a misplaced annotation (captured, but attached to the wrong role), which is a hard error.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- instReprParserWarning = { reprPrec := instReprParserWarning.repr }
Equations
Equations
Instances For
Equations
The -W<name>/-Wno-<name> name a given warning is filtered under.
Equations
- (ParserWarning.fairIgnored a).name = "fair"
- (ParserWarning.unusedAnnotation a).name = "unused-annotation"
Instances For
Equations
- One or more equations did not get rendered due to their size.
The base monad every parser in Parser_ runs against: Id plus a List ParserWarning
accumulator.
Equations
Instances For
The base-monad state a backtrack has to undo, alongside the stream position. For a parser
over ParserWarningM that is the accumulated ParserWarning list: a warning emitted inside an
alternative that is then abandoned must not survive. Id has no such state, so its instance is a
no-op and the lexer pays nothing.
- Saved : Type
The part of
m's state to snapshot and restore. - save : m (Saved m)
Take a snapshot.
Restore a snapshot.
Instances
Equations
- instMonadParserBacktrackParserWarningM = { Saved := List ParserWarning, save := get, restore := set }
debug name p runs p unchanged. It is the single seam parser tracing is inserted at, and
name is the label such a trace would carry; call sites tag themselves once and stay tagged.
Instances For
Tries to execute a parser p and returns its result.
If p fails without consuming tokens, returns none and rolls back any warnings p emitted
before failing; if p fails after consuming input, that failure propagates unchanged.
Equations
- One or more equations did not get rendered due to their size.
Instances For
takeMany1 p applies p at least once, collecting the results. Fails if p cannot be applied
at least once, or if p fails while consuming input. Warnings emitted by the final, failed
(non-consuming) application of p are rolled back; warnings from the applications that succeeded
are kept.
Equations
- One or more equations did not get rendered due to their size.
Instances For
takeMany p tries to repeatedly apply p until it does not parse, collecting its results.
Fails if p fails while consuming input at some point. Warnings from the final, failed
(non-consuming) application are rolled back.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Strict (megaparsec) choice combinators #
fgdorais/Parser's OrElse, first, sepBy* reset the stream position on every failure, so
p <|> q is really try p <|> q and every first alternative is implicitly atomic. These
shadow them with megaparsec semantics: a failure that consumed input propagates, and only a
failure at the entry position falls through to the next alternative. withBacktracking
(a.k.a. try) is the one sanctioned opt-out, and it now also rolls back base-monad warnings.
Kept in namespace Parser_ so a parser namespace opts in with open Parser_ while the lexer,
which still wants the library's backtracking first/<|> for its symbol trie, simply does not.
withBacktracking p runs p and, if p fails, rewinds the stream position and any
warnings p emitted back to the entry point, so a failed p leaves no trace. Shadows the
library's, which rewinds the position only. This is megaparsec try.
Equations
- One or more equations did not get rendered due to their size.
Instances For
tokenMap test reads one token and maps it through test. On none it fails without
consuming — the library's tokenCore advances the stream before the test runs, which turns
every rejected token into a phantom consumption and makes strict alt/first commit to the
wrong branch. Shadows Parser.tokenMap; tokenFilter/token/anyToken sit on top of it.
Equations
- One or more equations did not get rendered due to their size.
Instances For
tokenFilter test accepts and returns a token satisfying test, failing without consuming
otherwise.
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, failing without consuming otherwise.
Equations
- Parser_.token tk = Parser_.tokenFilter fun (x : τ) => x == tk
Instances For
anyToken consumes and returns one token, failing (without consuming) only at end of input.
Equations
Instances For
alt p q: run p; if it fails without consuming input, roll its warnings back and run
q; if p consumed input before failing, that failure propagates and q is never tried. This
is megaparsec <|> — wrap p in withBacktracking to get the retry-after-consumption the
library's <|> always gives. When q also fails at that same entry position, the two errors
combine (ErrorCombine) rather than p's being silently dropped — p <||> q failing means
"neither matched", and the report should say what either would have accepted.
Equations
- One or more equations did not get rendered due to their size.
Instances For
alt p q: run p; if it fails without consuming input, roll its warnings back and run
q; if p consumed input before failing, that failure propagates and q is never tried. This
is megaparsec <|> — wrap p in withBacktracking to get the retry-after-consumption the
library's <|> always gives. When q also fails at that same entry position, the two errors
combine (ErrorCombine) rather than p's being silently dropped — p <||> q failing means
"neither matched", and the report should say what either would have accepted.
Equations
- Parser_.«term_<||>_» = Lean.ParserDescr.trailingNode `Parser_.«term_<||>_» 20 20 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " <||> ") (Lean.ParserDescr.cat `term 21))
Instances For
first ps tries the alternatives in order with megaparsec semantics (see alt): the first
that consumes input commits, and only same-position failures fall through. On total failure every
alternative's expected is merged into the one reported error.
Equations
- Parser_.first [] = fun (s : σ) => pure (Parser.Result.error s (Parser.Error.unexpected (Parser.Stream.getPosition s) none))
- Parser_.first [p] = p
- Parser_.first (p :: ps_2) = (p <||> Parser_.first ps_2)
Instances For
withErrorMessage msg p: if p fails without consuming input, replace whatever it expected
with msg (megaparsec's <?>/label); a failure that consumed input propagates untouched.
Shadows the library's withErrorMessage, which wraps unconditionally: used directly on a
recursive-descent parser like parseExpression, every nested call would re-wrap whatever the
previous level had already wrapped, repeating "expected expression" once per level.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A variant of sepBy1 sep p which also returns the collected results of the parser sep.
Equations
- One or more equations did not get rendered due to their size.
Instances For
sepBy1 sep p parses one or more p separated by sep, megaparsec-style: sep is a probe
(a sep that consumes then fails — e.g. its whitespace/comment skip runs before the token check
misses — ends the list cleanly), but once sep is in, a p that fails after consuming
propagates its error rather than being silently dropped. No trailing sep is consumed.
Equations
- Parser_.sepBy1 sep p = do let x ← p let xs ← takeMany (Parser_.withBacktracking sep *> p) pure (#[x] ++ xs)
Instances For
sepBy sep p parses zero or more p separated by sep. Same strictness as sepBy1 once
the first p is in.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Alias: under strict semantics sepBy1 already refuses a trailing sep.
Equations
- Parser_.sepNoEndBy1 sep p = Parser_.sepBy1 sep p
Instances For
sepEndBy1 sep p parses one or more p separated by sep with an optional trailing
sep — the case where sep doubles as a terminator (PlusCal's statement ;). A sep with a
non-p after it ends the list; a p that fails after consuming still propagates its error.
Equations
- Parser_.sepEndBy1 sep p = do let x ← p Parser_.sepEndBy1.loop✝ sep p #[x]