-
Notifications
You must be signed in to change notification settings - Fork 126
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
Allow multiple expected values to be passed into desc and makeFailure calls #256
Conversation
Hmm, interesting. I have thought about this before but it didn't really seem worth the change to me. I guess I never really saw one parser as having multiple expectations, so it seems kind of backwards to me. Also because generally adding too many That being said, the error message behavior of I have purposefully avoided testing the specific error messages from the built-in parsers because I do not consider them part of the API as much as they are developer messages, and should be updated to reflect the most useful message they can. 👩💻 That message in particular has already been updated as it used to only say |
Oh and also, thank you very much for your first time contribution to Parsimmon! I'm always happy to see new folks happy to improve the library. |
I've changed |
Sounds good. Hopefully I'll get a chance to merge this, update the changelog, and release soon :) |
everything looks fine but the node 7 travis job failed for reasons i can't figure out… i'll try running the job a couple more times just in case |
hmm, I just realized a really weird thing: i'll make a quick change to stop using that helper since it's no longer safe :) |
There are certain parsers that will accept multiple strings/characters, but only return one expected value - most parsers created through the use of
Parsimmon.test()
fall into this category. For example,oneOf('+-%')
returns'expected a character/byte matching function [...]'
, whereas in most cases it should probably returnexpected one of '+', '-', '%'
. Especially when you have parsers that include branches, and description arrays are merged, it can become helpful to be able to specify arrays in.desc()
andmakeFailure()
I've made small changes to the
.desc()
andmakeFailure()
functions, and added tests to cover both of these changes. (None of the existing tests needed changing, although I did move the existingmakeFailure
test into a suite given that there are now multiple tests for that function.) I've also made changes to the API.md file to reflect the addition to the API.I believe the changes are backwards compatible, and constitute a minor semver change.
It might also be worth at this point changing
oneOf()
to modify the description of the returned parser. I wanted to make these changes because the 'matching function blah' error message is not very helpful. However, that arguably constitutes an additional change, and is probably closer to breaking backwards compatibility, at least if people rely on the output of the error message, so I haven't done it in this PR, but I can add it if you want.