Skip to content

Commit

Permalink
Allow infix inline modifier
Browse files Browse the repository at this point in the history
Fixes #366

Rebalance precedences of `match_expression` (which can contain "inline") and `modifiers`
  • Loading branch information
susliko committed Dec 26, 2023
1 parent 866f945 commit 6c99c83
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 29 deletions.
4 changes: 2 additions & 2 deletions corpus/definitions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1661,8 +1661,7 @@ Infix methods (Scala 3)
================================================================================

object Test:
infix private def hello = 25

inline infix private def hello = 25
--------------------------------------------------------------------------------

(compilation_unit
Expand All @@ -1671,6 +1670,7 @@ object Test:
(template_body
(function_definition
(modifiers
(inline_modifier)
(infix_modifier)
(access_modifier))
(identifier)
Expand Down
22 changes: 21 additions & 1 deletion corpus/expressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,12 @@ def other() {
else c()
}

def another() {
if (a) b match {
case _ => c
} else d
}

--------------------------------------------------------------------------------

(compilation_unit
Expand Down Expand Up @@ -375,7 +381,21 @@ def other() {
(identifier))
(call_expression
(identifier)
(arguments))))))
(arguments)))))
(function_definition
(identifier)
(parameters)
(block
(if_expression
(parenthesized_expression
(identifier))
(match_expression
(identifier)
(case_block
(case_clause
(wildcard)
(identifier))))
(identifier)))))

================================================================================
If expressions (Scala 3 syntax)
Expand Down
47 changes: 21 additions & 26 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -660,23 +660,21 @@ module.exports = grammar({
),

modifiers: $ =>
prec.left(
repeat1(
choice(
"abstract",
"final",
"sealed",
"implicit",
"lazy",
"override",
$.access_modifier,
$.inline_modifier,
$.infix_modifier,
$.open_modifier,
$.transparent_modifier,
),
),
),
prec.left(repeat1(
prec.left(choice(
"abstract",
"final",
"sealed",
"implicit",
"lazy",
"override",
$.access_modifier,
$.inline_modifier,
$.infix_modifier,
$.open_modifier,
$.transparent_modifier,
)),
)),

access_modifier: $ =>
prec.left(
Expand Down Expand Up @@ -790,7 +788,7 @@ module.exports = grammar({
),

_indentable_expression: $ =>
choice($.indented_block, $.indented_cases, $.expression),
prec.right(choice($.indented_block, $.indented_cases, $.expression)),

block: $ => seq("{", optional($._block), "}"),

Expand Down Expand Up @@ -1145,14 +1143,11 @@ module.exports = grammar({
* MatchClause ::= 'match' <<< CaseClauses >>>
*/
match_expression: $ =>
prec.left(
PREC.postfix,
seq(
optional($.inline_modifier),
field("value", $.expression),
"match",
field("body", choice($.case_block, $.indented_cases)),
),
seq(
optional($.inline_modifier),
field("value", $.expression),
"match",
field("body", choice($.case_block, $.indented_cases)),
),

try_expression: $ =>
Expand Down

0 comments on commit 6c99c83

Please sign in to comment.