type t1 = A | B type t2 = Foo of string * t1 let print_t2 = function Foo (s,t) -> let print_t1 = function A -> "A" | B -> "B" in Printf.printf "Foo (\"%s\",%s)\n" s (print_t1 t) open Camlp4.PreCast let foo = Gram.Entry.mk "foo" let bar = Gram.Entry.mk "bar" EXTEND Gram GLOBAL: foo bar; foo: [ [ "foo"; i = LIDENT; b = bar -> Foo(i,b) ] ]; bar: [ [ "?" -> A | "." -> B ] ]; END let r = Gram.parse_string foo (Loc.mk "") "foo x?" in print_t2 r let _ = Gram.Entry.print Format.std_formatter foo try DELETE_RULE Gram foo: "foo"; LIDENT; bar END with Not_found -> Format.printf "@[no rule matched!@]@\n" (* the correct sentence let _ = try Gram.delete_rule foo [ Gram.Skeyword "foo"; Gram.Stoken (((function | LIDENT ((_)) -> true | _ -> false), "LIDENT _")); Gram.Snterm (Gram.Entry.obj (bar : 'bar Gram.Entry.t)) ] with | Not_found -> Format.printf "@[no rule matched!@]@\n" *) let _ = Gram.Entry.print Format.std_formatter foo