aboutsummaryrefslogtreecommitdiff
path: root/rego-proofs
diff options
context:
space:
mode:
authorJakob L. Kreuze2023-10-17 15:48:49 -0400
committerJakob L. Kreuze2023-10-17 15:48:49 -0400
commitf379c4a1226fe932ad47ed7576bdf8da7404c424 (patch)
tree805ff7f92f4b1c8073b1f57f5e3eb0314d65717a /rego-proofs
parent51d974284a8e9e33b9041fb7a2950849bc1102c6 (diff)
Allow call as a term
I've validated that the reference implementation accepts arbitrary terms as ref arguments
Diffstat (limited to 'rego-proofs')
-rw-r--r--rego-proofs/compiler-rewrite/bin/main.ml76
1 files changed, 28 insertions, 48 deletions
diff --git a/rego-proofs/compiler-rewrite/bin/main.ml b/rego-proofs/compiler-rewrite/bin/main.ml
index 2d4811c..ae65c61 100644
--- a/rego-proofs/compiler-rewrite/bin/main.ml
+++ b/rego-proofs/compiler-rewrite/bin/main.ml
@@ -2,11 +2,7 @@ open Core
open Yojson.Basic.Util
type expr = Term of term
- | Call of reference * (term list)
- | Every of (string list) * every_item * query
-[@@deriving show]
-and every_item = Term of term
- | Call of (string list) * (term list)
+ | Every of (string list) * term * query
[@@deriving show]
and literal = expr * (with_modifier option)
[@@deriving show]
@@ -21,28 +17,23 @@ and term = Scalar of scalar
| ArrayComprehension of term * query
| ObjectComprehension of (object_key * term) * query
| SetComprehension of term * query
+ | Call of reference * (term list)
[@@deriving show]
and scalar = String of string
| Number of float
| Bool of bool
| Null
[@@deriving show]
-and reference = ref_target * (ref_arg list)
+and reference = ref_target * (term list)
[@@deriving show]
and ref_target = Var of string
- | Array of term list
- | Object of (object_key * term) list
- | Set of term list
- | ArrayComprehension of term * query
- | ObjectComprehension of (object_key * term) * query
- | SetComprehension of term * query
- | Call of reference * (term list)
-[@@deriving show]
-and ref_arg = Scalar of scalar
- | Var of string
- | Array of term list
- | Object of (object_key * term) list
- | Set of term list
+ | Array of term list
+ | Object of (object_key * term) list
+ | Set of term list
+ | ArrayComprehension of term * query
+ | ObjectComprehension of (object_key * term) * query
+ | SetComprehension of term * query
+ | Call of reference * (term list)
[@@deriving show]
and object_key = Scalar of scalar
| Ref of reference
@@ -132,52 +123,41 @@ let rec parse_term (tree : Yojson.Basic.t) : term =
((tree |> member "value" |> member "key" |> parse_term |> object_key_of_term,
tree |> member "value" |> member "value" |> parse_term),
tree |> member "value" |> member "body" |> to_list |> List.map ~f:(fun x -> (parse_expr x, None)))
+ | "call" ->
+ (match tree |> member "value" |> to_list with
+ | func :: args ->
+ Call (func |> member "value" |> to_list |> parse_ref,
+ List.map ~f:parse_term args)
+ | _ -> failwith "ill_formed call")
| _ -> failwith ("unsupported term type " ^ term_type)
and parse_expr tree : expr =
Printf.printf "%s: %s\n" "parse_expr" (Yojson.Basic.to_string tree);
match tree |> member "terms" with
| `List (func :: args) ->
- Call (func |> member "value" |> to_list |> parse_ref,
- List.map ~f:parse_term args)
+ Term (Call (func |> member "value" |> to_list |> parse_ref,
+ List.map ~f:parse_term args))
| `List _ -> failwith "todo"
| x -> Term (parse_term x)
and parse_ref_target tree : ref_target =
Printf.printf "%s: %s\n" "parse_ref_target" (Yojson.Basic.to_string tree);
- if String.equal (tree |> member "type" |> to_string) "call" then
- match tree |> member "value" |> to_list with
- | func :: args ->
- Call (func |> member "value" |> to_list |> parse_ref,
- List.map ~f:parse_term args)
- | _ -> failwith "ill_formed call"
- else
- let term = parse_term tree in
- match term with
- | Var term -> Var term
- | Array term -> Array term
- | Object term -> Object term
- | Set term -> Set term
- | ArrayComprehension (term, y) -> ArrayComprehension (term, y)
- | ObjectComprehension (term, y) -> ObjectComprehension (term, y)
- | SetComprehension (term, y) -> SetComprehension (term, y)
- | _ -> failwith ("unsupported ref_target " ^ (show_term term))
-
-and parse_ref_arg tree : ref_arg =
- Printf.printf "%s: %s\n" "parse_ref_arg" (Yojson.Basic.to_string tree);
let term = parse_term tree in
match term with
- | Scalar x -> Scalar x
- | Var x -> Var x
- | Array x -> Array x
- | Object x -> Object x
- | Set x -> Set x
- | _ -> failwith ("unsupported ref_arg " ^ (show_term term))
+ | Var term -> Var term
+ | Array term -> Array term
+ | Object term -> Object term
+ | Set term -> Set term
+ | ArrayComprehension (term, y) -> ArrayComprehension (term, y)
+ | ObjectComprehension (term, y) -> ObjectComprehension (term, y)
+ | SetComprehension (term, y) -> SetComprehension (term, y)
+ | Call (term, y) -> Call (term, y)
+ | _ -> failwith ("unsupported ref_target " ^ (show_term term))
and parse_ref tree =
Printf.printf "%s: %s\n" "parse_ref" (String.concat (List.map ~f:Yojson.Basic.to_string tree));
match tree with
- | target :: args -> (parse_ref_target target, List.map ~f:parse_ref_arg args)
+ | target :: args -> (parse_ref_target target, List.map ~f:parse_term args)
| _ -> failwith "empty reference"
let parse_head tree =

© 2015 - 2026 Jakob L. Kreuze