Project

General

Profile

Revision 0c0b0aff src/tools/stateflow/json-parser/json_parser.ml

View differences:

src/tools/stateflow/json-parser/json_parser.ml
15 15

  
16 16
module Parser (Ext : ParseExt) =
17 17
struct
18
  exception JSON_parse_error of string
19

  
18 20
  let path_split = String.split_on_char '/'
19 21
  let path_concat = String.concat (String.make 1 '/')
20 22

  
......
77 79
	(function
78 80
	| "State"    -> (fun p -> DPath p)
79 81
	| "Junction" -> (fun j -> DJunction (path_concat j))
80
	| _ -> failwith ("Invalid destination type: " ^ dest_type)))
82
	| _ -> raise (JSON_parse_error ("Invalid destination type: " ^ dest_type))))
81 83
      (json |> member "name" |> parse_path)
82 84
  and parse_internal_composition json =
83 85
    Logs.debug (fun m -> m "parse_internal_composition");
......
86 88
	(function
87 89
	| "EXCLUSIVE_OR" -> (fun tinit substates ->                      Or  (tinit, substates))
88 90
	| "PARALLEL_AND" -> (fun tinit substates -> assert (tinit = []); And (substates))
89
	| _ -> failwith ("Invalid state type: " ^ state_type)))
91
        | _ -> raise (JSON_parse_error ("Invalid state type: " ^ state_type))))
90 92
      (json |> member "tinit"     |> parse_tinit)
91 93
      (json |> member "substates" |> to_list |> List.map to_string)
92 94
  and parse_tinit json =
......
105 107
    | "Local"     -> Local
106 108
    | "Output"    -> Output
107 109
    | "Parameter" -> Parameter
108
    | _           -> failwith ("Invalid scope for variable: " ^ s)
110
    | _           -> raise (JSON_parse_error ("Invalid scope for variable: " ^ s))
109 111
  and parse_real_value s =
110 112
    Logs.debug (fun m -> m "parse_real_value %s" s);
111 113
    let real_regexp_simp = regexp "-?\\([0-9][0-9]*\\)\\.\\([0-9]*\\)" in
......
123 125
      let r = matched_group 2 s in
124 126
      Const_real (Num.num_of_string (l ^ r), String.length r, s)
125 127
    else
126
      failwith ("Invalid real constant " ^ s)
128
      raise (JSON_parse_error ("Invalid real constant " ^ s))
127 129
  and lustre_datatype_of_json json location =
128 130
    let datatype      = json |> member "datatype"      |> to_string in
129 131
    let initial_value = json |> member "initial_value" |> to_string in
......
134 136
                                     | "true"  -> tag_true
135 137
                                     | "false" -> tag_false
136 138
                                     | _       ->
137
                                       failwith ("Invalid constant for
138
     boolean: " ^ s)) initial_value))))
139
                                       raise (JSON_parse_error ("Invalid constant for
140
     boolean: " ^ s))) initial_value))))
139 141
    | "int"  -> (Tydec_int, mkexpr location
140 142
                   (Expr_const (Const_int (int_of_string
141 143
                                             initial_value))))
142 144
    | "real" -> (Tydec_real, mkexpr location
143 145
                   (Expr_const (parse_real_value initial_value)))
144
    | _      -> failwith ("Invalid datatype " ^ datatype
145
                          ^ " for variable " ^ (json |> member "name"
146
                                                |> to_string))
146
    | _      -> raise (JSON_parse_error ("Invalid datatype " ^ datatype
147
                                         ^ " for variable " ^ (json |> member "name"
148
                                                               |> to_string)))
147 149
  and parse_variable json =
148 150
    Logs.debug (fun m -> m "parse_variable %s" (json |> member "name" |> to_string));
149 151
    let location                  = Location.dummy_loc in

Also available in: Unified diff