Skip to content

Commit

Permalink
Merge symbol and quote capturing
Browse files Browse the repository at this point in the history
Syntax for quotes and symbols overlap. We can tag these as symbols and
quotes at the same time.
  • Loading branch information
nicolasstucki committed Feb 13, 2023
1 parent 6839617 commit cd24dc8
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 29 deletions.
38 changes: 23 additions & 15 deletions src/typescript/Scala.tmLanguage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,17 +299,14 @@ export const scalaTmLanguage: TmLanguage = {
{
include: '#constants'
},
{
include: '#scala-symbol'
},
{
include: '#singleton-type'
},
{
include: '#inline'
},
{
include: '#scala-quoted'
include: '#scala-quoted-or-symbol'
},
{
include: '#char-literal'
Expand Down Expand Up @@ -710,16 +707,31 @@ export const scalaTmLanguage: TmLanguage = {
}
]
},
'scala-quoted': {
'scala-quoted-or-symbol': {
patterns: [
{ // Start of `'{ .. }` or `${ .. }`
match: "['$][ \\t]*\\{(?!')",
name: 'punctuation.section.block.begin.scala'
{ // `'xyz`
match: `(')((?>${plainid}))(?!')`,
captures: {
'1': {
name: 'keyword.control.flow.staging.scala constant.other.symbol.scala'
},
'2': {
name: 'constant.other.symbol.scala'
}
}
},
{ // Start of `'{ .. }`
match: `'(?=\\s*\\{(?!'))`,
name: 'keyword.control.flow.staging.scala'
},
{ // Start of `'[ .. ]`
match: "'[ \\t]*\\[(?!')",
name: 'meta.bracket.scala'
}
match: "'(?=\\s*\\[(?!'))",
name: 'keyword.control.flow.staging.scala'
},
{ // Start of `${ .. }`
match: "\\$(?=\\s*\\{)",
name: 'keyword.control.flow.staging.scala'
},
]
},
'xml-doublequotedString': {
Expand Down Expand Up @@ -911,10 +923,6 @@ export const scalaTmLanguage: TmLanguage = {
}
}
},
'scala-symbol': {
match: `(?>'${plainid})(?!')`,
name: 'constant.other.symbol.scala'
},
'curly-braces': {
begin: '\\{',
end: '\\}',
Expand Down
2 changes: 1 addition & 1 deletion syntaxes/Scala.tmLanguage.json

Large diffs are not rendered by default.

15 changes: 10 additions & 5 deletions tests/snap/lexical.test.scala.snap
Original file line number Diff line number Diff line change
Expand Up @@ -378,15 +378,20 @@
> ('x, 'X, 'αρετη, '=, '+ )
#^^^^ source.scala
# ^ source.scala meta.bracket.scala
# ^^ source.scala constant.other.symbol.scala
# ^ source.scala keyword.control.flow.staging.scala constant.other.symbol.scala
# ^ source.scala constant.other.symbol.scala
# ^^ source.scala
# ^^ source.scala constant.other.symbol.scala
# ^ source.scala keyword.control.flow.staging.scala constant.other.symbol.scala
# ^ source.scala constant.other.symbol.scala
# ^^ source.scala
# ^^^^^^ source.scala constant.other.symbol.scala
# ^ source.scala keyword.control.flow.staging.scala constant.other.symbol.scala
# ^^^^^ source.scala constant.other.symbol.scala
# ^^ source.scala
# ^^ source.scala constant.other.symbol.scala
# ^ source.scala keyword.control.flow.staging.scala constant.other.symbol.scala
# ^ source.scala constant.other.symbol.scala
# ^^ source.scala
# ^^ source.scala constant.other.symbol.scala
# ^ source.scala keyword.control.flow.staging.scala constant.other.symbol.scala
# ^ source.scala constant.other.symbol.scala
# ^ source.scala
# ^ source.scala meta.bracket.scala
>}
Expand Down
1 change: 1 addition & 0 deletions tests/unit/lexical.test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ object ExampleIdentifiers {
// ^^^^^^^^^^^^^ variable.stable.declaration.scala
val __system = 3
// ^^^^^^^^ variable.stable.declaration.scala

val _MAX_LEN_ = 3
// ^^^^^^^^^ variable.stable.declaration.scala
}
Expand Down
29 changes: 21 additions & 8 deletions tests/unit/quoted.test.scala
Original file line number Diff line number Diff line change
@@ -1,37 +1,50 @@
// SYNTAX TEST "source.scala"

'x
// ^ keyword.control.flow.staging.scala constant.other.symbol.scala
// ^ constant.other.symbol.scala
'{ 2 }
// ^^ punctuation.section.block.begin.scala
// ^ keyword.control.flow.staging.scala
// ^ punctuation.section.block.begin.scala
// ^ constant.numeric.scala
// ^ punctuation.section.block.end.scala

' { 2 }
// ^^^^ punctuation.section.block.begin.scala
// ^ keyword.control.flow.staging.scala
// ^ punctuation.section.block.begin.scala
// ^ constant.numeric.scala
// ^ punctuation.section.block.end.scala

'
// ^ punctuation.definition.character.begin.scala
{ }

'[ String ]
// ^^ meta.bracket.scala
// ^ keyword.control.flow.staging.scala
// ^ meta.bracket.scala
// ^^^^^^ entity.name.class
// ^ meta.bracket.scala

' [ String ]
// ^^^ meta.bracket.scala
// ^ keyword.control.flow.staging.scala
// ^ meta.bracket.scala
// ^^^^^^ entity.name.class
// ^ meta.bracket.scala


${ 1 }
// ^^ punctuation.section.block.begin.scala
// ^ keyword.control.flow.staging.scala
// ^ punctuation.section.block.begin.scala
// ^ constant.numeric.scala
// ^ punctuation.section.block.end.scala

case '{ x } =>
// ^^^^ keyword.control.flow.scala
// ^^ punctuation.section.block.begin.scala
// ^ keyword.control.flow.staging.scala
// ^ punctuation.section.block.begin.scala
// ^ punctuation.section.block.end.scala

case '[ T ] =>
// ^^^^ keyword.control.flow.scala
// ^^ meta.bracket.scala
// ^ keyword.control.flow.staging.scala
// ^ meta.bracket.scala
// ^ meta.bracket.scala

0 comments on commit cd24dc8

Please # to comment.