Source

SmallCC / src / option.ml

exception OptionError of string * string

class option argv = 
object(this)

  val mutable files = []
  val mutable output = "a.out"

  method getFiles () = files

  method addFile (filepath:string) =
    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
        []                  ->
          ()
      | 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

end

let option =
  let a = new option Sys.argv in
    a