diff options
Diffstat (limited to 'ocaml-binary-annot/camlp4/examples/global_handler.ml')
| -rw-r--r-- | ocaml-binary-annot/camlp4/examples/global_handler.ml | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/ocaml-binary-annot/camlp4/examples/global_handler.ml b/ocaml-binary-annot/camlp4/examples/global_handler.ml new file mode 100644 index 0000000000..e2da52873d --- /dev/null +++ b/ocaml-binary-annot/camlp4/examples/global_handler.ml @@ -0,0 +1,19 @@ +open Camlp4.PreCast; + +value ghost = Loc.ghost; + +value global_handler_ref = ref <:expr@ghost<>>; + +value find_global_handler = + Ast.map_str_item begin + fun + [ <:str_item@_loc< value global_handler = $f$ >> -> + (global_handler_ref.val := f; <:str_item<>>) + | st -> st ] + end; + +AstFilters.register_str_item_filter begin fun st -> + let _ = find_global_handler#str_item st in + <:str_item@ghost< try let module Main = struct $st$ end in () + with e -> $global_handler_ref.val$ e >> +end; |
