summaryrefslogtreecommitdiffstats
path: root/parsing
diff options
context:
space:
mode:
authorGabriel Scherer <gabriel.scherer@gmail.com>2014-03-20 15:21:00 +0000
committerGabriel Scherer <gabriel.scherer@gmail.com>2014-03-20 15:21:00 +0000
commit9e410c0cfec2dcd9b1cda21050c593da55703e50 (patch)
tree6dea7a1e294e84a561fe7e7880f06d6dac46dc96 /parsing
parent05982a5fc7a704ef6fb9ccb982b0fea25ccbab29 (diff)
Shorten syntax for functor signatures (patch by Thomas Gazagnaire)
``` (* Optional naming of parameter implementation *) module type X = functor (X:S) -> ... module type X = functor (_:S) -> ... (* shortening of functor module signatures *) module type F = functor (X:S) -> functor (Y:S) -> ... module type F = functor (X:S) (Y:S) -> ... ``` For consistency reasons, this commits also add shortening of functor implementations: ``` (* shortening of functor implementations *) module F = functor (X:S) -> functor (Y:S) -> ... module F = functor (X:S) (Y:S) -> ... ``` git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@14474 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'parsing')
-rw-r--r--parsing/parser.mly45
1 files changed, 36 insertions, 9 deletions
diff --git a/parsing/parser.mly b/parsing/parser.mly
index 4cc5d9b77..f709eb98e 100644
--- a/parsing/parser.mly
+++ b/parsing/parser.mly
@@ -535,6 +535,22 @@ parse_pattern:
/* Module expressions */
+module_expr_functor_arg:
+ LPAREN RPAREN
+ { mkrhs "()" 2, None }
+ | LPAREN UIDENT COLON module_type RPAREN
+ { mkrhs $2 2, Some $4 }
+ | LPAREN UNDERSCORE COLON module_type RPAREN
+ { mkrhs "_" 2 , Some $4 }
+;
+
+module_expr_functor_args:
+ module_expr_functor_args module_expr_functor_arg
+ { $2 :: $1 }
+ | module_expr_functor_arg
+ { [ $1 ] }
+;
+
module_expr:
mod_longident
{ mkmod(Pmod_ident (mkrhs $1 1)) }
@@ -542,10 +558,8 @@ module_expr:
{ mkmod(Pmod_structure($2)) }
| STRUCT structure error
{ unclosed "struct" 1 "end" 3 }
- | FUNCTOR LPAREN UIDENT COLON module_type RPAREN MINUSGREATER module_expr
- { mkmod(Pmod_functor(mkrhs $3 3, Some $5, $8)) }
- | FUNCTOR LPAREN RPAREN MINUSGREATER module_expr
- { mkmod(Pmod_functor(mkrhs "()" 3, None, $5)) }
+ | FUNCTOR module_expr_functor_args MINUSGREATER module_expr
+ { List.fold_left (fun acc (n, t) -> mkmod(Pmod_functor(n, t, acc))) $4 $2 }
| module_expr LPAREN module_expr RPAREN
{ mkmod(Pmod_apply($1, $3)) }
| module_expr LPAREN RPAREN
@@ -665,6 +679,22 @@ module_binding:
/* Module types */
+module_type_functor_arg:
+ LPAREN RPAREN
+ { mkrhs "()" 1, None }
+ | LPAREN UIDENT COLON module_type RPAREN
+ { mkrhs $2 2, Some $4 }
+ | LPAREN UNDERSCORE COLON module_type RPAREN
+ { mkrhs "_" 2, Some $4 }
+;
+
+module_type_functor_args:
+ module_type_functor_args module_type_functor_arg
+ { $2 :: $1 }
+ | module_type_functor_arg
+ { [ $1 ] }
+;
+
module_type:
mty_longident
{ mkmty(Pmty_ident (mkrhs $1 1)) }
@@ -672,12 +702,9 @@ module_type:
{ mkmty(Pmty_signature $2) }
| SIG signature error
{ unclosed "sig" 1 "end" 3 }
- | FUNCTOR LPAREN UIDENT COLON module_type RPAREN MINUSGREATER module_type
- %prec below_WITH
- { mkmty(Pmty_functor(mkrhs $3 3, Some $5, $8)) }
- | FUNCTOR LPAREN RPAREN MINUSGREATER module_type
+ | FUNCTOR module_type_functor_args MINUSGREATER module_type
%prec below_WITH
- { mkmty(Pmty_functor(mkrhs "()" 2, None, $5)) }
+ { List.fold_left (fun acc (n, t) -> mkmty(Pmty_functor(n, t, acc))) $4 $2 }
| module_type WITH with_constraints
{ mkmty(Pmty_with($1, List.rev $3)) }
| MODULE TYPE OF module_expr %prec below_LBRACKETAT