Skip to content

Commit 0196b73

Browse files
author
fidgetingbits
committed
Fixes based on Pokey review
- iterator -> iteration - Calls are now also @commands - Item iteration for arrays - Comment no longer matches as a statement - Better handling of local / declare -a in variable assignments
1 parent ec4889c commit 0196b73

File tree

1 file changed

+76
-50
lines changed

1 file changed

+76
-50
lines changed

queries/shellscript.scm

Lines changed: 76 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,63 @@
22
;; Statements
33
;;
44

5-
(program
5+
(
6+
(program
67
(_) @statement
8+
)
9+
(#not-type? @statement comment)
710
)
811
[
9-
(if_statement)
10-
(command)
11-
(function_definition)
12-
(variable_assignment)
12+
(if_statement)
13+
(command)
14+
(function_definition)
15+
(declaration_command)
1316
] @statement
1417

18+
(
19+
(_
20+
(variable_assignment) @statement
21+
(#not-parent-type? @statement declaration_command)
22+
)
23+
)
24+
1525
;;
1626
;; Conditionals
1727
;;
1828

1929
;;!!
2030
(if_statement
21-
(_)*
22-
"then"
23-
(_)*
24-
"fi"
31+
(_)*
32+
"then"
33+
(_)*
34+
"fi"
2535
) @ifStatement @branch
2636

2737
(if_statement
28-
"if" @branch.start.startOf
29-
(_)
30-
"then"
31-
(_)* @branch.interior
32-
.
33-
[
34-
(elif_clause)
35-
(else_clause)
36-
] @branch.end.startOf
38+
"if" @branch.start.startOf
39+
(_)
40+
"then"
41+
(_)* @branch.interior
42+
.
43+
[
44+
(elif_clause)
45+
(else_clause)
46+
] @branch.end.startOf
3747
) @ifStatement @branch.iteration @_.domain
3848

3949
(elif_clause
40-
(_)* @condition
41-
"then"
42-
(_)* @branch.interior
50+
(_)* @condition
51+
"then"
52+
(_)* @branch.interior
4353
) @branch
4454

4555
(else_clause
46-
"else" @branch.interior.start.endOf
47-
(_) @branch.interior.end.endOf
56+
"else" @branch.interior.start.endOf
57+
(_) @branch.interior.end.endOf
4858
) @branch
4959

5060
(_
51-
condition: (_) @condition
61+
condition: (_) @condition
5262
) @_.domain
5363

5464
;;
@@ -59,10 +69,10 @@
5969
;;! ^^^^^^^^^^^^^
6070
;;! -------------
6171
(array
62-
"(" @_.interior.start.endOf
63-
(_)? @collectionItem
64-
")" @_.interior.end.startOf
65-
) @list
72+
"(" @_.interior.start.endOf
73+
(_)? @collectionItem
74+
")" @_.interior.end.startOf
75+
) @list @collectionItem.iteration
6676

6777
;;
6878
;; Strings
@@ -74,15 +84,15 @@
7484

7585
;;!! var="foo"
7686
;;! ^^^^^
77-
(string) @string @textFragment @argumentOrParameter.iteration
87+
(string) @string @textFragment
7888

7989
;;!! var="foo ${bar}"
8090
;;! ^^^^^^
8191
(string
82-
[
83-
(expansion)
84-
(simple_expansion)
85-
] @argumentOrParameter
92+
[
93+
(expansion)
94+
(simple_expansion)
95+
] @argumentOrParameter
8696
)
8797

8898
;;
@@ -92,8 +102,8 @@
92102
;;!! echo "foo"
93103
;;! ^^^^^
94104
(_
95-
argument: (_) @argumentOrParameter
96-
) @_.iterator
105+
argument: (_) @argumentOrParameter
106+
) @_.iteration
97107

98108
;; call:
99109
;;!! echo "foo"
@@ -103,8 +113,8 @@
103113
;;! ^^^^
104114
;;! ----------
105115
(command
106-
name: (_) @functionCallee
107-
) @_.domain @functionCall
116+
name: (_) @functionCallee
117+
) @_.domain @functionCall @command
108118

109119
;;!! function foo() {
110120
;;! ^^^
@@ -114,7 +124,7 @@
114124
;;!! }
115125
;;! -
116126
(function_definition
117-
name: (_) @functionName
127+
name: (_) @functionName
118128
) @_.domain
119129

120130
;; FIXME: Need to support redirections
@@ -127,13 +137,13 @@
127137
;;!! }
128138
;;! -
129139
(function_definition
130-
body: (_
131-
"{"
132-
.
133-
(_)? @_.interior
134-
.
135-
"}"
136-
)
140+
body: (_
141+
"{"
142+
.
143+
(_)? @_.interior
144+
.
145+
"}"
146+
)
137147
) @namedFunction @_.domain
138148

139149
;;
@@ -144,18 +154,34 @@
144154
;;! ^^^
145155
;;! xxxx
146156
;;! ---------
147-
(variable_assignment
157+
(
158+
(variable_assignment
148159
name: (_) @name @_.trailing.start.startOf
149160
.
150161
"=" @_.trailing.end.endOf
151-
) @_.domain
162+
) @dummy @_.domain
163+
(#not-parent-type? @dummy declaration_command)
164+
)
165+
166+
;;!! local foo="bar"
167+
;;! ^^^
168+
;;! xxxxxxxxxx
169+
;;! ---------------
170+
(declaration_command
171+
"local" @_.domain.start.startOf @_.trailing.start.startOf
172+
(variable_assignment
173+
name: (_) @name
174+
.
175+
"=" @_.trailing.end.endOf
176+
) @_.domain.end.endOf
177+
)
152178

153179
;;!! foo="bar"
154180
;;! ^^^^^
155181
;;! xxxxxx
156182
;;! ---------
157183
(variable_assignment
158-
"=" @value.leading.start.startOf
159-
.
160-
value: (_) @value @value.leading.end.endOf
184+
"=" @value.leading.start.startOf
185+
.
186+
value: (_) @value @value.leading.end.endOf
161187
) @_.domain

0 commit comments

Comments
 (0)