I'm new with ocamlp4. I'm reading Jake Donham's blog to get started with it.
I'm trying to write a small CamlP4 program wich will get a simple type as:
type t = Foo | Bar | Baz
and generate a t_of_string
and a t_to_string
function.
Following the code on the blog I should be able to match the type with:
let wrap_str_item si =
let _loc = Ast.loc_of_str_item si in
<:str_item< $si$ >>
match wrap_str_item si with
| <:str_item< type $lid:tid$ = $Ast.TySum (_, ors)$ >> ->
But this doesn't work. When I look at the AST with campl4of xx.ml -printer o
and I reduce it to the interesting part:
(Ast.TyDcl (_, tid, [],
(Ast.TySum (_,
(Ast.TySum (_, ors)))), [])
But I need to match something like
(Ast.TyDcl (_loc, "t", [],
(Ast.TySum (_loc,
(Ast.TyOr (_loc,
(Ast.TyOr (_loc, (Ast.TyId (_loc, (Ast.IdUid (_loc, "Foo")))),
(Ast.TyId (_loc, (Ast.IdUid (_loc, "Bar")))))),
(Ast.TyId (_loc, (Ast.IdUid (_loc, "Baz")))))))),
[]))
It seem like the AST in the match case has a spurious TySum
, but I wasn't able to get rid of it.
Does anyone have a solution for that ?
That's a well known bug that has been fixed recently after 3.12.1 Mantis. Beware that your solution might not work with the next version where the bug has been fixed.