aboutsummaryrefslogtreecommitdiff
path: root/src/expressions/show_expr.ml
diff options
context:
space:
mode:
Diffstat (limited to 'src/expressions/show_expr.ml')
-rwxr-xr-xsrc/expressions/show_expr.ml62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/expressions/show_expr.ml b/src/expressions/show_expr.ml
new file mode 100755
index 0000000..3a54929
--- /dev/null
+++ b/src/expressions/show_expr.ml
@@ -0,0 +1,62 @@
+let u = UTF8.from_utf8string
+
+module Show_Expr
+ (R:Sym_ref.SYM_REF with type 'a obs = (UTF8.Buffer.buffer -> unit))
+ (T:Sym_type.SYM_TYPE with type 'a obs = (UTF8.Buffer.buffer -> unit)) = struct
+
+ module T = T
+ module R = R
+
+ type t = unit
+ type repr = UTF8.Buffer.buffer -> unit
+ type obs = UTF8.Buffer.buffer -> unit
+
+ let observe buffer value = buffer value
+
+ let value v () buffer = T.observe v buffer
+
+ let ref r () buffer = R.observe r buffer
+
+ let call0 ident () buffer =
+ let utf8ident = UTF8.to_utf8string ident in
+ UTF8.Printf.bprintf buffer "%s()" utf8ident
+
+ let call1 ident p1 () buffer =
+ let utf8ident = UTF8.to_utf8string ident in
+ UTF8.Printf.bprintf buffer "%s(%a)"
+ utf8ident
+ (fun x b -> observe b x) p1
+
+ let call2 ident p1 p2 () buffer =
+ let utf8ident = UTF8.to_utf8string ident in
+ begin match utf8ident with
+ | "+" | "*" | "-" | "/" | "^" | "="
+ | "<>" | "<=" | ">=" | "<" | ">" ->
+ UTF8.Printf.bprintf buffer "%a%s%a"
+ (fun x b -> observe b x) p1
+ utf8ident
+ (fun x b -> observe b x) p2
+ | _ ->
+ UTF8.Printf.bprintf buffer "%s(%a;%a)"
+ utf8ident
+ (fun x b -> observe b x) p1
+ (fun x b -> observe b x) p2
+ end
+
+ let call3 ident p1 p2 p3 () buffer =
+ let utf8ident = UTF8.to_utf8string ident in
+ UTF8.Printf.bprintf buffer "%s(%a;%a;%a)"
+ utf8ident
+ (fun x b -> observe b x) p1
+ (fun x b -> observe b x) p2
+ (fun x b -> observe b x) p3
+
+ let callN ident (params: repr list) () buffer =
+ UTF8.Buffer.add_string buffer ident;
+ Tools.List.printb ~sep:(u";") (fun buffer value -> value buffer) buffer params
+
+ let expression e () buffer =
+ UTF8.Printf.bprintf buffer "(%a)"
+ (fun x b -> b x) e
+
+end