Skip to content

Commit

Permalink
Replace dynamic with additional node
Browse files Browse the repository at this point in the history
**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 tree-sitter#392 and and
I was hoping that removing dynamic precedence would
fix that, but it didn't seem to.
  • Loading branch information
eed3si9n committed Jun 30, 2024
1 parent de465b0 commit 06a5237
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
19 changes: 9 additions & 10 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -1133,17 +1133,16 @@ module.exports = grammar({
),
),

// NOTE(susliko): _if_condition and its magic dynamic precedence were introduced as a fix to
// 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(
$.parenthesized_expression,
seq($._indentable_expression, "then"),
),
choice(
$.parenthesized_expression,
$._then_condition,
),

_then_condition: $ =>
prec.right(
PREC.control,
seq($._indentable_expression, "then"),
),

/*
Expand Down
2 changes: 1 addition & 1 deletion script/smoke_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

SCALA_SCALA_LIBRARY_EXPECTED=100
SCALA_SCALA_COMPILER_EXPECTED=96
DOTTY_COMPILER_EXPECTED=83
DOTTY_COMPILER_EXPECTED=85
LILA_MODULES_EXPECTED=84
SYNTAX_COMPLEXITY_CEILING=1400

Expand Down

0 comments on commit 06a5237

Please sign in to comment.