Shells in OCaml
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

Until compound commands

+36 -4
+11 -4
src/lib/eval.ml
··· 778 778 in 779 779 loop (Exit.zero ctx) 780 780 781 + and handle_until_clause ctx 782 + (Until ((term, sep), (term', sep')) : Ast.until_clause) = 783 + let rec loop exit_so_far = 784 + let running_ctx = Exit.value exit_so_far in 785 + match exec running_ctx (term, Some sep) with 786 + | Exit.Zero _ -> exit_so_far (* TODO: Context? *) 787 + | Exit.Nonzero { value = ctx; _ } -> loop (exec ctx (term', Some sep')) 788 + in 789 + loop (Exit.zero ctx) 790 + 781 791 and handle_compound_command ctx v : ctx Exit.t = 782 792 match v with 783 793 | Ast.ForClause fc -> handle_for_clause ctx fc ··· 786 796 | Ast.Subshell s -> exec_subshell ctx s 787 797 | Ast.CaseClause cases -> handle_case_clause ctx cases 788 798 | Ast.WhileClause while_ -> handle_while_clause ctx while_ 789 - | _ as c -> 790 - Fmt.epr "Compound command not supported: %a\n%!" yojson_pp 791 - (Ast.compound_command_to_yojson c); 792 - exit 127 799 + | Ast.UntilClause until -> handle_until_clause ctx until 793 800 794 801 and handle_function_application (ctx : ctx) ~name argv : ctx Exit.t option = 795 802 match List.assoc_opt name ctx.functions with
+25
test/while.t
··· 23 23 Iteration 3... 24 24 Iteration 4... 25 25 Iteration 5... 26 + 27 + Also until loops. 28 + 29 + $ cat > test.sh << EOF 30 + > i=1 31 + > 32 + > until [ "\$i" -ge 5 ] 33 + > do 34 + > echo "Iteration \$i..." 35 + > i=\$((i + 1)) 36 + > done 37 + > 38 + > EOF 39 + 40 + 41 + $ sh test.sh 42 + Iteration 1... 43 + Iteration 2... 44 + Iteration 3... 45 + Iteration 4... 46 + $ msh test.sh 47 + Iteration 1... 48 + Iteration 2... 49 + Iteration 3... 50 + Iteration 4...