on master help sign in
Update tree-sitter grammar for nu (#7873)

* Update tree-sitter grammar for nu Change tree-sitter grammar for nushell to 'officially' maintained by nushell project https://github.com/nushell/tree-sitter-nu. Update to the latest version. Replace queries with supported * Restore injection queries for nu Restore injection.scm queries for nushell tree-sitter grammar

commit107763083405868f3679d8e12476ed0688896f87 authorArtemiy <artem-itf@yandex.ru> dateWed 9 Aug 2023, 15:00 (3 years ago) parent48eb0d4
5 files changed+278−63
languages.toml+1−1 runtime/queries/nu/folds.scm−4 runtime/queries/nu/highlights.scm+276−44 runtime/queries/nu/injections.scm+1−1 runtime/queries/nu/locals.scm−13
languages.toml+1−1
@@ -1697,7 +1697,7 @@ indent = { tab-width = 2, unit = " " }
16971697
16981698[[grammar]]
16991699name = "nu"
1700−source = { git = "https://github.com/LhKipp/tree-sitter-nu", rev = "eb95bdac3abd73ef47e53f19c63e74a31405ebd2" }
1700+source = { git = "https://github.com/nushell/tree-sitter-nu", rev = "98c11c491e3405c75affa1cf004097692da3dda2" }
17011701
17021702[[language]]
17031703name = "vala"
runtime/queries/nu/folds.scmdeleted−4
@@ -1,4 +0,0 @@
1−[
2− (function_definition)
3− (block)
4−] @fold
runtime/queries/nu/highlights.scm+276−44
@@ -1,55 +1,287 @@
1−(string) @string
2−(type) @type
3−(value_path) @variable
4−(comment) @comment
1+;;; ---
2+;;; keywords
3+[
4+ "def"
5+ "def-env"
6+ "alias"
7+ "export-env"
8+ "export"
9+ "extern"
10+ "module"
511
6−(number_literal) @constant.numeric
7−(range from: (number_literal) @constant.numeric)
8−(range to: (number_literal) @constant.numeric)
12+ "let"
13+ "let-env"
14+ "mut"
15+ "const"
916
10−(command cmd_name: (identifier) @function)
11−(function_definition func_name: (identifier) @function)
17+ "hide-env"
1218
13−[
14− (variable_declaration name: (identifier))
15− (parameter (identifier))
16− (flag (flag_name))
17− (flag (flag_shorthand_name))
18− (record_entry entry_name: (identifier))
19− (block_args block_param: (identifier))
20−] @variable.other.member
21−; (parameter (identifier) @variable.parameter) ; -- alternative highlighting group?
19+ "source"
20+ "source-env"
2221
23−(cmd_invocation) @embedded
22+ "overlay"
23+ "register"
2424
25+ "loop"
26+ "while"
27+ "error"
2528
26−((identifier) @constant
27− (#match? @constant "^[A-Z][A-Z\\d_]*$"))
29+ "do"
30+ "if"
31+ "else"
32+ "try"
33+ "catch"
34+ "match"
35+
36+ "break"
37+ "continue"
38+ "return"
2839
29−[
30− "if"
31− "else"
32− "let"
33− "def"
34− "export"
3540] @keyword
3641
42+(hide_mod "hide" @keyword)
43+(decl_use "use" @keyword)
44+
45+(ctrl_for
46+ "for" @keyword
47+ "in" @keyword
48+)
49+(overlay_list "list" @keyword.storage.modifier)
50+(overlay_hide "hide" @keyword.storage.modifier)
51+(overlay_new "new" @keyword.storage.modifier)
52+(overlay_use
53+ "use" @keyword.storage.modifier
54+ "as" @keyword
55+)
56+(ctrl_error "make" @keyword.storage.modifier)
57+
58+;;; ---
59+;;; literals
60+(val_number) @constant.numeric
61+(val_duration
62+ unit: [
63+ "ns" "µs" "us" "ms" "sec" "min" "hr" "day" "wk"
64+ ] @variable.parameter
65+)
66+(val_filesize
67+ unit: [
68+ "b" "B"
69+
70+ "kb" "kB" "Kb" "KB"
71+ "mb" "mB" "Mb" "MB"
72+ "gb" "gB" "Gb" "GB"
73+ "tb" "tB" "Tb" "TB"
74+ "pb" "pB" "Pb" "PB"
75+ "eb" "eB" "Eb" "EB"
76+ "zb" "zB" "Zb" "ZB"
77+
78+ "kib" "kiB" "kIB" "kIb" "Kib" "KIb" "KIB"
79+ "mib" "miB" "mIB" "mIb" "Mib" "MIb" "MIB"
80+ "gib" "giB" "gIB" "gIb" "Gib" "GIb" "GIB"
81+ "tib" "tiB" "tIB" "tIb" "Tib" "TIb" "TIB"
82+ "pib" "piB" "pIB" "pIb" "Pib" "PIb" "PIB"
83+ "eib" "eiB" "eIB" "eIb" "Eib" "EIb" "EIB"
84+ "zib" "ziB" "zIB" "zIb" "Zib" "ZIb" "ZIB"
85+ ] @variable.parameter
86+)
87+(val_binary
88+ [
89+ "0b"
90+ "0o"
91+ "0x"
92+ ] @constant.numeric
93+ "[" @punctuation.bracket
94+ digit: [
95+ "," @punctuation.delimiter
96+ (hex_digit) @constant.number
97+ ]
98+ "]" @punctuation.bracket
99+) @constant.numeric
100+(val_bool) @constant.builtin
101+(val_nothing) @constant.builtin
102+(val_string) @string
103+(val_date) @constant.number
104+(inter_escape_sequence) @constant.character.escape
105+(escape_sequence) @constant.character.escape
106+(val_interpolated [
107+ "$\""
108+ "$\'"
109+ "\""
110+ "\'"
111+] @string)
112+(unescaped_interpolated_content) @string
113+(escaped_interpolated_content) @string
114+(expr_interpolated ["(" ")"] @variable.parameter)
115+
116+;;; ---
117+;;; operators
118+(expr_binary [
119+ "+"
120+ "-"
121+ "*"
122+ "/"
123+ "mod"
124+ "//"
125+ "++"
126+ "**"
127+ "=="
128+ "!="
129+ "<"
130+ "<="
131+ ">"
132+ ">="
133+ "=~"
134+ "!~"
135+ "and"
136+ "or"
137+ "xor"
138+ "bit-or"
139+ "bit-xor"
140+ "bit-and"
141+ "bit-shl"
142+ "bit-shr"
143+ "in"
144+ "not-in"
145+ "starts-with"
146+ "ends-with"
147+] @operator )
148+
149+(where_command [
150+ "+"
151+ "-"
152+ "*"
153+ "/"
154+ "mod"
155+ "//"
156+ "++"
157+ "**"
158+ "=="
159+ "!="
160+ "<"
161+ "<="
162+ ">"
163+ ">="
164+ "=~"
165+ "!~"
166+ "and"
167+ "or"
168+ "xor"
169+ "bit-or"
170+ "bit-xor"
171+ "bit-and"
172+ "bit-shl"
173+ "bit-shr"
174+ "in"
175+ "not-in"
176+ "starts-with"
177+ "ends-with"
178+] @operator)
179+
180+(assignment [
181+ "="
182+ "+="
183+ "-="
184+ "*="
185+ "/="
186+ "++="
187+] @operator)
188+
189+(expr_unary ["not" "-"] @operator)
190+
191+(val_range [
192+ ".."
193+ "..="
194+ "..<"
195+] @operator)
196+
197+["=>" "=" "|"] @operator
198+
37199[
38− ; "/" Not making / an operator may lead to better highlighting?
39− "$"
40− "|"
41− "+"
42− "-"
43− "*"
44− "="
45− "!="
46− "&&"
47− "||"
48− "=="
49− ">"
50−] @operator
51−
52−["."
53− ","
54− ";"
200+ "o>" "out>"
201+ "e>" "err>"
202+ "e+o>" "err+out>"
203+ "o+e>" "out+err>"
204+] @special
205+
206+;;; ---
207+;;; punctuation
208+[
209+ ","
210+ ";"
55211] @punctuation.delimiter
212+
213+(param_short_flag "-" @punctuation.delimiter)
214+(param_long_flag ["--"] @punctuation.delimiter)
215+(long_flag ["--"] @punctuation.delimiter)
216+(param_rest "..." @punctuation.delimiter)
217+(param_type [":"] @punctuation.special)
218+(param_value ["="] @punctuation.special)
219+(param_cmd ["@"] @punctuation.special)
220+(param_opt ["?"] @punctuation.special)
221+
222+[
223+ "(" ")"
224+ "{" "}"
225+ "[" "]"
226+] @punctuation.bracket
227+
228+(val_record
229+ (record_entry ":" @punctuation.delimiter))
230+;;; ---
231+;;; identifiers
232+(param_rest
233+ name: (_) @variable.parameter)
234+(param_opt
235+ name: (_) @variable.parameter)
236+(parameter
237+ param_name: (_) @variable.parameter)
238+(param_cmd
239+ (cmd_identifier) @string)
240+(param_long_flag) @variable.parameter
241+(param_short_flag) @variable.parameter
242+
243+(short_flag) @variable.parameter
244+(long_flag) @variable.parameter
245+
246+(scope_pattern [(wild_card) @function])
247+
248+(cmd_identifier) @function
249+
250+(command
251+ "^" @punctuation.delimiter
252+ head: (_) @function
253+)
254+
255+"where" @function
256+
257+(path
258+ ["." "?"] @punctuation.delimiter
259+) @variable.parameter
260+
261+(val_variable
262+ "$" @variable.parameter
263+ [
264+ (identifier) @namespace
265+ "in"
266+ "nu"
267+ "env"
268+ "nothing"
269+ ] @special
270+)
271+;;; ---
272+;;; types
273+(flat_type) @type.builtin
274+(list_type
275+ "list" @type.enum
276+ ["<" ">"] @punctuation.bracket
277+)
278+(collection_type
279+ ["record" "table"] @type.enum
280+ "<" @punctuation.bracket
281+ key: (_) @variable.parameter
282+ ["," ":"] @punctuation.delimiter
283+ ">" @punctuation.bracket
284+)
285+
286+(shebang) @comment
287+(comment) @comment
runtime/queries/nu/injections.scm+1−1
@@ -1,2 +1,2 @@
11((comment) @injection.content
2− (#set! injection.language "comment"))
2+ (#set! injection.language "comment"))
runtime/queries/nu/locals.scmdeleted−13
@@ -1,13 +0,0 @@
1−; Scopes
2−(function_definition) @scope
3−
4−; Definitions
5−(variable_declaration
6− name: (identifier) @definition.var)
7−
8−(function_definition
9− func_name: (identifier) @definition.function)
10−
11−; References
12−(value_path) @reference
13−(word) @reference