aboutsummaryrefslogtreecommitdiff
path: root/lib/syntax/tree.ml
diff options
context:
space:
mode:
Diffstat (limited to 'lib/syntax/tree.ml')
-rw-r--r--lib/syntax/tree.ml23
1 files changed, 22 insertions, 1 deletions
diff --git a/lib/syntax/tree.ml b/lib/syntax/tree.ml
index b7d9d15..72ae754 100644
--- a/lib/syntax/tree.ml
+++ b/lib/syntax/tree.ml
@@ -45,10 +45,31 @@ module Ast = struct
end
(** Default implementation for the expression *)
-module Expression : S.Expression with type t' = S.pos Ast.expression = struct
+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
+end = struct
type t = S.pos Ast.expression
type t' = t
+ let eq : (S.pos -> S.pos -> bool) -> t -> t -> bool = Ast.equal_expression
+
+ let rec hash : (S.pos -> int) -> t -> int =
+ fun f -> function
+ | Integer (pos, v) -> Hashtbl.hash (f pos, v)
+ | Literal (pos, l) ->
+ let litt = List.map ~f:(T.map_litteral ~f:(hash f)) l in
+ Hashtbl.hash (f pos, litt)
+ | Ident { pos; name; index } ->
+ Hashtbl.hash (f pos, name, Option.map (hash f) index)
+ | BinaryOp (pos, op, o1, o2) ->
+ Hashtbl.hash (f pos, op, hash f o1, hash f o2)
+ | Op (pos, op, o1) -> Hashtbl.hash (f pos, op, hash f o1)
+ | Function (pos, name, args) ->
+ Hashtbl.hash (f pos, name, List.map ~f:(hash f) args)
+
let v : t -> t' = fun t -> t
let integer : S.pos -> string -> t = fun pos i -> Ast.Integer (pos, i)