A | B != B | A - cats-parse
maybe, remove this |
method. just use orElse
6 Answer:
While it is true that | is not commutative (a.backtrack | b.backtrack would be), having an infix operator is very nice.
Do you have any other suggestions?
maybe |
would act like oneOf
.
I just write graphql schema parser.
Parser2.scala.
there are some user experience to share:
1. need insert lots of whitespaces, maybe it's a good idea to create ParserContext, just like fastparse to handle whitespaces.
2. so much backtrack
, and ?
always need backtrack
. maybe it's my code fault, there would have nice way to avoid using so much backtrack.
3. P[A] ~ (P[B].surround(whitespaces).backtrack.? ~ P[C].surround(whitespaces).backtrack.?)
will read whitespaces twice when P[B] fails. but I don't know how to avoid.
PEGs use /
for their non-commutative "or" for this reason - would that fit here?
Sorry I'm slow to reply on the weekend.
You definitely don't always need backtrack with ?. I'll rewrite some of your examples without backtrack and it might give you a feel for how to do it.
A big design property of this library is to encourage you to write parsers avoiding backtracking since that can easily result in accidental exponential complexity and also it generally results in poor descriptions of what went wrong.
That said, we could probably do with better educational materials to help people get started.
Also note | does act like oneOf. It is a synonym. oneOf is also not commutative, it matches left to right.
@johnynek thanks. And I'm sorry that I misunderstand the usage of |
. It's good.
Read next
- 1882 - Player 1 has 13/14 certificates, but cannot purchase a share. - 18xx
- truffle Debugger Fails Cryptically: Error: Compilation shimmedcompilation has unreliable source order - JavaScript
- Getting `message failed` on uploading more than 10 images - stream-chat-react-native
- mdx Missing typings and typescript files from `@mdx-js/mdx` - JavaScript
- Change OTLP gRPC port number - agent
- keras TensorBoard write_grads prevents training from starting - Python
- [Bug] Unable to use the Firebase Resize Image Extension when uploading from the Unity SDK - quickstart-unity
- firejail prevents Firefox from deactivating screen dimming during video watch C