Skip to content

Commit

Permalink
Improve highlighting strategy for illegal $
Browse files Browse the repository at this point in the history
Also fix missing rules for `"""` and `raw`
  • Loading branch information
nicolasstucki committed Feb 5, 2021
1 parent b28000b commit e72b4c9
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 16 deletions.
28 changes: 20 additions & 8 deletions src/typescript/Scala.tmLanguage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ export const scalaTmLanguage: TmLanguage = {
},
{
begin: `\\b(raw)(""")`,
end: '"""(?!")',
end: `(""")(?!")|\\$\n|(\\$[^\\$"_{${letterChars}])`,
beginCaptures: {
'1': {
name: 'keyword.interpolation.scala'
Expand All @@ -356,14 +356,17 @@ export const scalaTmLanguage: TmLanguage = {
}
],
endCaptures: {
'0': {
'1': {
name: 'string.quoted.triple.interpolated.scala punctuation.definition.string.end.scala'
},
'2': {
name: 'invalid.illegal.unrecognized-string-escape.scala'
}
}
},
{
begin: `\\b(${alphaId})(""")`,
end: '"""(?!")',
end: `(""")(?!")|\\$\n|(\\$[^\\$"_{${letterChars}])`,
beginCaptures: {
'1': {
name: 'keyword.interpolation.scala'
Expand All @@ -386,8 +389,11 @@ export const scalaTmLanguage: TmLanguage = {
}
],
endCaptures: {
'0': {
'1': {
name: 'string.quoted.triple.interpolated.scala punctuation.definition.string.end.scala'
},
'2': {
name: 'invalid.illegal.unrecognized-string-escape.scala'
}
}
},
Expand Down Expand Up @@ -418,7 +424,7 @@ export const scalaTmLanguage: TmLanguage = {
},
{
begin: `\\b(raw)(")`,
end: `"|\\$(?=[^\\$"_{${letterChars}])`,
end: `(")|\\$\n|(\\$[^\\$"_{${letterChars}])`,
beginCaptures: {
'1': {
name: 'keyword.interpolation.scala'
Expand All @@ -441,14 +447,17 @@ export const scalaTmLanguage: TmLanguage = {
}
],
endCaptures: {
'0': {
'1': {
name: 'string.quoted.double.interpolated.scala punctuation.definition.string.end.scala'
},
'2': {
name: 'invalid.illegal.unrecognized-string-escape.scala'
}
}
},
{
begin: `\\b(${alphaId})(")`,
end: `"|\\$(?=[^\\$"_{${letterChars}])`,
end: `(")|\\$\n|(\\$[^\\$"_{${letterChars}])`,
beginCaptures: {
'1': {
name: 'keyword.interpolation.scala'
Expand Down Expand Up @@ -479,8 +488,11 @@ export const scalaTmLanguage: TmLanguage = {
}
],
endCaptures: {
'0': {
'1': {
name: 'string.quoted.double.interpolated.scala punctuation.definition.string.end.scala'
},
'2': {
name: 'invalid.illegal.unrecognized-string-escape.scala'
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/#183.test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@
raw"$
// ^^^ source.scala keyword.interpolation.scala
// ^ string.quoted.double.interpolated.scala punctuation.definition.string.begin.scala
// ^ string.quoted.double.interpolated.scala punctuation.definition.string.end.scala
// ^ - string.quoted.double.interpolated.scala punctuation.definition.string.end.scala
49 changes: 42 additions & 7 deletions tests/unit/#195.test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,53 @@
// ^ string.quoted.double.interpolated.scala punctuation.definition.string.end.scala


s"$
// ^ string.quoted.double.interpolated.scala punctuation.definition.string.begin.scala
// ^ - string.quoted.double.interpolated.scala punctuation.definition.string.end.scala
// ^ - constant.character.escape.scala


s"$ //
// ^ string.quoted.double.interpolated.scala punctuation.definition.string.begin.scala
// ^ string.quoted.double.interpolated.scala punctuation.definition.string.end.scala
// ^^ comment.line.double-slash.scala punctuation.definition.comment.scala
// ^^ invalid.illegal.unrecognized-string-escape.scala

s"$+
s"$++
// ^ string.quoted.double.interpolated.scala punctuation.definition.string.begin.scala
// ^ string.quoted.double.interpolated.scala punctuation.definition.string.end.scala
// ^ keyword.operator.arithmetic.scala
// ^^ invalid.illegal.unrecognized-string-escape.scala
// ^ keyword.operator.arithmetic.scala

s"$; val a =
// ^ string.quoted.double.interpolated.scala punctuation.definition.string.begin.scala
// ^ string.quoted.double.interpolated.scala punctuation.definition.string.end.scala
// ^^^^^^^^^^ -string.quoted.double.interpolated.scala
// ^^ invalid.illegal.unrecognized-string-escape.scala
// ^^^^^^^^ -string.quoted.double.interpolated.scala
// ^^^ keyword.declaration.stable.scala

raw"$
// ^^^ source.scala keyword.interpolation.scala
// ^ string.quoted.double.interpolated.scala punctuation.definition.string.begin.scala
// ^ - string.quoted.double.interpolated.scala invalid.illegal.unrecognized-string-escape.scala

raw"$4
// ^^^ source.scala keyword.interpolation.scala
// ^ string.quoted.double.interpolated.scala punctuation.definition.string.begin.scala
// ^^ invalid.illegal.unrecognized-string-escape.scala

raw"""$
// ^^^ source.scala keyword.interpolation.scala
// ^^^ string.quoted.triple.interpolated.scala punctuation.definition.string.begin.scala
// ^ - string.quoted.triple.interpolated.scala invalid.illegal.unrecognized-string-escape.scala

raw"""$8
// ^^^ source.scala keyword.interpolation.scala
// ^^^ string.quoted.triple.interpolated.scala punctuation.definition.string.begin.scala
// ^^ invalid.illegal.unrecognized-string-escape.scala

s"""$
// ^ source.scala keyword.interpolation.scala
// ^^^ string.quoted.triple.interpolated.scala punctuation.definition.string.begin.scala
// ^ - string.quoted.triple.interpolated.scala invalid.illegal.unrecognized-string-escape.scala

s"""$8
// ^ source.scala keyword.interpolation.scala
// ^^^ string.quoted.triple.interpolated.scala punctuation.definition.string.begin.scala
// ^^ invalid.illegal.unrecognized-string-escape.scala

0 comments on commit e72b4c9

Please sign in to comment.