Guest User

Untitled

a guest
Feb 16th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. Index: Changes
  2. ===================================================================
  3. --- Changes (revision 13804)
  4. +++ Changes (working copy)
  5. @@ -6,6 +6,7 @@
  6. Bug fixes:
  7.  
  8. Features wishes:
  9. +- PR#6039: Syntax improvement for functor type definitions
  10.  
  11.  
  12. OCaml 4.01.0:
  13. Index: parsing/parser.mly
  14. ===================================================================
  15. --- parsing/parser.mly (revision 13803)
  16. +++ parsing/parser.mly (working copy)
  17. @@ -18,6 +18,12 @@
  18. open Longident
  19. open Parsetree
  20.  
  21. +let merge_loc loc1 loc2 =
  22. + (* Make a ghost location that goes from the beginning of [loc1] to
  23. + the end of [loc2]. *)
  24. + { loc_start = loc1.loc_start; loc_end = loc2.loc_end; loc_ghost = true }
  25. +;;
  26. +
  27. let mktyp d =
  28. { ptyp_desc = d; ptyp_loc = symbol_rloc() }
  29. let mkpat d =
  30. @@ -592,8 +598,8 @@
  31. { mkstr(Pstr_module(mkrhs $2 2, $3)) }
  32. | MODULE REC module_rec_bindings
  33. { mkstr(Pstr_recmodule(List.rev $3)) }
  34. - | MODULE TYPE ident EQUAL module_type
  35. - { mkstr(Pstr_modtype(mkrhs $3 3, $5)) }
  36. + | MODULE TYPE ident functor_args EQUAL module_type
  37. + { mkstr(Pstr_modtype(mkrhs $3 3, ($4 $6))) }
  38. | OPEN override_flag mod_longident
  39. { mkstr(Pstr_open ($2, mkrhs $3 3)) }
  40. | CLASS class_declarations
  41. @@ -628,9 +634,8 @@
  42. { mkmty(Pmty_signature(List.rev $2)) }
  43. | SIG signature error
  44. { unclosed "sig" 1 "end" 3 }
  45. - | FUNCTOR LPAREN UIDENT COLON module_type RPAREN MINUSGREATER module_type
  46. - %prec below_WITH
  47. - { mkmty(Pmty_functor(mkrhs $3 3, $5, $8)) }
  48. + | FUNCTOR functor_arg functor_args MINUSGREATER module_type %prec below_WITH
  49. + { {($2 ($3 $5)) with pmty_loc = symbol_rloc ()} }
  50. | module_type WITH with_constraints
  51. { mkmty(Pmty_with($1, List.rev $3)) }
  52. | MODULE TYPE OF module_expr
  53. @@ -640,6 +645,19 @@
  54. | LPAREN module_type error
  55. { unclosed "(" 1 ")" 3 }
  56. ;
  57. +functor_arg:
  58. + LPAREN UIDENT COLON module_type RPAREN
  59. + { let rloc = symbol_rloc () in
  60. + let id = mkrhs $2 2 in
  61. + fun mt ->
  62. + { pmty_desc = Pmty_functor (id, $4, mt);
  63. + pmty_loc = merge_loc rloc mt.pmty_loc }
  64. + }
  65. +;
  66. +functor_args:
  67. + /* nothing */ { fun mt -> mt }
  68. + | functor_arg functor_args { fun mt -> $1 ($2 mt) }
  69. +;
  70. signature:
  71. /* empty */ { [] }
  72. | signature signature_item { $2 :: $1 }
  73. @@ -662,8 +680,8 @@
  74. { mksig(Psig_recmodule(List.rev $3)) }
  75. | MODULE TYPE ident
  76. { mksig(Psig_modtype(mkrhs $3 3, Pmodtype_abstract)) }
  77. - | MODULE TYPE ident EQUAL module_type
  78. - { mksig(Psig_modtype(mkrhs $3 3, Pmodtype_manifest $5)) }
  79. + | MODULE TYPE ident functor_args EQUAL module_type
  80. + { mksig(Psig_modtype(mkrhs $3 3, Pmodtype_manifest ($4 $6))) }
  81. | OPEN override_flag mod_longident
  82. { mksig(Psig_open ($2, mkrhs $3 3)) }
  83. | INCLUDE module_type
Add Comment
Please, Sign In to add comment