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

Errors at EOF #19

Closed
shwestrick opened this issue Sep 8, 2021 · 0 comments
Closed

Errors at EOF #19

shwestrick opened this issue Sep 8, 2021 · 0 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@shwestrick
Copy link
Owner

shwestrick commented Sep 8, 2021

Problem

Error positions are currently reported by attaching to a token, but this doesn't work at the end of the file.

For example, on a file containing just the word val, the parser attempts to parse a pattern immediately after the val, but since this is the last token of the file, it crashes.

This particular example crashes at the call tok i below, because it is an out-of-bounds access.
https://github.com/shwestrick/parse-sml/blob/6e61e1e431ca2aa8f4ddf6f3a47a9d1f8a0b5851/parse/ParsePat.sml#L106-L111

But this problem is more pervasive: many of the errors throughout the parser are similarly designed.

Suggested Solution

Introduce a new error function which similar to previous but now is aware of the token stream, e.g.

fun error (toks: Token.t Seq.t) {pos: int, what: string, explain: string option} =
  if pos >= Seq.length tokens then
    ... (* EOF error *)
  else
    ... (* normal error *)

Then all of the error sites need to be replaced (should be a nice little bit of zen refactoring 💆🏻‍♂️)

@shwestrick shwestrick added bug Something isn't working good first issue Good for newcomers labels Sep 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant