Skip to content

Commit 8de56f0

Browse files
committed
simplify offset processing
1 parent dc39a6d commit 8de56f0

File tree

3 files changed

+29
-24
lines changed

3 files changed

+29
-24
lines changed

jscomp/bsb_helper/bsb_helper_arg.ml

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ type key = string
33
type doc = string
44
type anon_fun = rev_args:string list -> unit
55

6+
type string_action =
7+
| Call of (string -> unit)
8+
| Set of {mutable contents : string}
9+
610
type spec =
7-
| Set of bool ref
8-
| String of (string -> unit)
9-
| Set_string of string ref
11+
| Bool of bool ref
12+
| String of string_action
13+
1014

1115
exception Bad of string
1216

@@ -15,10 +19,6 @@ type error =
1519
| Unknown of string
1620
| Missing of string
1721

18-
19-
20-
21-
2222
type t = (string * spec * string) list
2323

2424
let rec assoc3 (x : string) (l : t) =
@@ -78,17 +78,17 @@ let parse_exn ~progname ~argv ~start (speclist : t) anonfun =
7878
match assoc3 s speclist with
7979
| Some action -> begin
8080
begin match action with
81-
| Set r -> r := true;
81+
| Bool r -> r := true;
8282
| String f ->
83-
if !current < l then begin
84-
f argv.(!current);
85-
incr current;
86-
end else stop_raise ~progname ~error:(Missing s) speclist
87-
| Set_string r ->
88-
if !current < l then begin
89-
r := argv.(!current);
90-
incr current;
91-
end else stop_raise ~progname ~error:(Missing s) speclist
83+
if !current >= l then stop_raise ~progname ~error:(Missing s) speclist
84+
else begin
85+
let arg = argv.(!current) in
86+
incr current;
87+
match f with
88+
| Call f ->
89+
f arg
90+
| Set u -> u.contents <- arg
91+
end
9292
end;
9393
end;
9494
| None -> stop_raise ~progname ~error:(Unknown s) speclist

jscomp/bsb_helper/bsb_helper_arg.mli

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11

22

33

4+
type string_action =
5+
| Call of (string -> unit)
6+
| Set of {mutable contents : string}
7+
48
type spec =
5-
| Set of bool ref
6-
| String of (string -> unit)
7-
| Set_string of string ref
9+
| Bool of bool ref
10+
| String of string_action
811

912
type key = string
1013
type doc = string

jscomp/main/bsb_helper_main.ml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424
let compilation_kind = ref Bsb_helper_depfile_gen.Js
2525

26-
let hash : string ref = ref ""
26+
let hash : Bsb_helper_arg.string_action =
27+
Set {contents = ""}
28+
2729
let dev_group = ref false
2830
let namespace = ref None
2931

@@ -33,12 +35,12 @@ let () =
3335
~argv:Sys.argv
3436
~start:1
3537
[
36-
"-g", Set dev_group ,
38+
"-g", Bool dev_group ,
3739
" Set the dev group (default to be 0)"
3840
;
39-
"-bs-ns", String (fun s -> namespace := Some s),
41+
"-bs-ns", String (Call (fun s -> namespace := Some s)),
4042
" Set namespace";
41-
"-hash", Set_string hash,
43+
"-hash", String hash,
4244
" Set hash(internal)";
4345
] (fun ~rev_args ->
4446
match rev_args with

0 commit comments

Comments
 (0)