Skip to content

Commit 16f9ff3

Browse files
author
fidgetingbits
committed
Fix callee and args, and add inherit keyword specialc ase
1 parent 1db5b69 commit 16f9ff3

File tree

1 file changed

+116
-2
lines changed

1 file changed

+116
-2
lines changed

queries/nix.scm

Lines changed: 116 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
;;
12
;; Statements
3+
;;
24

35
;; Any top-level expression that isn't a comment is a statement
46
(
@@ -51,7 +53,9 @@
5153
(_) @statement.iteration @value.iteration @name.iteration
5254
)
5355

56+
;;
5457
;; Conditionals
58+
;;
5559

5660
;;!! key = if a then b else c;
5761
;;! ^^^^^^^^^^^^^^^^^^
@@ -79,7 +83,9 @@
7983
condition: (_) @condition
8084
) @_.domain
8185

86+
;;
8287
;; Lists and maps
88+
;;
8389

8490
;;!! foo = [ a b c ];
8591
;;! ^^^^^^^^^
@@ -103,7 +109,9 @@
103109
expression: (_) @_.trailing.end.startOf
104110
) @_.domain
105111

112+
;;
106113
;; Strings
114+
;;
107115

108116
;;!! # foo
109117
;;! ^^^^^
@@ -122,7 +130,9 @@
122130
(interpolation) @argumentOrParameter
123131
) @_.iteration
124132

133+
;;
125134
;; Functions
135+
;;
126136

127137
;; Note for this part of the function, we identify is as lambda only
128138
;;!! x = a: b: a + b;
@@ -154,17 +164,121 @@
154164
expression: (function_expression) @namedFunction.interior
155165
) @namedFunction @functionName.domain
156166

167+
;; Calls to functions are a bit finicky, because of everything being curried lambdas
168+
(
169+
(apply_expression) @dummy @functionCall @argumentOrParameter.iteration
170+
(#not-parent-type? @functionCall apply_expression)
171+
)
172+
173+
;; This is gross, but not sure how to do fuzzy matching against an unknown number of
174+
;; nested child nodes. Arbitrarily stopping at 5 args for now, as that ought to be enough
175+
;; arguments for anyone
176+
;; Args:
177+
;;!! mkHost a b c d e
178+
;;! ^
179+
;;! xx
180+
;;! <*********>
181+
;;! Callee:
182+
;;!! mkHost a b c d e
183+
;;! ^^^^^^
184+
;;! xxxxxxx
185+
;;! ----------------
186+
;; The mkHost node looks like this:
187+
;; # (binding_set
188+
;; # binding: (binding
189+
;; # expression: (attrset_expression
190+
;; # (binding_set
191+
;; # binding: (binding
192+
;; # expression: (apply_expression
193+
;; # function: (apply_expression
194+
;; # function: (apply_expression
195+
;; # function: (variable_expression
196+
;; # name: (identifier)
197+
;; # )
198+
(apply_expression
199+
[
200+
(apply_expression
201+
function: (variable_expression
202+
name: (identifier) @functionCallee
203+
)
204+
)
205+
(apply_expression
206+
[
207+
(apply_expression
208+
function: (variable_expression
209+
name: (identifier) @functionCallee
210+
)
211+
)
212+
(apply_expression
213+
[
214+
(apply_expression
215+
function: (variable_expression
216+
name: (identifier) @functionCallee
217+
)
218+
)
219+
(apply_expression
220+
(apply_expression
221+
function: (variable_expression
222+
name: (identifier) @functionCallee
223+
)
224+
)
225+
)
226+
]
227+
)
228+
]
229+
)
230+
]
231+
) @_.domain
232+
233+
;; Args:
234+
;;!! mkHost a
235+
;;! ^
236+
;;! x
237+
;;! --------
238+
;;! Callee:
239+
;;!! mkHost a
240+
;;! ^^^^^^
241+
;;! xxxxxx
242+
;;! --------
157243
(apply_expression
158-
function: (_) @functionCallee
244+
function: (variable_expression
245+
name: (identifier) @functionCallee
246+
)
159247
argument: (_) @argumentOrParameter
160248
) @_.domain
161249

162-
(apply_expression) @functionCall
250+
(apply_expression
251+
argument: (_) @argumentOrParameter
252+
)
253+
163254
(function_expression
164255
(formals) @argumentOrParameter
165256
) @_.domain
166257

258+
;; inherit is a built-in keyword, but is close enough to a function...
259+
;; Callee:
260+
;;!! inherit pkgs input output;
261+
;;! ^^^^^^^
262+
;;! xxxxxxxx
263+
;;! -------------------------
264+
;; Args:
265+
;;!! inherit pkgs input output;
266+
;;! ^^^^
267+
;;! xxxxx
268+
;;! <*****************>
269+
(inherit
270+
"inherit" @functionCallee
271+
(
272+
(inherited_attrs) @argumentOrParameter.iteration
273+
)
274+
) @functionCall @_.domain
275+
(inherited_attrs
276+
attr: (_) @argumentOrParameter
277+
)
278+
279+
;;
167280
;; Names and Values
281+
;;
168282

169283
;;!! a = 25;
170284
;;! ^^

0 commit comments

Comments
 (0)