Skip to content

Commit 8ab4e36

Browse files
committed
Add wordPattern regex under language-configuration.json
1 parent 3ee4cc9 commit 8ab4e36

File tree

3 files changed

+195
-1
lines changed

3 files changed

+195
-1
lines changed

package.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"keywords": [
2020
"package.json",
2121
"shellscript",
22-
"scripts embed"
22+
"scripts embed",
23+
"language-configuration"
2324
],
2425
"categories": [
2526
"Programming Languages"
@@ -30,6 +31,10 @@
3031
"scopeName": "source.json",
3132
"path": "./syntaxes/JSON.tmLanguage.json"
3233
},
34+
{
35+
"scopeName": "source.json.comments",
36+
"path": "./syntaxes/JSONC.tmLanguage.json"
37+
},
3338
{
3439
"scopeName": "source.json.shellscript",
3540
"path": "./syntaxes/scripts.tmLanguage.json",
@@ -47,6 +52,16 @@
4752
"source.json"
4853
]
4954
},
55+
{
56+
"scopeName": "source.json.comments.language-configuration",
57+
"path": "./syntaxes/language-configuration.tmLanguage.json",
58+
"embeddedLanguages": {
59+
"meta.embedded.json.textmate.regexp": "json-textmate-regex"
60+
},
61+
"injectTo": [
62+
"source.json.comments"
63+
]
64+
},
5065
{
5166
"scopeName": "source.json.legacy_tox_ini",
5267
"path": "./syntaxes/legacy_tox_ini.tmLanguage.json",

syntaxes/JSONC.tmLanguage.json

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/RedCMD/TmLanguage-Syntax-Highlighter/main/vscode.tmLanguage.schema.json",
3+
"name": "JSON with Comments",
4+
"scopeName": "source.json.comments",
5+
"patterns": [
6+
{ "include": "#value" }
7+
],
8+
"repository": {
9+
"array": {
10+
"begin": "\\[",
11+
"beginCaptures": { "0": { "name": "punctuation.definition.array.begin.json.comments" } },
12+
"end": "]",
13+
"endCaptures": { "0": { "name": "punctuation.definition.array.end.json.comments" } },
14+
"name": "meta.structure.array.json.comments",
15+
"patterns": [
16+
{ "include": "#value" },
17+
{
18+
"match": ",",
19+
"name": "punctuation.separator.array.json.comments"
20+
},
21+
{
22+
"match": "\\S",
23+
"name": "invalid.illegal.expected-array-separator.json.comments"
24+
}
25+
]
26+
},
27+
"comments": {
28+
"patterns": [
29+
{
30+
"begin": "/\\*\\*(?!/)",
31+
"captures": { "0": { "name": "punctuation.definition.comment.json.comments" } },
32+
"end": "\\*/",
33+
"name": "comment.block.documentation.json.comments"
34+
},
35+
{
36+
"begin": "/\\*",
37+
"captures": { "0": { "name": "punctuation.definition.comment.json.comments" } },
38+
"end": "\\*/",
39+
"name": "comment.block.json.comments"
40+
},
41+
{
42+
"begin": "//",
43+
"end": "$",
44+
"beginCaptures": { "0": { "name": "punctuation.definition.comment.json.comments" } },
45+
"name": "comment.line.double-slash.js"
46+
}
47+
]
48+
},
49+
"constant": {
50+
"match": "\\b(?>true|false|null)\\b",
51+
"name": "constant.language.json.comments"
52+
},
53+
"number": {
54+
"match": "-?(?>0|[1-9][0-9]*)(?>(?>\\.[0-9]+)?(?>[eE][+-]?[0-9]+)?)?",
55+
"name": "constant.numeric.json.comments"
56+
},
57+
"object": {
58+
"begin": "{",
59+
"beginCaptures": { "0": { "name": "punctuation.definition.dictionary.begin.json.comments" } },
60+
"end": "}",
61+
"endCaptures": { "0": { "name": "punctuation.definition.dictionary.end.json.comments" } },
62+
"name": "meta.structure.dictionary.json.comments",
63+
"patterns": [
64+
{
65+
"begin": "(?=\"((?>[^\\\\\"]++|\\\\.)*+)\")",
66+
"end": "(?<=,)|(?=})",
67+
"name": ".$1.",
68+
"patterns": [ { "include": "#objectpair" } ]
69+
},
70+
{ "include": "#objectpair" }
71+
]
72+
},
73+
"objectpair": {
74+
"patterns": [
75+
{
76+
"comment": "the JSON object key",
77+
"include": "#objectkey"
78+
},
79+
{ "include": "#comments" },
80+
{
81+
"begin": ":",
82+
"beginCaptures": { "0": { "name": "punctuation.separator.dictionary.key-value.json.comments" } },
83+
"end": "(,)|(?=})",
84+
"endCaptures": { "1": { "name": "punctuation.separator.dictionary.pair.json.comments" } },
85+
"name": "meta.structure.dictionary.value.json.comments",
86+
"patterns": [
87+
{
88+
"comment": "the JSON object value",
89+
"include": "#value"
90+
},
91+
{
92+
"match": "\\S",
93+
"name": "invalid.illegal.expected-dictionary-separator.json.comments"
94+
}
95+
]
96+
},
97+
{
98+
"match": "\\S",
99+
"name": "invalid.illegal.expected-dictionary-separator.json.comments"
100+
}
101+
]
102+
},
103+
"string": {
104+
"begin": "\"",
105+
"beginCaptures": { "0": { "name": "punctuation.definition.string.begin.json.comments" } },
106+
"end": "\"",
107+
"endCaptures": { "0": { "name": "punctuation.definition.string.end.json.comments" } },
108+
"name": "string.quoted.double.json.comments",
109+
"patterns": [ { "include": "#stringcontent" } ]
110+
},
111+
"objectkey": {
112+
"begin": "\"",
113+
"beginCaptures": { "0": { "name": "punctuation.support.type.property-name.begin.json.comments" } },
114+
"end": "\"",
115+
"endCaptures": { "0": { "name": "punctuation.support.type.property-name.end.json.comments" } },
116+
"name": "string.json.comments support.type.property-name.json.comments",
117+
"patterns": [ { "include": "#stringcontent" } ]
118+
},
119+
"stringcontent": {
120+
"patterns": [
121+
{
122+
"match": "\\\\(?>[\"\\\\/bfnrt]|u[0-9a-fA-F]{4})",
123+
"name": "constant.character.escape.json.comments"
124+
},
125+
{
126+
"match": "\\\\.",
127+
"name": "invalid.illegal.unrecognized-string-escape.json.comments"
128+
}
129+
]
130+
},
131+
"value": {
132+
"patterns": [
133+
{ "include": "#constant" },
134+
{ "include": "#number" },
135+
{ "include": "#string" },
136+
{ "include": "#array" },
137+
{ "include": "#object" },
138+
{ "include": "#comments" }
139+
]
140+
}
141+
}
142+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/RedCMD/TmLanguage-Syntax-Highlighter/main/vscode.tmLanguage.schema.json",
3+
"comment": "https://github.com/wraith13/vscode-schemas/blob/master/en/latest/schemas/language-configuration.json#L237-L258",
4+
"name": "language-configuration",
5+
"scopeName": "source.json.comments.language-configuration",
6+
"injectionSelector": "L:source.json.comments .wordPattern. meta.structure.dictionary.value.json.comments -(meta.structure.dictionary.json.comments meta.structure.dictionary.json.comments) -meta.structure.array.json.comments -string -comment, L:source.json.comments .wordPattern. .pattern. meta.structure.dictionary.value.json.comments -(meta.structure.dictionary.json.comments meta.structure.dictionary.json.comments meta.structure.dictionary.json.comments) -meta.structure.array.json.comments -string -comment",
7+
"patterns": [
8+
{ "include": "#wordPattern" }
9+
],
10+
"repository": {
11+
"wordPattern": {
12+
"patterns": [
13+
{
14+
"comment": "VSCode TextMate bug. For some reason, including a grammar from within a capture group doesn't load the include. We have to pre-load the include outside of a capture group. https://github.com/microsoft/vscode-textmate/issues/242",
15+
"begin": "(*FAIL)",
16+
"end": "|",
17+
"patterns": [ { "include": "source.json.textmate.regexp" } ]
18+
},
19+
{
20+
"match": "(\")((?>[^\\\\\"]++|\\\\.)++)(\")",
21+
"captures": {
22+
"0": { "name": "string.quoted.double.json" },
23+
"1": { "name": "punctuation.definition.string.begin.json" },
24+
"2": {
25+
"name": "meta.embedded.json.textmate.regexp",
26+
"patterns": [
27+
{ "include": "source.json.textmate.regexp" },
28+
{ "include": "source.json#stringcontent" }
29+
]
30+
},
31+
"3": { "name": "punctuation.definition.string.end.json" }
32+
}
33+
}
34+
]
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)