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

Fix case clauses with guards #221

Merged
merged 2 commits into from
May 24, 2023
Merged

Conversation

susliko
Copy link
Collaborator

@susliko susliko commented May 24, 2023

Fixes #200

Problem

Guards in case clauses are thought to be lambda expressions sometimes, e.g. in

{case a if b => c}

This happens, because $.lambda_expression has a higher parsing precedence than $._simple_expression

Solution

Avoid using numeric parsing precedence for $.lambda_expression. Resolve specific conflicts instead

@susliko
Copy link
Collaborator Author

susliko commented May 24, 2023

This change bumps smoke test parsing reports for compiler codebases:

scala: 68 -> 84
dotty: 66 -> 71

Problem
-------
Guards in case clauses are thought to be lambda expressions sometimes,
e.g. in
```scala
{case a if b => c}
```
This happens, because `$.lambda_expression` has a higher parsing
precedence than `$._simple_expression`

Solution
-------
Avoid using numeric parsing precedence for `$.lambda_expression`.
Resolve specific conflicts instead
Copy link
Collaborator

@eed3si9n eed3si9n left a comment

Choose a reason for hiding this comment

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

Thanks @susliko!

Copy link
Collaborator

@eed3si9n eed3si9n left a comment

Choose a reason for hiding this comment

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

Thanks @susliko!

@keynmol
Copy link
Collaborator

keynmol commented May 25, 2023

Those smoke test bumps are great!

Note, @susliko, that you don't have to check in parser.c or grammar.json: https://github.com/tree-sitter/tree-sitter-scala/blob/master/CONTRIBUTING.md#generation

Just the grammar and the test changes.

@susliko
Copy link
Collaborator Author

susliko commented May 25, 2023

@keynmol
Oh, nice! I've missed this automation for parser generation

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.

Pattern matching with guards
3 participants