Skip to content

Commit dd5f6ec

Browse files
committed
Fix injection syntax highlighting
1 parent c202029 commit dd5f6ec

File tree

2 files changed

+130
-93
lines changed

2 files changed

+130
-93
lines changed

src/tree-sitter/tree-sitter-json/grammar.js

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -393,37 +393,31 @@ module.exports = grammar({
393393
injection_string: $ => choice(
394394
repeat1($._injection_scopes),
395395
seq(
396-
seq(
397-
optional($._injection_whitespace),
398-
choice(
399-
alias(
400-
token(
401-
prec(1,
402-
choice(
403-
'L:',
404-
'R:',
405-
),
396+
optional($._injection_whitespace),
397+
choice(
398+
alias(
399+
token(
400+
prec(1,
401+
choice(
402+
'L:',
403+
'R:',
406404
),
407405
),
408-
$.selector,
409406
),
410-
seq(
411-
alias(
412-
/[_a-zA-Z0-9:.]:/,
413-
$.selector,
414-
),
415-
$._injection_whitespace,
407+
$.selector,
408+
),
409+
seq(
410+
alias(
411+
/[_a-zA-Z0-9:.]:/,
412+
$.selector,
416413
),
414+
$._injection_whitespace,
417415
),
418416
),
419417
repeat($._injection_scopes),
420418
),
421419
),
422420
_injection_scopes: $ => choice(
423-
// fieldAlias($,
424-
// "scope",
425-
// /[_a-zA-Z0-9.:][_a-zA-Z0-9.:-]*/,
426-
// ),
427421
alias(
428422
/[_a-zA-Z0-9.:][_a-zA-Z0-9.:-]*/,
429423
$.scope,
@@ -441,7 +435,8 @@ module.exports = grammar({
441435
_injection_whitespace: $ => token(
442436
repeat1(
443437
choice(
444-
/\\[\\"/bfnrt]/,
438+
/\\u[0-9a-fA-F]{4}/,
439+
/\\./,
445440
/[^\\"\w.:|()-]/,
446441
),
447442
),

syntaxes/json.tmLanguage.json

Lines changed: 113 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
"name": "support.function.json.tm"
147147
},
148148
{
149-
"match": "[\\w-]+",
149+
"match": "[0-9A-Za-z_-]+",
150150
"name": "string.json.tm"
151151
},
152152
{
@@ -409,85 +409,127 @@
409409
]
410410
},
411411
"injection-string": {
412-
"comment": "All non-functional characters are treated as whitespace. This includes whitespace ` ` and asterisk `*`. [^\\w.,:|()-]",
412+
"comment": "https://github.com/microsoft/vscode-textmate/blob/main/src/matcher.ts",
413413
"patterns": [
414414
{
415-
"match": "(?>\\\\[\\\\\"/bfnrt])+",
416-
"name": "comment.injection.whitespace.tm"
415+
"begin": "[LR]:|[0-9A-Za-z_.:]:(?![0-9A-Za-z_.:-])",
416+
"end": "(?=,|\")|$",
417+
"beginCaptures": { "0": { "name": "keyword.control.priority.tm" } },
418+
"patterns": [ { "include": "#injection-string-inner" } ]
417419
},
418-
{ "include": "#escape-characters" },
419-
{
420-
"begin": "[)|]",
421-
"end": "(?=\")",
422-
"name": "comment.injection.whitespace.tm"
423-
},
424-
{
425-
"match": "(?<=^\"|[^\\\\]\"|,)((?>\\\\[\\\\\"/bfnrt]|[^\\\\\"\\w.:|()-])*)([LR]:|[\\w.:]:(?![\\w.:-]))",
426-
"captures": {
427-
"1": { "name": "comment.injection.whitespace.tm" },
428-
"2": { "name": "support.function.tm" }
429-
}
430-
},
431-
{
432-
"begin": "(?>text|source)(?=\\.[\\w.:])",
433-
"end": "(?![\\w.:-])",
434-
"beginCaptures": { "0": { "name": "support.function.tm" } },
435-
"name": "string",
420+
{ "include": "#injection-string-inner" }
421+
],
422+
"repository": {
423+
"injection-string-inner": {
436424
"patterns": [
425+
{ "include": "#escape-characters" },
426+
{
427+
"begin": "(?>text|source)(?=\\.[0-9A-Za-z_.:-])",
428+
"end": "(?![0-9A-Za-z_.:-])",
429+
"beginCaptures": { "0": { "name": "support.function.tm" } },
430+
"name": "string.tm",
431+
"patterns": [
432+
{
433+
"match": "\\.",
434+
"name": "support.function.tm"
435+
}
436+
]
437+
},
438+
{
439+
"match": "[0-9A-Za-z_.:][0-9A-Za-z_.:-]*",
440+
"captures": { "0": { "name": "$0" } },
441+
"name": "string.tm"
442+
},
443+
{
444+
"begin": "\\(",
445+
"end": "\\)|(?=\")|$",
446+
"captures": { "0": { "name": "constant.character.set.regexp.tm" } },
447+
"patterns": [
448+
{
449+
"match": "\\|",
450+
"name": "keyword.control.negate.tm"
451+
},
452+
{ "include": "#injection-string-inner" }
453+
]
454+
},
455+
{
456+
"match": ",",
457+
"name": "keyword.control.tm"
458+
},
437459
{
438-
"match": "\\.",
439-
"name": "support.function.tm"
460+
"comment": "Negates the following negation `-`, group `()` or series of scopes `foo bar abc`",
461+
"begin": "-",
462+
"end": "(?=[\",|)-])|(?!\\G)(?=\\()|(?<=\\))|$",
463+
"beginCaptures": { "0": { "name": "support.function.tm" } },
464+
"patterns": [
465+
{
466+
"begin": "\\G(?![\",|0-9A-Za-z_.:-])",
467+
"end": "(?=[\",|0-9A-Za-z_.:-])|(?<=\\))|$",
468+
"patterns": [ { "include": "#injection-string-inner-negated" } ]
469+
},
470+
{ "include": "#injection-string-inner-negated" }
471+
]
472+
},
473+
{
474+
"begin": "[)|]",
475+
"end": "(?=\")|$",
476+
"name": "comment.injection.whitespace.tm"
477+
},
478+
{
479+
"comment": "All non-functional characters are treated as whitespace. This includes whitespace ` ` and asterisk `*`",
480+
"match": "[^\\\\\"0-9A-Za-z_.:,|()-]+",
481+
"name": "comment.injection.whitespace.tm"
440482
}
441483
]
442484
},
443-
{
444-
"match": "[\\w.:][\\w.:-]*",
445-
"name": "string $0"
446-
},
447-
{
448-
"begin": "\\(",
449-
"end": "\\)|(?=\")",
450-
"captures": { "0": { "name": "constant.character.set.regexp.tm" } },
485+
"injection-string-inner-negated": {
451486
"patterns": [
452487
{
453-
"match": "(?<=[,|])(?>\\\\[\\\\\"/bfnrt]|[^\\\\\\w.:()-])+",
454-
"name": "comment.injection.whitespace.tm"
488+
"begin": "(?>text|source)(?=\\.[0-9A-Za-z_.:-])",
489+
"end": "(?![0-9A-Za-z_.:-])",
490+
"beginCaptures": { "0": { "name": "support.function.tm" } },
491+
"name": "string.tm emphasis.tm",
492+
"patterns": [
493+
{
494+
"match": "\\.",
495+
"name": "support.function.tm"
496+
}
497+
]
455498
},
456499
{
457-
"match": "\\|",
458-
"name": "keyword.control.tm"
500+
"match": "[0-9A-Za-z_.:][0-9A-Za-z_.:-]*",
501+
"captures": { "0": { "name": "$0" } },
502+
"name": "string.tm emphasis.tm"
503+
},
504+
{
505+
"begin": "\\(",
506+
"end": "\\)|(?=\")|$",
507+
"captures": { "0": { "name": "constant.character.set.regexp.tm" } },
508+
"patterns": [
509+
{
510+
"match": "\\|",
511+
"name": "keyword.control.negate.tm"
512+
},
513+
{ "include": "#injection-string-inner-negated" }
514+
]
515+
},
516+
{
517+
"begin": "-",
518+
"end": "(?=[\",|)-])|(?!\\G)(?=\\()|(?<=\\))|$",
519+
"beginCaptures": { "0": { "name": "support.function.tm" } },
520+
"patterns": [
521+
{
522+
"begin": "\\G(?![\",|0-9A-Za-z_.:-])",
523+
"end": "(?=[\",|0-9A-Za-z_.:-])|(?<=\\))|$",
524+
"patterns": [ { "include": "#injection-string-inner" } ]
525+
},
526+
{ "include": "#injection-string-inner" }
527+
]
459528
},
460-
{ "include": "#injection-string" }
529+
{ "include": "#injection-string-inner" }
461530
]
462-
},
463-
{
464-
"match": "(?>\\\\[\\\\\"/bfnrt]|[^\\\\\"\\w.:,|()-])+",
465-
"name": "comment.injection.whitespace.tm"
466-
},
467-
{
468-
"match": "(?<=,)(?>\\\\[\\\\\"/bfnrt]|[^\\\\\"\\w.:|()-])+",
469-
"name": "comment.injection.whitespace.tm"
470-
},
471-
{
472-
"match": ",",
473-
"name": "keyword.control.tm"
474-
},
475-
{
476-
"match": "-(?>\\\\[\\\\\"/bfnrt]|[^\\\\\"\\w.:|()-])*-",
477-
"name": "comment.injection.whitespace.tm"
478-
},
479-
{
480-
"begin": "-",
481-
"end": "(?=[\"\t\n,|()-])",
482-
"beginCaptures": { "0": { "name": "support.function.tm" } },
483-
"name": "emphasis",
484-
"patterns": [ { "include": "#injection-string" } ]
485-
},
486-
{
487-
"match": "-",
488-
"name": "support.function.tm"
489531
}
490-
]
532+
}
491533
},
492534
"firstLineMatch": {
493535
"comment": "\"firstLineMatch\": \"...\"",
@@ -899,15 +941,15 @@
899941
{
900942
"comment": "${0:/upcase} ${000999:/downcase}",
901943
"match": "(\\${)(0*)([0-9]{1,3})(:/)(upcase|downcase)(})",
902-
"name": "meta.embedded.replace.capture.json.tm",
903944
"captures": {
904945
"1": { "name": "constant.character.escape.json.tm" },
905946
"2": { "name": "punctuation.definition.tag.json.tm" },
906947
"3": { "name": "constant.numeric.json.tm" },
907948
"4": { "name": "constant.character.escape.json.tm" },
908949
"5": { "name": "markup.heading.json.tm" },
909950
"6": { "name": "constant.character.escape.json.tm" }
910-
}
951+
},
952+
"name": "meta.embedded.replace.capture.json.tm"
911953
}
912954
]
913955
},
@@ -1117,7 +1159,7 @@
11171159
"applyEndPatternLast": {
11181160
"comment": "\"applyEndPatternLast\": true",
11191161
"begin": "(\")(applyEndPatternLast)(\")",
1120-
"end": "(?<=\\w)|(?=[},])",
1162+
"end": "(?<=[0-9A-Za-z_])|(?=[},])",
11211163
"beginCaptures": {
11221164
"1": { "name": "punctuation.definition.string.begin.json.tm" },
11231165
"2": { "name": "keyword.property-name.string.applyEndPatternLast.json.tm" },
@@ -1126,7 +1168,7 @@
11261168
"patterns": [
11271169
{
11281170
"begin": ":",
1129-
"end": "(?<=\\w)|(?=[},])",
1171+
"end": "(?<=[0-9A-Za-z_])|(?=[},])",
11301172
"beginCaptures": { "0": { "name": "punctuation.separator.dictionary.key-value.json.tm" } },
11311173
"patterns": [
11321174
{
@@ -1155,7 +1197,7 @@
11551197
"patterns": [
11561198
{
11571199
"begin": ":",
1158-
"end": "(?<=\\w)|(?=[},])",
1200+
"end": "(?<=[0-9A-Za-z_])|(?=[},])",
11591201
"beginCaptures": { "0": { "name": "punctuation.separator.dictionary.key-value.json.tm" } },
11601202
"patterns": [ { "include": "#json-value" } ]
11611203
},
@@ -1316,7 +1358,7 @@
13161358
"name": "support.function.json.tm"
13171359
},
13181360
{
1319-
"match": "[\\w:][\\w:-]*+",
1361+
"match": "[0-9A-Za-z_:][0-9A-Za-z_:-]*+",
13201362
"name": "string"
13211363
},
13221364
{

0 commit comments

Comments
 (0)