Skip to content

Commit 2a4b6b5

Browse files
committed
Simplify operators
Instead of dancing around around special operators we can just enumerate them now. This fixes a lot of edge cases.
1 parent 044ea66 commit 2a4b6b5

File tree

4 files changed

+70
-52
lines changed

4 files changed

+70
-52
lines changed

src/typescript/Scala.tmLanguage.ts

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -676,31 +676,55 @@ export const scalaTmLanguage: TmLanguage = {
676676
}
677677
}
678678
},
679-
{ // Higher precedence than other kinds of operators to prevent
680-
// decomposition of operators like ->
681-
match: `(<-|←|->|→|=>|⇒|\\?|\\:|@|\\^)+${opchar}*`,
679+
{ // Operators with three or more characters
680+
match: `(${opchar}${opchar}${opchar}+)`,
682681
name: 'keyword.operator.scala'
683682
},
684-
{ // The 'special' below operators directly follower by another symbol
685-
// are just operators for example +:, /:, ++ and ==>
686-
match: `(\\-|\\+|\\*|/(?![/*])|%|~|==|!=|<=|>=|<>)${opchar}+`,
687-
name: 'keyword.operator.scala'
688-
},
689-
{
690-
match: '(==?|!=|<=|>=|<>|<|>)',
691-
name: 'keyword.operator.comparison.scala'
692-
},
693-
{
694-
match: '(\\-|\\+|\\*|/(?![/*])|%|~)',
695-
name: 'keyword.operator.arithmetic.scala'
696-
},
697-
{
698-
match: `(?<!${opchar}|_)(!|&&|\\|\\|)(?!${opchar})`,
699-
name: 'keyword.operator.logical.scala'
683+
{ // Operators with two characters
684+
match: `(${opchar}${opchar}|\\\\${opchar})`,
685+
captures: {
686+
'1': {
687+
patterns: [
688+
{
689+
match: '(\\|\\||&&)',
690+
name: 'keyword.operator.logical.scala'
691+
},
692+
{
693+
match: '(\\!=|==|\\<=|>=)',
694+
name: 'keyword.operator.comparison.scala'
695+
},
696+
{
697+
match: '..',
698+
name: 'keyword.operator.scala'
699+
}
700+
]
701+
}
702+
}
700703
},
701-
{ // Lower precedence than logical || operator
702-
match: `(\\|)${opchar}*`,
703-
name: 'keyword.operator.scala'
704+
{ // Operators with one character
705+
match: `(?<!${letter}_)(${opchar})`,
706+
captures: {
707+
'1': {
708+
patterns: [
709+
{
710+
match: '(\\!)',
711+
name: 'keyword.operator.logical.scala'
712+
},
713+
{
714+
match: '(\\*|-|\\+|/|%|~)',
715+
name: 'keyword.operator.arithmetic.scala'
716+
},
717+
{
718+
match: '(=|\\<|>)',
719+
name: 'keyword.operator.comparison.scala'
720+
},
721+
{
722+
match: '.',
723+
name: 'keyword.operator.scala'
724+
}
725+
]
726+
}
727+
}
704728
}
705729
]
706730
},

0 commit comments

Comments
 (0)