crates/highlight/syntaxes/fish.json 18.4 KiB raw
1
{
2
  "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
3
  "firstLineMatch": "^#!.*\\bfish\\b",
4
  "keyEquivalent": "^~F",
5
  "name": "fish",
6
  "patterns": [
7
    { "include": "#string-double" },
8
    { "include": "#string-single" },
9
    { "include": "#comment" },
10
    { "include": "#subshell-bare" },
11
    { "include": "#subshell" },
12
    { "include": "#command" },
13
    { "include": "#keywords" },
14
    { "include": "#io-redirection" },
15
    { "include": "#operators" },
16
    { "include": "#options" },
17
    { "include": "#variable" },
18
    { "include": "#escape" }
19
  ],
20
  "repository": {
21
    "string-double": {
22
      "begin": "\"",
23
      "beginCaptures": {
24
        "0": { "name": "punctuation.definition.string.begin.fish" }
25
      },
26
      "comment": "Double quoted string",
27
      "end": "\"",
28
      "endCaptures": {
29
        "0": { "name": "punctuation.definition.string.end.fish" }
30
      },
31
      "name": "string.quoted.double.fish",
32
      "patterns": [
33
        { "include": "#subshell" },
34
        { "include": "#variable-string-double" },
35
        {
36
          "comment": "https://fishshell.com/docs/current/#quotes",
37
          "match": "\\\\(\\\"|\\$|$|\\\\)",
38
          "name": "constant.character.escape.fish"
39
        }
40
      ]
41
    },
42
    "string-single": {
43
      "begin": "'",
44
      "beginCaptures": {
45
        "0": { "name": "punctuation.definition.string.begin.fish" }
46
      },
47
      "comment": "Single quoted string",
48
      "end": "'",
49
      "endCaptures": {
50
        "0": { "name": "punctuation.definition.string.end.fish" }
51
      },
52
      "name": "string.quoted.single.fish",
53
      "patterns": [
54
        {
55
          "comment": "https://fishshell.com/docs/current/#quotes",
56
          "match": "\\\\('|`|\\\\)",
57
          "name": "constant.character.escape.fish"
58
        }
59
      ]
60
    },
61
    "comment": {
62
      "captures": { "1": { "name": "punctuation.definition.comment.fish" } },
63
      "comment": "line comment",
64
      "match": "(?<!\\$)(#)(?!\\{).*$\\n?",
65
      "name": "comment.line.number-sign.fish"
66
    },
67
    "command": {
68
      "comment": "name of command, either a function or a binary",
69
      "match": "(^\\s*|&&\\s*|(\\|)\\s*|\\(\\s*|[;]\\s*|\\b(if|while)\\b\\s+)(?!(?<!\\.)\\b(function|while|if|else|switch|case|for|in|begin|end|continue|break|return|source|exit|wait|and|or|not)\\b(?![?!]))([a-zA-Z_\\-0-9\\[\\].]+)",
70
      "captures": {
71
        "2": { "name": "keyword.operator.pipe.fish" },
72
        "3": { "name": "keyword.control.fish" },
73
        "5": { "name": "support.function.command.fish" }
74
      }
75
    },
76
    "command-subshell": {
77
      "comment": "name of command in subshell context",
78
      "match": "(\\G\\s*|&&\\s*|(\\|)\\s*|\\(\\s*|[;]\\s*|\\b(if|while)\\b\\s+)(?!(?<!\\.)\\b(function|while|if|else|switch|case|for|in|begin|end|continue|break|return|source|exit|wait|and|or|not)\\b(?![?!]))([a-zA-Z_\\-0-9\\[\\].]+)",
79
      "captures": {
80
        "2": { "name": "keyword.operator.pipe.fish" },
81
        "3": { "name": "keyword.control.fish" },
82
        "5": { "name": "support.function.command.fish" }
83
      }
84
    },
85
    "keywords": {
86
      "patterns": [
87
        {
88
          "comment": "command-expecting keywords (allow subsequent keywords)",
89
          "match": "(^\\s*|&&\\s*|(?<=\\|)\\s*|\\(\\s*|[;]\\s*|(?<=\\bwhile\\b)\\s+|(?<=\\bif\\b)\\s+|(?<=\\band\\b)\\s+|(?<=\\bor\\b)\\s+|(?<=\\bnot\\b)\\s+)(?<!\\.)\\b(while|if|and|or|not)\\b(?![?!])",
90
          "captures": { "2": { "name": "keyword.control.fish" } }
91
        },
92
        {
93
          "comment": "regular keywords (command position only)",
94
          "match": "(^\\s*|&&\\s*|(?<=\\|)\\s*|\\(\\s*|[;]\\s*)(?<!\\.)\\b(function|else|switch|case|for|begin|end|continue|break|return|source|exit|wait)\\b(?![?!])",
95
          "captures": { "2": { "name": "keyword.control.fish" } }
96
        },
97
        {
98
          "comment": "in keyword (special case for 'for' loops)",
99
          "match": "\\b(in)\\b(?![?!])",
100
          "name": "keyword.control.fish"
101
        }
102
      ]
103
    },
104
    "keywords-subshell": {
105
      "patterns": [
106
        {
107
          "comment": "command-expecting keywords in subshell (allow subsequent keywords)",
108
          "match": "(\\G\\s*|&&\\s*|(?<=\\|)\\s*|\\(\\s*|[;]\\s*|(?<=\\bwhile\\b)\\s+|(?<=\\bif\\b)\\s+|(?<=\\band\\b)\\s+|(?<=\\bor\\b)\\s+|(?<=\\bnot\\b)\\s+)(?<!\\.)\\b(while|if|and|or|not)\\b(?![?!])",
109
          "captures": { "2": { "name": "keyword.control.fish" } }
110
        },
111
        {
112
          "comment": "regular keywords in subshell (command position only)",
113
          "match": "(\\G\\s*|&&\\s*|(?<=\\|)\\s*|\\(\\s*|[;]\\s*)(?<!\\.)\\b(function|else|switch|case|for|begin|end|continue|break|return|source|exit|wait)\\b(?![?!])",
114
          "captures": { "2": { "name": "keyword.control.fish" } }
115
        },
116
        {
117
          "comment": "in keyword (special case for 'for' loops)",
118
          "match": "\\b(in)\\b(?![?!])",
119
          "name": "keyword.control.fish"
120
        }
121
      ]
122
    },
123
    "io-redirection": {
124
      "patterns": [
125
        {
126
          "comment": "IO Redirection with simple target",
127
          "match": "(<|(?:>|\\^|>>|\\^\\^)(?:&[012\\-])?|[012](?:<|>|>>)(?:&[012\\-])?)\\s*(?!\\()([a-zA-Z0-9_./\\-]+)",
128
          "captures": {
129
            "1": { "name": "keyword.operator.redirect.fish" },
130
            "2": { "name": "keyword.operator.redirect.target.fish" }
131
          }
132
        },
133
        {
134
          "comment": "IO Redirection without target",
135
          "match": "(?x:\n<|(>|\\^|>>|\\^\\^)(&[012\\-])?|[012](<|>|>>)(&[012\\-])?)",
136
          "name": "keyword.operator.redirect.fish"
137
        }
138
      ]
139
    },
140
    "operators": {
141
      "patterns": [
142
        {
143
          "match": "&",
144
          "name": "keyword.operator.background.fish"
145
        },
146
        {
147
          "match": "\\*\\*|\\*|\\?",
148
          "name": "keyword.operator.glob.fish"
149
        }
150
      ]
151
    },
152
    "options": {
153
      "comment": "command short/long options",
154
      "match": "\\s(-{1,2}[a-zA-Z_\\-0-9]+|-\\w)\\b",
155
      "captures": { "1": { "name": "source.option.fish" } }
156
    },
157
    "subshell": {
158
      "comment": "Command substitution $(command)",
159
      "begin": "\\$\\(",
160
      "beginCaptures": {
161
        "0": { "name": "punctuation.definition.subshell.begin.fish" }
162
      },
163
      "end": "(?<!\\\\)((\\\\\\\\)*)(\\))",
164
      "endCaptures": {
165
        "1": { "name": "constant.character.escape.string.fish" },
166
        "3": { "name": "punctuation.definition.subshell.end.fish" }
167
      },
168
      "name": "meta.embedded.subshell.fish",
169
      "patterns": [
170
        { "include": "#string-double" },
171
        { "include": "#string-single" },
172
        { "include": "#comment" },
173
        { "include": "#keywords-subshell" },
174
        { "include": "#command-subshell" },
175
        { "include": "#io-redirection" },
176
        { "include": "#operators" },
177
        { "include": "#options" },
178
        { "include": "#subshell" },
179
        { "include": "#variable" },
180
        { "include": "#escape" }
181
      ]
182
    },
183
    "slice": {
184
      "comment": "List variable slice $variable[...] outside of strings",
185
      "begin": "\\[",
186
      "beginCaptures": {
187
        "0": { "name": "punctuation.definition.slice.begin.fish" }
188
      },
189
      "end": "(?<!\\\\)((\\\\\\\\)*)(\\])",
190
      "endCaptures": {
191
        "1": { "name": "constant.character.escape.string.fish" },
192
        "3": { "name": "punctuation.definition.slice.end.fish" }
193
      },
194
      "name": "meta.embedded.slice.fish variable.interpolation.fish",
195
      "patterns": [
196
        { "include": "#string-double" },
197
        { "include": "#string-single" },
198
        { "include": "#subshell-bare" },
199
        { "include": "#subshell" },
200
        { "include": "#variable" },
201
        { "include": "#escape" }
202
      ]
203
    },
204
    "slice-string-double": {
205
      "comment": "List variable slice $variable[...] inside double-quoted strings",
206
      "begin": "\\[",
207
      "beginCaptures": {
208
        "0": { "name": "punctuation.definition.slice.begin.fish" }
209
      },
210
      "end": "(?<!\\\\)((\\\\\\\\)*)(\\])",
211
      "endCaptures": {
212
        "1": { "name": "constant.character.escape.string.fish" },
213
        "3": { "name": "punctuation.definition.slice.end.fish" }
214
      },
215
      "name": "meta.embedded.slice.fish variable.interpolation.string.fish",
216
      "patterns": [
217
        { "include": "#subshell" },
218
        { "include": "#variable" },
219
        {
220
          "comment": "https://fishshell.com/docs/current/#quotes",
221
          "match": "\\\\(\\\"|\\$|$|\\\\)",
222
          "name": "constant.character.escape.fish"
223
        }
224
      ]
225
    },
226
    "subshell-bare": {
227
      "comment": "Bare parentheses command substitution (command) - valid in fish 3.4+",
228
      "begin": "\\(",
229
      "beginCaptures": {
230
        "0": { "name": "punctuation.definition.subshell.begin.fish" }
231
      },
232
      "end": "(?<!\\\\)((\\\\\\\\)*)(\\))",
233
      "endCaptures": {
234
        "1": { "name": "constant.character.escape.string.fish" },
235
        "3": { "name": "punctuation.definition.subshell.end.fish" }
236
      },
237
      "name": "meta.embedded.subshell.fish",
238
      "patterns": [
239
        { "include": "#string-double" },
240
        { "include": "#string-single" },
241
        { "include": "#comment" },
242
        { "include": "#keywords-subshell" },
243
        { "include": "#command-subshell" },
244
        { "include": "#io-redirection" },
245
        { "include": "#operators" },
246
        { "include": "#options" },
247
        { "include": "#subshell-bare" },
248
        { "include": "#subshell" },
249
        { "include": "#variable" },
250
        { "include": "#escape" }
251
      ]
252
    },
253
    "escape": {
254
      "patterns": [
255
        {
256
          "comment": "single character character escape sequences",
257
          "match": "\\\\[abefnrtv $*?~#(){}\\[\\]<>^&|;\"']",
258
          "name": "constant.character.escape.string.fish"
259
        },
260
        {
261
          "comment": "escapes the ascii character with the specified value (hexadecimal)",
262
          "match": "\\\\x[0-9a-fA-F]{1,2}",
263
          "name": "constant.character.escape.hex-ascii.fish"
264
        },
265
        {
266
          "comment": "escapes a byte of data with the specified value (hexadecimal). If you are using mutibyte encoding, this can be used to enter invalid strings. Only use this if you know what are doing.",
267
          "match": "\\\\X[0-9a-fA-F]{1,2}",
268
          "name": "constant.character.escape.hex-byte.fish"
269
        },
270
        {
271
          "comment": "escapes the ascii character with the specified value (octal)",
272
          "match": "\\\\[0-7]{1,3}",
273
          "name": "constant.character.escape.octal.fish"
274
        },
275
        {
276
          "comment": "escapes the 16-bit unicode character with the specified value (hexadecimal)",
277
          "match": "\\\\u[0-9a-fA-F]{1,4}",
278
          "name": "constant.character.escape.unicode-16-bit.fish"
279
        },
280
        {
281
          "comment": "escapes the 32-bit unicode character with the specified value (hexadecimal)",
282
          "match": "\\\\U[0-9a-fA-F]{1,8}",
283
          "name": "constant.character.escape.unicode-32-bit.fish"
284
        },
285
        {
286
          "comment": "escapes the control sequence generated by pressing the control key and the specified letter",
287
          "match": "\\\\c[a-zA-Z]",
288
          "name": "constant.character.escape.control.fish"
289
        }
290
      ]
291
    },
292
    "variable": {
293
      "patterns": [
294
        {
295
          "comment": "Built-in variables with slice",
296
          "begin": "(\\$)(argv|CMD_DURATION|COLUMNS|fish_bind_mode|fish_color_autosuggestion|fish_color_cancel|fish_color_command|fish_color_comment|fish_color_cwd|fish_color_cwd_root|fish_color_end|fish_color_error|fish_color_escape|fish_color_hg_added|fish_color_hg_clean|fish_color_hg_copied|fish_color_hg_deleted|fish_color_hg_dirty|fish_color_hg_modified|fish_color_hg_renamed|fish_color_hg_unmerged|fish_color_hg_untracked|fish_color_history_current|fish_color_host|fish_color_host_remote|fish_color_match|fish_color_normal|fish_color_operator|fish_color_param|fish_color_quote|fish_color_redirection|fish_color_search_match|fish_color_selection|fish_color_status|fish_color_user|fish_color_valid_path|fish_complete_path|fish_function_path|fish_greeting|fish_key_bindings|fish_pager_color_completion|fish_pager_color_description|fish_pager_color_prefix|fish_pager_color_progress|fish_pid|fish_prompt_hg_status_added|fish_prompt_hg_status_copied|fish_prompt_hg_status_deleted|fish_prompt_hg_status_modified|fish_prompt_hg_status_order|fish_prompt_hg_status_unmerged|fish_prompt_hg_status_untracked|FISH_VERSION|history|hostname|IFS|LINES|pipestatus|status|umask|version)\\b(?=\\[)",
297
          "beginCaptures": {
298
            "1": { "name": "punctuation.definition.variable.fish" },
299
            "2": { "name": "variable.language.fish" }
300
          },
301
          "end": "(?<=\\])",
302
          "name": "variable.language.fish",
303
          "patterns": [{ "include": "#slice" }]
304
        },
305
        {
306
          "comment": "Built-in variables without slice",
307
          "captures": {
308
            "1": { "name": "punctuation.definition.variable.fish" }
309
          },
310
          "match": "(\\$)(argv|CMD_DURATION|COLUMNS|fish_bind_mode|fish_color_autosuggestion|fish_color_cancel|fish_color_command|fish_color_comment|fish_color_cwd|fish_color_cwd_root|fish_color_end|fish_color_error|fish_color_escape|fish_color_hg_added|fish_color_hg_clean|fish_color_hg_copied|fish_color_hg_deleted|fish_color_hg_dirty|fish_color_hg_modified|fish_color_hg_renamed|fish_color_hg_unmerged|fish_color_hg_untracked|fish_color_history_current|fish_color_host|fish_color_host_remote|fish_color_match|fish_color_normal|fish_color_operator|fish_color_param|fish_color_quote|fish_color_redirection|fish_color_search_match|fish_color_selection|fish_color_status|fish_color_user|fish_color_valid_path|fish_complete_path|fish_function_path|fish_greeting|fish_key_bindings|fish_pager_color_completion|fish_pager_color_description|fish_pager_color_prefix|fish_pager_color_progress|fish_pid|fish_prompt_hg_status_added|fish_prompt_hg_status_copied|fish_prompt_hg_status_deleted|fish_prompt_hg_status_modified|fish_prompt_hg_status_order|fish_prompt_hg_status_unmerged|fish_prompt_hg_status_untracked|FISH_VERSION|history|hostname|IFS|LINES|pipestatus|status|umask|version)\\b",
311
          "name": "variable.language.fish"
312
        },
313
        {
314
          "comment": "Normal variables with slice",
315
          "begin": "(\\$)([a-zA-Z_][a-zA-Z0-9_]*)(?=\\[)",
316
          "beginCaptures": {
317
            "1": { "name": "punctuation.definition.variable.fish" },
318
            "2": { "name": "variable.other.normal.fish" }
319
          },
320
          "end": "(?<=\\])",
321
          "name": "variable.other.normal.fish",
322
          "patterns": [{ "include": "#slice" }]
323
        },
324
        {
325
          "comment": "Normal variables without slice",
326
          "captures": {
327
            "1": { "name": "punctuation.definition.variable.fish" }
328
          },
329
          "match": "(\\$)[a-zA-Z_][a-zA-Z0-9_]*",
330
          "name": "variable.other.normal.fish"
331
        }
332
      ]
333
    },
334
    "variable-string-double": {
335
      "patterns": [
336
        {
337
          "comment": "Built-in variables with slice inside double-quoted strings",
338
          "begin": "(\\$)(argv|CMD_DURATION|COLUMNS|fish_bind_mode|fish_color_autosuggestion|fish_color_cancel|fish_color_command|fish_color_comment|fish_color_cwd|fish_color_cwd_root|fish_color_end|fish_color_error|fish_color_escape|fish_color_hg_added|fish_color_hg_clean|fish_color_hg_copied|fish_color_hg_deleted|fish_color_hg_dirty|fish_color_hg_modified|fish_color_hg_renamed|fish_color_hg_unmerged|fish_color_hg_untracked|fish_color_history_current|fish_color_host|fish_color_host_remote|fish_color_match|fish_color_normal|fish_color_operator|fish_color_param|fish_color_quote|fish_color_redirection|fish_color_search_match|fish_color_selection|fish_color_status|fish_color_user|fish_color_valid_path|fish_complete_path|fish_function_path|fish_greeting|fish_key_bindings|fish_pager_color_completion|fish_pager_color_description|fish_pager_color_prefix|fish_pager_color_progress|fish_pid|fish_prompt_hg_status_added|fish_prompt_hg_status_copied|fish_prompt_hg_status_deleted|fish_prompt_hg_status_modified|fish_prompt_hg_status_order|fish_prompt_hg_status_unmerged|fish_prompt_hg_status_untracked|FISH_VERSION|history|hostname|IFS|LINES|pipestatus|status|umask|version)\\b(?=\\[)",
339
          "beginCaptures": {
340
            "1": { "name": "punctuation.definition.variable.fish" },
341
            "2": { "name": "variable.language.fish" }
342
          },
343
          "end": "(?<=\\])",
344
          "name": "variable.language.fish",
345
          "patterns": [{ "include": "#slice-string-double" }]
346
        },
347
        {
348
          "comment": "Built-in variables without slice inside double-quoted strings",
349
          "captures": {
350
            "1": { "name": "punctuation.definition.variable.fish" }
351
          },
352
          "match": "(\\$)(argv|CMD_DURATION|COLUMNS|fish_bind_mode|fish_color_autosuggestion|fish_color_cancel|fish_color_command|fish_color_comment|fish_color_cwd|fish_color_cwd_root|fish_color_end|fish_color_error|fish_color_escape|fish_color_hg_added|fish_color_hg_clean|fish_color_hg_copied|fish_color_hg_deleted|fish_color_hg_dirty|fish_color_hg_modified|fish_color_hg_renamed|fish_color_hg_unmerged|fish_color_hg_untracked|fish_color_history_current|fish_color_host|fish_color_host_remote|fish_color_match|fish_color_normal|fish_color_operator|fish_color_param|fish_color_quote|fish_color_redirection|fish_color_search_match|fish_color_selection|fish_color_status|fish_color_user|fish_color_valid_path|fish_complete_path|fish_function_path|fish_greeting|fish_key_bindings|fish_pager_color_completion|fish_pager_color_description|fish_pager_color_prefix|fish_pager_color_progress|fish_pid|fish_prompt_hg_status_added|fish_prompt_hg_status_copied|fish_prompt_hg_status_deleted|fish_prompt_hg_status_modified|fish_prompt_hg_status_order|fish_prompt_hg_status_unmerged|fish_prompt_hg_status_untracked|FISH_VERSION|history|hostname|IFS|LINES|pipestatus|status|umask|version)\\b",
353
          "name": "variable.language.fish"
354
        },
355
        {
356
          "comment": "Normal variables with slice inside double-quoted strings",
357
          "begin": "(\\$)([a-zA-Z_][a-zA-Z0-9_]*)(?=\\[)",
358
          "beginCaptures": {
359
            "1": { "name": "punctuation.definition.variable.fish" },
360
            "2": { "name": "variable.other.normal.fish" }
361
          },
362
          "end": "(?<=\\])",
363
          "name": "variable.other.normal.fish",
364
          "patterns": [{ "include": "#slice-string-double" }]
365
        },
366
        {
367
          "comment": "Normal variables without slice inside double-quoted strings",
368
          "captures": {
369
            "1": { "name": "punctuation.definition.variable.fish" }
370
          },
371
          "match": "(\\$)[a-zA-Z_][a-zA-Z0-9_]*",
372
          "name": "variable.other.normal.fish"
373
        }
374
      ]
375
    }
376
  },
377
  "scopeName": "source.fish",
378
  "uuid": "9CA6DB6F-A16F-4836-A058-617C7378775D"
379
}