tree-sitter / tree-sitter-scala

Scala grammar for tree-sitter
MIT License
158 stars 55 forks source link

Exclude colon, at, and equal from single opchar #394

Closed eed3si9n closed 6 months ago

eed3si9n commented 6 months ago

Problem

Currently operator_identifier includes characters like : (colon), @ (at), and = (equal) even though they cannot be a legal operator without backticks. Having equal etc pushes tree-sitter into falsely thinking some construct to be an infix operation when they are =.

Another complication is Unicode Math symbols, which includes equal sign.

Solution

  1. Remove colon, at, equal sign, and Math symbols from the single-char operator_identifier.
  2. Add back back a few Math symbol unicodes.

All tests pass as-is.

Note

$ scala
Welcome to Scala 3.4.0 (1.8.0_402, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.

scala> def : = 0
-- [E040] Syntax Error: --------------------------------------------------------
1 |def : = 0
  |    ^
  |    an identifier expected, but ':' found
  |
  | longer explanation available when compiling with `-explain`

scala> def @ = 0
-- [E040] Syntax Error: --------------------------------------------------------
1 |def @ = 0
  |    ^
  |    an identifier expected, but '@' found
  |
  | longer explanation available when compiling with `-explain`

scala> def = = 0
-- [E040] Syntax Error: --------------------------------------------------------
1 |def = = 0
  |    ^
  |    an identifier expected, but '=' found
  |
  | longer explanation available when compiling with `-explain`