Skip to content

Commit 7d29122

Browse files
committed
progress
1 parent 9a4b74d commit 7d29122

File tree

2 files changed

+71
-17
lines changed

2 files changed

+71
-17
lines changed

rule_schema_v2.atd

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ type options <ocaml from="Rule_options" t="t"> = abstract
234234
*)
235235

236236
type formula = {
237+
(* alt: have ?all: ... ?any: ... ?regex: ... ?pattern: ... with only one *)
237238
f: formula_bis;
238239
(* alt: we could instead do 'All of formula list * condition list' below
239240
* but syntactically we also allow 'where' with pattern:, regex:, etc.
@@ -263,18 +264,34 @@ type formula_bis = [
263264
(* TODO? Taint of taint_spec *)
264265
]
265266

266-
(* TODO *)
267-
type condition = raw_json
268-
269-
type condition_TODO = [
267+
(* Just like for formula, we're using an adapter to transform
268+
* conditions in YAML like:
269+
*
270+
* where:
271+
* - metavariable: $X
272+
* regex: $Z
273+
*
274+
* which when turned into JSON gives:
275+
*
276+
* XXX
277+
*
278+
* which we must transform in an ATD-compliant:
279+
*
280+
* YYY
281+
*)
282+
type condition = [
270283
(* either a single string or an array in JSON, that is
271284
* {focus: "$FOO"}, but also {focus: ["$FOO", "$BAR"]}
272285
*)
273-
| Focus of mvar list
274-
| Comparison of comparison
275-
| Metavariable of (mvar * metavariable_cond)
286+
| Focus <json name="F"> of focus
287+
| Comparison <json name="C"> of comparison
288+
| Metavariable <json name="M"> of metavariable_cond
276289
]
277-
<json adapter.ocaml="Rule_schema_v2_adapter.Where">
290+
<json adapter.ocaml="Rule_schema_v2_adapter.Condition">
291+
292+
type focus = {
293+
focus: mvar list;
294+
}
278295

279296
type mvar = string
280297

@@ -284,11 +301,21 @@ type comparison = {
284301
~strip: bool;
285302
}
286303

287-
type metavariable_cond = [
288-
| Type of string
289-
(* TODO: for metavariable-regex, can also enable constant_propagation *)
290-
| Formula of formula
291-
| Analyzer of string
304+
type metavariable_cond = {
305+
metavariable: mvar;
306+
(* alt: have ?type: ... ?types:... ?regex: ... *)
307+
c: metavariable_cond_bis;
308+
}
309+
310+
type metavariable_cond_bis = [
311+
| Type <json name="type"> of string
312+
| Types <json name="types"> of string list
313+
(* alt: we could remove Regex as Formula itself as a Regex
314+
* TODO: for metavariable-regex, can also enable constant_propagation
315+
*)
316+
| Regex <json name="regex"> of regex
317+
| Formula <json name="F"> of formula
318+
| Analyzer <json name="analyzer"> of string
292319
]
293320

294321
(*****************************************************************************)

rule_schema_v2_adapter.ml

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,41 @@ module Formula = struct
2323
failwith "Rule_schema_v2_adapter.Formula.restore not implemented"
2424
end
2525

26-
module Where = struct
26+
module Condition = struct
2727

2828
(** Convert from original json to ATD-compatible json *)
29-
let normalize (_orig : Yojson.Safe.t ) : Yojson.Safe.t =
30-
failwith "TODO: Where.normalize"
29+
let normalize (orig : Yojson.Safe.t ) : Yojson.Safe.t =
30+
match orig with
31+
| `Assoc (("comparison", cmp)::rest) ->
32+
`List [`String "C";
33+
`Assoc (("comparison", cmp)::rest)]
34+
| `Assoc [("metavariable", mvar); ("regex", reg)] ->
35+
`List [`String "M";
36+
`Assoc [("metavariable", mvar);
37+
("c", `List [`String "regex"; reg])]]
38+
| `Assoc [("metavariable", mvar); ("type", ty)] ->
39+
`List [`String "M";
40+
`Assoc [("metavariable", mvar);
41+
("c", `List [`String "type"; ty])]]
42+
| `Assoc [("metavariable", mvar); ("types", tys)] ->
43+
`List [`String "M";
44+
`Assoc [("metavariable", mvar);
45+
("c", `List [`String "types"; tys])]]
46+
| `Assoc [("metavariable", _mvar); ("pattern", _p)] ->
47+
Common.pr2_gen orig;
48+
failwith "TODO"
49+
(*
50+
`List [`String "M";
51+
`Assoc [("metavariable", mvar);
52+
("c", `List [`String "F"; `Assoc [("pattern", p)]])]]
53+
*)
54+
| x ->
55+
Common.pr2_gen x;
56+
failwith "TODO2"
57+
3158

3259
(** Convert from ATD-compatible json to original json *)
3360
let restore (_atd : Yojson.Safe.t) : Yojson.Safe.t =
3461
(* not needed for now; we care just about parsing *)
35-
failwith "Rule_schema_v2_adapter.Where.restore not implemented"
62+
failwith "Rule_schema_v2_adapter.Condition.restore not implemented"
3663
end

0 commit comments

Comments
 (0)