Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading