Skip to content

Commit 734c8a7

Browse files
author
fidgetingbits
committed
Tweak assert match, add top level statement matching
1 parent bb820ba commit 734c8a7

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

queries/nix.scm

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
11
;; Statements
22

3-
[
4-
(binding)
5-
] @statement
3+
;; Any top-level expression that isn't a comment is a statement
4+
(
5+
(source_code
6+
(_) @statement
7+
) @_.iteration
8+
(#not-type? @statement comment)
9+
)
10+
(source_code) @comment.iteration
11+
12+
;; Any foo = <expression> anywhere is a statement
13+
(binding) @statement
14+
(binding_set) @map.iteration @list.iteration @ifStatement.iteration
15+
616
;; This matches assert statements as stand-alone statements. This
717
;; is because it's common to have a series of assert statements in a file, which
818
;; would otherwise all match as a single statement. See the playground/nix/asserts.nix
919
;; file for an example.
10-
(assert_expression
11-
"assert" @statement.start
12-
condition: (_) @condition
13-
";" @statement.end
14-
) @_.domain
15-
(binding_set) @map.iteration @list.iteration @ifStatement.iteration
16-
(source_code) @statement.iteration @map.iteration @comment.iteration
20+
(
21+
(assert_expression
22+
"assert" @statement.start
23+
condition: (_) @condition
24+
";" @statement.end
25+
body: (_)
26+
) @_.domain
27+
(#not-parent-type? @_.domain binding)
28+
)
1729

1830
;;!! let
1931
;;!! a = 1;
@@ -95,9 +107,14 @@
95107
;;! ^^^^^^^^ Func1 due to currying
96108
;;! ^^^^^^^^^^^ Func2 due to currying
97109
(function_expression
98-
universal: (identifier) @argumentOrParameter
110+
[
111+
;; Match a: style arg
112+
(identifier)
113+
;; Match { a, b }: style
114+
(formals)
115+
] @argumentOrParameter
99116
body: (_) @anonymousFunction.interior
100-
) @anonymousFunction @argumentOrParameter.iteration
117+
) @_.domain @anonymousFunction @argumentOrParameter.iteration
101118

102119
;; We define the named function as the full assignment of the lambda
103120
;; This means funk name becomes the variable holding the lambda

0 commit comments

Comments
 (0)