-
Notifications
You must be signed in to change notification settings - Fork 53
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
Expression parser #449
base: main
Are you sure you want to change the base?
Expression parser #449
Conversation
Thanks for the PR. I think we could add something like this. I haven't had a chance to review in detail, but I had a couple of comments:
|
Great. I just published the draft here to check if something like this was wanted. I don't know how many use cats parse for expression parsers. I will give each of the points a go when I have time. I am not sure about (4), but I will have a think about it. |
I have not addressed (4). I think that route is still possible with this approach. You just don't munch whitespace in the base parser but in the operators instead, or some combination that suits the use case. Handling of whitespace is not done at all in the expression parser. |
Feel like it might be worth highlighting a similar but alternative approach: https://www.cs.tufts.edu/comp/150FP/archive/jamie-willis/parsing-patterns.pdf with a Scala version available in https://dl.acm.org/doi/10.1145/3550198.3550427 (I can get a pdf on request). It is slightly different to the parser-combinators version in that it allows for heterogeneity in the levels of the precedence table. The same mechanism is used by https://github.com/j-mie6/parsley within the The precedence scheme encoded by that paper does not have the ternary operators, but does avoid avoid I concur that whitespace parsing is not something that should be handled by the precedence machinery: this is explicitly a convention that should be kept in the "lexer" (see section 3 of those papers). Anecdotally, we use these design patterns at Imperial, for our compilers project and it works wonders compared to when we didn't have them! |
Essentially a port of https://hackage.haskell.org/package/parser-combinators-1.3.0/docs/src/Control.Monad.Combinators.Expr.html