Skip to content

Commit 234b0a2

Browse files
committed
Overhaul Injection design
1 parent 5620280 commit 234b0a2

File tree

5 files changed

+202
-119
lines changed

5 files changed

+202
-119
lines changed

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@
2727
"contributes": {
2828
"grammars": [
2929
{
30-
"scopeName": "source.json.package",
31-
"path": "./syntaxes/package.json.tmLanguage.json",
30+
"scopeName": "source.json",
31+
"path": "./syntaxes/JSON.tmLanguage.json"
32+
},
33+
{
34+
"scopeName": "source.json.shellscript",
35+
"path": "./syntaxes/scripts.tmLanguage.json",
3236
"embeddedLanguages": {
3337
"meta.embedded.shellscript": "shellscript"
3438
},

syntaxes/JSON.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",
4+
"scopeName": "source.json",
5+
"patterns": [
6+
{ "include": "#value" }
7+
],
8+
"repository": {
9+
"array": {
10+
"begin": "\\[",
11+
"beginCaptures": { "0": { "name": "punctuation.definition.array.begin.json" } },
12+
"end": "]",
13+
"endCaptures": { "0": { "name": "punctuation.definition.array.end.json" } },
14+
"name": "meta.structure.array.json",
15+
"patterns": [
16+
{ "include": "#value" },
17+
{
18+
"match": ",",
19+
"name": "punctuation.separator.array.json"
20+
},
21+
{
22+
"match": "\\S",
23+
"name": "invalid.illegal.expected-array-separator.json"
24+
}
25+
]
26+
},
27+
"comments": {
28+
"patterns": [
29+
{
30+
"begin": "/\\*\\*(?!/)",
31+
"captures": { "0": { "name": "punctuation.definition.comment.json" } },
32+
"end": "\\*/",
33+
"name": "comment.block.documentation.json"
34+
},
35+
{
36+
"begin": "/\\*",
37+
"captures": { "0": { "name": "punctuation.definition.comment.json" } },
38+
"end": "\\*/",
39+
"name": "comment.block.json"
40+
},
41+
{
42+
"begin": "//",
43+
"end": "$",
44+
"beginCaptures": { "0": { "name": "punctuation.definition.comment.json" } },
45+
"name": "comment.line.double-slash.js"
46+
}
47+
]
48+
},
49+
"constant": {
50+
"match": "\\b(?>true|false|null)\\b",
51+
"name": "constant.language.json"
52+
},
53+
"number": {
54+
"match": "-?(?>0|[1-9][0-9]*)(?>(?>\\.[0-9]+)?(?>[eE][+-]?[0-9]+)?)?",
55+
"name": "constant.numeric.json"
56+
},
57+
"object": {
58+
"begin": "{",
59+
"beginCaptures": { "0": { "name": "punctuation.definition.dictionary.begin.json" } },
60+
"end": "}",
61+
"endCaptures": { "0": { "name": "punctuation.definition.dictionary.end.json" } },
62+
"name": "meta.structure.dictionary.json",
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" } },
83+
"end": "(,)|(?=})",
84+
"endCaptures": { "1": { "name": "punctuation.separator.dictionary.pair.json" } },
85+
"name": "meta.structure.dictionary.value.json",
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"
94+
}
95+
]
96+
},
97+
{
98+
"match": "\\S",
99+
"name": "invalid.illegal.expected-dictionary-separator.json"
100+
}
101+
]
102+
},
103+
"string": {
104+
"begin": "\"",
105+
"beginCaptures": { "0": { "name": "punctuation.definition.string.begin.json" } },
106+
"end": "\"",
107+
"endCaptures": { "0": { "name": "punctuation.definition.string.end.json" } },
108+
"name": "string.quoted.double.json",
109+
"patterns": [ { "include": "#stringcontent" } ]
110+
},
111+
"objectkey": {
112+
"begin": "\"",
113+
"beginCaptures": { "0": { "name": "punctuation.support.type.property-name.begin.json" } },
114+
"end": "\"",
115+
"endCaptures": { "0": { "name": "punctuation.support.type.property-name.end.json" } },
116+
"name": "string.json support.type.property-name.json",
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"
124+
},
125+
{
126+
"match": "\\\\.",
127+
"name": "invalid.illegal.unrecognized-string-escape.json"
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+
}

syntaxes/package.json.tmLanguage.json

Lines changed: 0 additions & 115 deletions
This file was deleted.

syntaxes/scripts.tmLanguage.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/RedCMD/TmLanguage-Syntax-Highlighter/main/vscode.tmLanguage.schema.json",
3+
"name": "package.json",
4+
"scopeName": "source.json.shellscript",
5+
"injectionSelector": "L:source.json .scripts. meta.structure.dictionary.json meta.structure.dictionary.value.json -(meta.structure.dictionary.json meta.structure.dictionary.json meta.structure.dictionary.json) -meta.structure.array.json -string -comment",
6+
"patterns": [
7+
{ "include": "#scripts" }
8+
],
9+
"repository": {
10+
"scripts": {
11+
"patterns": [
12+
{
13+
"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. `source.shell`",
14+
"begin": "(*FAIL)",
15+
"end": "|",
16+
"patterns": [ { "include": "source.shell" } ]
17+
},
18+
{
19+
"match": "(\")((?>[^\\\\\"]++|\\\\.)++)(\")",
20+
"captures": {
21+
"0": { "name": "string.quoted.double.json" },
22+
"1": { "name": "punctuation.definition.string.begin.json" },
23+
"2": {
24+
"name": "meta.embedded.shellscript.json",
25+
"patterns": [
26+
{
27+
"comment": "Setup a `\\G` anchor for ShellScript to use",
28+
"begin": "|",
29+
"end": "(*FAIL)",
30+
"patterns": [
31+
{ "include": "source.shell" },
32+
{
33+
"begin": "(?!^[ \\t]*+$)(?:(?<=^until | until |\\tuntil |^while | while |\\twhile |^elif | elif |\\telif |^else | else |\\telse |^then | then |\\tthen |^do | do |\\tdo |^if | if |\\tif )|(?<=\"\\G|^|;|\\||&|!|\\(|\\{|`))[ \\t]*+(?!nocorrect\\W|nocorrect\\$|function\\W|function\\$|foreach\\W|foreach\\$|repeat\\W|repeat\\$|logout\\W|logout\\$|coproc\\W|coproc\\$|select\\W|select\\$|while\\W|while\\$|pushd\\W|pushd\\$|until\\W|until\\$|case\\W|case\\$|done\\W|done\\$|elif\\W|elif\\$|else\\W|else\\$|esac\\W|esac\\$|popd\\W|popd\\$|then\\W|then\\$|time\\W|time\\$|for\\W|for\\$|end\\W|end\\$|fi\\W|fi\\$|do\\W|do\\$|in\\W|in\\$|if\\W|if\\$)",
34+
"end": "(?=;|\\||&|\\n|\\)|`|\\{|\\}|[ \\t]*#|\\])(?<!\\\\)",
35+
"beginCaptures": { },
36+
"endCaptures": { },
37+
"name": "meta.statement.shell",
38+
"patterns": [ { "include": "source.shell#typical_statements" } ]
39+
}
40+
]
41+
},
42+
{ "include": "source.json#stringcontent" }
43+
]
44+
},
45+
"3": { "name": "punctuation.definition.string.end.json" }
46+
}
47+
}
48+
]
49+
}
50+
}
51+
}

syntaxes/shellscript.json.escaped.tmLanguage.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/RedCMD/TmLanguage-Syntax-Highlighter/main/vscode.tmLanguage.schema.json",
3-
"name": "package.json",
3+
"name": "Shellscript JSON escaped",
4+
"comment": "Double quotes requiring escaping when embedded inside JSON",
45
"scopeName": "source.shellscript.json.escaped",
5-
"injectionSelector": "L:source.json meta.embedded.shellscript.json.package -string.quoted.double.shell",
6+
"injectionSelector": "L:source.json meta.embedded.shellscript.json.scripts -string.quoted.double.shell",
67
"patterns": [
78
{ "include": "#string" }
89
],

0 commit comments

Comments
 (0)