我有一段包含camlp4引用的代码。
let f_name = "my_func"
<:str_item< value $lid:f_name$ a = a * 2 >>
通过运行 camlp4of
,它会产生以下结果:
Ast.StExp (_loc,
(Ast.ExApp (_loc,
(Ast.ExApp (_loc, (Ast.ExId (_loc, (Ast.IdLid (_loc, "=")))),
(Ast.ExApp (_loc,
(Ast.ExApp (_loc,
(Ast.ExId (_loc, (Ast.IdLid (_loc, "value")))),
(Ast.ExId (_loc, (Ast.IdLid (_loc, f_name)))))),
(Ast.ExId (_loc, (Ast.IdLid (_loc, "a")))))))),
(Ast.ExApp (_loc,
(Ast.ExApp (_loc, (Ast.ExId (_loc, (Ast.IdLid (_loc, "*")))),
(Ast.ExId (_loc, (Ast.IdLid (_loc, "a")))))),
(Ast.ExInt (_loc, "2")))))))
我的问题是,有没有办法打印生成的ocaml代码?我应该使用什么 camlp4of 命令或选项来显示代码?从上面的例子中,我期望看到:
value my_func a = a * 2
这可能吗?原因是我想进行一些调试,以查看生成的ocaml代码的样子。
Camlp4.PreCast.Printers.OCaml.print_implem
д»…йҖӮз”ЁдәҺstr_item
гҖӮжҳҜеҗҰжңүе…¶д»–жү“еҚ°еҷЁеҸҜд»Ҙжү“еҚ°expr
пјҹ - Jason Yeolet _ = <expr>
str_item如何?对于类型,您也可以使用type foo = <type-expr>
等。 - gasche