Parser values in `postfix`
Closed this issue · 2 comments
I need to parse some SQL expression like:
expr COLLATE name
COLLATE
is defined as a postfix operator, but the current postfix does not allow extracting values because it imposes a Parser ()
.
So I implemented a custom postfix function to allow extracting a value, which is useful in my situation:
postfix_ : Int -> Parser c x a -> (a -> e -> e) -> Config c x e -> ( Int, e -> Parser c x e )
postfix_ precedence operator apply _ =
( precedence
, \left -> map (\a -> apply a left) operator
)
What do you think? Is there an other way of achieving this?
Yes it's fine. Helpers supplied with the library are just a selection of the most common ones, but it's expected to have to define your own ones occasionally.
As said in the README:
Helpers are provided for literals, constants, prefix, infix and postfix expressions but custom ones can be defined when needed.
And this is also why the prefix
one is described in subExpression documentation.
Maybe just give it a more meaningful name to differentiate from the default one.
The default version of prefix
could be the one your propose for the library to be more generic, but I'm not convinced the use case is common enough to worth it. I will keep it in mind though.
OK thank you for validating this. Yes naming should be improved on my side.
Big thanks for this library, it is super useful!