Closed loxs closed 4 years ago
@loxs Sorry to be so late to see this issue, since this project is not actively updated.
This is in my plan. You are not able to do it elegantly for now.
The secret is in the ParserOutput interface. What I would do is, write a new combinator err
, accepting a sub parser, a predefined message and a predefined result. When the sub parser failed (successful === false
), it replaces all error messages from the sub parser, and also add the predefined result to candidates
.
For example, the usage will look like err(Number(), "A number is expected", 0)
. The err
parser always succeeds, if Number()
failed, it returns the hard-coded result.
This is what I am planning to do, but a pull request is also welcome if you are interested in doing it.
err
and errd
are available in 0.3.2, please checkout the document.
I am trying to achieve this, but I can't figure out what's the proper solution:
What is the proper idiomatic solution to this case?