Skip to content

Commit 210f1d3

Browse files
committed
Add package.json "when" regexes
1 parent 5210700 commit 210f1d3

File tree

5 files changed

+179
-2
lines changed

5 files changed

+179
-2
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ Then using multiple injection grammars that target and inject specific languages
99
Requires the builtin `ShellScript` extension or [better-shell-syntax](https://marketplace.visualstudio.com/items?itemName=jeff-hykin.better-shellscript-syntax)
1010
![Example `package.json`](images/Example-Scripts.png)
1111

12+
* [when-clause-contexts](https://code.visualstudio.com/api/references/when-clause-contexts) within `"when"` for `package.json` (`JSON`)
13+
![Example `package.json/when`](images/Example-when.png)
14+
1215
* Regular Expressions within `"wordPattern"`, `"folding"`, `"onEnterRules"` and `"indentationRules"` for `language-configuration.json` (`JSONC`)
1316
Requires [JSON TextMate](https://marketplace.visualstudio.com/items?itemName=RedCMD.tmlanguage-syntax-highlighter) extension
1417
![Example `language-configuration.json`](images/Example-language-configuration.png)
@@ -33,6 +36,4 @@ Please report any you come across.
3336

3437

3538
## TODO:
36-
* `package.json`/`"when"`
3739
* `globs`/`"filenamePatterns"`
38-
* switch JSON escaped oniguruma regex for JSON escaped JavaScript regex

images/Example-when.png

135 KB
Loading

package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,17 @@
7979
"source.json.embedded"
8080
]
8181
},
82+
{
83+
"scopeName": "source.json.package.when",
84+
"path": "./syntaxes/package-when.tmLanguage.json",
85+
"embeddedLanguages": {
86+
"meta.embedded.when.json": "javascript"
87+
},
88+
"injectTo": [
89+
"source.json.comments.embedded",
90+
"source.json.embedded"
91+
]
92+
},
8293
{
8394
"scopeName": "source.json.package.scopes",
8495
"path": "./syntaxes/package-scopes.tmLanguage.json",
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/RedCMD/TmLanguage-Syntax-Highlighter/main/vscode.tmLanguage.schema.json",
3+
"name": "\"when\" & \"enablement\" inside package.json and keybingings.json",
4+
"comment": "https://code.visualstudio.com/api/references/when-clause-contexts",
5+
"scopeName": "source.json.package.when",
6+
"injectionSelector": [
7+
"L:source.json.embedded .meta.embedded.contributes. (.meta.embedded.continueEditSession. | .meta.embedded.keybindings. | .meta.embedded.viewsWelcome. | .meta.embedded.taskDefinitions. | .meta.embedded.chatParticipants. | .meta.embedded.languageModelTools. | .meta.embedded.debuggers. | .meta.embedded.debugVisualizers. | .meta.embedded.walkthroughs. | .meta.embedded.chatViewsWelcome. | .meta.embedded.breakpoints.) meta.structure.array.json .meta.embedded.when. string.quoted.double.json -(meta.structure.dictionary.json meta.structure.dictionary.json meta.structure.dictionary.json meta.structure.dictionary.json) -(meta.structure.array.json meta.structure.array.json) -meta.embedded.when.json -comment",
8+
"L:source.json.embedded .meta.embedded.contributes. (.meta.embedded.walkthroughs. meta.structure.array.json .meta.embedded.steps. | .meta.embedded.chatParticipants. meta.structure.array.json .meta.embedded.commands.) meta.structure.array.json .meta.embedded.when. string.quoted.double.json -(meta.structure.dictionary.json meta.structure.dictionary.json meta.structure.dictionary.json meta.structure.dictionary.json meta.structure.dictionary.json) -(meta.structure.array.json meta.structure.array.json meta.structure.array.json) -meta.embedded.when.json -comment",
9+
"L:source.json.embedded .meta.embedded.contributes. (.meta.embedded.views. | .meta.embedded.menus. | .meta.embedded.viewsContainers.) meta.structure.dictionary.json meta.structure.array.json .meta.embedded.when. string.quoted.double.json -(meta.structure.dictionary.json meta.structure.dictionary.json meta.structure.dictionary.json meta.structure.dictionary.json meta.structure.dictionary.json) -(meta.structure.array.json meta.structure.array.json) -meta.embedded.when.json -comment",
10+
"L:source.json.embedded .meta.embedded.contributes. (.meta.embedded.keybindings. .meta.embedded.when. | .meta.embedded.commands. .meta.embedded.enablement.) string.quoted.double.json -(meta.structure.dictionary.json meta.structure.dictionary.json meta.structure.dictionary.json meta.structure.dictionary.json) -(meta.structure.array.json meta.structure.array.json) -meta.embedded.when.json -comment",
11+
"L:source.json.embedded .meta.embedded.contributes. .meta.embedded.viewsWelcome. meta.structure.array.json .meta.embedded.enablement. string.quoted.double.json -(meta.structure.dictionary.json meta.structure.dictionary.json meta.structure.dictionary.json meta.structure.dictionary.json) -(meta.structure.array.json meta.structure.array.json) -meta.embedded.when.json -comment",
12+
"L:source.json.comments.embedded meta.structure.array.json.comments .meta.embedded.when. string.quoted.double.json.comments -(meta.structure.dictionary.json.comments meta.structure.dictionary.json.comments) -(meta.structure.array.json.comments meta.structure.array.json.comments) -meta.embedded.when.json -comment"
13+
],
14+
"patterns": [
15+
{
16+
"begin": "(?<=\")\\G(?=(?>[^\\x00-\\x1F\"\\\\]++|\\\\.)++\")",
17+
"end": "(?=\"|$)",
18+
"name": "meta.embedded.when.json",
19+
"patterns": [ { "include": "#when" } ]
20+
}
21+
],
22+
"repository": {
23+
"when": {
24+
"comment": "https://vscode.dev/github/microsoft/vscode/blob/main/src/vs/platform/contextkey/common/scanner.ts#L198-L268",
25+
"patterns": [
26+
{ "include": "#parenthesized" },
27+
{ "include": "#single-quote" },
28+
{ "include": "#regexp" },
29+
{ "include": "#operator" },
30+
{ "include": "#in" },
31+
{ "include": "#key" },
32+
{ "include": "source.json#stringcontent" }
33+
]
34+
},
35+
"parenthesized": {
36+
"patterns": [
37+
{
38+
"begin": "\\(",
39+
"end": "\\)|(?=\")|$",
40+
"beginCaptures": { "0": { "name": "meta.brace.round.begin.when.json" } },
41+
"endCaptures": { "0": { "name": "meta.brace.round.end.when.json" } },
42+
"patterns": [
43+
{ "include": "source.json#stringcontent" },
44+
{ "include": "#when" }
45+
]
46+
},
47+
{
48+
"match": "\\)+",
49+
"name": "invalid.illegal.brace.when.json"
50+
}
51+
]
52+
},
53+
"operator": {
54+
"patterns": [
55+
{
56+
"begin": "([!=]==?)|([<>]=?)|(=~)",
57+
"end": "(?=[\"&)|])|$",
58+
"beginCaptures": {
59+
"1": { "name": "keyword.operator.comparison.when.json" },
60+
"2": { "name": "keyword.operator.relational.when.json" },
61+
"3": { "name": "keyword.operator.comparison.when.json" }
62+
},
63+
"name": "meta.value.when.json",
64+
"patterns": [
65+
{ "include": "#regexp" },
66+
{
67+
"begin": "(?=[]#$%*-<>-\\[^_\\p{L}]|\\\\[\\\\\"/])",
68+
"end": "(?![]#$%*-<>-\\[^_\\p{L}]|\\\\[\\\\\"/])",
69+
"name": "string.unquoted.when.json",
70+
"patterns": [
71+
{
72+
"comment": "parseFloat()",
73+
"match": "\\G[-+]?(?>(?>[0-9]+(?>\\.[0-9]*)?|\\.[0-9]+)(?>[Ee][-+]?[0-9]+)?|Infinity)",
74+
"name": "constant.numeric.when.json"
75+
},
76+
{ "include": "#boolean" },
77+
{ "include": "source.json#stringcontent" }
78+
]
79+
},
80+
{ "include": "#when" }
81+
]
82+
},
83+
{
84+
"match": "!",
85+
"name": "keyword.operator.logical.not.when.json"
86+
},
87+
{
88+
"match": "&&",
89+
"name": "keyword.operator.logical.and.when.json"
90+
},
91+
{
92+
"match": "\\|\\|",
93+
"name": "keyword.operator.logical.or.when.json"
94+
},
95+
{
96+
"match": "[&=|~]+",
97+
"name": "invalid.illegal.keyword.operator.when.json"
98+
}
99+
]
100+
},
101+
"in": {
102+
"patterns": [
103+
{
104+
"begin": "in(?![]#$%*-<>-\\[^_\\p{L}]|\\\\[\\\\\"/])",
105+
"end": "(?=[!\"&)|]|$)",
106+
"beginCaptures": { "0": { "name": "keyword.operator.expression.in.when.json" } },
107+
"name": "meta.value.when.json",
108+
"patterns": [
109+
{
110+
"begin": "(?=[]#$%*-<>-\\[^_\\p{L}]|\\\\[\\\\\"/])",
111+
"end": "(?![]#$%*-<>-\\[^_\\p{L}]|\\\\[\\\\\"/])",
112+
"name": "variable.other.value.when.json",
113+
"patterns": [ { "include": "source.json#stringcontent" } ]
114+
},
115+
{ "include": "#when" }
116+
]
117+
},
118+
{
119+
"match": "not(?![]#$%*-<>-\\[^_\\p{L}]|\\\\[\\\\\"/])",
120+
"name": "keyword.operator.expression.not.when.json"
121+
}
122+
]
123+
},
124+
"boolean": {
125+
"match": "\\G(?>true|false)(?![]#$%*-<>-\\[^_\\p{L}]|\\\\[\\\\\"/])",
126+
"name": "constant.language.boolean.$0.when.json"
127+
},
128+
"single-quote": {
129+
"begin": "'",
130+
"end": "'|(?=\")|$",
131+
"beginCaptures": { "0": { "name": "punctuation.definition.string.begin.when.json" } },
132+
"endCaptures": { "0": { "name": "punctuation.definition.string.end.when.json" } },
133+
"name": "string.quoted.single.when.json",
134+
"patterns": [ { "include": "source.json#stringcontent" } ]
135+
},
136+
"key": {
137+
"begin": "(?=[]#$%*-<>-\\[^_\\p{L}]|\\\\[\\\\\"/])",
138+
"end": "(?![]#$%*-<>-\\[^_\\p{L}]|\\\\[\\\\\"/])",
139+
"name": "variable.other.constant.key.when.json",
140+
"patterns": [
141+
{ "include": "#boolean" },
142+
{ "include": "source.json#stringcontent" }
143+
]
144+
},
145+
"regexp": {
146+
"begin": "(\\\\)?(/)",
147+
"end": "(\\\\)?(/)([igsmyu]*)|(?=\")|$",
148+
"beginCaptures": {
149+
"1": { "name": "constant.character.escape.regexp.json" },
150+
"2": { "name": "punctuation.definition.string.begin.when.json" }
151+
},
152+
"endCaptures": {
153+
"1": { "name": "constant.character.escape.regexp.json" },
154+
"2": { "name": "punctuation.definition.string.end.when.json" },
155+
"3": { "name": "keyword.other.when.json" }
156+
},
157+
"name": "string.regexp.when.json",
158+
"patterns": [
159+
{ "include": "source.json.regexp#regexp" },
160+
{ "include": "source.json#stringcontent" }
161+
]
162+
}
163+
}
164+
}

syntaxes/regexp.tmLanguage.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@
174174
]
175175
},
176176
"unicode": {
177+
"comment": "Unicode requires flag u or v to be active",
177178
"patterns": [
178179
{
179180
"match": "\\\\{2}u{(0*\\h{4,5})}",

0 commit comments

Comments
 (0)