diff options
Diffstat (limited to 'parsing/parser.mly')
-rw-r--r-- | parsing/parser.mly | 45 |
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 |