Project

General

Profile

Download (1.7 KB) Statistics
| Branch: | Tag: | Revision:
1
open Basetypes
2
open Cmdliner
3
open Datatype
4
open Json_parser
5
open Sys
6

    
7
module ParseExt =
8
struct
9
  let parse_condition _ = Condition.tru
10
  let parse_action    _ = Action.nil
11
  let parse_event json  = Some Yojson.Basic.(json |> to_string)
12
end
13

    
14
module Parse = Parser (ParseExt)
15

    
16
(* setup for logging *)
17
let setup_log style_renderer level =
18
  Fmt_tty.setup_std_outputs ?style_renderer ();
19
  Logs.set_level level;
20
  Logs.set_reporter (Logs_fmt.reporter ());
21
  ()
22

    
23
(* function representing the program to execute *)
24
let json_parse _ file pp =
25
  let prog = Parse.parse_prog (Yojson.Basic.from_file file) in
26
  if pp then
27
    SF.pp_prog Format.std_formatter prog
28

    
29
(* term representing argument for file *)
30
let file =
31
  let doc = "The file to parse." in
32
  let env = Arg.env_var "JSON_FILE" ~doc in
33
  let doc = "The file to parse." in
34
  Arg.(required & pos 0 (some string) None & info [] ~env ~docv:"FILE" ~doc)
35

    
36
(* term representing argument for flag for pretty printing the program *)
37
let pp =
38
  let doc = "Pretty print the resulting program" in
39
  Arg.(value & flag & info ["pp"; "pretty-print"] ~docv:"PP" ~doc)
40

    
41
(* term for argument for logging *)
42
let setup_log_arg =
43
  let env = Arg.env_var "TOOL_VERBOSITY" in
44
  Term.(const setup_log $ Fmt_cli.style_renderer () $ Logs_cli.level ~env ())
45

    
46
(* term representing the program to execute *)
47
let json_parse_t = Term.(const json_parse $ setup_log_arg $ file $ pp)
48

    
49
(* term info for manpages etc. *)
50
let info =
51
  let doc = "parse a JSON file representing a Stateflow model" in
52
  let man = [
53
    `S Manpage.s_bugs;
54
    `P "Report bug to Github issues tracking." ]
55
  in
56
  Term.info "parse_json_file" ~doc ~exits:Term.default_exits ~man
57

    
58
(* program *)
59
let _ = Term.exit @@ Term.eval (json_parse_t, info)
(2-2/2)