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

"choice" / "or" examples missing "try" ? #53

Closed
acdimalev opened this issue Dec 18, 2015 · 2 comments
Closed

"choice" / "or" examples missing "try" ? #53

acdimalev opened this issue Dec 18, 2015 · 2 comments

Comments

@acdimalev
Copy link

I just had a heck of a time figuring out why the following examples both yield errors:

choice([
    string("one"),
    string("two"),
    string("three"),
]).parse("two");
string("this").or(string("that")).parse("that");

From what I can tell, for either of these examples to work properly, they need to be written as follows:

choice([
    try(string("one")),
    try(string("two")),
    try(string("three")),  // optional, but nice for consistency
]).parse("two");
try(string("this")).or(string("that")).parse("that");

I'm not sure which behavior is desirable / whether it's the documentation or the code that should be updated. In either case, I would be happy to take a stab at throwing together some pull requests here. Combine has been saving me a ton of hassle.

@Marwes
Copy link
Owner

Marwes commented Dec 20, 2015

I think it is the documentation that should be changed in this case to make it more explicit that having two parsers in choice/or which have the same prefix will cause trouble (and that try can be used to fix it). I tried to express that in the documentation but looking at it now it could probably be clearer. Feel free to submit a PR improving it if you like. I may take a look at sometime next week otherwise.

@Marwes
Copy link
Owner

Marwes commented Feb 2, 2016

Closing. Feel free to reopen if the documentation is still confusing.

@Marwes Marwes closed this as completed Feb 2, 2016
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

2 participants