Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail error messages do not show choices of attempted elements as an option #104

Open
bookofproofs opened this issue Oct 1, 2023 · 0 comments

Comments

@bookofproofs
Copy link

bookofproofs commented Oct 1, 2023

I have a grammar that has choices of elements, some of which have to be proceeded by the attempt parser (otherwise, I would get different grammar).

My problem is that a failing parser does not reflect the actual possibilities of the grammar.

To illustrate this behavior, check out this example:

let a = pchar 'a'
let bra = pchar '<'
let ket = pchar '>'
let comma = skipChar ','
let aBraKet = a .>> bra .>> ket 
let aChoice = attempt aBraKet <|> a
// note that `let aChoice = aBraKet <|> a` would define a different grammar, in which we would never be able to parse a single `a`
// neither would `let aChoice = a <|> aBraKet` do the trick, because we would never be able to parse a single `a<>`.
let list = sepBy1 aChoice comma

let input = "a<>,a<>,a,axxx"
let result = run (list .>> eof) input
printf "%O" result

This will output

Failure:
Error in Ln: 1 Col: 12
a<>,a<>,a,axxx
           ^
Expecting: end of input or ','

The actual grammar, however, expects '<', ',' or end of input.

This behavior may be a feature and not a bug of FParsec, but would it be possible to enhance the error message to display every choice that is available in the grammar at this parsing state?

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

No branches or pull requests

1 participant