Hi,
I’m loving learning/using OCaml to build a compiler.
However since OCaml is complex I’m havin some issues with some libraries.
Using ppx_deriving.show
pre-processor I was able to print the AST of the code , to help in development and debugging.
However I do not want to print every node of the AST as it clutters our output.
For example, the output of the loc
(location) node makes the output verbose and makes it difficult to read our AST.
I’m just showing the nodes of id
and loc
to help with the question. id
contains loc
node but I do not want the loc
node to be printed.
How can I disable it?
I tried removing [@@deriving show { with_path = false }]
from loc
node, but then the code does not compile for some reason.
Thanks.
and id = Id of string * loc [@@deriving show { with_path = false }]
and loc = Loc of int * int [@@deriving show { with_path = false }]
I print the AST using this method.
(** Print Ix AST for debugging. *)
let print_ast (ast : Ixast.executable) =
print_endline ("> " ^ Ixast.show_executable ast ^ "\n")
;;
This is the output where the information of loc
nodes clutters it.
> (Executable
[(StatementFunction (TypeInt, (Id ("main", (Loc (8, 326)))),
(BlockStatement (
[(StatementReturn
(ExpressionTerminal ((TerminalInt (0, (Loc (9, 344)))),
(Loc (9, 344)))))
],
(Loc (8, 333)))),
(Loc (1, 0))))
])