Skip to content

Commit 15a17db

Browse files
committed
Merge symbol and quote capturing
Syntax for quotes and symbols overlap. We can tag these as symbols and quotes at the same time.
1 parent d81796e commit 15a17db

File tree

6 files changed

+80
-60
lines changed

6 files changed

+80
-60
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"build:extension": "vsce package --yarn",
6262
"test": "npm-run-all test:*",
6363
"test:unit": "vscode-tmgrammar-test -s source.scala -g syntaxes/Scala.tmLanguage.json -t 'tests/unit/**/*.test.scala'",
64-
"test:snap": "vscode-tmgrammar-snap -s source.scala -g syntaxes/Scala.tmLanguage.json -t 'tests/snap/**/*.test.scala'"
64+
"test:snap": "vscode-tmgrammar-snap -s source.scala -g syntaxes/Scala.tmLanguage.json -t 'tests/snap/**/*.test.scala'",
65+
"update:snapshots": "vscode-tmgrammar-snap --updateSnapshot -s source.scala -g syntaxes/Scala.tmLanguage.json -t 'tests/snap/**/*.test.scala'"
6566
}
6667
}

src/typescript/Scala.tmLanguage.ts

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -299,17 +299,14 @@ export const scalaTmLanguage: TmLanguage = {
299299
{
300300
include: '#constants'
301301
},
302-
{
303-
include: '#scala-symbol'
304-
},
305302
{
306303
include: '#singleton-type'
307304
},
308305
{
309306
include: '#inline'
310307
},
311308
{
312-
include: '#scala-quoted'
309+
include: '#scala-quoted-or-symbol'
313310
},
314311
{
315312
include: '#char-literal'
@@ -710,16 +707,31 @@ export const scalaTmLanguage: TmLanguage = {
710707
}
711708
]
712709
},
713-
'scala-quoted': {
710+
'scala-quoted-or-symbol': {
714711
patterns: [
715-
{ // Start of `'{ .. }` or `${ .. }`
716-
match: "['$][ \\t]*\\{(?!')",
717-
name: 'punctuation.section.block.begin.scala'
712+
{ // `'xyz`
713+
match: `(')((?>${plainid}))(?!')`,
714+
captures: {
715+
'1': {
716+
name: 'keyword.control.flow.staging.scala constant.other.symbol.scala'
717+
},
718+
'2': {
719+
name: 'constant.other.symbol.scala'
720+
}
721+
}
722+
},
723+
{ // Start of `'{ .. }`
724+
match: `'(?=\\s*\\{(?!'))`,
725+
name: 'keyword.control.flow.staging.scala'
718726
},
719727
{ // Start of `'[ .. ]`
720-
match: "'[ \\t]*\\[(?!')",
721-
name: 'meta.bracket.scala'
722-
}
728+
match: "'(?=\\s*\\[(?!'))",
729+
name: 'keyword.control.flow.staging.scala'
730+
},
731+
{ // Start of `${ .. }`
732+
match: "\\$(?=\\s*\\{)",
733+
name: 'keyword.control.flow.staging.scala'
734+
},
723735
]
724736
},
725737
'xml-doublequotedString': {
@@ -914,10 +926,6 @@ export const scalaTmLanguage: TmLanguage = {
914926
}
915927
}
916928
},
917-
'scala-symbol': {
918-
match: `(?>'${plainid})(?!')`,
919-
name: 'constant.other.symbol.scala'
920-
},
921929
'curly-braces': {
922930
begin: '\\{',
923931
end: '\\}',

syntaxes/Scala.tmLanguage.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

tests/snap/lexical.test.scala.snap

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -378,15 +378,20 @@
378378
> ('x, 'X, 'αρετη, '=, '+ )
379379
#^^^^ source.scala
380380
# ^ source.scala meta.bracket.scala
381-
# ^^ source.scala constant.other.symbol.scala
381+
# ^ source.scala keyword.control.flow.staging.scala constant.other.symbol.scala
382+
# ^ source.scala constant.other.symbol.scala
382383
# ^^ source.scala
383-
# ^^ source.scala constant.other.symbol.scala
384+
# ^ source.scala keyword.control.flow.staging.scala constant.other.symbol.scala
385+
# ^ source.scala constant.other.symbol.scala
384386
# ^^ source.scala
385-
# ^^^^^^ source.scala constant.other.symbol.scala
387+
# ^ source.scala keyword.control.flow.staging.scala constant.other.symbol.scala
388+
# ^^^^^ source.scala constant.other.symbol.scala
386389
# ^^ source.scala
387-
# ^^ source.scala constant.other.symbol.scala
390+
# ^ source.scala keyword.control.flow.staging.scala constant.other.symbol.scala
391+
# ^ source.scala constant.other.symbol.scala
388392
# ^^ source.scala
389-
# ^^ source.scala constant.other.symbol.scala
393+
# ^ source.scala keyword.control.flow.staging.scala constant.other.symbol.scala
394+
# ^ source.scala constant.other.symbol.scala
390395
# ^ source.scala
391396
# ^ source.scala meta.bracket.scala
392397
>}

tests/unit/lexical.test.scala

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
1-
// SYNTAX TEST "source.scala"
1+
// SYNTAX TEST "source.scala"
22

33
object ExampleIdentifiers {
44
val x = 3
55
// ^ variable.other.declaration.scala
6-
val Object = 3
6+
val Object = 3
77
val maxIndex = 3
8-
// ^^^^^^^^ variable.other.declaration.scala
9-
val p2p = 3
8+
// ^^^^^^^^ variable.other.declaration.scala
9+
val p2p = 3
1010
// ^^^ variable.other.declaration.scala
1111
val empty_? = 3
1212
// ^^^^^^^ variable.other.declaration.scala
13-
val + = 3
14-
// ^ variable.other.declaration.scala
15-
val `yield` = 3
16-
// ^^^^^^^ variable.other.declaration.scala
17-
val αρετη = 3
18-
val _y = 3
19-
// ^^ variable.other.declaration.scala
13+
val + = 3
14+
// ^ variable.other.declaration.scala
15+
val `yield` = 3
16+
// ^^^^^^^ variable.other.declaration.scala
17+
val αρετη = 3
18+
val _y = 3
19+
// ^^ variable.other.declaration.scala
2020
val dot_product_* = 3
2121
// ^^^^^^^^^^^^^ variable.other.declaration.scala
22-
val __system = 3
22+
val __system = 3
2323
// ^^^^^^^^ variable.other.declaration.scala
2424
val _MAX_LEN_ = 3
2525
// ^^^^^^^^^ variable.other.declaration.scala
2626
}
2727

2828
object IntegerLiterals {
2929
(0, 21, 0xFFFFFFFF, -42L)
30-
// ^ constant.numeric.scala
30+
// ^ constant.numeric.scala
3131
// ^^ constant.numeric.scala
3232
// ^^^^^^^^^^ constant.numeric.scala
3333
// ^ keyword.operator.arithmetic.scala
@@ -37,9 +37,9 @@ object IntegerLiterals {
3737
object FloatingPointLiterals {
3838
( 0.0, 1e30f, 3.14159f, 1.0e-100, .1 )
3939
// ^^^ constant.numeric.scala
40-
// ^^^^^^^^ constant.numeric.scala
41-
// ^^^^^^^^ constant.numeric.scala
42-
// ^^ constant.numeric.scala
40+
// ^^^^^^^^ constant.numeric.scala
41+
// ^^^^^^^^ constant.numeric.scala
42+
// ^^ constant.numeric.scala
4343
}
4444

4545
object Boolean {
@@ -54,9 +54,9 @@ object CharacterLiterals {
5454
// ^^^ constant.character.literal.scala
5555
// ^ punctuation.definition.character.end.scala
5656
// ^^^^^^^^ constant.character.literal.scala
57-
// ^^^^^^ constant.character.escape.scala
57+
// ^^^^^^ constant.character.escape.scala
5858
// ^^ constant.character.escape.scala
59-
// ^^ constant.character.escape.scala
59+
// ^^ constant.character.escape.scala
6060
}
6161

6262
object StringLiterals {
@@ -65,14 +65,14 @@ object StringLiterals {
6565
// ^^^^^^^^^^^^^^^^ string.quoted.double.scala
6666
// ^^ constant.character.escape.scala
6767
// ^ punctuation.definition.string.end.scala
68-
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double.scala
68+
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double.scala
6969
"""the present string
7070
// ^^^ punctuation.definition.string.begin.scala
7171
// ^^^^^^^^^^^^^^^^^^^^^ string.quoted.triple.scala
7272
spans three
7373
// ^^^^^^^^^^^ string.quoted.triple.scala
7474
lines."""
75-
// ^^^^^^^^^ string.quoted.triple.scala
75+
// ^^^^^^^^^ string.quoted.triple.scala
7676
// ^^^ punctuation.definition.string.end.scala
7777

7878
"""the present string
@@ -86,8 +86,8 @@ object StringLiterals {
8686

8787
s"$x plain ${val x = y}"
8888
//^ keyword.interpolation.scala
89-
// ^ punctuation.definition.string.begin.scala
90-
// ^ punctuation.definition.template-expression.begin.scala
89+
// ^ punctuation.definition.string.begin.scala
90+
// ^ punctuation.definition.template-expression.begin.scala
9191
// ^ - string.quoted.double.interpolated.scala string.quoted.double.scala
9292
// ^^^^^^^ string.quoted.double.interpolated.scala
9393
// ^^^^^^^^^^^^ meta.template.expression.scala
@@ -96,12 +96,12 @@ object StringLiterals {
9696
// ^^^ keyword.declaration.stable.scala
9797
// ^^^^^^^^^ - string.quoted.double.interpolated.scala string.quoted.double.scala
9898
// ^ punctuation.definition.template-expression.end.scala
99-
// ^ string.quoted.double.interpolated.scala punctuation.definition.string.end.scala
99+
// ^ string.quoted.double.interpolated.scala punctuation.definition.string.end.scala
100100

101101
custom"$x plain ${val x = y}"
102102
//^^^^^^ keyword.interpolation.scala
103-
// ^ punctuation.definition.string.begin.scala
104-
// ^ punctuation.definition.template-expression.begin.scala
103+
// ^ punctuation.definition.string.begin.scala
104+
// ^ punctuation.definition.template-expression.begin.scala
105105
// ^ - string.quoted.double.interpolated.scala string.quoted.double.scala
106106
// ^^^^^^^ string.quoted.double.interpolated.scala
107107
// ^^^^^^^^^^^^ meta.template.expression.scala
@@ -110,26 +110,26 @@ object StringLiterals {
110110
// ^^^ keyword.declaration.stable.scala
111111
// ^^^^^^^^^ - string.quoted.double.interpolated.scala string.quoted.double.scala
112112
// ^ punctuation.definition.template-expression.end.scala
113-
// ^ string.quoted.double.interpolated.scala punctuation.definition.string.end.scala
113+
// ^ string.quoted.double.interpolated.scala punctuation.definition.string.end.scala
114114

115115
object Symbols {
116116
('x, 'X, 'αρετη, '=, '+ )
117117
// ^^ constant.other.symbol.scala
118118
// ^^ constant.other.symbol.scala
119-
// ^^^^^^ constant.other.symbol.scala
119+
// ^^^^^^ constant.other.symbol.scala
120120
}
121121

122122
// single line comment
123-
// ^^ punctuation.definition.comment.scala
124-
// ^^^^^^^^^^^^^^^^^^^^^^ comment.line.double-slash.scala
123+
// ^^ punctuation.definition.comment.scala
124+
// ^^^^^^^^^^^^^^^^^^^^^^ comment.line.double-slash.scala
125125

126126
/*
127127
// ^^ punctuation.definition.comment.scala
128128
multiline comment*/
129129
// ^^^^^^^^^^^^^^^^^^^ comment.block.scala
130130
/**
131131
* Scaladoc comment
132-
* @scaladoc @param
132+
* @scaladoc @param
133133
*/
134134

135135
/* nested /* multi-line */ comment */

tests/unit/quoted.test.scala

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,43 @@
11
// SYNTAX TEST "source.scala"
22

3+
'x
4+
// ^ keyword.control.flow.staging.scala constant.other.symbol.scala
5+
// ^ constant.other.symbol.scala
36
'{ 2 }
4-
// ^^ punctuation.section.block.begin.scala
7+
// ^ keyword.control.flow.staging.scala
58
// ^ constant.numeric.scala
69
// ^ punctuation.section.block.end.scala
710

811
' { 2 }
9-
// ^^^^ punctuation.section.block.begin.scala
12+
// ^ keyword.control.flow.staging.scala
1013
// ^ constant.numeric.scala
1114
// ^ punctuation.section.block.end.scala
1215

16+
'
17+
// ^ punctuation.definition.character.begin.scala
18+
{ }
19+
1320
'[ String ]
14-
// ^^ meta.bracket.scala
21+
// ^ keyword.control.flow.staging.scala
1522
// ^^^^^^ entity.name.class
1623
// ^ meta.bracket.scala
1724

1825
' [ String ]
19-
// ^^^ meta.bracket.scala
26+
// ^ keyword.control.flow.staging.scala
2027
// ^^^^^^ entity.name.class
2128
// ^ meta.bracket.scala
2229

23-
2430
${ 1 }
25-
// ^^ punctuation.section.block.begin.scala
31+
// ^ keyword.control.flow.staging.scala
2632
// ^ constant.numeric.scala
2733
// ^ punctuation.section.block.end.scala
2834

2935
case '{ x } =>
3036
// ^^^^ keyword.control.flow.scala
31-
// ^^ punctuation.section.block.begin.scala
37+
// ^ keyword.control.flow.staging.scala
3238
// ^ punctuation.section.block.end.scala
3339

3440
case '[ T ] =>
3541
// ^^^^ keyword.control.flow.scala
36-
// ^^ meta.bracket.scala
42+
// ^ keyword.control.flow.staging.scala
3743
// ^ meta.bracket.scala

0 commit comments

Comments
 (0)