Commits

Corentin Derbois committed 3cd4baf

Fix option parsing

Comments (0)

Files changed (2)

 class compiler file = 
 object(this)
 
-
+  
 
 end
   val mutable files = []
   val mutable output = "a.out"
 
-  method getFiles () = files
+  method getFiles = files
+  method getOutput = output
 
   method addFile (filepath:string) =
-    files = filepath::files
+    files <- filepath::files
 
   method next (l:string list) (f:string -> unit) = match l with
       []   -> raise (OptionError("next", "Option missing"))
     | e::r -> f e; this#rec_parce r
 
-  method rec_parce l = match l with
+  method rec_parce (l:string list) = match l with
         []                  ->
           ()
-      | e::r when e == "-o" ->
-          this#next r (fun e -> output = e; ()); ()
+      | e::r when e = "-o" ->
+          this#next r (fun e -> output <- e; ()); ()
       | e::r                ->
           this#addFile e; this#rec_parce r; ()
   
-  method parse () =
-    let _::args = Array.to_list argv in 
-      this#rec_parce args
+  method parse () = match (Array.to_list argv) with
+      []      -> ()
+    | _::args -> this#rec_parce args
+
+  method dump () =
+    print_endline ("Output: " ^ output);
+    print_endline "File {";
+    let f e = print_endline e; () in
+      List.iter f files;
+    print_endline "}"
+      
 
 end