Skip to content

parsers: report the name when a named Choice fails - #25

Merged
rameel merged 1 commit into
mainfrom
choice-named-diagnostics
Sep 22, 2026
Merged

rameel merged 1 commit into
mainfrom
choice-named-diagnostics

Conversation

@rameel

@rameel rameel commented Sep 22, 2026 •

Copy link
Copy Markdown
Owner

A named Choice suppresses the diagnostics of its alternatives, but did not report its own name when all of them failed. Parsing a choice with at least one unnamed alternative returned an empty error message.

using static Ramstack.Parsing.Parser;

var parser = Choice(L('a'), L('b').Between(L('('), L(')'))).As("value");

parser.Parse("?").ErrorMessage;

// Before: "(1:1) "
// After:  "(1:1) Expected value"

The name is reported after the diagnostic state is restored.

An unnamed choice keeps reporting the alternatives of its sub-parsers.

@rameel
rameel merged commit 3ecc170 into main Sep 22, 2026
2 checks passed
@rameel
rameel deleted the choice-named-diagnostics branch September 22, 2026 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant