-
Notifications
You must be signed in to change notification settings - Fork 50
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
Bug? - surroundedBy with optional whitespace fails to parse #201
Comments
See this comment: surroundedBy with whitespace does not work great. The problem is lack of backtracking. Your design is assuming backtracking. As soon as you see whitespace, the first item will start to parse, if you don't hit the surrounded thing, you will get an error (again, an intentional goal is opt-in backtracking). So, I think instead you want something like: The reason your final example fails is because with you hit Altenatively, you could make val listSeparator = comma.surroundedBy(whitespaces0).backtrack |
Thanks for the explanation. It pointed me to a reasonable solution. Rather than introducing backtracking just to eliminate whitespace, I'm removing whitespace after each token, rather than both before and after. I created a ".strip" method to skip over trailing whitespace.
I fell into my way of errors by following the README example. Given the pitfalls, it probably isn't good practice to use surroundedBy to remove whitespace. |
you are right. We need to improve the readme... it compiles, but it actually isn't great for the same reason. |
actually... What do you think of that API? |
`
/**
Demonstrates a possible bug with cats-parse.
*/
import cats.parse.Parser=>P
@main def main():Unit =
`
The text was updated successfully, but these errors were encountered: