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
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
# Iteration 8: Loops - while/until/for with do/done
# Comprehensive edge cases from tree-sitter-bash, Oil Shell, POSIX spec

# === Basic while loops ===

=== simple while
while true; do echo yes; done
---
(while (command (word "true")) (command (word "echo") (word "yes")))
---


=== while with test
while [ -f file ]; do sleep 1; done
---
(while (command (word "[") (word "-f") (word "file") (word "]")) (command (word "sleep") (word "1")))
---


=== while with pipeline condition
while read line; do echo "$line"; done
---
(while (command (word "read") (word "line")) (command (word "echo") (word "\"$line\"")))
---


=== while with complex condition
while cmd1 && cmd2; do echo both; done
---
(while (and (command (word "cmd1")) (command (word "cmd2"))) (command (word "echo") (word "both")))
---


=== while with or condition
while cmd1 || cmd2; do echo either; done
---
(while (or (command (word "cmd1")) (command (word "cmd2"))) (command (word "echo") (word "either")))
---


=== while with multiple body commands
while true; do echo a; echo b; done
---
(while (command (word "true")) (semi (command (word "echo") (word "a")) (command (word "echo") (word "b"))))
---


=== while false does nothing
while false; do echo never; done
---
(while (command (word "false")) (command (word "echo") (word "never")))
---


=== while with colon condition
while :; do echo forever; break; done
---
(while (command (word ":")) (semi (command (word "echo") (word "forever")) (command (word "break"))))
---


# === Multiple commands in while condition (from tree-sitter-bash) ===

=== while with multiple condition commands
while echo a; echo b; do echo body; break; done
---
(while (semi (command (word "echo") (word "a")) (command (word "echo") (word "b"))) (semi (command (word "echo") (word "body")) (command (word "break"))))
---


=== while with pipeline in condition
while cat file | grep pattern; do echo found; break; done
---
(while (pipe (command (word "cat") (word "file")) (command (word "grep") (word "pattern"))) (semi (command (word "echo") (word "found")) (command (word "break"))))
---


# === Basic until loops ===

=== simple until
until false; do echo yes; done
---
(until (command (word "false")) (command (word "echo") (word "yes")))
---


=== until with test
until [ -f file ]; do sleep 1; done
---
(until (command (word "[") (word "-f") (word "file") (word "]")) (command (word "sleep") (word "1")))
---


=== until with complex condition
until cmd1 || cmd2; do echo waiting; done
---
(until (or (command (word "cmd1")) (command (word "cmd2"))) (command (word "echo") (word "waiting")))
---


=== until with multiple body commands
until false; do echo a; echo b; done
---
(until (command (word "false")) (semi (command (word "echo") (word "a")) (command (word "echo") (word "b"))))
---


=== until true exits immediately
until true; do echo never; done
---
(until (command (word "true")) (command (word "echo") (word "never")))
---


=== until with and condition
until cmd1 && cmd2; do echo waiting; done
---
(until (and (command (word "cmd1")) (command (word "cmd2"))) (command (word "echo") (word "waiting")))
---


# === Basic for loops ===

=== for with word list
for x in a b c; do echo $x; done
---
(for (word "x") (in (word "a") (word "b") (word "c")) (command (word "echo") (word "$x")))
---


=== for with single word
for x in item; do echo $x; done
---
(for (word "x") (in (word "item")) (command (word "echo") (word "$x")))
---


=== for with many words
for i in 1 2 3 4 5; do echo $i; done
---
(for (word "i") (in (word "1") (word "2") (word "3") (word "4") (word "5")) (command (word "echo") (word "$i")))
---


=== for with quoted words
for f in "file one" "file two"; do cat "$f"; done
---
(for (word "f") (in (word "\"file one\"") (word "\"file two\"")) (command (word "cat") (word "\"$f\"")))
---


=== for with single quoted words
for f in 'file one' 'file two'; do cat "$f"; done
---
(for (word "f") (in (word "'file one'") (word "'file two'")) (command (word "cat") (word "\"$f\"")))
---


=== for with glob pattern
for f in *.txt; do cat $f; done
---
(for (word "f") (in (word "*.txt")) (command (word "cat") (word "$f")))
---


=== for with multiple globs
for f in *.txt *.md; do cat $f; done
---
(for (word "f") (in (word "*.txt") (word "*.md")) (command (word "cat") (word "$f")))
---


=== for with question mark glob
for f in file?.txt; do cat $f; done
---
(for (word "f") (in (word "file?.txt")) (command (word "cat") (word "$f")))
---


=== for with bracket glob
for f in file[0-9].txt; do cat $f; done
---
(for (word "f") (in (word "file[0-9].txt")) (command (word "cat") (word "$f")))
---


=== for with variable expansion
for x in $items; do echo $x; done
---
(for (word "x") (in (word "$items")) (command (word "echo") (word "$x")))
---


=== for with array expansion
for x in "${array[@]}"; do echo $x; done
---
(for (word "x") (in (word "\"${array[@]}\"")) (command (word "echo") (word "$x")))
---


=== for without in clause
for x; do echo $x; done
---
(for (word "x") (in (word "\"$@\"")) (command (word "echo") (word "$x")))
---


=== for with multiple body commands
for x in a b; do echo start; echo $x; echo end; done
---
(for (word "x") (in (word "a") (word "b")) (semi (semi (command (word "echo") (word "start")) (command (word "echo") (word "$x"))) (command (word "echo") (word "end"))))
---


# === For loop with special variable names (from Oil Shell) ===

=== for using in as variable name
for in in a b c; do echo $in; done
---
(for (word "in") (in (word "a") (word "b") (word "c")) (command (word "echo") (word "$in")))
---


=== for using do as variable name
for do in a b c; do echo $do; done
---
(for (word "do") (in (word "a") (word "b") (word "c")) (command (word "echo") (word "$do")))
---


=== for with underscore variable
for _ in a b c; do echo $_; done
---
(for (word "_") (in (word "a") (word "b") (word "c")) (command (word "echo") (word "$_")))
---


=== for with long variable name
for very_long_variable_name in a b c; do echo $very_long_variable_name; done
---
(for (word "very_long_variable_name") (in (word "a") (word "b") (word "c")) (command (word "echo") (word "$very_long_variable_name")))
---


# === For loop word list edge cases ===

=== for with tilde expansion
for name in ~/src ~/git; do echo $name; done
---
(for (word "name") (in (word "~/src") (word "~/git")) (command (word "echo") (word "$name")))
---


=== for with path words
for dir in /usr/bin /usr/local/bin /opt/bin; do echo $dir; done
---
(for (word "dir") (in (word "/usr/bin") (word "/usr/local/bin") (word "/opt/bin")) (command (word "echo") (word "$dir")))
---


=== for with mixed quoted and unquoted
for x in a "b c" d; do echo $x; done
---
(for (word "x") (in (word "a") (word "\"b c\"") (word "d")) (command (word "echo") (word "$x")))
---


=== for with equals in words
for opt in --foo=bar --baz=qux; do echo $opt; done
---
(for (word "opt") (in (word "--foo=bar") (word "--baz=qux")) (command (word "echo") (word "$opt")))
---


=== for with command substitution in words
for x in $(seq 1 3); do echo $x; done
---
(for (word "x") (in (word "$(seq 1 3)")) (command (word "echo") (word "$x")))
---


# === Loops with newlines ===

=== while with newlines
while true
do
echo yes
done
---
(while (command (word "true")) (command (word "echo") (word "yes")))
---


=== until with newlines
until false
do
echo yes
done
---
(until (command (word "false")) (command (word "echo") (word "yes")))
---


=== for with newlines
for x in a b c
do
echo $x
done
---
(for (word "x") (in (word "a") (word "b") (word "c")) (command (word "echo") (word "$x")))
---


=== for multiline body
for x in a b
do
echo start
echo $x
echo end
done
---
(for (word "x") (in (word "a") (word "b")) (semi (semi (command (word "echo") (word "start")) (command (word "echo") (word "$x"))) (command (word "echo") (word "end"))))
---


=== while with newline after condition
while true; do
echo yes
done
---
(while (command (word "true")) (command (word "echo") (word "yes")))
---


# === Deeply nested loops ===

=== nested while
while a; do while b; do echo inner; done; done
---
(while (command (word "a")) (while (command (word "b")) (command (word "echo") (word "inner"))))
---


=== nested for
for x in a b; do for y in 1 2; do echo $x$y; done; done
---
(for (word "x") (in (word "a") (word "b")) (for (word "y") (in (word "1") (word "2")) (command (word "echo") (word "$x$y"))))
---


=== for inside while
while true; do for x in a b; do echo $x; done; done
---
(while (command (word "true")) (for (word "x") (in (word "a") (word "b")) (command (word "echo") (word "$x"))))
---


=== while inside for
for x in a b; do while test $x; do echo $x; break; done; done
---
(for (word "x") (in (word "a") (word "b")) (while (command (word "test") (word "$x")) (semi (command (word "echo") (word "$x")) (command (word "break")))))
---


=== triple nested for
for x in a b; do for y in 1 2; do for z in p q; do echo $x$y$z; done; done; done
---
(for (word "x") (in (word "a") (word "b")) (for (word "y") (in (word "1") (word "2")) (for (word "z") (in (word "p") (word "q")) (command (word "echo") (word "$x$y$z")))))
---


=== until inside while inside for
for x in a; do while true; do until false; do echo deep; break 3; done; done; done
---
(for (word "x") (in (word "a")) (while (command (word "true")) (until (command (word "false")) (semi (command (word "echo") (word "deep")) (command (word "break") (word "3"))))))
---


=== nested while with newlines
while a
do
while b
do
echo inner
done
done
---
(while (command (word "a")) (while (command (word "b")) (command (word "echo") (word "inner"))))
---


# === Loops in pipelines and lists ===

=== while in pipeline
while read line; do echo $line; done | cat
---
(pipe (while (command (word "read") (word "line")) (command (word "echo") (word "$line"))) (command (word "cat")))
---


=== for in pipeline
for x in a b c; do echo $x; done | wc -l
---
(pipe (for (word "x") (in (word "a") (word "b") (word "c")) (command (word "echo") (word "$x"))) (command (word "wc") (word "-l")))
---


=== while in and list
while true; do echo yes; break; done && echo done
---
(and (while (command (word "true")) (semi (command (word "echo") (word "yes")) (command (word "break")))) (command (word "echo") (word "done")))
---


=== while in or list
while false; do echo no; done || echo fallback
---
(or (while (command (word "false")) (command (word "echo") (word "no"))) (command (word "echo") (word "fallback")))
---


=== for in background
for x in a b c; do echo $x; done &
---
(background (for (word "x") (in (word "a") (word "b") (word "c")) (command (word "echo") (word "$x"))))
---


=== multiple loops in sequence
for x in a; do echo $x; done; for y in b; do echo $y; done
---
(semi (for (word "x") (in (word "a")) (command (word "echo") (word "$x"))) (for (word "y") (in (word "b")) (command (word "echo") (word "$y"))))
---


=== loop in middle of pipeline
echo input | while read x; do echo $x; done | cat
---
(pipe (command (word "echo") (word "input")) (pipe (while (command (word "read") (word "x")) (command (word "echo") (word "$x"))) (command (word "cat"))))
---


=== multiple loops in pipeline
for x in a; do echo $x; done | while read y; do echo $y; done
---
(pipe (for (word "x") (in (word "a")) (command (word "echo") (word "$x"))) (while (command (word "read") (word "y")) (command (word "echo") (word "$y"))))
---


=== loop after command in sequence
echo before; while true; do echo loop; break; done
---
(semi (command (word "echo") (word "before")) (while (command (word "true")) (semi (command (word "echo") (word "loop")) (command (word "break")))))
---


# === Loops with compound commands in body ===

=== while with if in body
while read line; do if [ -n "$line" ]; then echo $line; fi; done
---
(while (command (word "read") (word "line")) (if (command (word "[") (word "-n") (word "\"$line\"") (word "]")) (command (word "echo") (word "$line"))))
---


=== for with if else in body
for x in a b c; do if [ "$x" = "b" ]; then echo match; else echo no; fi; done
---
(for (word "x") (in (word "a") (word "b") (word "c")) (if (command (word "[") (word "\"$x\"") (word "=") (word "\"b\"") (word "]")) (command (word "echo") (word "match")) (command (word "echo") (word "no"))))
---


=== for with subshell in body
for x in a b; do (echo $x); done
---
(for (word "x") (in (word "a") (word "b")) (subshell (command (word "echo") (word "$x"))))
---


=== for with brace group in body
for x in a b; do { echo $x; }; done
---
(for (word "x") (in (word "a") (word "b")) (brace-group (command (word "echo") (word "$x"))))
---


=== while with nested while in body
while a; do while b; do echo inner; break; done; done
---
(while (command (word "a")) (while (command (word "b")) (semi (command (word "echo") (word "inner")) (command (word "break")))))
---


=== for with nested for in body
for x in a b; do for y in 1 2; do echo $x$y; done; done
---
(for (word "x") (in (word "a") (word "b")) (for (word "y") (in (word "1") (word "2")) (command (word "echo") (word "$x$y"))))
---


# === Loops with compound commands in condition ===

=== while with subshell condition
while (true); do echo yes; break; done
---
(while (subshell (command (word "true"))) (semi (command (word "echo") (word "yes")) (command (word "break"))))
---


=== while with brace group condition
while { true; }; do echo yes; break; done
---
(while (brace-group (command (word "true"))) (semi (command (word "echo") (word "yes")) (command (word "break"))))
---


=== until with subshell condition
until (false); do echo yes; break; done
---
(until (subshell (command (word "false"))) (semi (command (word "echo") (word "yes")) (command (word "break"))))
---


# === Loops with redirections ===

=== while with redirect in body
while read line; do echo $line > out.txt; done
---
(while (command (word "read") (word "line")) (command (word "echo") (word "$line") (redirect ">" "out.txt")))
---


=== for with redirect in body
for f in *.txt; do cat $f >> all.txt; done
---
(for (word "f") (in (word "*.txt")) (command (word "cat") (word "$f") (redirect ">>" "all.txt")))
---


=== while with multiple redirects in body
while read line; do echo $line > out.txt 2>&1; done
---
(while (command (word "read") (word "line")) (command (word "echo") (word "$line") (redirect ">" "out.txt") (redirect ">&" 1)))
---


=== while with input redirect in condition
while read line < input.txt; do echo $line; done
---
(while (command (word "read") (word "line") (redirect "<" "input.txt")) (command (word "echo") (word "$line")))
---


=== for with here string in body
for x in a b; do cat <<< "$x"; done
---
(for (word "x") (in (word "a") (word "b")) (command (word "cat") (redirect "<<<" ""$x"")))
---


# === Loops in compound commands ===

=== while in subshell
(while true; do echo yes; break; done)
---
(subshell (while (command (word "true")) (semi (command (word "echo") (word "yes")) (command (word "break")))))
---


=== for in brace group
{ for x in a b; do echo $x; done; }
---
(brace-group (for (word "x") (in (word "a") (word "b")) (command (word "echo") (word "$x"))))
---


=== while in if body
if true; then while false; do echo no; done; fi
---
(if (command (word "true")) (while (command (word "false")) (command (word "echo") (word "no"))))
---


=== for in if body
if true; then for x in a b; do echo $x; done; fi
---
(if (command (word "true")) (for (word "x") (in (word "a") (word "b")) (command (word "echo") (word "$x"))))
---


=== while in if else
if false; then echo no; else while true; do echo yes; break; done; fi
---
(if (command (word "false")) (command (word "echo") (word "no")) (while (command (word "true")) (semi (command (word "echo") (word "yes")) (command (word "break")))))
---


=== for in elif
if false; then echo no; elif true; then for x in a; do echo $x; done; fi
---
(if (command (word "false")) (command (word "echo") (word "no")) (if (command (word "true")) (for (word "x") (in (word "a")) (command (word "echo") (word "$x")))))
---


=== nested subshells with loops
( (while true; do echo inner; break; done) )
---
(subshell (subshell (while (command (word "true")) (semi (command (word "echo") (word "inner")) (command (word "break"))))))
---


# === Whitespace variations ===

=== while no spaces after semicolons
while true;do echo yes;done
---
(while (command (word "true")) (command (word "echo") (word "yes")))
---


=== for no spaces after semicolons
for x in a b;do echo $x;done
---
(for (word "x") (in (word "a") (word "b")) (command (word "echo") (word "$x")))
---


=== until no spaces
until false;do echo yes;done
---
(until (command (word "false")) (command (word "echo") (word "yes")))
---


=== extra spaces
while   true  ;  do   echo yes  ;  done
---
(while (command (word "true")) (command (word "echo") (word "yes")))
---


=== tabs instead of spaces
while	true;	do	echo yes;	done
---
(while (command (word "true")) (command (word "echo") (word "yes")))
---


=== mixed whitespace in for
for	x   in	 a   b	 c  ;  do   echo $x  ;	done
---
(for (word "x") (in (word "a") (word "b") (word "c")) (command (word "echo") (word "$x")))
---


# === Break and continue ===

=== while with break
while true; do echo once; break; done
---
(while (command (word "true")) (semi (command (word "echo") (word "once")) (command (word "break"))))
---


=== while with continue
while read line; do continue; echo never; done
---
(while (command (word "read") (word "line")) (semi (command (word "continue")) (command (word "echo") (word "never"))))
---


=== for with break
for x in a b c; do echo $x; break; done
---
(for (word "x") (in (word "a") (word "b") (word "c")) (semi (command (word "echo") (word "$x")) (command (word "break"))))
---


=== for with conditional break
for x in a b c; do if [ "$x" = "b" ]; then break; fi; echo $x; done
---
(for (word "x") (in (word "a") (word "b") (word "c")) (semi (if (command (word "[") (word "\"$x\"") (word "=") (word "\"b\"") (word "]")) (command (word "break"))) (command (word "echo") (word "$x"))))
---


=== break with level number
for x in a b; do for y in 1 2; do break 2; done; done
---
(for (word "x") (in (word "a") (word "b")) (for (word "y") (in (word "1") (word "2")) (command (word "break") (word "2"))))
---


=== continue with level number
for x in a b; do for y in 1 2; do continue 2; done; done
---
(for (word "x") (in (word "a") (word "b")) (for (word "y") (in (word "1") (word "2")) (command (word "continue") (word "2"))))
---


=== break 1 explicit
while true; do break 1; done
---
(while (command (word "true")) (command (word "break") (word "1")))
---


=== continue 1 explicit
while true; do continue 1; done
---
(while (command (word "true")) (command (word "continue") (word "1")))
---


=== break in nested if
for x in a b; do if true; then break; fi; done
---
(for (word "x") (in (word "a") (word "b")) (if (command (word "true")) (command (word "break"))))
---


# === Complex real-world examples ===

=== process all files
for f in *.sh; do chmod +x "$f"; done
---
(for (word "f") (in (word "*.sh")) (command (word "chmod") (word "+x") (word "\"$f\"")))
---


=== read lines from file
while IFS= read -r line; do echo "$line"; done
---
(while (command (word "IFS=") (word "read") (word "-r") (word "line")) (command (word "echo") (word "\"$line\"")))
---


=== countdown
while [ $n -gt 0 ]; do echo $n; done
---
(while (command (word "[") (word "$n") (word "-gt") (word "0") (word "]")) (command (word "echo") (word "$n")))
---


=== retry loop
until curl -s http://localhost; do sleep 1; done
---
(until (command (word "curl") (word "-s") (word "http://localhost")) (command (word "sleep") (word "1")))
---


=== iterate with index
for i in 1 2 3 4 5; do echo "Item $i"; done
---
(for (word "i") (in (word "1") (word "2") (word "3") (word "4") (word "5")) (command (word "echo") (word "\"Item $i\"")))
---


=== find and process
for f in $(find . -name "*.txt"); do echo $f; done
---
(for (word "f") (in (word "$(find . -name \"*.txt\")")) (command (word "echo") (word "$f")))
---


=== parallel background loops
for x in a b c; do process $x & done
---
(for (word "x") (in (word "a") (word "b") (word "c")) (background (command (word "process") (word "$x"))))
---


=== wait for condition
until [ -f /tmp/ready ]; do sleep 0.1; done
---
(until (command (word "[") (word "-f") (word "/tmp/ready") (word "]")) (command (word "sleep") (word "0.1")))
---


=== loop with error handling
for f in *.txt; do cat "$f" || echo "failed: $f"; done
---
(for (word "f") (in (word "*.txt")) (or (command (word "cat") (word "\"$f\"")) (command (word "echo") (word "\"failed: $f\""))))
---


=== loop with and chain
for f in *.txt; do test -f "$f" && cat "$f"; done
---
(for (word "f") (in (word "*.txt")) (and (command (word "test") (word "-f") (word "\"$f\"")) (command (word "cat") (word "\"$f\""))))
---


=== complex condition with double bracket
while [[ -f file && ! -f done ]]; do sleep 1; done
---
(while (cond (cond-and (cond-unary "-f" (cond-term "file")) (cond-unary "-f" (cond-term "done")))) (command (word "sleep") (word "1")))
---


=== for over command output
for user in $(cut -d: -f1 /etc/passwd); do echo $user; done
---
(for (word "user") (in (word "$(cut -d: -f1 /etc/passwd)")) (command (word "echo") (word "$user")))
---


=== nested loop with complex body
for i in 1 2; do for j in a b; do echo "$i$j"; if [ "$j" = "b" ]; then continue 2; fi; done; done
---
(for (word "i") (in (word "1") (word "2")) (for (word "j") (in (word "a") (word "b")) (semi (command (word "echo") (word "\"$i$j\"")) (if (command (word "[") (word "\"$j\"") (word "=") (word "\"b\"") (word "]")) (command (word "continue") (word "2"))))))
---

=== for loop with command substitution as variable name
for $(echo i) in a b; do echo $i; done
---
(for (word "$(echo i)") (in (word "a") (word "b")) (command (word "echo") (word "$i")))
---

=== for loop with brace group body instead of do/done
for x in a b; { echo $x; }
---
(for (word "x") (in (word "a") (word "b")) (command (word "echo") (word "$x")))
---

=== for loop done with line continuation into pipe
for i in x; do echo y; done\
| cat
---
(pipe (for (word "i") (in (word "x")) (command (word "echo") (word "y"))) (command (word "cat")))
---