Commit ca5f1d98 authored by Bruno Guillaume's avatar Bruno Guillaume

Add parametrized rules to json export

parent 78b79bf3
......@@ -203,7 +203,7 @@ module Grs = struct
ast: Ast.grs;
}
let to_json t = `List (List.map Modul.to_json t.modules)
let to_json t = `List (List.map (Modul.to_json ?domain:t.domain) t.modules)
let get_modules t = t.modules
let get_ast t = t.ast
......
......@@ -384,13 +384,20 @@ module Rule = struct
let is_filter t = t.commands = []
let to_json ?domain t =
match t.param with
| None -> `Assoc [
let param_json = match t.param with
| None -> []
| Some lex_par -> [
("pattern_param", `List (List.map (fun x -> `String x) (fst t.param_names)));
("command_param", `List (List.map (fun x -> `String x) (snd t.param_names)));
("lex_par", Lex_par.to_json lex_par);
] in
`Assoc
([
("rule_name", `String t.name);
("match", basic_to_json ?domain (fst t.pattern));
("without", `List (List.map (basic_to_json ?domain) (snd t.pattern)));
]
| Some _ -> Error.build "Rule.to_json undefined for parametrized rules"
] @ param_json
)
(* ====================================================================== *)
let to_dep ?domain t =
......
......@@ -97,8 +97,15 @@ module Lex_par = struct
type item = string list * string list (* first list: pattern parameters $id , second list command parameters @id *)
let item_to_string = function
| (l,[]) -> String.concat "#" l
| (pat,com) -> (String.concat "#" pat) ^ "##" ^ (String.concat "#" com)
type t = item list
let to_json t =
`List (List.map (fun item -> `String (item_to_string item)) t)
let size = List.length
let append = List.append
......
......@@ -68,6 +68,8 @@ module Massoc_pid : S with type key = Pid.t
module Lex_par: sig
type t
val to_json: t -> Yojson.Basic.json
val append: t -> t -> t
val dump: t -> unit
......
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