@@ -986,7 +986,8 @@ let unboxed_type sloc lident tys =
986
986
% token IN " in"
987
987
% token INCLUDE " include"
988
988
% token < string > INFIXOP0 " !=" (* just an example *)
989
- % token < string > INFIXOP1 " @" (* just an example *)
989
+ % token AT " @"
990
+ % token < string > INFIXOP1 " ^" (* just an example *)
990
991
% token < string > INFIXOP2 " +!" (* chosen with care; see above *)
991
992
% token < string > INFIXOP3 " land" (* just an example *)
992
993
% token < string > INFIXOP4 " **" (* just an example *)
@@ -1123,6 +1124,7 @@ The precedences must be listed from low to high.
1123
1124
%right AMPERSAND AMPERAMPER /* expr (e && e && e ) */
1124
1125
%nonassoc below_EQUAL
1125
1126
%left INFIXOP0 EQUAL LESS GREATER /* expr (e OP e OP e ) */
1127
+ %right AT
1126
1128
%right INFIXOP1 /* expr (e OP e OP e ) */
1127
1129
%nonassoc below_LBRACKETAT
1128
1130
%nonassoc LBRACKETAT
@@ -2588,31 +2590,39 @@ seq_expr:
2588
2590
| or_function(fun_seq_expr) { $ 1 }
2589
2591
;
2590
2592
labeled_simple_pattern:
2591
- QUESTION LPAREN mode_expr_legacy label_let_pattern opt_default RPAREN
2592
- { (Optional (fst $ 4 ), $ 5 , mkpat_with_modes $ 3 (snd $ 4 ) ) }
2593
+ QUESTION LPAREN mode_expr_legacy label_let_pattern mode_expr opt_default RPAREN
2594
+ { (Optional (fst $ 4 ), $ 6 ,
2595
+ mkpat_with_modes (Mode. concat $ 3 $ 5 ) (snd $ 4 ) ) }
2593
2596
| QUESTION label_var
2594
2597
{ (Optional (fst $ 2 ), None , snd $ 2 ) }
2595
- | OPTLABEL LPAREN mode_expr_legacy let_pattern opt_default RPAREN
2596
- { (Optional $ 1 , $ 5 , mkpat_with_modes $ 3 $ 4 ) }
2598
+ | OPTLABEL LPAREN mode_expr_legacy let_pattern mode_expr opt_default RPAREN
2599
+ { (Optional $ 1 , $ 6 ,
2600
+ mkpat_with_modes (Mode. concat $ 3 $ 5 ) $ 4 ) }
2597
2601
| OPTLABEL pattern_var
2598
2602
{ (Optional $ 1 , None , $ 2 ) }
2599
- | TILDE LPAREN mode_expr_legacy label_let_pattern RPAREN
2603
+ | TILDE LPAREN mode_expr_legacy label_let_pattern mode_expr RPAREN
2600
2604
{ (Labelled (fst $ 4 ), None ,
2601
- mkpat_with_modes $ 3 (snd $ 4 ) ) }
2605
+ mkpat_with_modes ( Mode. concat $ 3 $ 5 ) (snd $ 4 ) ) }
2602
2606
| TILDE label_var
2603
2607
{ (Labelled (fst $ 2 ), None , snd $ 2 ) }
2604
2608
| LABEL simple_pattern
2605
2609
{ (Labelled $ 1 , None , $ 2 ) }
2606
- | LABEL LPAREN mode_expr_legacy_nonempty pattern RPAREN
2607
- { (Labelled $ 1 , None , mkpat_with_modes $ 3 $ 4 ) }
2610
+ | LABEL LPAREN mode_expr_legacy_nonempty pattern mode_expr RPAREN
2611
+ { (Labelled $ 1 , None , mkpat_with_modes (Mode. concat $ 3 $ 5 ) $ 4 ) }
2612
+ | LABEL LPAREN pattern mode_expr_nonempty RPAREN
2613
+ { (Labelled $ 1 , None , mkpat_with_modes $ 4 $ 3 ) }
2608
2614
| simple_pattern
2609
2615
{ (Nolabel , None , $ 1 ) }
2610
- | LPAREN mode_expr_legacy_nonempty let_pattern RPAREN
2611
- { (Nolabel , None , mkpat_with_modes $ 2 $ 3 ) }
2616
+ | LPAREN mode_expr_legacy_nonempty let_pattern mode_expr RPAREN
2617
+ { (Nolabel , None , mkpat_with_modes (Mode. concat $ 2 $ 4 ) $ 3 ) }
2618
+ | LPAREN let_pattern mode_expr_nonempty RPAREN
2619
+ { (Nolabel , None , mkpat_with_modes $ 3 $ 2 ) }
2612
2620
| LABEL LPAREN poly_pattern RPAREN
2613
2621
{ (Labelled $ 1 , None , $ 3 ) }
2614
- | LABEL LPAREN mode_expr_legacy_nonempty poly_pattern RPAREN
2615
- { (Labelled $ 1 , None , mkpat_with_modes $ 3 $ 4 ) }
2622
+ | LABEL LPAREN mode_expr_legacy_nonempty poly_pattern mode_expr RPAREN
2623
+ { (Labelled $ 1 , None , mkpat_with_modes (Mode. concat $ 3 $ 5 ) $ 4 ) }
2624
+ | LABEL LPAREN poly_pattern mode_expr_nonempty RPAREN
2625
+ { (Labelled $ 1 , None , mkpat_with_modes $ 4 $ 3 ) }
2616
2626
| LPAREN poly_pattern RPAREN
2617
2627
{ (Nolabel , None , $ 2 ) }
2618
2628
;
@@ -2737,6 +2747,8 @@ fun_expr:
2737
2747
| mode_legacy seq_expr
2738
2748
{ let {txt; loc} = $ 1 in
2739
2749
mkexp_with_modes $ sloc (Mode. singleton txt loc) $ 2 }
2750
+ | mode_expr_nonempty seq_expr
2751
+ { mkexp_with_modes $ sloc $ 1 $ 2 }
2740
2752
| EXCLAVE seq_expr
2741
2753
{ mkexp_exclave ~loc: $ sloc ~kwd_loc: ($ loc($ 1 )) $ 2 }
2742
2754
;
@@ -3048,27 +3060,29 @@ labeled_simple_expr:
3048
3060
let_binding_body_no_punning:
3049
3061
let_ident strict_binding
3050
3062
{ ($ 1 , $ 2 , None , [] ) }
3051
- | mode_expr_legacy let_ident type_constraint EQUAL seq_expr
3063
+ | mode_expr_legacy let_ident mode_expr type_constraint EQUAL seq_expr
3052
3064
{ let v = $ 2 in (* PR#7344 *)
3053
3065
let t =
3054
- match $ 3 with
3066
+ match $ 4 with
3055
3067
| N_ary. Pconstraint t ->
3056
3068
Pvc_constraint { locally_abstract_univars = [] ; typ= t }
3057
3069
| N_ary. Pcoerce (ground , coercion ) -> Pvc_coercion { ground; coercion}
3058
3070
in
3059
- let exp = mkexp_with_modes $ sloc $ 1 $ 5 in
3060
- (v, exp, Some t, let_binding_mode_attrs $ 1 )
3071
+ let modes = Mode. concat $ 1 $ 3 in
3072
+ let exp = mkexp_with_modes $ sloc modes $ 6 in
3073
+ (v, exp, Some t, let_binding_mode_attrs modes)
3061
3074
}
3062
- | mode_expr_legacy let_ident COLON poly(core_type) EQUAL seq_expr
3063
- { let bound_vars, inner_type = $ 4 in
3075
+ | mode_expr_legacy let_ident mode_expr COLON poly(core_type) EQUAL seq_expr
3076
+ { let bound_vars, inner_type = $ 5 in
3064
3077
let ltyp = Jane_syntax.Layouts. Ltyp_poly { bound_vars; inner_type } in
3065
- let typ_loc = Location. ghostify (make_loc $ loc($ 4 )) in
3078
+ let typ_loc = Location. ghostify (make_loc $ loc($ 5 )) in
3066
3079
let typ =
3067
3080
Jane_syntax.Layouts. type_of ~loc: typ_loc ltyp
3068
3081
in
3069
- let exp = mkexp_with_modes $ sloc $ 1 $ 6 in
3082
+ let modes = Mode. concat $ 1 $ 3 in
3083
+ let exp = mkexp_with_modes $ sloc modes $ 7 in
3070
3084
($ 2 , exp, Some (Pvc_constraint { locally_abstract_univars = [] ; typ }),
3071
- let_binding_mode_attrs $ 1 )
3085
+ let_binding_mode_attrs modes )
3072
3086
}
3073
3087
| let_ident COLON TYPE newtypes DOT core_type EQUAL seq_expr
3074
3088
(* The code upstream looks like:
@@ -3097,9 +3111,13 @@ let_binding_body_no_punning:
3097
3111
{ ($ 1 , $ 3 , None , [] ) }
3098
3112
| simple_pattern_not_ident COLON core_type EQUAL seq_expr
3099
3113
{ ($ 1 , $ 5 , Some (Pvc_constraint { locally_abstract_univars= [] ; typ=$ 3 }), [] ) }
3100
- | mode_expr_legacy_nonempty let_ident strict_binding_modes
3101
- { ($ 2 , mkexp_with_modes $ sloc $ 1 ($ 3 $ 1 ), None ,
3102
- let_binding_mode_attrs $ 1 ) }
3114
+ | mode_expr_legacy_nonempty let_ident mode_expr strict_binding_modes
3115
+ { let modes = Mode. concat $ 1 $ 3 in
3116
+ ($ 2 , mkexp_with_modes $ sloc modes ($ 4 modes), None ,
3117
+ let_binding_mode_attrs modes) }
3118
+ | let_ident mode_expr_nonempty strict_binding_modes
3119
+ { ($ 1 , mkexp_with_modes $ sloc $ 2 ($ 3 $ 2 ), None ,
3120
+ let_binding_mode_attrs $ 2 ) }
3103
3121
;
3104
3122
let_binding_body:
3105
3123
| let_binding_body_no_punning
@@ -3945,7 +3963,8 @@ generalized_constructor_arguments:
3945
3963
;
3946
3964
3947
3965
% inline atomic_type_gbl:
3948
- gbl = global_flag cty = atomic_type {
3966
+ gbl = global_flag cty = atomic_type gbl_ = mode_expr {
3967
+ let gbl = Mode. concat gbl gbl_ in
3949
3968
mkcty_modality gbl cty
3950
3969
}
3951
3970
;
@@ -3963,23 +3982,25 @@ label_declarations:
3963
3982
| label_declaration_semi label_declarations { $ 1 :: $ 2 }
3964
3983
;
3965
3984
label_declaration:
3966
- mutable_or_global_flag mkrhs(label) COLON poly_type_no_attr attributes
3985
+ mutable_or_global_flag mkrhs(label) gbl_ = mode_expr COLON poly_type_no_attr attributes
3967
3986
{ let info = symbol_info $ endpos in
3968
3987
let mut, gbl = $ 1 in
3988
+ let gbl = Mode. concat gbl gbl_ in
3969
3989
mkld_modality gbl
3970
- (Type. field $ 2 $ 4 ~mut ~attrs: $ 5 ~loc: (make_loc $ sloc) ~info )}
3990
+ (Type. field $ 2 $ 5 ~mut ~attrs: $ 6 ~loc: (make_loc $ sloc) ~info )}
3971
3991
;
3972
3992
label_declaration_semi:
3973
- mutable_or_global_flag mkrhs(label) COLON poly_type_no_attr attributes
3993
+ mutable_or_global_flag mkrhs(label) gbl_ = mode_expr COLON poly_type_no_attr attributes
3974
3994
SEMI attributes
3975
3995
{ let info =
3976
3996
match rhs_info $ endpos($ 5 ) with
3977
3997
| Some _ as info_before_semi -> info_before_semi
3978
3998
| None -> symbol_info $ endpos
3979
3999
in
3980
4000
let mut, gbl = $ 1 in
4001
+ let gbl = Mode. concat gbl gbl_ in
3981
4002
mkld_modality gbl
3982
- (Type. field $ 2 $ 4 ~mut ~attrs: ($ 5 @ $ 7 ) ~loc: (make_loc $ sloc) ~info )}
4003
+ (Type. field $ 2 $ 5 ~mut ~attrs: ($ 6 @ $ 8 ) ~loc: (make_loc $ sloc) ~info )}
3983
4004
;
3984
4005
3985
4006
/* Type Extensions */
@@ -4168,20 +4189,26 @@ strict_function_or_labeled_tuple_type:
4168
4189
label = arg_label
4169
4190
arg_modes = mode_expr_legacy
4170
4191
domain = extra_rhs(param_type)
4192
+ arg_modes_ = mode_expr
4171
4193
MINUSGREATER
4172
4194
codomain = strict_function_or_labeled_tuple_type
4173
- { Ptyp_arrow (label, mktyp_with_modes arg_modes domain , codomain) }
4195
+ { let arg_modes = Mode. concat arg_modes arg_modes_ in
4196
+ Ptyp_arrow (label, mktyp_with_modes arg_modes domain , codomain) }
4174
4197
)
4175
4198
{ $ 1 }
4176
4199
| mktyp(
4177
4200
label = arg_label
4178
4201
arg_modes = mode_expr_legacy
4179
4202
domain = extra_rhs(param_type)
4203
+ arg_modes_ = mode_expr
4180
4204
MINUSGREATER
4181
4205
ret_modes = mode_expr_legacy
4182
4206
codomain = tuple_type
4207
+ ret_modes_ = mode_expr
4183
4208
% prec MINUSGREATER
4184
- { Ptyp_arrow (label,
4209
+ { let arg_modes = Mode. concat arg_modes arg_modes_ in
4210
+ let ret_modes = Mode. concat ret_modes ret_modes_ in
4211
+ Ptyp_arrow (label,
4185
4212
mktyp_with_modes arg_modes domain ,
4186
4213
mktyp_with_modes ret_modes (maybe_curry_typ codomain $ loc(codomain))) }
4187
4214
)
@@ -4202,9 +4229,11 @@ strict_function_or_labeled_tuple_type:
4202
4229
label = LIDENT COLON
4203
4230
arg_modes = mode_expr_legacy
4204
4231
tuple = proper_tuple_type
4232
+ arg_modes_ = mode_expr
4205
4233
MINUSGREATER
4206
4234
codomain = strict_function_or_labeled_tuple_type
4207
4235
{
4236
+ let arg_modes = Mode. concat arg_modes arg_modes_ in
4208
4237
let ty, ltys = tuple in
4209
4238
let label = Labelled label in
4210
4239
let domain = ptyp_ltuple $ loc(tuple) ((None , ty) :: ltys) in
@@ -4216,10 +4245,15 @@ strict_function_or_labeled_tuple_type:
4216
4245
label = LIDENT COLON
4217
4246
arg_modes = mode_expr_legacy
4218
4247
tuple = proper_tuple_type
4248
+ arg_modes_ = mode_expr
4219
4249
MINUSGREATER
4220
4250
ret_modes = mode_expr_legacy
4221
4251
codomain = tuple_type
4222
- { let ty, ltys = tuple in
4252
+ ret_modes_ = mode_expr
4253
+ % prec MINUSGREATER
4254
+ { let arg_modes = Mode. concat arg_modes arg_modes_ in
4255
+ let ret_modes = Mode. concat ret_modes ret_modes_ in
4256
+ let ty, ltys = tuple in
4223
4257
let label = Labelled label in
4224
4258
let domain = ptyp_ltuple $ loc(tuple) ((None , ty) :: ltys) in
4225
4259
let domain = extra_rhs_core_type domain ~pos: $ endpos(tuple) in
@@ -4248,6 +4282,7 @@ strict_function_or_labeled_tuple_type:
4248
4282
| /* empty */
4249
4283
{ Nolabel }
4250
4284
;
4285
+ /* Legacy mode annotations */
4251
4286
% inline mode_legacy:
4252
4287
| LOCAL
4253
4288
{ mkloc " local" (make_loc $ sloc) }
@@ -4264,6 +4299,18 @@ strict_function_or_labeled_tuple_type:
4264
4299
% inline mode_expr_legacy:
4265
4300
| { Mode. empty }
4266
4301
| mode_expr_legacy_nonempty {$ 1 }
4302
+
4303
+ /* Mode expression followed by an " @" symbol and thus enjoying a whole namespace */
4304
+ %inline mode_expr_nonempty :
4305
+ | AT mkloc (LIDENT)
4306
+ {let modes = [$ 2 ] in
4307
+ mkloc modes (make_loc $loc ($2 ))}
4308
+ | AT LPAREN modes = mkloc(LIDENT )+ RPAREN
4309
+ { mkloc modes (make_loc $ loc(modes))}
4310
+ ;
4311
+ % inline mode_expr:
4312
+ { Mode. empty }
4313
+ | mode_expr_nonempty {$ 1 }
4267
4314
;
4268
4315
% inline param_type:
4269
4316
| mktyp_jane_syntax_ltyp(
@@ -4529,6 +4576,7 @@ operator:
4529
4576
;
4530
4577
%inline infix_operator:
4531
4578
| op = INFIXOP0 { op }
4579
+ | AT {" @"}
4532
4580
| op = INFIXOP1 { op }
4533
4581
| op = INFIXOP2 { op }
4534
4582
| op = INFIXOP3 { op }
0 commit comments