rable 0.2.0

A Rust implementation of the Parable bash parser — complete GNU Bash 5.3-compatible parsing with Python bindings
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
# Iteration 5: Redirections - comprehensive edge cases

# === Output redirects ===

=== output redirect
echo foo > file.txt
---
(command (word "echo") (word "foo") (redirect ">" "file.txt"))
---


=== output redirect no space before
echo foo> file.txt
---
(command (word "echo") (word "foo") (redirect ">" "file.txt"))
---


=== output redirect no space after
echo foo >file.txt
---
(command (word "echo") (word "foo") (redirect ">" "file.txt"))
---


=== output redirect no spaces
echo foo>file.txt
---
(command (word "echo") (word "foo") (redirect ">" "file.txt"))
---


=== output to dev null
whoami > /dev/null
---
(command (word "whoami") (redirect ">" "/dev/null"))
---


=== output redirect quoted target
echo foo > "file with spaces.txt"
---
(command (word "echo") (word "foo") (redirect ">" ""file with spaces.txt""))
---


# === Append redirects ===

=== append redirect
echo foo >> file.txt
---
(command (word "echo") (word "foo") (redirect ">>" "file.txt"))
---


=== append no spaces
echo foo>>file.txt
---
(command (word "echo") (word "foo") (redirect ">>" "file.txt"))
---


=== append to log
date >> /var/log/myapp.log
---
(command (word "date") (redirect ">>" "/var/log/myapp.log"))
---


# === Input redirects ===

=== input redirect
cat < file.txt
---
(command (word "cat") (redirect "<" "file.txt"))
---


=== input redirect no spaces
cat<file.txt
---
(command (word "cat") (redirect "<" "file.txt"))
---


=== input with arguments
wc -l < input.txt
---
(command (word "wc") (word "-l") (redirect "<" "input.txt"))
---


=== sort from file
sort < unsorted.txt
---
(command (word "sort") (redirect "<" "unsorted.txt"))
---


# === File descriptor redirects ===

=== stderr redirect
cmd 2> errors.txt
---
(command (word "cmd") (redirect ">" "errors.txt"))
---


=== stderr append
cmd 2>> errors.txt
---
(command (word "cmd") (redirect ">>" "errors.txt"))
---


=== stderr to dev null
cmd 2> /dev/null
---
(command (word "cmd") (redirect ">" "/dev/null"))
---


=== stdout and stderr separate
cmd > out.txt 2> err.txt
---
(command (word "cmd") (redirect ">" "out.txt") (redirect ">" "err.txt"))
---


=== fd3 redirect
cmd 3> custom.txt
---
(command (word "cmd") (redirect ">" "custom.txt"))
---


=== fd9 redirect
cmd 9> fd9.txt
---
(command (word "cmd") (redirect ">" "fd9.txt"))
---


# === File descriptor duplication ===

=== stderr to stdout
cmd 2>&1
---
(command (word "cmd") (redirect ">&" 1))
---


=== stdout to stderr
echo error >&2
---
(command (word "echo") (word "error") (redirect ">&" 2))
---


=== stdout and stderr combined
cmd > out.txt 2>&1
---
(command (word "cmd") (redirect ">" "out.txt") (redirect ">&" 1))
---


=== stderr first then stdout
cmd 2>&1 > out.txt
---
(command (word "cmd") (redirect ">&" 1) (redirect ">" "out.txt"))
---


# === Multiple redirects ===

=== input and output
cmd < in.txt > out.txt
---
(command (word "cmd") (redirect "<" "in.txt") (redirect ">" "out.txt"))
---


=== three redirects
cmd < in.txt > out.txt 2> err.txt
---
(command (word "cmd") (redirect "<" "in.txt") (redirect ">" "out.txt") (redirect ">" "err.txt"))
---


=== redirect before command args
< input.txt cat
---
(command (word "cat") (redirect "<" "input.txt"))
---


=== redirect between args
cat < input.txt -n
---
(command (word "cat") (word "-n") (redirect "<" "input.txt"))
---


# === Here strings ===

=== here string simple
cat <<< "hello"
---
(command (word "cat") (redirect "<<<" ""hello""))
---


=== here string single quoted
cat <<< 'hello world'
---
(command (word "cat") (redirect "<<<" "'hello world'"))
---


=== here string bare word
cat <<< hello
---
(command (word "cat") (redirect "<<<" "hello"))
---


=== here string with fd
cat 0<<< "hello"
---
(command (word "cat") (redirect "<<<" ""hello""))
---


# === Redirects with special targets ===

=== redirect to path with spaces quoted
cmd > "/path/with spaces/file.txt"
---
(command (word "cmd") (redirect ">" ""/path/with spaces/file.txt""))
---


=== redirect to glob pattern
cmd > *.log
---
(command (word "cmd") (redirect ">" "*.log"))
---


=== redirect to path with dots
cmd > ../output/file.txt
---
(command (word "cmd") (redirect ">" "../output/file.txt"))
---


# === From tree-sitter-bash ===

=== redirect at start
2>&1 whoami
---
(command (word "whoami") (redirect ">&" 1))
---


=== redirect stderr to stdout for echo
echo "foobar" >&2
---
(command (word "echo") (word "\"foobar\"") (redirect ">&" 2))
---


# === Noclobber override (if supported) ===

=== noclobber override
whoami >| /dev/null
---
(command (word "whoami") (redirect ">|" "/dev/null"))
---


# === Combined stdout/stderr redirects (&>) ===

=== combined redirect to dev null
ls &>/dev/null
---
(command (word "ls") (redirect "&>" "/dev/null"))
---


=== combined redirect to file
cmd &> output.log
---
(command (word "cmd") (redirect "&>" "output.log"))
---


=== combined redirect append
cmd &>> output.log
---
(command (word "cmd") (redirect "&>>" "output.log"))
---


# === Combined redirect edge cases ===

=== combined redirect no space
cmd &>file.log
---
(command (word "cmd") (redirect "&>" "file.log"))
---


=== combined append no space
cmd &>>file.log
---
(command (word "cmd") (redirect "&>>" "file.log"))
---


=== alternative combined form
cmd >& output.log
---
(command (word "cmd") (redirect ">&" "output.log"))
---


=== alternative combined no space
cmd >&output.log
---
(command (word "cmd") (redirect ">&" "output.log"))
---


=== combined with other redirect
cmd &> out.log < in.txt
---
(command (word "cmd") (redirect "&>" "out.log") (redirect "<" "in.txt"))
---


=== combined after other redirect
cmd < in.txt &> out.log
---
(command (word "cmd") (redirect "<" "in.txt") (redirect "&>" "out.log"))
---


=== combined before command
&> log.txt cmd
---
(command (word "cmd") (redirect "&>" "log.txt"))
---


# === Close file descriptor ===

=== close stdout
cmd >&-
---
(command (word "cmd") (redirect ">&-" 0))
---


=== close stderr
cmd 2>&-
---
(command (word "cmd") (redirect ">&-" 0))
---


=== close stdin
cmd <&-
---
(command (word "cmd") (redirect ">&-" 0))
---


=== close fd3
cmd 3>&-
---
(command (word "cmd") (redirect ">&-" 0))
---


=== close input fd3
cmd 3<&-
---
(command (word "cmd") (redirect ">&-" 0))
---


=== close after dup
cmd 3>&1 3>&-
---
(command (word "cmd") (redirect ">&" 1) (redirect ">&-" 0))
---


# === Move file descriptor (dup and close) ===

=== move fd input
cmd 3<&0-
---
(command (word "cmd") (redirect "<&" 0))
---


=== move fd output
cmd 3>&1-
---
(command (word "cmd") (redirect ">&" 1))
---


# === Mixed brutal patterns ===

=== multiple combined redirects
cmd &> out1.log 2>&1 &>> out2.log
---
(command (word "cmd") (redirect "&>" "out1.log") (redirect ">&" 1) (redirect "&>>" "out2.log"))
---


=== combined with here string
cmd &> log.txt <<< "input"
---
(command (word "cmd") (redirect "&>" "log.txt") (redirect "<<<" ""input""))
---


=== combined in pipeline
cmd1 &> /dev/null | cmd2
---
(pipe (command (word "cmd1") (redirect "&>" "/dev/null")) (command (word "cmd2")))
---


=== combined in list with background
cmd1 &> log1.txt & cmd2 &> log2.txt
---
(background (command (word "cmd1") (redirect "&>" "log1.txt")) (command (word "cmd2") (redirect "&>" "log2.txt")))
---


=== combined in and list
cmd1 &> log1.txt && cmd2 &> log2.txt
---
(and (command (word "cmd1") (redirect "&>" "log1.txt")) (command (word "cmd2") (redirect "&>" "log2.txt")))
---


=== combined with stderr dup
cmd 2>&1 &> file.log
---
(command (word "cmd") (redirect ">&" 1) (redirect "&>" "file.log"))
---


=== combined in subshell
(cmd &> log.txt)
---
(subshell (command (word "cmd") (redirect "&>" "log.txt")))
---


=== combined in brace group
{ cmd &> log.txt; }
---
(brace-group (command (word "cmd") (redirect "&>" "log.txt")))
---