Hello. I am having issues with my parser combinators in this code: Haskell Playground
(You can change the input
binding to test out the parser)
The issue is that I am unable to parse function application:
ghci> parseTest (recexpr 0 <* eof) "let x = \\x -> x + 1 in x 1"
1:26:
|
1 | let x = \x -> x + 1 in x 1
| ^
unexpected '1'
expecting end of input, symbol, or white space
I believe the issue here is that appP
's left <- absP
always expects an abstraction as the LHS of an application, while in this situation, it is a Var
.
I have tried to replace it with left <- parens absP <|> varP
, but it errors in a different place here:
ghci> parseTest (recexpr 0 <* eof) "let x = \\x -> x + 1 in x 1"
1:17:
|
1 | let x = \x -> x + 1 in x 1
| ^^^^^
unexpected "+ 1 i"
expecting "false", "let", "true", '"', '(', '\', alphanumeric character, integer, or white space
Seemingly because it parses x + 1
as an application, and it doesn’t let the pratt parsing recexpr
do it’s job of parsing operators?
So I had the thought process of “maybe, if I make valP
do ... <|> try appP <|> ...
instead of ... <|> appP <|> ...
so that it backtracks, recexpr
would get to the binary operators before appP
,” and I tried to change the code for that, but I think that’s a dead end.