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

version based error recovery #811

Open
OmarTawfik opened this issue Feb 13, 2024 · 0 comments
Open

version based error recovery #811

OmarTawfik opened this issue Feb 13, 2024 · 0 comments

Comments

@OmarTawfik
Copy link
Collaborator

OmarTawfik commented Feb 13, 2024

When the parser encounters a language item that is not enabled/reserved in the current language version, it currently doesn't attempt to parse it, and eventually entering error recovery:

  • EnumVariants
  • Optional Fields
  • PrimaryExpression
  • Keyword
  • Possibly others?

For example, for Optional Fields that are not legal in the current version, instead of skipping, we can still attempt parsing it, and if successful, produce the complete tree, along with an error about versioning. It is a very common case of errors for end users, and a core goal of the DSL v2 to enable:

  • We can still produce complete valid trees, with no missing/skipped nodes.
  • Instead of a long list of tokens: Expected Foo or Bar or Baz, we will produce meaningful/actionable errors: Foo is not valid in the current language version 'XXX'. It requires language version 'YYY' or above.

I suspect EnumVariants and Optional Fields have the biggest impact. We can experiment/start with that. That means instead of this:

if self.version_is_at_least_XXXX {
    let result = self.parse_foo_bar(input);
    helper.consider(input, result)?;
}

With the errors API we will have by #804, we can switch this bit around:

let result = self.parse_foo_bar(input);
if !self.version_is_at_least_XXXX {
    result.add_diagnostic(DiagnosticKind::VersionTooLow(XXXX));
}
helper.consider(input, result)?;

Open Questions

  • Can this later enable other features like Error recovery grammar nodes #128? We can add a reason: String field to VersionSpecifier::Never, and use it to "manually guide" error recovery. For example, adding an EventDefinition under SourceUnitMember with VersionSpecifier::Never(reason = "Events are only valid inside contracts").
@OmarTawfik OmarTawfik self-assigned this Feb 21, 2024
@OmarTawfik OmarTawfik removed their assignment Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

1 participant