public
Description: Batteries Included
Homepage: http://forge.ocamlcore.org/projects/batteries/
Clone URL: git://github.com/thelema/batteries.git
Make Unit required arguments not get run immediately, but when the queue 
hits them.
thelema (author)
Mon Oct 06 05:29:51 -0700 2008
commit  da6acc4e8c2481502415e95aae813e8c3c184053
tree    22cae09b48500cbd98926650e067de58177f4c79
parent  1a638e9a930634c93576a7fce3d727d2463136eb
...
270
271
272
 
273
274
275
...
280
281
282
283
284
285
286
287
288
289
290
291
292
...
309
310
311
312
 
313
314
315
316
317
 
 
318
319
320
321
322
323
324
325
 
 
 
 
 
 
 
 
326
327
328
 
 
329
330
331
...
270
271
272
273
274
275
276
...
281
282
283
 
284
285
286
287
288
 
289
290
291
...
308
309
310
 
311
312
313
314
 
 
315
316
317
 
 
 
 
 
 
 
318
319
320
321
322
323
324
325
326
 
 
327
328
329
330
331
0
@@ -270,6 +270,7 @@ let tokenize raw =
0
 
0
 let qflush hq =
0
   let noarg = function
0
+ | Required (Unit uh) -> uh ()
0
     | Required _ -> raise (Bad "no data left for required arguments")
0
     | Optional (_,unitfun) -> unitfun () in
0
   Queue.iter noarg hq;
0
@@ -280,13 +281,11 @@ let parse ~keywords ~others ~usage:args ~descr ~notes =
0
   let handler_queue = Queue.create ()
0
   and extra_arg_handler = ref others in
0
   let enqueue_require = function
0
- | Unit noarg -> noarg ()
0
     | Set ref -> ref := true
0
     | Clear ref -> ref := false
0
     | Rest sh -> extra_arg_handler := sh
0
     | h -> Queue.add (Required h) handler_queue
0
   and enqueue_option = function
0
- | (Unit u,_) -> raise (Bad "Unit arguments can't be optional")
0
     | (Set _,_) -> raise (Bad "Set arguments can't be optional")
0
     | (Clear _,_) -> raise (Bad "Clear options can't be optional")
0
     | (Rest sh,_) -> extra_arg_handler := sh
0
@@ -309,23 +308,24 @@ let parse ~keywords ~others ~usage:args ~descr ~notes =
0
     with
0
       Not_found -> raise (Bad ("argument not found:" ^ name))
0
   in
0
- let handle arg =
0
+ let rec handle arg =
0
     try
0
       let handler =
0
   match Queue.take handler_queue with
0
- Required h -> h
0
- | Optional (h,_) -> h in
0
+ Required h -> h
0
+ | Optional (h,_) -> h in
0
       match handler with
0
- String sh -> sh arg
0
- | Int ih -> ih (int_of_string arg)
0
- | Float fh -> fh (float_of_string arg)
0
- | String_var svh -> svh := arg
0
- | Int_var ivh -> ivh := (int_of_string arg)
0
- | Float_var fvh -> fvh := (float_of_string arg)
0
- | _ -> raise (Bad "Ran into bad argument handler")
0
+ String sh -> sh arg
0
+ | Int ih -> ih (int_of_string arg)
0
+ | Float fh -> fh (float_of_string arg)
0
+ | String_var svh -> svh := arg
0
+ | Int_var ivh -> ivh := (int_of_string arg)
0
+ | Float_var fvh -> fvh := (float_of_string arg)
0
+ | Unit uh -> uh (); handle arg
0
+ | _ -> raise (Bad "Ran into bad argument handler")
0
     with
0
- Queue.Empty -> !extra_arg_handler arg
0
- | Failure x -> raise (Bad ("Failed converting: "^x))
0
+ Queue.Empty -> !extra_arg_handler arg
0
+ | Failure x -> raise (Bad ("Failed converting: "^x))
0
   in
0
   let act_on_arg arg =
0
     match tokenize arg with

Comments

    No one has commented yet.