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 parenthesized expressions in braceless if conditions #350

Merged

Conversation

susliko
Copy link
Collaborator

@susliko susliko commented Sep 16, 2023

Fixes #263 and #342
_if_condition extracted from if_expression and given a magic dynamic
precedence of 4

@@ -26,19 +26,19 @@ object Hello {
trait Test {
// ^ keyword
// ^ type
def meth(i: Int)(implicit x: Boolean) = ???
def meth(i: Int)(implicit x: Boolean) = ???
Copy link
Collaborator Author

@susliko susliko Sep 16, 2023

Choose a reason for hiding this comment

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

I've made definitions in this trait to be of the same indentation because

trait Foo {
    def meth = ???
  def anonFun = ???
}

is parsed with an ERROR and this causes flacking of the highlighting test

We might want to open an issue on this, but I'm reluctant to it as scalac raises a warning for this code

-- Warning: foo.scala:3:2 ------------------------------------------------------
3 |  def anonFun = ???
  |  ^
  |  Line is indented too far to the left, or a `}` is missing

@susliko susliko marked this pull request as draft September 16, 2023 22:41
@susliko susliko force-pushed the fix-parenthesized-expr-in-braceless-if branch 2 times, most recently from a9dc60f to e8579fa Compare September 18, 2023 18:46
// https://github.com/tree-sitter/tree-sitter-scala/issues/263 and
// https://github.com/tree-sitter/tree-sitter-scala/issues/342
// Neither do I understand why this works, nor have I found a better solution
_if_condition: $ => prec.dynamic(4, choice(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm ashamed of this

Fixes tree-sitter#263 and tree-sitter#342
`_if_condition` extracted from `if_expression` and given a magic dynamic
precedence of 4
@susliko susliko force-pushed the fix-parenthesized-expr-in-braceless-if branch from e8579fa to 5c54434 Compare September 18, 2023 18:57
@susliko susliko marked this pull request as ready for review September 18, 2023 19:00
@@ -404,6 +404,11 @@ class C:
else
()

if (a) || b(c) then return true
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice!

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!
I've tried this one in the past and gave up, so happy to see this fix.

@eed3si9n eed3si9n merged commit 045ce59 into tree-sitter:master Sep 19, 2023
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.

Braceless if with args in parens and field expressions
2 participants