diff options
| author | Jakob L. Kreuze | 2023-10-26 12:49:19 -0400 |
|---|---|---|
| committer | Jakob L. Kreuze | 2023-10-26 12:49:19 -0400 |
| commit | 03d9cf7cfd9b6beb85ff634cffe8feda507a8127 (patch) | |
| tree | 70e704435408254c3f1966fb7f46ac2a7e441a0f | |
| parent | 7b844c3e9a93e7f67964b513419a779cf5c44d59 (diff) | |
Export more operations on AST elements
| -rw-r--r-- | rego-proofs/compiler-rewrite/lib/ast.ml | 32 | ||||
| -rw-r--r-- | rego-proofs/compiler-rewrite/lib/ast.mli | 49 | ||||
| -rw-r--r-- | rego-proofs/compiler-rewrite/lib/dune | 2 |
3 files changed, 66 insertions, 17 deletions
diff --git a/rego-proofs/compiler-rewrite/lib/ast.ml b/rego-proofs/compiler-rewrite/lib/ast.ml index 3abf234..052496d 100644 --- a/rego-proofs/compiler-rewrite/lib/ast.ml +++ b/rego-proofs/compiler-rewrite/lib/ast.ml @@ -4,15 +4,15 @@ open Yojson.Basic.Util (* AST types. *) type expr = Term of term | Every of string option * string * term * query -[@@deriving show] +[@@deriving eq, show] and literal = | Exists of expr list * with_modifier option | Expr of expr * with_modifier option | Negate of expr * with_modifier option -[@@deriving show] +[@@deriving eq, show] -and query = literal list [@@deriving show] +and query = literal list [@@deriving eq, show] and term = | Scalar of scalar @@ -25,12 +25,12 @@ and term = | ObjectComprehension of (object_key * term) * query | SetComprehension of term * query | Call of reference * term list -[@@deriving show] +[@@deriving eq, show] and scalar = String of string | Number of float | Bool of bool | Null -[@@deriving show] +[@@deriving eq, show] -and reference = ref_target * term list [@@deriving show] +and reference = ref_target * term list [@@deriving eq, show] and ref_target = | Var of string @@ -41,23 +41,23 @@ and ref_target = | ObjectComprehension of (object_key * term) * query | SetComprehension of term * query | Call of reference * term list -[@@deriving show] +[@@deriving eq, show] and object_key = Scalar of scalar | Ref of reference | Var of string -[@@deriving show] +[@@deriving eq, show] -and with_modifier = (term * term) list [@@deriving show] +and with_modifier = (term * term) list [@@deriving eq, show] -type assign_operator = Assign | Unify [@@deriving show] -type rule_head_lhs = reference [@@deriving show] +type assign_operator = Assign | Unify [@@deriving eq, show] +type rule_head_lhs = reference [@@deriving eq, show] type rule_head_rhs = | Assignment of assign_operator * term | Function of assign_operator * string list * term | Set of term -[@@deriving show] +[@@deriving eq, show] -type rule_head = rule_head_lhs * rule_head_rhs [@@deriving show] +type rule_head = rule_head_lhs * rule_head_rhs [@@deriving eq, show] type rule = { default : bool; @@ -65,12 +65,12 @@ type rule = { body : query; otherwise : rule option; } -[@@deriving fields, show] +[@@deriving eq, show] -type import = { alias : string option; path : reference } [@@deriving show] +type import = { alias : string option; path : reference } [@@deriving eq, show] type package = { path : reference; imports : import list; policy : rule list } -[@@deriving fields, show] +[@@deriving eq, show] (* Additional JSON utility functions. *) diff --git a/rego-proofs/compiler-rewrite/lib/ast.mli b/rego-proofs/compiler-rewrite/lib/ast.mli index b2cae21..1d3d69a 100644 --- a/rego-proofs/compiler-rewrite/lib/ast.mli +++ b/rego-proofs/compiler-rewrite/lib/ast.mli @@ -57,3 +57,52 @@ type package = { path : reference; imports : import list; policy : rule list } val ast_of_string : string -> package val show_package : package -> string + +val equal_assign_operator : assign_operator -> assign_operator -> bool +val equal_expr : expr -> expr -> bool +val equal_import : import -> import -> bool +val equal_literal : literal -> literal -> bool +val equal_object_key : object_key -> object_key -> bool +val equal_package : package -> package -> bool +val equal_query : query -> query -> bool +val equal_ref_target : ref_target -> ref_target -> bool +val equal_reference : reference -> reference -> bool +val equal_rule : rule -> rule -> bool +val equal_rule_head : rule_head -> rule_head -> bool +val equal_rule_head_lhs : rule_head_lhs -> rule_head_lhs -> bool +val equal_rule_head_rhs : rule_head_rhs -> rule_head_rhs -> bool +val equal_scalar : scalar -> scalar -> bool +val equal_term : term -> term -> bool +val equal_with_modifier : with_modifier -> with_modifier -> bool +val pp_assign_operator : Format.formatter -> assign_operator -> unit +val pp_expr : Format.formatter -> expr -> unit +val pp_import : Format.formatter -> import -> unit +val pp_literal : Format.formatter -> literal -> unit +val pp_object_key : Format.formatter -> object_key -> unit +val pp_package : Format.formatter -> package -> unit +val pp_query : Format.formatter -> query -> unit +val pp_ref_target : Format.formatter -> ref_target -> unit +val pp_reference : Format.formatter -> reference -> unit +val pp_rule : Format.formatter -> rule -> unit +val pp_rule_head : Format.formatter -> rule_head -> unit +val pp_rule_head_lhs : Format.formatter -> rule_head_lhs -> unit +val pp_rule_head_rhs : Format.formatter -> rule_head_rhs -> unit +val pp_scalar : Format.formatter -> scalar -> unit +val pp_term : Format.formatter -> term -> unit +val pp_with_modifier : Format.formatter -> with_modifier -> unit +val show_assign_operator : assign_operator -> string +val show_expr : expr -> string +val show_import : import -> string +val show_literal : literal -> string +val show_object_key : object_key -> string +val show_package : package -> string +val show_query : query -> string +val show_ref_target : ref_target -> string +val show_reference : reference -> string +val show_rule : rule -> string +val show_rule_head : rule_head -> string +val show_rule_head_lhs : rule_head_lhs -> string +val show_rule_head_rhs : rule_head_rhs -> string +val show_scalar : scalar -> string +val show_term : term -> string +val show_with_modifier : with_modifier -> string diff --git a/rego-proofs/compiler-rewrite/lib/dune b/rego-proofs/compiler-rewrite/lib/dune index b7623f0..72a5e68 100644 --- a/rego-proofs/compiler-rewrite/lib/dune +++ b/rego-proofs/compiler-rewrite/lib/dune @@ -2,7 +2,7 @@ (name compiler_rewrite) (libraries core unix yojson) (preprocess - (pps ppx_deriving.show ppx_fields_conv))) + (pps ppx_deriving.eq ppx_deriving.show ppx_fields_conv))) (env (dev |