- Commit
- f6739a32df3e1196c8093ec4915222c0c5449f7b
- Parent
- 4da5a6d6d4b15412cba9732ea48bda6c1c75f1f0
- Author
- Pablo <pablo-escobar@riseup.net>
- Date
Cleaned the code a bit
A OCaml module for manipulating unlimited register machines
Cleaned the code a bit
1 file changed, 13 insertions, 12 deletions
Status | File Name | N° Changes | Insertions | Deletions |
Modified | main.ml | 25 | 13 | 12 |
diff --git a/main.ml b/main.ml @@ -34,19 +34,20 @@ let parse_regs (regs : string list) : (int * int) list * int list = usage (); exit 1 and f reg (acc_vals, acc_prints) = - if not (String.starts_with ~prefix:"-R" reg) then fail reg - else let reg' = String.sub reg 2 (String.length reg - 2) in - match String.split_on_char '=' reg' with - | [reg_n] -> - (match int_of_string_opt reg_n with - | Some reg_n -> (acc_vals, reg_n :: acc_prints) - | None -> fail reg) - | [ reg_n ; reg_val ] -> - (match (int_of_string_opt reg_n, int_of_string_opt reg_val) with - | (Some reg_n, Some reg_val) -> + if String.starts_with ~prefix:"-R" reg then + let reg' = String.sub reg 2 (String.length reg - 2) in + match String.split_on_char '=' reg' with + | [reg_n] -> + (match int_of_string_opt reg_n with + | Some reg_n -> (acc_vals, reg_n :: acc_prints) + | None -> fail reg) + | [ reg_n ; reg_val ] -> + (match (int_of_string_opt reg_n, int_of_string_opt reg_val) with + | (Some reg_n, Some reg_val) -> ((reg_n, reg_val) :: acc_vals, acc_prints) - | _ -> fail reg) - | _ -> fail reg + | _ -> fail reg) + | _ -> fail reg + else fail reg in List.fold_right f regs ([], []) (** Parses the [-i] command line argument *)