Skip to content

Improve parse error messages for .purs-repl#3249

Merged
kritzcreek merged 1 commit into
purescript:masterfrom
rndnoise:fix-3248
Apr 22, 2018
Merged

Improve parse error messages for .purs-repl#3249
kritzcreek merged 1 commit into
purescript:masterfrom
rndnoise:fix-3248

Conversation

@rndnoise

Copy link
Copy Markdown
Contributor

This fixes #3248

  • Set the file name in error message
  • Parse whole file at once so correct lines numbers are given in errors
  • Don't fail on empty lines, whitespace, etc

To ensure line numbers are given on errors, I made a new parser that only parses import statements, instead of parsing all kinds of commands and rejecting them after the line numbers are forgotten.

Since the whole file is parsed all at once, it no longer makes sense to interleave printing, parsing, and executing line-by-line. So I've printed the whole contents verbatim before executing all the imports (assuming the file parsed).

Example:

$ cat .purs-repl
import Prelude
:help

$ pulp repl
PSCi, version 0.11.7
Type :? for help

"/home/guest-user/example/.purs-repl" (line 2, column 1):
unexpected :
expecting "import" or end of input
The .purs-repl file only supports import declarations

- Set the file name in error message
- Parse whole file at once so correct lines numbers are given in errors
- Don't fail on empty lines, whitespace, etc

This fixes #3248
@kritzcreek

Copy link
Copy Markdown
Member

Can we write a test for this? Just to make sure it doesn't regress.

@rndnoise

rndnoise commented Mar 23, 2018

Copy link
Copy Markdown
Contributor Author

Would it suffice to test parseDotFile? Testing the code which uses the parser, here, seems difficult without making more changes to that code. If you want to test that stuff in command, I'll need some advice on how to go about it.

@kritzcreek kritzcreek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this and it works great, Thanks!

@kritzcreek kritzcreek merged commit 270dc07 into purescript:master Apr 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Trailing blank line in .purs-repl fails, with a confusing error message

3 participants