@@ -97,45 +97,45 @@ module.exports = grammar({
97
97
) ,
98
98
99
99
redirected_statement : $ => prec ( - 1 , seq (
100
- $ . _statement ,
101
- repeat1 ( choice (
100
+ field ( 'body' , $ . _statement ) ,
101
+ field ( 'redirect' , repeat1 ( choice (
102
102
$ . file_redirect ,
103
103
$ . heredoc_redirect ,
104
104
$ . herestring_redirect
105
- ) )
105
+ ) ) )
106
106
) ) ,
107
107
108
108
for_statement : $ => seq (
109
109
'for' ,
110
- $ . _simple_variable_name ,
110
+ field ( 'variable' , $ . _simple_variable_name ) ,
111
111
optional ( seq (
112
112
'in' ,
113
- repeat1 ( $ . _literal )
113
+ field ( 'value' , repeat1 ( $ . _literal ) )
114
114
) ) ,
115
115
$ . _terminator ,
116
- $ . do_group
116
+ field ( 'body' , $ . do_group )
117
117
) ,
118
118
119
119
c_style_for_statement : $ => seq (
120
120
'for' ,
121
121
'((' ,
122
- optional ( $ . _expression ) ,
122
+ field ( 'initializer' , optional ( $ . _expression ) ) ,
123
123
$ . _terminator ,
124
- optional ( $ . _expression ) ,
124
+ field ( 'condition' , optional ( $ . _expression ) ) ,
125
125
$ . _terminator ,
126
- optional ( $ . _expression ) ,
126
+ field ( 'update' , optional ( $ . _expression ) ) ,
127
127
'))' ,
128
128
optional ( ';' ) ,
129
- choice (
129
+ field ( 'body' , choice (
130
130
$ . do_group ,
131
131
$ . compound_statement
132
- )
132
+ ) )
133
133
) ,
134
134
135
135
while_statement : $ => seq (
136
136
'while' ,
137
- $ . _terminated_statement ,
138
- $ . do_group
137
+ field ( 'condition' , $ . _terminated_statement ) ,
138
+ field ( 'body' , $ . do_group )
139
139
) ,
140
140
141
141
do_group : $ => seq (
@@ -146,7 +146,7 @@ module.exports = grammar({
146
146
147
147
if_statement : $ => seq (
148
148
'if' ,
149
- $ . _terminated_statement ,
149
+ field ( 'condition' , $ . _terminated_statement ) ,
150
150
'then' ,
151
151
optional ( $ . _statements2 ) ,
152
152
repeat ( $ . elif_clause ) ,
@@ -168,7 +168,7 @@ module.exports = grammar({
168
168
169
169
case_statement : $ => seq (
170
170
'case' ,
171
- $ . _literal ,
171
+ field ( 'value' , $ . _literal ) ,
172
172
optional ( $ . _terminator ) ,
173
173
'in' ,
174
174
$ . _terminator ,
@@ -180,36 +180,39 @@ module.exports = grammar({
180
180
) ,
181
181
182
182
case_item : $ => seq (
183
- $ . _literal ,
184
- repeat ( seq ( '|' , $ . _literal ) ) ,
183
+ field ( 'value' , $ . _literal ) ,
184
+ repeat ( seq ( '|' , field ( 'value' , $ . _literal ) ) ) ,
185
185
')' ,
186
186
optional ( $ . _statements ) ,
187
187
prec ( 1 , ';;' )
188
188
) ,
189
189
190
190
last_case_item : $ => seq (
191
- $ . _literal ,
192
- repeat ( seq ( '|' , $ . _literal ) ) ,
191
+ field ( 'value' , $ . _literal ) ,
192
+ repeat ( seq ( '|' , field ( 'value' , $ . _literal ) ) ) ,
193
193
')' ,
194
194
optional ( $ . _statements ) ,
195
195
optional ( prec ( 1 , ';;' ) )
196
196
) ,
197
197
198
198
function_definition : $ => seq (
199
199
choice (
200
- seq ( 'function' , $ . word , optional ( seq ( '(' , ')' ) ) ) ,
201
- seq ( $ . word , '(' , ')' )
200
+ seq (
201
+ 'function' ,
202
+ field ( 'name' , $ . word ) ,
203
+ optional ( seq ( '(' , ')' ) )
204
+ ) ,
205
+ seq (
206
+ field ( 'name' , $ . word ) ,
207
+ '(' , ')'
208
+ )
202
209
) ,
203
- $ . compound_statement
210
+ field ( 'body' , $ . compound_statement )
204
211
) ,
205
212
206
213
compound_statement : $ => seq (
207
214
'{' ,
208
- repeat ( seq (
209
- $ . _statement ,
210
- optional ( seq ( '\n' , $ . heredoc_body ) ) ,
211
- $ . _terminator
212
- ) ) ,
215
+ optional ( $ . _statements2 ) ,
213
216
'}'
214
217
) ,
215
218
@@ -272,47 +275,47 @@ module.exports = grammar({
272
275
$ . variable_assignment ,
273
276
$ . file_redirect
274
277
) ) ,
275
- $ . command_name ,
276
- repeat ( choice (
278
+ field ( 'name' , $ . command_name ) ,
279
+ repeat ( field ( 'argument' , choice (
277
280
$ . _literal ,
278
281
seq (
279
282
choice ( '=~' , '==' ) ,
280
283
choice ( $ . _literal , $ . regex )
281
284
)
282
- ) )
285
+ ) ) )
283
286
) ) ,
284
287
285
288
command_name : $ => $ . _literal ,
286
289
287
290
variable_assignment : $ => seq (
288
- choice (
291
+ field ( 'name' , choice (
289
292
$ . variable_name ,
290
293
$ . subscript
291
- ) ,
294
+ ) ) ,
292
295
choice (
293
296
'=' ,
294
297
'+='
295
298
) ,
296
- choice (
299
+ field ( 'value' , choice (
297
300
$ . _literal ,
298
301
$ . array ,
299
302
$ . _empty_value
300
- )
303
+ ) )
301
304
) ,
302
305
303
306
subscript : $ => seq (
304
- $ . variable_name ,
307
+ field ( 'name' , $ . variable_name ) ,
305
308
'[' ,
306
- $ . _literal ,
309
+ field ( 'index' , $ . _literal ) ,
307
310
optional ( $ . _concat ) ,
308
311
']' ,
309
312
optional ( $ . _concat )
310
313
) ,
311
314
312
315
file_redirect : $ => prec . left ( seq (
313
- optional ( $ . file_descriptor ) ,
316
+ field ( 'descriptor' , optional ( $ . file_descriptor ) ) ,
314
317
choice ( '<' , '>' , '>>' , '&>' , '&>>' , '<&' , '>&' ) ,
315
- $ . _literal
318
+ field ( 'destination' , $ . _literal )
316
319
) ) ,
317
320
318
321
heredoc_redirect : $ => seq (
@@ -351,20 +354,20 @@ module.exports = grammar({
351
354
352
355
binary_expression : $ => prec . left ( choice (
353
356
seq (
354
- $ . _expression ,
355
- choice (
357
+ field ( 'left' , $ . _expression ) ,
358
+ field ( 'operator' , choice (
356
359
'=' , '==' , '=~' , '!=' ,
357
360
'+' , '-' , '+=' , '-=' ,
358
361
'<' , '>' , '<=' , '>=' ,
359
362
'||' , '&&' ,
360
363
$ . test_operator
361
- ) ,
362
- $ . _expression
364
+ ) ) ,
365
+ field ( 'right' , $ . _expression )
363
366
) ,
364
367
seq (
365
- $ . _expression ,
366
- choice ( '==' , '=~' ) ,
367
- $ . regex
368
+ field ( 'left' , $ . _expression ) ,
369
+ field ( 'operator' , choice ( '==' , '=~' ) ) ,
370
+ field ( 'right' , $ . regex )
368
371
)
369
372
) ) ,
370
373
0 commit comments