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

Better parse error messages for reserved words used incorrectly #289

Open
byorgey opened this issue Jun 24, 2021 · 5 comments
Open

Better parse error messages for reserved words used incorrectly #289

byorgey opened this issue Jun 24, 2021 · 5 comments

Comments

@byorgey
Copy link
Member

byorgey commented Jun 24, 2021

Trying to load a file containing

if : N
if = 0

results in

./bad.disco:1:1:
  |
1 | if : N
  | ^
unexpected 'i'
expecting "import", "using", or end of input

The error message does not say anything about the fact that if is a reserved word.

@byorgey
Copy link
Member Author

byorgey commented Jul 28, 2021

The test case for #283 now suffers from this problem as well, now that REPL inputs are parsed as modules (once #304 is merged).

@byorgey
Copy link
Member Author

byorgey commented Mar 25, 2022

Note that just typing if by itself already illustrates the issue:

Disco> if
1:1:
  |
1 | if
  | ^
unexpected 'i'
expecting "import", "operator", "using", ':', or end of input

@byorgey
Copy link
Member Author

byorgey commented May 26, 2022

The problem seems to arise whenever there are multiple options: whichever option involves parsing an expression fails because if is not an identifier, so the other options are used instead. I guess what we want to do is something like specify which error message(s) take priority if all the possible alternatives fail?

@byorgey byorgey added the C-Moderate Effort Should take a moderate amount of time to address. label Feb 8, 2024
@byorgey byorgey changed the title Bad parse error message when defining reserved word Better parse error messages for reserved words used incorrectly Sep 16, 2024
@byorgey
Copy link
Member Author

byorgey commented Dec 17, 2024

Might require researching a bit about megaparsec's error reporting mechanisms.

@byorgey
Copy link
Member Author

byorgey commented Jan 3, 2025

Something from Willis & Wu "Design Patterns for Parser Combinators" might help? https://dl.acm.org/doi/10.1145/3471874.3472984

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

No branches or pull requests

1 participant