From 06a5237c5e6078303ef41c8cad126f0732fce268 Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Sat, 13 Apr 2024 18:56:30 -0400 Subject: [PATCH] Replace dynamic with additional node **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. --- grammar.js | 19 +++++++++---------- script/smoke_test.sh | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/grammar.js b/grammar.js index 6b83e8b..227f8b8 100644 --- a/grammar.js +++ b/grammar.js @@ -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"), ), /* diff --git a/script/smoke_test.sh b/script/smoke_test.sh index ce7f737..76a7260 100755 --- a/script/smoke_test.sh +++ b/script/smoke_test.sh @@ -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