-
Notifications
You must be signed in to change notification settings - Fork 83
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
More expressive functions in expression parsers #22
Comments
The proposed change amounts to rewriting of data Operator s u m a
= Infix (ParsecT s u m (a -> a -> a)) Assoc
| Prefix (ParsecT s u m (a -> a))
| Postfix (ParsecT s u m (a -> a)) will become data Operator s u m a
= Infix (a -> a -> ParsecT s u m a) Assoc
| Prefix (a -> ParsecT s u m a)
| Postfix (a -> ParsecT s u m a) I think this is doable and is actually a good idea that will make expression parsers more powerful. Apart from this change If you have some comments regarding this particular change or would like to propose other changes related to |
I think I'll rename |
There also exist |
@tulcod, great idea. Do you have any specific suggestions? |
I think we should use Then we can rename the functions this way:
|
Actually, I was wrong. makeTokenParser takes a language definition and generates a GenTokenParser, which is a collection of Parsec-style parsers. But I think that's not a big problem. But to fit the naming scheme, it would have to be named Here are some permutations:
So in retrospect I'm not quite sure about the token parser thing, but the expression and permutation parser combinators seem to fit this scheme quite well. |
Well, |
Although result of |
That last bit definitely has my support. So what about, say, Great work on megaparsec so far, by the way - thanks for all the effort, I'm sure this will attract more attention over time. |
I like this your proposition, although I would call it shorter, so
Thank you very much! Most interesting thing so far is all the improvement in error messages, there is whole lot of cases when Megaparsec's error messages are more descriptive and precise. |
This will also make things like parsing things like mixfix operators easier, since one could use additional information during further parsing. |
@ahmadsalim, wouldn't you normally do that using backtracking? where the syntax is
|
@tulcod This would avoid having backtracking, and provide better error messages! Also, having the syntax that way makes it left-recursive and you have to do factorization of the grammar to get things working. |
This seems to be not that easy to implement. Actually to parse operator with something like Maybe I'm missing something? @ahmadsalim, can you clarify? |
I'm closing this for now, since it's not clear how to implement it. Feel free to reopen this issue if you can clarify implementation details. For now work on
|
Of course, you are right. So, actually they should be (or similar): data Operator s u m a
= Infix (ParsecT s u m (a -> a -> m a)) Assoc
| Prefix (ParsecT s u m (a -> m a))
| Postfix (ParsecT s u m (a -> m a)) |
@ahmadsalim, how this new definition of You can of course use something like Another option is: data Operator s u m a
= Infix (ParsecT s u m (a -> a -> ParsecT s u m a)) Assoc
| Prefix (ParsecT s u m (a -> ParsecT s u m a))
| Postfix (ParsecT s u m (a -> ParsecT s u m a)) In this case you can parse argument, operator, then second argument and apply the arguments to the operator, which will be able to However, in vast majority of cases this system will be overcomplicated for end user. |
@mrkkrp It allows me to record something in the state, and then check that in the context that calls the parser which can do the backtracking (which the pure thing cannot do). |
(Title is a sort of pan.) See haskell/parsec#32 for more information. This may be good thing to implement.
The text was updated successfully, but these errors were encountered: