Created
February 19, 2021 03:44
-
-
Save droyo/2adb11720e2f0265aece175754e1d2bc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type t = term list | |
and term = | |
| Int of int | |
| Bool of bool | |
| Float of float | |
| Id of string | |
| Str of string | |
| Expr of t | |
(* pp_term calls pp *) | |
let rec pp_term ppf = function | |
| Int x -> Fmt.int ppf x | |
| Bool x -> Fmt.bool ppf x | |
| Float x -> Fmt.float ppf x | |
| Str x -> Fmt.Dump.string ppf x | |
| Id x -> Fmt.string ppf x | |
| Expr x -> pp ppf x | |
(* and pp calls pp_term *) | |
and pp ppf ast = | |
if List.for_all (function Expr _ -> true | _ -> false) ast | |
then Fmt.(pf ppf "@[<hv 1>(%a)@]" (list ~sep:sp pp_term) ast) | |
else Fmt.(pf ppf "@[<b 1>(%a)@]" (list ~sep:sp pp_term) ast) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment