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

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

Merged
merged 2 commits into from
Apr 15, 2024

Conversation

eed3si9n
Copy link
Collaborator

@eed3si9n eed3si9n commented Apr 14, 2024

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`

**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 thinking some
construct to be an infix operation when they are `=`.

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

**Solution**
Remove colon, at, equal sign, and Math symbols from the
single-char operator_identifier.
This adds back back a few Math symbol unicodes.
@@ -3,7 +3,7 @@
# This is an integration test to generally check the quality of parsing.

SCALA_SCALA_LIBRARY_EXPECTED=100
SCALA_SCALA_COMPILER_EXPECTED=96
SCALA_SCALA_COMPILER_EXPECTED=97
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notice: ok, scala_scala/src/compiler/: 97.54%, expected at least 96%

Copy link
Collaborator

@ckipp01 ckipp01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice improvement!

@ckipp01 ckipp01 merged commit d3eb6b2 into tree-sitter:master Apr 15, 2024
4 checks passed
@eed3si9n eed3si9n deleted the wip/op branch April 15, 2024 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants