Commit b8a6747e authored by Bruno Guillaume's avatar Bruno Guillaume
Browse files

reorganise code to handle Conllx error with -config option

parent 69fcc1b1
......@@ -13,6 +13,8 @@ open Log
open Conllx
open Libgrew
open Grew_utils
module Grew_args = struct
type mode = Undefined | Gui of string | Transform | Grep | Count | Valid | Compile | Clean | Test
......@@ -27,7 +29,6 @@ module Grew_args = struct
let (input_data : string list ref) = ref []
let (output_data : string option ref) = ref None
let strat = ref "main"
let quiet = ref false
let timeout = ref None
let (patterns : string list ref) = ref []
let html = ref false
......@@ -130,7 +131,7 @@ module Grew_args = struct
| "-debug" :: args -> Libgrew.set_debug_mode true; loop args
| "-dep_dir" :: dir :: args -> dep_dir := Some dir; loop args
| "-config" :: value :: args -> config := Conllx_config.build value; loop args
| "-config" :: value :: args -> config := handle (fun () -> Conllx_config.build value) (); loop args
| x :: args -> Log.fwarning "Invalid argument: %s, it is ignored!" x; loop args
......
......@@ -16,22 +16,6 @@ open Libgrew
open Grew_utils
open Grew_args
(* -------------------------------------------------------------------------------- *)
let fail msg = Log.fmessage "%s" msg; exit 2
let handle fct () =
try fct ()
with
| Error json -> fail (Yojson.Basic.pretty_to_string json)
| Conllx_error json -> fail (Yojson.Basic.pretty_to_string json)
| Libgrew.Error msg -> fail msg
| Sys_error msg -> fail (sprintf "System error: %s" msg)
| Yojson.Json_error msg -> fail (sprintf "Json error: %s" msg)
| Libgrew.Bug msg -> fail (sprintf "Libgrew.bug, please report: %s" msg)
| exc -> fail (sprintf "Uncaught exception, please report: %s" (Printexc.to_string exc))
(* -------------------------------------------------------------------------------- *)
let load_file f =
if Filename.check_suffix f ".json"
......@@ -296,7 +280,7 @@ let valid () =
(fun conf_file ->
List.iter
(fun corpus_desc ->
if not !Grew_args.quiet then printf "%s\n" (Corpus_desc.get_id corpus_desc);
if not !quiet then printf "%s\n" (Corpus_desc.get_id corpus_desc);
Validation.check ~dir validator_list corpus_desc
) (Corpus_desc.load_json conf_file)
) !Grew_args.input_data
......
......@@ -13,12 +13,11 @@ open Log
open Conllx
open Libgrew
open Grew_args
(* ==================================================================================================== *)
module Int_set = Set.Make (Int)
module Int_map = Map.Make (Int)
let quiet = ref false
(* ==================================================================================================== *)
exception Error of Yojson.Basic.t
......@@ -36,6 +35,20 @@ let error_ ?file ?line ?fct ?data msg =
let error ?file ?line ?fct ?data = Printf.ksprintf (error_ ?file ?line ?fct ?data)
(* -------------------------------------------------------------------------------- *)
let fail msg = Log.fmessage "%s" msg; exit 2
let handle fct () =
try fct ()
with
| Error json -> fail (Yojson.Basic.pretty_to_string json)
| Conllx_error json -> fail (Yojson.Basic.pretty_to_string json)
| Libgrew.Error msg -> fail msg
| Sys_error msg -> fail (sprintf "System error: %s" msg)
| Yojson.Json_error msg -> fail (sprintf "Json error: %s" msg)
| Libgrew.Bug msg -> fail (sprintf "Libgrew.bug, please report: %s" msg)
| exc -> fail (sprintf "Uncaught exception, please report: %s" (Printexc.to_string exc))
(* ---------------------------------------------------------------------------------------------------- *)
let ensure_dir dir =
......@@ -77,10 +90,10 @@ module Counter = struct
let back = sprintf "\r%s\r" (String.make 100 ' ')
let print value total text =
if not !Grew_args.quiet
if not !quiet
then eprintf "%s%.2f%% (%s)%!" back (((float value) /. (float total))*. 100. ) text
let finish () = if not !Grew_args.quiet then eprintf "%s100.00%%\n%!" back
let finish () = if not !quiet then eprintf "%s100.00%%\n%!" back
end (* module Counter *)
(* ================================================================================ *)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment