Skip to content

Commit

Permalink
Merge pull request #275 from Jentsch/fix-operators
Browse files Browse the repository at this point in the history
Stop splitting common operators
  • Loading branch information
tgodzik authored Oct 11, 2024
2 parents f450a3d + d868753 commit f92d65a
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 128 deletions.
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: '(=|\\<|>)',
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

0 comments on commit f92d65a

Please sign in to comment.