Skip to content

Commit 7685421

Browse files
committed
Factor out the productions for functor parameters.
Functor parameters can occur in three contexts: (1) in functor bindings: module M (X : S) (Y : T) = ... (2) in anonymous functor expressionms: functor (X : S) (Y : T) -> ... (3) in signature expressions module type T = functor (X : S) (Y : T) -> ... This patch simplifies the grammar by using common productions (functor_arg, functor_args) to handle all three contexts, and by combining the productions for named and unnamed parameters. As a side effect, unnamed functor arguments are now available in functor bindings: module M (_ : S) (_ : T) = ...
1 parent eeae918 commit 7685421

File tree

1 file changed

+14
-29
lines changed

1 file changed

+14
-29
lines changed

parsing/parser.mly

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -535,19 +535,22 @@ parse_pattern:
535535

536536
/* Module expressions */
537537

538-
module_expr_functor_arg:
538+
functor_arg:
539539
LPAREN RPAREN
540540
{ mkrhs "()" 2, None }
541-
| LPAREN UIDENT COLON module_type RPAREN
541+
| LPAREN functor_arg_name COLON module_type RPAREN
542542
{ mkrhs $2 2, Some $4 }
543-
| LPAREN UNDERSCORE COLON module_type RPAREN
544-
{ mkrhs "_" 2 , Some $4 }
545543
;
546544

547-
module_expr_functor_args:
548-
module_expr_functor_args module_expr_functor_arg
545+
functor_arg_name:
546+
UIDENT { $1 }
547+
| UNDERSCORE { "_" }
548+
;
549+
550+
functor_args:
551+
functor_args functor_arg
549552
{ $2 :: $1 }
550-
| module_expr_functor_arg
553+
| functor_arg
551554
{ [ $1 ] }
552555
;
553556

@@ -558,7 +561,7 @@ module_expr:
558561
{ mkmod(Pmod_structure($2)) }
559562
| STRUCT structure error
560563
{ unclosed "struct" 1 "end" 3 }
561-
| FUNCTOR module_expr_functor_args MINUSGREATER module_expr
564+
| FUNCTOR functor_args MINUSGREATER module_expr
562565
{ List.fold_left (fun acc (n, t) -> mkmod(Pmod_functor(n, t, acc))) $4 $2 }
563566
| module_expr LPAREN module_expr RPAREN
564567
{ mkmod(Pmod_apply($1, $3)) }
@@ -663,10 +666,8 @@ module_binding_body:
663666
{ $2 }
664667
| COLON module_type EQUAL module_expr
665668
{ mkmod(Pmod_constraint($4, $2)) }
666-
| LPAREN UIDENT COLON module_type RPAREN module_binding_body
667-
{ mkmod(Pmod_functor(mkrhs $2 2, Some $4, $6)) }
668-
| LPAREN RPAREN module_binding_body
669-
{ mkmod(Pmod_functor(mkrhs "()" 1, None, $3)) }
669+
| functor_arg module_binding_body
670+
{ mkmod(Pmod_functor(fst $1, snd $1, $2)) }
670671
;
671672
module_bindings:
672673
module_binding { [$1] }
@@ -679,30 +680,14 @@ module_binding:
679680

680681
/* Module types */
681682

682-
module_type_functor_arg:
683-
LPAREN RPAREN
684-
{ mkrhs "()" 1, None }
685-
| LPAREN UIDENT COLON module_type RPAREN
686-
{ mkrhs $2 2, Some $4 }
687-
| LPAREN UNDERSCORE COLON module_type RPAREN
688-
{ mkrhs "_" 2, Some $4 }
689-
;
690-
691-
module_type_functor_args:
692-
module_type_functor_args module_type_functor_arg
693-
{ $2 :: $1 }
694-
| module_type_functor_arg
695-
{ [ $1 ] }
696-
;
697-
698683
module_type:
699684
mty_longident
700685
{ mkmty(Pmty_ident (mkrhs $1 1)) }
701686
| SIG signature END
702687
{ mkmty(Pmty_signature $2) }
703688
| SIG signature error
704689
{ unclosed "sig" 1 "end" 3 }
705-
| FUNCTOR module_type_functor_args MINUSGREATER module_type
690+
| FUNCTOR functor_args MINUSGREATER module_type
706691
%prec below_WITH
707692
{ List.fold_left (fun acc (n, t) -> mkmty(Pmty_functor(n, t, acc))) $4 $2 }
708693
| module_type WITH with_constraints

0 commit comments

Comments
 (0)