summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Pouillard <np@nicolaspouillard.fr>2010-05-12 16:00:06 +0000
committerNicolas Pouillard <np@nicolaspouillard.fr>2010-05-12 16:00:06 +0000
commitf40a38533ba26de474094272eb22327d9d536246 (patch)
tree6dea9084f7aea1f40438563f641915c012696746
parentdc949324379acfddeb84074f70807ea86e00dcdd (diff)
downloadocaml-f40a38533ba26de474094272eb22327d9d536246.tar.gz
camlp4: add support for let-open-in
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10395 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r--camlp4/Camlp4/Camlp4Ast.partial.ml4
-rw-r--r--camlp4/Camlp4/Printers/OCaml.ml4
-rw-r--r--camlp4/Camlp4/Struct/Camlp4Ast2OCamlAst.ml2
-rw-r--r--camlp4/Camlp4Parsers/Camlp4OCamlParser.ml5
-rw-r--r--camlp4/Camlp4Parsers/Camlp4OCamlRevisedParser.ml4
-rw-r--r--camlp4/boot/Camlp4.ml43
-rw-r--r--camlp4/boot/Camlp4Ast.ml35
-rw-r--r--camlp4/boot/camlp4boot.ml20
8 files changed, 109 insertions, 8 deletions
diff --git a/camlp4/Camlp4/Camlp4Ast.partial.ml b/camlp4/Camlp4/Camlp4Ast.partial.ml
index 19b5053b86..4ed2fb9946 100644
--- a/camlp4/Camlp4/Camlp4Ast.partial.ml
+++ b/camlp4/Camlp4/Camlp4Ast.partial.ml
@@ -148,7 +148,9 @@
(* `s *)
| ExVrn of loc and string
(* while e do { e } *)
- | ExWhi of loc and expr and expr ]
+ | ExWhi of loc and expr and expr
+ (* let open i in e *)
+ | ExOpI of loc and ident and expr ]
and module_type =
[ MtNil of loc
(* i *) (* A.B.C *)
diff --git a/camlp4/Camlp4/Printers/OCaml.ml b/camlp4/Camlp4/Printers/OCaml.ml
index b3641718cb..b47d4555ed 100644
--- a/camlp4/Camlp4/Printers/OCaml.ml
+++ b/camlp4/Camlp4/Printers/OCaml.ml
@@ -456,6 +456,9 @@ module Make (Syntax : Sig.Camlp4Syntax) = struct
| _ ->
pp f "@[<hv0>@[<2>let %a%a@]@ @[<hv2>in@ %a@]@]"
o#rec_flag r o#binding bi o#reset_semi#expr e ]
+ | <:expr< let open $i$ in $e$ >> ->
+ pp f "@[<2>let open %a@]@ @[<2>in@ %a@]"
+ o#ident i o#reset_semi#expr e
| <:expr< match $e$ with [ $a$ ] >> ->
pp f "@[<hv0>@[<hv0>@[<2>match %a@]@ with@]%a@]"
o#expr e o#match_case a
@@ -549,6 +552,7 @@ module Make (Syntax : Sig.Camlp4Syntax) = struct
<:expr< if $_$ then $_$ else $_$ >> |
<:expr< let $rec:_$ $_$ in $_$ >> |
<:expr< let module $_$ = $_$ in $_$ >> |
+ <:expr< let open $_$ in $_$ >> |
<:expr< assert $_$ >> | <:expr< assert False >> |
<:expr< lazy $_$ >> | <:expr< new $_$ >> |
<:expr< object ($_$) $_$ end >> ->
diff --git a/camlp4/Camlp4/Struct/Camlp4Ast2OCamlAst.ml b/camlp4/Camlp4/Struct/Camlp4Ast2OCamlAst.ml
index de6e8add48..8354935d6a 100644
--- a/camlp4/Camlp4/Struct/Camlp4Ast2OCamlAst.ml
+++ b/camlp4/Camlp4/Struct/Camlp4Ast2OCamlAst.ml
@@ -735,6 +735,8 @@ module Make (Ast : Sig.Camlp4Ast) = struct
| ExWhi loc e1 el ->
let e2 = ExSeq loc el in
mkexp loc (Pexp_while (expr e1) (expr e2))
+ | <:expr@loc< let open $i$ in $e$ >> ->
+ mkexp loc (Pexp_open (long_uident i) (expr e))
| <:expr@loc< $_$,$_$ >> -> error loc "expr, expr: not allowed here"
| <:expr@loc< $_$;$_$ >> ->
error loc "expr; expr: not allowed here, use do {...} or [|...|] to surround them"
diff --git a/camlp4/Camlp4Parsers/Camlp4OCamlParser.ml b/camlp4/Camlp4Parsers/Camlp4OCamlParser.ml
index d9db7b2964..2bedf9aa11 100644
--- a/camlp4/Camlp4Parsers/Camlp4OCamlParser.ml
+++ b/camlp4/Camlp4Parsers/Camlp4OCamlParser.ml
@@ -180,6 +180,7 @@ module Make (Syntax : Sig.Camlp4Syntax) = struct
DELETE_RULE Gram meth_list: meth_decl; opt_dot_dot END;
DELETE_RULE Gram expr: "let"; opt_rec; binding; "in"; SELF END;
DELETE_RULE Gram expr: "let"; "module"; a_UIDENT; module_binding0; "in"; SELF END;
+ DELETE_RULE Gram expr: "let"; "open"; module_longident; "in"; SELF END;
DELETE_RULE Gram expr: "fun"; "["; LIST0 match_case0 SEP "|"; "]" END;
DELETE_RULE Gram expr: "if"; SELF; "then"; SELF; "else"; SELF END;
DELETE_RULE Gram expr: "do"; do_sequence END;
@@ -286,6 +287,8 @@ module Make (Syntax : Sig.Camlp4Syntax) = struct
| _ -> <:str_item< value $rec:r$ $bi$ >> ]
| "let"; "module"; m = a_UIDENT; mb = module_binding0; "in"; e = expr ->
<:str_item< let module $m$ = $mb$ in $e$ >>
+ | "let"; "open"; i = module_longident; "in"; e = expr ->
+ <:str_item< let open $id:i$ in $e$ >>
] ]
;
seq_expr:
@@ -302,6 +305,8 @@ module Make (Syntax : Sig.Camlp4Syntax) = struct
| "let"; "module"; m = a_UIDENT; mb = module_binding0; "in";
e = expr LEVEL ";" ->
<:expr< let module $m$ = $mb$ in $e$ >>
+ | "let"; "open"; i = module_longident; "in"; e = expr LEVEL ";" ->
+ <:expr< let open $id:i$ in $e$ >>
| "function"; a = match_case ->
<:expr< fun [ $a$ ] >>
| "if"; e1 = SELF; "then"; e2 = expr LEVEL "top";
diff --git a/camlp4/Camlp4Parsers/Camlp4OCamlRevisedParser.ml b/camlp4/Camlp4Parsers/Camlp4OCamlRevisedParser.ml
index fbd16aae3c..f31636e22c 100644
--- a/camlp4/Camlp4Parsers/Camlp4OCamlRevisedParser.ml
+++ b/camlp4/Camlp4Parsers/Camlp4OCamlRevisedParser.ml
@@ -604,6 +604,8 @@ Very old (no more supported) syntax:\n\
<:expr< let $rec:r$ $bi$ in $x$ >>
| "let"; "module"; m = a_UIDENT; mb = module_binding0; "in"; e = SELF ->
<:expr< let module $m$ = $mb$ in $e$ >>
+ | "let"; "open"; i = module_longident; "in"; e = SELF ->
+ <:expr< let open $id:i$ in $e$ >>
| "fun"; "["; a = LIST0 match_case0 SEP "|"; "]" ->
<:expr< fun [ $list:a$ ] >>
| "fun"; e = fun_def -> e
@@ -760,6 +762,8 @@ Very old (no more supported) syntax:\n\
k <:expr< let module $m$ = $mb$ in $e$ >>
| "let"; "module"; m = a_UIDENT; mb = module_binding0; ";"; el = SELF ->
<:expr< let module $m$ = $mb$ in $mksequence _loc el$ >>
+ | "let"; "open"; i = module_longident; "in"; e = SELF ->
+ <:expr< let open $id:i$ in $e$ >>
| `ANTIQUOT ("list" as n) s -> <:expr< $anti:mk_anti ~c:"expr;" n s$ >>
| e = expr; k = sequence' -> k e ] ]
;
diff --git a/camlp4/boot/Camlp4.ml b/camlp4/boot/Camlp4.ml
index 9e49f8f872..fa03d37ca3 100644
--- a/camlp4/boot/Camlp4.ml
+++ b/camlp4/boot/Camlp4.ml
@@ -1046,6 +1046,8 @@ module Sig =
ExVrn of loc * string
| (* while e do { e } *)
ExWhi of loc * expr * expr
+ | (* let open i in e *)
+ ExOpI of loc * ident * expr
and module_type =
| MtNil of loc
| (* i *)
@@ -1821,6 +1823,7 @@ module Sig =
| ExTyc of loc * expr * ctyp
| ExVrn of loc * string
| ExWhi of loc * expr * expr
+ | ExOpI of loc * ident * expr
and module_type =
| MtNil of loc
| MtId of loc * ident
@@ -8064,6 +8067,17 @@ module Struct =
meta_loc _loc x0)
and meta_expr _loc =
function
+ | Ast.ExOpI (x0, x1, x2) ->
+ Ast.ExApp (_loc,
+ Ast.ExApp (_loc,
+ Ast.ExApp (_loc,
+ Ast.ExId (_loc,
+ Ast.IdAcc (_loc,
+ Ast.IdUid (_loc, "Ast"),
+ Ast.IdUid (_loc, "ExOpI"))),
+ meta_loc _loc x0),
+ meta_ident _loc x1),
+ meta_expr _loc x2)
| Ast.ExWhi (x0, x1, x2) ->
Ast.ExApp (_loc,
Ast.ExApp (_loc,
@@ -10103,6 +10117,17 @@ module Struct =
meta_loc _loc x0)
and meta_expr _loc =
function
+ | Ast.ExOpI (x0, x1, x2) ->
+ Ast.PaApp (_loc,
+ Ast.PaApp (_loc,
+ Ast.PaApp (_loc,
+ Ast.PaId (_loc,
+ Ast.IdAcc (_loc,
+ Ast.IdUid (_loc, "Ast"),
+ Ast.IdUid (_loc, "ExOpI"))),
+ meta_loc _loc x0),
+ meta_ident _loc x1),
+ meta_expr _loc x2)
| Ast.ExWhi (x0, x1, x2) ->
Ast.PaApp (_loc,
Ast.PaApp (_loc,
@@ -11950,6 +11975,10 @@ module Struct =
let _x = o#loc _x in
let _x_i1 = o#expr _x_i1 in
let _x_i2 = o#expr _x_i2 in ExWhi (_x, _x_i1, _x_i2)
+ | ExOpI (_x, _x_i1, _x_i2) ->
+ let _x = o#loc _x in
+ let _x_i1 = o#ident _x_i1 in
+ let _x_i2 = o#expr _x_i2 in ExOpI (_x, _x_i1, _x_i2)
method ctyp : ctyp -> ctyp =
function
@@ -12715,6 +12744,9 @@ module Struct =
| ExWhi (_x, _x_i1, _x_i2) ->
let o = o#loc _x in
let o = o#expr _x_i1 in let o = o#expr _x_i2 in o
+ | ExOpI (_x, _x_i1, _x_i2) ->
+ let o = o#loc _x in
+ let o = o#ident _x_i1 in let o = o#expr _x_i2 in o
method ctyp : ctyp -> 'self_type =
function
@@ -14195,6 +14227,8 @@ module Struct =
| ExWhi (loc, e1, el) ->
let e2 = ExSeq (loc, el)
in mkexp loc (Pexp_while (expr e1, expr e2))
+ | Ast.ExOpI (loc, i, e) ->
+ mkexp loc (Pexp_open (long_uident i, expr e))
| Ast.ExCom (loc, _, _) ->
error loc "expr, expr: not allowed here"
| Ast.ExSem (loc, _, _) ->
@@ -18414,6 +18448,9 @@ module Printers =
"@[<hv0>@[<2>let %a%a@]@ @[<hv2>in@ %a@]@]"
o#rec_flag r o#binding bi o#reset_semi#expr
e)
+ | Ast.ExOpI (_, i, e) ->
+ pp f "@[<2>let open %a@]@ @[<2>in@ %a@]" o#ident i
+ o#reset_semi#expr e
| Ast.ExMat (_, e, a) ->
pp f "@[<hv0>@[<hv0>@[<2>match %a@]@ with@]%a@]"
o#expr e o#match_case a
@@ -18528,9 +18565,9 @@ module Printers =
Ast.ExFun (_, _) | Ast.ExMat (_, _, _) |
Ast.ExTry (_, _, _) | Ast.ExIfe (_, _, _, _) |
Ast.ExLet (_, _, _, _) | Ast.ExLmd (_, _, _, _) |
- Ast.ExAsr (_, _) | Ast.ExAsf _ | Ast.ExLaz (_, _) |
- Ast.ExNew (_, _) | Ast.ExObj (_, _, _) ->
- pp f "(%a)" o#reset#expr e
+ Ast.ExOpI (_, _, _) | Ast.ExAsr (_, _) |
+ Ast.ExAsf _ | Ast.ExLaz (_, _) | Ast.ExNew (_, _) |
+ Ast.ExObj (_, _, _) -> pp f "(%a)" o#reset#expr e
method direction_flag =
fun f b ->
diff --git a/camlp4/boot/Camlp4Ast.ml b/camlp4/boot/Camlp4Ast.ml
index 68ce6da48a..d7af05e744 100644
--- a/camlp4/boot/Camlp4Ast.ml
+++ b/camlp4/boot/Camlp4Ast.ml
@@ -1180,7 +1180,17 @@ module Make (Loc : Sig.Loc) : Sig.Camlp4Ast with module Loc = Loc =
(meta_loc _loc x0) ]
and meta_expr _loc =
fun
- [ Ast.ExWhi x0 x1 x2 ->
+ [ Ast.ExOpI x0 x1 x2 ->
+ Ast.ExApp _loc
+ (Ast.ExApp _loc
+ (Ast.ExApp _loc
+ (Ast.ExId _loc
+ (Ast.IdAcc _loc (Ast.IdUid _loc "Ast")
+ (Ast.IdUid _loc "ExOpI")))
+ (meta_loc _loc x0))
+ (meta_ident _loc x1))
+ (meta_expr _loc x2)
+ | Ast.ExWhi x0 x1 x2 ->
Ast.ExApp _loc
(Ast.ExApp _loc
(Ast.ExApp _loc
@@ -3100,7 +3110,17 @@ module Make (Loc : Sig.Loc) : Sig.Camlp4Ast with module Loc = Loc =
(meta_loc _loc x0) ]
and meta_expr _loc =
fun
- [ Ast.ExWhi x0 x1 x2 ->
+ [ Ast.ExOpI x0 x1 x2 ->
+ Ast.PaApp _loc
+ (Ast.PaApp _loc
+ (Ast.PaApp _loc
+ (Ast.PaId _loc
+ (Ast.IdAcc _loc (Ast.IdUid _loc "Ast")
+ (Ast.IdUid _loc "ExOpI")))
+ (meta_loc _loc x0))
+ (meta_ident _loc x1))
+ (meta_expr _loc x2)
+ | Ast.ExWhi x0 x1 x2 ->
Ast.PaApp _loc
(Ast.PaApp _loc
(Ast.PaApp _loc
@@ -4817,7 +4837,11 @@ module Make (Loc : Sig.Loc) : Sig.Camlp4Ast with module Loc = Loc =
| ExWhi _x _x_i1 _x_i2 ->
let _x = o#loc _x in
let _x_i1 = o#expr _x_i1 in
- let _x_i2 = o#expr _x_i2 in ExWhi _x _x_i1 _x_i2 ];
+ let _x_i2 = o#expr _x_i2 in ExWhi _x _x_i1 _x_i2
+ | ExOpI _x _x_i1 _x_i2 ->
+ let _x = o#loc _x in
+ let _x_i1 = o#ident _x_i1 in
+ let _x_i2 = o#expr _x_i2 in ExOpI _x _x_i1 _x_i2 ];
method ctyp : ctyp -> ctyp =
fun
[ TyNil _x -> let _x = o#loc _x in TyNil _x
@@ -5457,7 +5481,10 @@ module Make (Loc : Sig.Loc) : Sig.Camlp4Ast with module Loc = Loc =
| ExVrn _x _x_i1 -> let o = o#loc _x in let o = o#string _x_i1 in o
| ExWhi _x _x_i1 _x_i2 ->
let o = o#loc _x in
- let o = o#expr _x_i1 in let o = o#expr _x_i2 in o ];
+ let o = o#expr _x_i1 in let o = o#expr _x_i2 in o
+ | ExOpI _x _x_i1 _x_i2 ->
+ let o = o#loc _x in
+ let o = o#ident _x_i1 in let o = o#expr _x_i2 in o ];
method ctyp : ctyp -> 'self_type =
fun
[ TyNil _x -> let o = o#loc _x in o
diff --git a/camlp4/boot/camlp4boot.ml b/camlp4/boot/camlp4boot.ml
index 0a6c071d11..d84dc53bc3 100644
--- a/camlp4/boot/camlp4boot.ml
+++ b/camlp4/boot/camlp4boot.ml
@@ -1880,6 +1880,16 @@ Very old (no more supported) syntax:\n\
(_loc : Gram.Loc.t) ->
(Ast.ExFun (_loc, Ast.mcOr_of_list a) :
'expr))));
+ ([ Gram.Skeyword "let"; Gram.Skeyword "open";
+ Gram.Snterm
+ (Gram.Entry.obj
+ (module_longident :
+ 'module_longident Gram.Entry.t));
+ Gram.Skeyword "in"; Gram.Sself ],
+ (Gram.Action.mk
+ (fun (e : 'expr) _ (i : 'module_longident) _ _
+ (_loc : Gram.Loc.t) ->
+ (Ast.ExOpI (_loc, i, e) : 'expr))));
([ Gram.Skeyword "let"; Gram.Skeyword "module";
Gram.Snterm
(Gram.Entry.obj
@@ -2677,6 +2687,16 @@ Very old (no more supported) syntax:\n\
mk_anti ~c: "expr;" n s) :
'sequence)
| _ -> assert false)));
+ ([ Gram.Skeyword "let"; Gram.Skeyword "open";
+ Gram.Snterm
+ (Gram.Entry.obj
+ (module_longident :
+ 'module_longident Gram.Entry.t));
+ Gram.Skeyword "in"; Gram.Sself ],
+ (Gram.Action.mk
+ (fun (e : 'sequence) _ (i : 'module_longident) _
+ _ (_loc : Gram.Loc.t) ->
+ (Ast.ExOpI (_loc, i, e) : 'sequence))));
([ Gram.Skeyword "let"; Gram.Skeyword "module";
Gram.Snterm
(Gram.Entry.obj