Skip to content

Commit abc27f3

Browse files
committed
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.
1 parent de465b0 commit abc27f3

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

grammar.js

+11-8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const PREC = {
1515
constructor_app: 7,
1616
prefix: 7,
1717
compound: 7,
18+
then: 7,
1819
call: 8,
1920
field: 8,
2021
macro: 10,
@@ -1133,17 +1134,19 @@ module.exports = grammar({
11331134
),
11341135
),
11351136

1136-
// NOTE(susliko): _if_condition and its magic dynamic precedence were introduced as a fix to
1137-
// https://github.com/tree-sitter/tree-sitter-scala/issues/263 and
1138-
// https://github.com/tree-sitter/tree-sitter-scala/issues/342
1139-
// Neither do I understand why this works, nor have I found a better solution
11401137
_if_condition: $ =>
1141-
prec.dynamic(
1142-
4,
1138+
prec.right(
1139+
PREC.then,
11431140
choice(
11441141
$.parenthesized_expression,
1145-
seq($._indentable_expression, "then"),
1146-
),
1142+
$._then_condition,
1143+
)
1144+
),
1145+
1146+
_then_condition: $ =>
1147+
prec.right(
1148+
PREC.then,
1149+
seq($._indentable_expression, "then"),
11471150
),
11481151

11491152
/*

0 commit comments

Comments
 (0)