Skip to content

Commit 290cb50

Browse files
authored
Add spread to syntax highlighting (#174)
* Add spread to syntax highlighting Fixes #173. * Extend spread sytnax highlighting to commands and params * Make spread regex more restrictive * Make spread more specific to tables and commands * Fix spread tokens in parameter list Replaces `include` with a capture for the existing regex. * Extend spread syntax highlighting change to flags Traps command flags and shortcuts bare string parsing. * Fix and clean up flag highlighting Reuses an unused `parameters` expression. Fixes broken word boundary with whitespace lookbehind instead. Also fixes previous `(.+)` (code smell) matching the entire command.
1 parent bd9d19f commit 290cb50

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

syntaxes/nushell.tmLanguage.json

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,11 @@
115115
"name": "keyword.other.nushell"
116116
},
117117
"parameters": {
118-
"match": "\\b-{1,2}[\\w-]*",
119-
"name": "variable.parameter.nushell"
118+
"match": "(?<=\\s)(-{1,2})[\\w-]+",
119+
"name": "variable.parameter.nushell",
120+
"captures": {
121+
"1": { "name": "keyword.control.nushell" }
122+
}
120123
},
121124
"variables": {
122125
"match": "(\\$[a-zA-Z0-9_]+)((?:\\.(?:[\\w-]+|\"[\\w\\- ]+\"))*)",
@@ -183,8 +186,12 @@
183186
{ "include": "#binary" }
184187
]
185188
},
189+
"spread": {
190+
"match": "\\.\\.\\.(?=[^\\s\\]}])",
191+
"name": "keyword.control.nushell"
192+
},
186193
"ranges": {
187-
"match": "\\.\\.<?|:",
194+
"match": "\\.\\.<?",
188195
"name": "keyword.control.nushell"
189196
},
190197
"operators-word": {
@@ -213,17 +220,17 @@
213220
},
214221
"name": "meta.table.nushell",
215222
"patterns": [
223+
{ "include": "#spread" },
216224
{ "include": "#value" },
217225
{
218226
"match": ",",
219227
"name": "punctuation.separator.nushell"
220-
},
221-
{ "include": "#comment" }
228+
}
222229
]
223230
},
224231
"types": {
225232
"patterns": [
226-
{
233+
{
227234
"name": "meta.list.nushell",
228235
"begin": "\\b(list)\\s*<",
229236
"beginCaptures": {
@@ -243,15 +250,15 @@
243250
"end": ">",
244251
"patterns": [
245252
{
246-
"match": "([\\w\\-]+|\"[\\w\\- ]+\"|'[^']+')\\s*:\\s*",
253+
"match": "([\\w\\-]+|\"[\\w\\- ]+\"|'[^']+')\\s*:\\s*",
247254
"captures": {
248255
"1": { "name": "variable.parameter.nushell" }
249256
}
250257
},
251258
{ "include": "#types" }
252259
]
253260
},
254-
{
261+
{
255262
"match": "\\b(\\w+)\\b",
256263
"name": "entity.name.type.nushell"
257264
}
@@ -260,8 +267,11 @@
260267
"function-parameter": {
261268
"patterns": [
262269
{
263-
"match": "((?:-{0,2}|\\.{3})[\\w-]+)(?:\\((-[\\w?])\\))?",
264-
"name": "variable.parameter.nushell"
270+
"match": "(-{0,2}|\\.{3})[\\w-]+(?:\\((-[\\w?])\\))?",
271+
"name": "variable.parameter.nushell",
272+
"captures": {
273+
"1": { "name": "keyword.control.nushell" }
274+
}
265275
},
266276
{
267277
"begin": "\\??:\\s*",
@@ -561,6 +571,7 @@
561571
},
562572
"name": "meta.record-entry.nushell"
563573
},
574+
{ "include": "#spread" },
564575
{ "include": "source.nushell" }
565576
]
566577
},
@@ -643,14 +654,18 @@
643654
},
644655
"end": "(?=\\||\\)|\\}|;)|$",
645656
"name": "meta.command.nushell",
646-
"patterns": [{ "include": "#value" }]
657+
"patterns": [
658+
{ "include": "#parameters" },
659+
{ "include": "#spread" },
660+
{ "include": "#value" }
661+
]
647662
},
648663
"expression": {
649664
"patterns": [
650665
{ "include": "#pre-command" },
651666
{ "include": "#for-loop" },
652667
{ "include": "#operators" },
653-
{
668+
{
654669
"match": "\\|",
655670
"name": "keyword.control.nushell"
656671
},
@@ -667,7 +682,6 @@
667682
{ "include": "#control-keywords" },
668683
{ "include": "#constant-value" },
669684
{ "include": "#table" },
670-
{ "include": "#parameters" },
671685
{ "include": "#operators" },
672686
{ "include": "#paren-expression" },
673687
{ "include": "#braced-expression" },

0 commit comments

Comments
 (0)