tree-sitter / tree-sitter-scala

Scala grammar for tree-sitter
MIT License
158 stars 55 forks source link

Replace dynamic prec in if-then with an additional node #393

Open eed3si9n opened 6 months ago

eed3si9n commented 6 months ago

Problem

350 introduced a dynamic precedence to resolve the conflict of Scala 2 and Scala 3 grammar for if-then.

Solution

This removes the dynamic precedence and replaces it with prec.right around then side.

Note

There's a report of parser getting stuck #392 and and I was hoping that removing dynamic precedence would fix that, but it didn't seem to.

eed3si9n commented 6 months ago

The regression in smoke test is on BigInt.scala, which kind of looks like the following:

class A
{
  def bar(that: A): A =
    if (true) A(1)
    else 2

  def foo(that: A): (A, A) =
    if (true) 1
    else 2
}

I think it fails to parse the above because it thinks (A, A) = if (true) 1 else 2 is an infixed type, which is a separate issue we probably need to address.

susliko commented 3 months ago

Just a note.

Running tree-sitter parse -d sample.scala.txt (sample file from the issue) gives the line where parser stucks - it's line 969. If we remove a newline between lines 968 and 969 it stops getting stuck.

For now I had no luck in fixing this.