(* ocamlc -pp "camlp4o pa_extend.cmo q_MLast.cmo" -I +camlp4 -c syntax1.ml *) open Pcaml;; EXTEND str_item: LAST [[ EOI -> assert false | "WHERE" -> <:str_item< $lid:"wHERE"$ >> ]]; END;; (* generally, this splits a list, then reverses the large parts and concat them back *) let wrap f x = let split pred l = (* cound not found it *) let rec s1 rl add argl = try let e = List.hd argl and tl = List.tl argl in match (pred e,add,rl) with (false,true,rl) -> s1 ([e]::rl) false tl | (false,false,re::rl') -> s1 ((e::re)::rl') false tl | (false,false,[]) -> assert false | (true,false,rl) -> s1 rl true tl | (true,true,rl) -> s1 ([]::rl) true tl with Failure "hd" | Failure "tl" -> rl in s1 [] true l in let wrapV (l,fl) = let m1 = function (<:str_item< $lid:"wHERE"$ >>,_) -> true | _ -> false in let (&>) f1 f2 x = f2 (f1 x) in let res = (split m1 &> List.map List.rev &> List.concat) l in (res,fl) in wrapV (f x);; Pcaml.parse_implem := wrap (!Pcaml.parse_implem);;