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

Clarify whitespace lex error in qualified identifier lexing #3845

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

colinwahl
Copy link
Contributor

This intends to close #3801 . See issue for motivation/some discussion.

This PR adds a new lex error for when an unexpected character is encountered when tokenizing a qualified identifier.

My hope is that this indicates that the error is likely caused by a missing identifier, whereas the old error said "Illegal whitespace".

I'm not sure how useful it is to print out the unexpected whitespace character - I'm willing to remove that if others agree.

I'm not sure if parser tests exist/where they are, but if there's a useful way of writing a test for this, I'd be happy to add it if someone points me in the right direction.

@hdgarrood
Copy link
Contributor

Right now most of the parser tests live in the main compiler repo, even though it arguably would make more sense to put them into the purescript-cst library. You can see examples by searching for @shouldFailWith ErrorParsingModule in tests/purs/failing. I think adding a new test should be as simple as writing an example whose filename matches tests/purs/failing/*.purs, and then checking in the corresponding .out file which should be generated after running the tests again (after checking that it looks sensible).

Copy link
Member

@rhendric rhendric left a comment

Choose a reason for hiding this comment

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

I like the overall approach; I think this will be an easy PR to land once you add a few tests per @hdgarrood's comment.

@@ -53,6 +53,7 @@ data ParserErrorType
| ErrQualifiedName
| ErrEmptyDo
| ErrLexeme (Maybe String) [String]
| ErrQualifierLexeme Char
Copy link
Member

Choose a reason for hiding this comment

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

By analogy with ErrImportInDecl, ErrTypeInConstraint, etc., should this be ErrLexemeInQualified?

@@ -128,6 +129,10 @@ prettyPrintErrorMessage (ParserErrorInfo {..}) = case errType of
"Illegal whitespace character " <> displayCodePoint hd
ErrLexeme (Just a) _ ->
"Unexpected " <> a
ErrQualifierLexeme hd | isSpace hd ->
"Unexpected whitespace character " <> displayCodePoint hd <> ", expected qualifier"
Copy link
Member

Choose a reason for hiding this comment

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

Don't you mean ‘expected identifier or operator’ instead of ‘expected qualifier’? The qualifier has already been seen at this point in the parse, right?

Also, it looks like the other error messages of this nature follow an ‘Expected X, saw Y’ pattern; I'd expect these messages to match that.

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

Successfully merging this pull request may close these issues.

Misleading lex error when forgetting to access qualified identifier
3 participants