--- camlp4/meta/pa_macro.ml 29 Oct 2003 22:49:48 -0000 +++ camlp4/meta/pa_macro.ml 31 Oct 2003 01:02:24 -0000 @@ -18,6 +18,7 @@ IFDEF THEN [ ELSE ] ENDIF IFNDEF THEN [ ELSE ] ENDIF + DEFINE = in __FILE__ __LOCATION__ @@ -36,6 +37,9 @@ can use it in expressions *and* in patterns. If the expression defining the macro cannot be used as a pattern, there is an error message if it is used in a pattern. + + You can also define a local macro in an expression usigng the DEFINE ... IN form. + Note that local macros have lowercase names and can not take parameters. INCLUDE can be used to include a file with a number of macro definitions; however it can not have any non-macro toplevel items. The INCLUDE files @@ -86,9 +90,15 @@ try <:expr< $anti:List.assoc x env$ >> with [ Not_found -> e ] | <:expr< ($list:x$) >> -> <:expr< ($list:List.map loop x$) >> + | <:expr< do {$list:x$} >> -> <:expr< do {$list:List.map loop x$} >> | <:expr< { $list:pel$ } >> -> let pel = List.map (fun (p, e) -> (p, loop e)) pel in <:expr< { $list:pel$ } >> + | <:expr< try $e$ with [ $list:pel$ ] >> -> + let loop' = fun + [ (p, Some e1, e2) -> (p, Some (loop e1), loop e2) + | (p, None, e2) -> (p, None, loop e2) ] in + <:expr< try $loop e$ with [ $list: (List.map loop' pel)$ ] >> | e -> e ] ; @@ -283,7 +293,10 @@ [ [ "IFDEF"; i = uident; "THEN"; e1 = expr; e2 = else_expr -> if is_defined i then e1 else e2 | "IFNDEF"; i = uident; "THEN"; e1 = expr; e2 = else_expr -> - if is_defined i then e2 else e1 ]] + if is_defined i then e2 else e1 + | "DEFINE"; i = LIDENT; "="; def = expr; "IN"; body = expr -> + subst loc [(i, def)] body + ]] ; expr: LEVEL "simple" [ [ LIDENT "__FILE__" -> <:expr< $str:Pcaml.input_file.val$ >>