Skip to content

Commit

Permalink
Fix 'longer' operators
Browse files Browse the repository at this point in the history
'Longer' operators like -> aren't an arithmetic operator
and than a comparison, but one operator.
  • Loading branch information
Jentsch committed Oct 11, 2024
1 parent 0493778 commit cdc67c9
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 63 deletions.
9 changes: 7 additions & 2 deletions src/typescript/Scala.tmLanguage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,11 @@ export const scalaTmLanguage: TmLanguage = {
}
}
},
{ // Higher precedence than other kinds of operators to prevent
// decomposition of operators like ->
match: `(<-|←|->|→|=>|⇒|\\?|\\:|@)+${opchar}*`,
name: 'keyword.operator.scala'
},
{
match: '(==?|!=|<=|>=|<>|<|>)',
name: 'keyword.operator.comparison.scala'
Expand All @@ -688,8 +693,8 @@ export const scalaTmLanguage: TmLanguage = {
match: `(?<!${opchar}|_)(!|&&|\\|\\|)(?!${opchar})`,
name: 'keyword.operator.logical.scala'
},
{
match: `(<-|←|->|→|=>|⇒|\\?|\\:|@|\\|)+${opchar}*`,
{ // Lower precedence than logical || operator
match: `(\\|)${opchar}*`,
name: 'keyword.operator.scala'
}
]
Expand Down
2 changes: 1 addition & 1 deletion syntaxes/Scala.tmLanguage.json

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions tests/snap/end.test.scala.snap
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@
# ^ source.scala
# ^ source.scala constant.numeric.scala
# ^ source.scala
# ^ source.scala keyword.operator.comparison.scala
# ^ source.scala keyword.operator.comparison.scala
# ^^ source.scala keyword.operator.scala
# ^^^^^^^^ source.scala
# ^ source.scala meta.bracket.scala
# ^ source.scala string.quoted.double.scala punctuation.definition.string.begin.scala
Expand All @@ -126,8 +125,7 @@
#^^^^^^^^^^^^^^^^^^ source.scala
# ^^^^ source.scala keyword.control.flow.scala
# ^^^ source.scala
# ^ source.scala keyword.operator.comparison.scala
# ^ source.scala keyword.operator.comparison.scala
# ^^ source.scala keyword.operator.scala
> end match
#^^^^^^^^^^^^^^^^^^^^^^^^ source.scala keyword.control.flow.end.scala
> finally
Expand Down
84 changes: 28 additions & 56 deletions tests/snap/scala_spec.test.scala.snap
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,7 @@
# ^ source.scala
# ^ source.scala entity.name.class
# ^ source.scala
# ^ source.scala keyword.operator.comparison.scala
# ^ source.scala keyword.operator.comparison.scala
# ^^ source.scala keyword.operator.scala
# ^^^^^^^^ source.scala
# ^ source.scala meta.bracket.scala
# ^ source.scala entity.name.class
Expand Down Expand Up @@ -673,8 +672,7 @@
# ^^^^ source.scala variable.parameter.scala
# ^ source.scala meta.colon.scala
# ^ source.scala
# ^ source.scala keyword.operator.comparison.scala
# ^ source.scala keyword.operator.comparison.scala
# ^^ source.scala keyword.operator.scala
# ^ source.scala
# ^^^^^^^ source.scala entity.name.class
# ^ source.scala meta.bracket.scala
Expand All @@ -683,8 +681,7 @@
# ^^^^ source.scala variable.parameter.scala
# ^ source.scala meta.colon.scala
# ^ source.scala
# ^ source.scala keyword.operator.comparison.scala
# ^ source.scala keyword.operator.comparison.scala
# ^^ source.scala keyword.operator.scala
# ^ source.scala
# ^^^^ source.scala entity.name.class
# ^ source.scala meta.bracket.scala
Expand Down Expand Up @@ -723,8 +720,7 @@
# ^ source.scala
# ^ source.scala meta.bracket.scala
# ^^^^ source.scala
# ^ source.scala keyword.operator.comparison.scala
# ^ source.scala keyword.operator.arithmetic.scala
# ^^ source.scala keyword.operator.scala
# ^^^^^ source.scala
# ^ source.scala meta.bracket.scala
# ^^^^^^^^ source.scala
Expand Down Expand Up @@ -1164,8 +1160,7 @@
# ^ source.scala
# ^^^ source.scala entity.name.class
# ^ source.scala
# ^ source.scala keyword.operator.comparison.scala
# ^ source.scala keyword.operator.comparison.scala
# ^^ source.scala keyword.operator.scala
> var head = ???
#^^^^ source.scala
# ^^^ source.scala keyword.declaration.volatile.scala
Expand Down Expand Up @@ -1301,8 +1296,7 @@
# ^ source.scala
# ^ source.scala entity.name.class
# ^ source.scala
# ^ source.scala keyword.operator.comparison.scala
# ^ source.scala keyword.operator.comparison.scala
# ^^ source.scala keyword.operator.scala
> def < (that: T): Boolean
#^^^^ source.scala
# ^^^ source.scala keyword.declaration.scala
Expand Down Expand Up @@ -1456,8 +1450,7 @@
# ^^^^ source.scala
# ^ source.scala meta.bracket.scala
# ^ source.scala
# ^ source.scala keyword.operator.comparison.scala
# ^ source.scala keyword.operator.comparison.scala
# ^^ source.scala keyword.operator.scala
# ^^^ source.scala
# ^ source.scala keyword.operator.arithmetic.scala
# ^^ source.scala
Expand Down Expand Up @@ -1731,17 +1724,15 @@
# ^^^^ source.scala variable.parameter.scala
# ^ source.scala meta.colon.scala
# ^ source.scala
# ^ source.scala keyword.operator.comparison.scala
# ^ source.scala keyword.operator.comparison.scala
# ^^ source.scala keyword.operator.scala
# ^ source.scala
# ^^^^^^^ source.scala entity.name.class
# ^ source.scala meta.bracket.scala
# ^ source.scala meta.bracket.scala
# ^^^^ source.scala variable.parameter.scala
# ^ source.scala meta.colon.scala
# ^ source.scala
# ^ source.scala keyword.operator.comparison.scala
# ^ source.scala keyword.operator.comparison.scala
# ^^ source.scala keyword.operator.scala
# ^ source.scala
# ^^^^ source.scala entity.name.class
# ^ source.scala meta.bracket.scala
Expand Down Expand Up @@ -1801,15 +1792,13 @@
# ^^ source.scala
# ^ source.scala punctuation.section.block.begin.scala
# ^^^ source.scala
# ^ source.scala keyword.operator.comparison.scala
# ^ source.scala keyword.operator.arithmetic.scala
# ^^ source.scala keyword.operator.scala
# ^ source.scala
# ^ source.scala constant.numeric.scala
# ^^^^^^^^^ source.scala
> j <- 1 until i
#^^^^^^^^^^ source.scala
# ^ source.scala keyword.operator.comparison.scala
# ^ source.scala keyword.operator.arithmetic.scala
# ^^ source.scala keyword.operator.scala
# ^ source.scala
# ^ source.scala constant.numeric.scala
# ^^^^^^^^^ source.scala
Expand Down Expand Up @@ -1845,8 +1834,7 @@
#^^^^^ source.scala
# ^^^^ source.scala keyword.control.flow.scala
# ^^^ source.scala
# ^ source.scala keyword.operator.comparison.scala
# ^ source.scala keyword.operator.comparison.scala
# ^^ source.scala keyword.operator.scala
# ^ source.scala
# ^ source.scala meta.bracket.scala
# ^ source.scala constant.numeric.scala
Expand All @@ -1856,8 +1844,7 @@
#^^^^^^^^^^^^^^^^^^^ source.scala
# ^ source.scala punctuation.section.block.begin.scala
# ^^^ source.scala
# ^ source.scala keyword.operator.comparison.scala
# ^ source.scala keyword.operator.comparison.scala
# ^^ source.scala keyword.operator.scala
# ^^^^^^^^ source.scala
# ^ source.scala meta.bracket.scala
# ^ source.scala
Expand All @@ -1872,8 +1859,7 @@
# ^ source.scala
# ^^^^ source.scala keyword.control.flow.scala
# ^^^ source.scala
# ^ source.scala keyword.operator.comparison.scala
# ^ source.scala keyword.operator.comparison.scala
# ^^ source.scala keyword.operator.scala
# ^ source.scala
# ^ source.scala meta.bracket.scala
# ^^^^ source.scala
Expand Down Expand Up @@ -1908,17 +1894,15 @@
# ^ source.scala
# ^ source.scala meta.bracket.scala
# ^ source.scala
# ^ source.scala keyword.operator.comparison.scala
# ^ source.scala keyword.operator.comparison.scala
# ^^ source.scala keyword.operator.scala
# ^ source.scala
# ^^^^^ source.scala keyword.control.flow.jump.scala
# ^^^^ source.scala
> case other => throw other
#^^^^^^^^ source.scala
# ^^^^ source.scala keyword.control.flow.scala
# ^^^^^^^ source.scala
# ^ source.scala keyword.operator.comparison.scala
# ^ source.scala keyword.operator.comparison.scala
# ^^ source.scala keyword.operator.scala
# ^ source.scala
# ^^^^^ source.scala keyword.control.flow.jump.scala
# ^^^^^^^ source.scala
Expand Down Expand Up @@ -1954,8 +1938,7 @@
# ^^^ source.scala entity.name.class
# ^ source.scala meta.bracket.scala
# ^ source.scala
# ^ source.scala keyword.operator.comparison.scala
# ^ source.scala keyword.operator.comparison.scala
# ^^ source.scala keyword.operator.scala
# ^^^ source.scala
# ^ source.scala keyword.operator.arithmetic.scala
# ^^^^ source.scala
Expand Down Expand Up @@ -2115,8 +2098,7 @@
# ^ source.scala
# ^ source.scala entity.name.class
# ^ source.scala
# ^ source.scala keyword.operator.comparison.scala
# ^ source.scala keyword.operator.comparison.scala
# ^^ source.scala keyword.operator.scala
# ^ source.scala
# ^^^^^^^ source.scala entity.name.class
# ^ source.scala meta.bracket.scala
Expand Down Expand Up @@ -2169,8 +2151,7 @@
# ^ source.scala
# ^^^ source.scala
# ^ source.scala
# ^ source.scala keyword.operator.comparison.scala
# ^ source.scala keyword.operator.comparison.scala
# ^^ source.scala keyword.operator.scala
# ^^ source.scala
> case s @ Seq(_, _, _) =>
#^^^^^^^^ source.scala
Expand All @@ -2183,8 +2164,7 @@
# ^^^^^^^ source.scala
# ^ source.scala meta.bracket.scala
# ^ source.scala
# ^ source.scala keyword.operator.comparison.scala
# ^ source.scala keyword.operator.comparison.scala
# ^^ source.scala keyword.operator.scala
# ^^ source.scala
> case Seq(first, tail @ _*) =>
#^^^^^^^^ source.scala
Expand All @@ -2198,17 +2178,15 @@
# ^ source.scala keyword.operator.arithmetic.scala
# ^ source.scala meta.bracket.scala
# ^ source.scala
# ^ source.scala keyword.operator.comparison.scala
# ^ source.scala keyword.operator.comparison.scala
# ^^ source.scala keyword.operator.scala
> case first +: tail =>
#^^^^^^^^ source.scala
# ^^^^ source.scala keyword.control.flow.scala
# ^^^^^^^ source.scala
# ^ source.scala keyword.operator.arithmetic.scala
# ^ source.scala keyword.operator.scala
# ^^^^^^ source.scala
# ^ source.scala keyword.operator.comparison.scala
# ^ source.scala keyword.operator.comparison.scala
# ^^ source.scala keyword.operator.scala
> case 3 | 5 | 6 =>
#^^^^^^^^ source.scala
# ^^^^ source.scala keyword.control.flow.scala
Expand All @@ -2223,8 +2201,7 @@
# ^ source.scala
# ^ source.scala constant.numeric.scala
# ^ source.scala
# ^ source.scala keyword.operator.comparison.scala
# ^ source.scala keyword.operator.comparison.scala
# ^^ source.scala keyword.operator.scala
> case y: Number => y.n
#^^^^^^^^ source.scala
# ^^^^ source.scala keyword.control.flow.scala
Expand All @@ -2234,8 +2211,7 @@
# ^ source.scala
# ^^^^^^ source.scala entity.name.class
# ^ source.scala
# ^ source.scala keyword.operator.comparison.scala
# ^ source.scala keyword.operator.comparison.scala
# ^^ source.scala keyword.operator.scala
# ^^^^^ source.scala
> case Lit(n) => n
#^^^^^^^^ source.scala
Expand All @@ -2246,8 +2222,7 @@
# ^ source.scala
# ^ source.scala meta.bracket.scala
# ^^^^^^^^ source.scala
# ^ source.scala keyword.operator.comparison.scala
# ^ source.scala keyword.operator.comparison.scala
# ^^ source.scala keyword.operator.scala
# ^^^ source.scala
> case IsZero(u) => eval(u) == 0
#^^^^^^^^ source.scala
Expand All @@ -2258,8 +2233,7 @@
# ^ source.scala
# ^ source.scala meta.bracket.scala
# ^^^^^ source.scala
# ^ source.scala keyword.operator.comparison.scala
# ^ source.scala keyword.operator.comparison.scala
# ^^ source.scala keyword.operator.scala
# ^^^^^ source.scala
# ^ source.scala meta.bracket.scala
# ^ source.scala
Expand All @@ -2272,8 +2246,7 @@
#^^^^^^^^ source.scala
# ^^^^ source.scala keyword.control.flow.scala
# ^^^ source.scala
# ^ source.scala keyword.operator.comparison.scala
# ^ source.scala keyword.operator.comparison.scala
# ^^ source.scala keyword.operator.scala
# ^ source.scala
# ^^ source.scala constant.numeric.scala
> }
Expand Down Expand Up @@ -2473,8 +2446,7 @@
# ^ source.scala
# ^ source.scala meta.bracket.scala
# ^ source.scala
# ^ source.scala keyword.operator.comparison.scala
# ^ source.scala keyword.operator.comparison.scala
# ^^ source.scala keyword.operator.scala
# ^^^ source.scala
> }
#^^^^ source.scala
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/#191.test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,17 @@
// ^^ keyword.operator.scala
setting := value
// ^^ keyword.operator.scala

a->b
// ^^ keyword.operator.scala
a->>b
// ^^^ keyword.operator.scala
a->->b
// ^^^ keyword.operator.scala

a | b
// ^ keyword.operator.scala
a ||| b
// ^^^ keyword.operator.scala
a |+ b
// ^^ keyword.operator.scala

0 comments on commit cdc67c9

Please sign in to comment.