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

Stop splitting common operators #275

Merged
merged 8 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"build": "npm-run-all build:syntax build:extension",
"build:syntax": "ts-node src/typescript/GenerateTmLanguageFile.ts > ./syntaxes/Scala.tmLanguage.json",
"build:extension": "vsce package --yarn",
"test": "npm-run-all test:*",
"test": "npm-run-all -c test:*",
"test:unit": "vscode-tmgrammar-test -s source.scala -g syntaxes/Scala.tmLanguage.json -t 'tests/unit/**/*.test.scala'",
"test:snap": "vscode-tmgrammar-snap -s source.scala -g syntaxes/Scala.tmLanguage.json -t 'tests/snap/**/*.test.scala'",
"update:snapshots": "vscode-tmgrammar-snap --updateSnapshot -s source.scala -g syntaxes/Scala.tmLanguage.json -t 'tests/snap/**/*.test.scala'"
Expand Down
61 changes: 47 additions & 14 deletions src/typescript/Scala.tmLanguage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const letterChars = `${upperLetterChars}${lowerLetterChars}`
const letter = `[${letterChars}]`
const letterOrDigitChars = `${letterChars}0-9`
const letterOrDigit = `[${letterOrDigitChars}]`
const alphaId = `${letter}+`
const letterOrDigitNoDollarSign = letterOrDigit.replace("\\$", "")
const simpleInterpolatedVariable = `${letter}${letterOrDigitNoDollarSign}*` // see SIP-11 https://docs.scala-lang.org/sips/string-interpolation.html
const opchar = `[!#%&*+\\-\\/:<>=?@^|~\\p{Sm}\\p{So}]`
Expand Down Expand Up @@ -677,21 +676,55 @@ export const scalaTmLanguage: TmLanguage = {
}
}
},
{
match: '(==?|!=|<=|>=|<>|<|>)',
name: 'keyword.operator.comparison.scala'
},
{
match: '(\\-|\\+|\\*|/(?![/*])|%|~)',
name: 'keyword.operator.arithmetic.scala'
{ // Operators with three or more characters
match: `(${opchar}|[\\\\]){3,}`,
name: 'keyword.operator.scala'
},
{
match: `(?<!${opchar}|_)(!|&&|\\|\\|)(?!${opchar})`,
name: 'keyword.operator.logical.scala'
{ // Operators with two characters
match: `((?:${opchar}|[\\\\]){2,}|_\\*)`,
captures: {
'1': {
patterns: [
{
match: '(\\|\\||&&)',
name: 'keyword.operator.logical.scala'
},
{
match: '(\\!=|==|\\<=|>=)',
name: 'keyword.operator.comparison.scala'
},
{
match: '..',
name: 'keyword.operator.scala'
}
]
}
}
},
{
match: '(<-|←|->|→|=>|⇒|\\?|\\:+|@|\\|)+',
name: 'keyword.operator.scala'
{ // Operators with one character
match: `(?<!_)(${opchar}|\\\\)`,
captures: {
'1': {
patterns: [
{
match: '(\\!)',
name: 'keyword.operator.logical.scala'
},
{
match: '(\\*|-|\\+|/|%|~)',
name: 'keyword.operator.arithmetic.scala'
},
{
match: '(=|\\<|>)',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here I think we shouln't match =, as a single = doesn't compare but defines things.

name: 'keyword.operator.comparison.scala'
},
{
match: '.',
name: 'keyword.operator.scala'
}
]
}
}
}
]
},
Expand Down
2 changes: 1 addition & 1 deletion syntaxes/Scala.tmLanguage.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions tests/snap/#191.test.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
a \\\ b

a \+\ b
10 changes: 10 additions & 0 deletions tests/snap/#191.test.scala.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
>a \\\ b
#^^ source.scala
# ^^^ source.scala keyword.operator.scala
# ^^^ source.scala
>
>a \+\ b
#^^ source.scala
# ^^^ source.scala keyword.operator.scala
# ^^^ source.scala
>
12 changes: 4 additions & 8 deletions tests/snap/end.test.scala.snap
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@
# ^ source.scala meta.bracket.scala
> y -= 1
#^^^^^^^^^^^^^^^^^ source.scala
# ^ source.scala keyword.operator.arithmetic.scala
# ^ source.scala keyword.operator.comparison.scala
# ^^ source.scala keyword.operator.scala
# ^ source.scala
# ^ source.scala constant.numeric.scala
> end while
Expand All @@ -114,8 +113,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 +124,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 Expand Up @@ -237,8 +234,7 @@
# ^ source.scala
# ^ source.scala keyword.operator.comparison.scala
# ^^^^^ source.scala
# ^ source.scala keyword.operator.arithmetic.scala
# ^ source.scala keyword.operator.arithmetic.scala
# ^^ source.scala keyword.operator.scala
# ^^^^^ source.scala
> end extension
#^^^ source.scala
Expand Down
Loading
Loading