Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: Changes
- ===================================================================
- --- Changes (revision 13804)
- +++ Changes (working copy)
- @@ -6,6 +6,7 @@
- Bug fixes:
- Features wishes:
- +- PR#6039: Syntax improvement for functor type definitions
- OCaml 4.01.0:
- Index: parsing/parser.mly
- ===================================================================
- --- parsing/parser.mly (revision 13803)
- +++ parsing/parser.mly (working copy)
- @@ -18,6 +18,12 @@
- open Longident
- open Parsetree
- +let merge_loc loc1 loc2 =
- + (* Make a ghost location that goes from the beginning of [loc1] to
- + the end of [loc2]. *)
- + { loc_start = loc1.loc_start; loc_end = loc2.loc_end; loc_ghost = true }
- +;;
- +
- let mktyp d =
- { ptyp_desc = d; ptyp_loc = symbol_rloc() }
- let mkpat d =
- @@ -592,8 +598,8 @@
- { mkstr(Pstr_module(mkrhs $2 2, $3)) }
- | MODULE REC module_rec_bindings
- { mkstr(Pstr_recmodule(List.rev $3)) }
- - | MODULE TYPE ident EQUAL module_type
- - { mkstr(Pstr_modtype(mkrhs $3 3, $5)) }
- + | MODULE TYPE ident functor_args EQUAL module_type
- + { mkstr(Pstr_modtype(mkrhs $3 3, ($4 $6))) }
- | OPEN override_flag mod_longident
- { mkstr(Pstr_open ($2, mkrhs $3 3)) }
- | CLASS class_declarations
- @@ -628,9 +634,8 @@
- { mkmty(Pmty_signature(List.rev $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, $5, $8)) }
- + | FUNCTOR functor_arg functor_args MINUSGREATER module_type %prec below_WITH
- + { {($2 ($3 $5)) with pmty_loc = symbol_rloc ()} }
- | module_type WITH with_constraints
- { mkmty(Pmty_with($1, List.rev $3)) }
- | MODULE TYPE OF module_expr
- @@ -640,6 +645,19 @@
- | LPAREN module_type error
- { unclosed "(" 1 ")" 3 }
- ;
- +functor_arg:
- + LPAREN UIDENT COLON module_type RPAREN
- + { let rloc = symbol_rloc () in
- + let id = mkrhs $2 2 in
- + fun mt ->
- + { pmty_desc = Pmty_functor (id, $4, mt);
- + pmty_loc = merge_loc rloc mt.pmty_loc }
- + }
- +;
- +functor_args:
- + /* nothing */ { fun mt -> mt }
- + | functor_arg functor_args { fun mt -> $1 ($2 mt) }
- +;
- signature:
- /* empty */ { [] }
- | signature signature_item { $2 :: $1 }
- @@ -662,8 +680,8 @@
- { mksig(Psig_recmodule(List.rev $3)) }
- | MODULE TYPE ident
- { mksig(Psig_modtype(mkrhs $3 3, Pmodtype_abstract)) }
- - | MODULE TYPE ident EQUAL module_type
- - { mksig(Psig_modtype(mkrhs $3 3, Pmodtype_manifest $5)) }
- + | MODULE TYPE ident functor_args EQUAL module_type
- + { mksig(Psig_modtype(mkrhs $3 3, Pmodtype_manifest ($4 $6))) }
- | OPEN override_flag mod_longident
- { mksig(Psig_open ($2, mkrhs $3 3)) }
- | INCLUDE module_type
Add Comment
Please, Sign In to add comment