diff options
author | Chimrod <> | 2024-03-15 10:45:12 +0100 |
---|---|---|
committer | Chimrod <> | 2024-03-27 15:34:10 +0100 |
commit | baa258ac91df8a80209b322e8d42c5deb2ada536 (patch) | |
tree | e1a9d1f2df9d65c19b68d0acfc258338783e3e06 /lib/syntax/tree.ml | |
parent | 141db078408f94c410508970d07382d4a6087f17 (diff) |
New test for duplicates evalutations in the code
Diffstat (limited to 'lib/syntax/tree.ml')
-rw-r--r-- | lib/syntax/tree.ml | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/lib/syntax/tree.ml b/lib/syntax/tree.ml index 72ae754..0074df8 100644 --- a/lib/syntax/tree.ml +++ b/lib/syntax/tree.ml @@ -48,14 +48,31 @@ end module Expression : sig include S.Expression with type t' = S.pos Ast.expression - val eq : (S.pos -> S.pos -> bool) -> t -> t -> bool - val hash : (S.pos -> int) -> t -> int + val eq : (S.pos -> S.pos -> bool) -> t' -> t' -> bool + val hash : (S.pos -> int) -> t' -> int + val exists : f:(t' -> bool) -> t' -> bool end = struct type t = S.pos Ast.expression type t' = t let eq : (S.pos -> S.pos -> bool) -> t -> t -> bool = Ast.equal_expression + (* Add a way to filter an expression *) + let rec exists : f:(t -> bool) -> t -> bool = + fun ~f -> function + | BinaryOp (_, _, o1, o2) as op -> f op || exists ~f o1 || exists ~f o2 + | Op (_, _, expr) as op -> f op || exists ~f expr + | Function (_, _, exprs) as fn -> f fn || List.exists exprs ~f:(exists ~f) + | Literal (_, litts) as litt -> + f litt + || List.exists litts ~f:(function + | T.Text _ -> false + | T.Expression ex -> exists ~f ex) + | Ident { index; _ } as ident -> ( + f ident + || match index with None -> false | Some expr -> exists ~f expr) + | Integer _ as int -> f int + let rec hash : (S.pos -> int) -> t -> int = fun f -> function | Integer (pos, v) -> Hashtbl.hash (f pos, v) |