Skip to content
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

Improve Parser Error Message When Using Malformed Function Argument #3825

Open
tmciver opened this issue Mar 28, 2020 · 5 comments
Open

Improve Parser Error Message When Using Malformed Function Argument #3825

tmciver opened this issue Mar 28, 2020 · 5 comments

Comments

@tmciver
Copy link

tmciver commented Mar 28, 2020

As a PS newbie coming from Haskell, I tried to do the following:

> a = map (+1) [1, 2, 3]

not realizing that the correct syntax for the increment function is (_ + 1) . The above produces the error:

Unexpected token '=' at line 1, column 3

It would be nice to improve that error message so that the actual problem is clearer.

@natefaubion
Copy link
Contributor

Note, this is only in the repl. The error from purs compile is:

Error found:
at Test3.purs:3:10 - 3:11 (line 3, column 10 - line 3, column 11)

  Unable to parse module:
  Unexpected token '+'

This is due to the parser backtracking the repl is doing. I did fix an issue with that in the polykinds branch, so I wonder if the error is better on master.

@natefaubion
Copy link
Contributor

For reference, I fixed an issue with how it accumulated errors in a oneOf, which the repl parser uses.
https://github.com/purescript/purescript/blame/323df38b5fffcabd219f72cd8efd706750e2ac90/lib/purescript-cst/src/Language/PureScript/CST/Monad.hs#L151-L153

@natefaubion
Copy link
Contributor

This error is not better in master for the repl.

@huntwj
Copy link

huntwj commented Apr 26, 2020

I'm guessing this is the same bug I'm running into. You get similarly weird stuff in the REPL when you forget your function arrow in a lambda function:

> foldr (\n acc show n <> acc) "" myNonEmptyData
Unexpected token 'foldr' at line 1, column 1
> foldr (\n acc -> show n <> acc) "" myNonEmptyData
"123"

I'll not create a duplicate issue for now and assume this is the same issue.

@hdgarrood
Copy link
Contributor

I think in general the repl syntax errors are bad because we're assembling the parser out of the parser combinator language provided by the CST. If we write a proper Happy parser for the repl then the syntax error ought to be on par with those from the compiler, I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants