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 599d12b commit 5a2a3e4
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const PREC = {
constructor_app: 7,
prefix: 7,
compound: 7,
then: 7,
call: 8,
field: 8,
macro: 10,
Expand Down Expand Up @@ -1133,17 +1134,19 @@ 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,
prec.right(
PREC.then,
choice(
$.parenthesized_expression,
seq($._indentable_expression, "then"),
),
$._then_condition,
)
),

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

/*
Expand Down

0 comments on commit 5a2a3e4

Please sign in to comment.