@@ -95,7 +95,7 @@ import qualified Data.List.NonEmpty as N
95
95
%errorhandlertype explist
96
96
%error { expParseError }
97
97
98
- %expect 0
98
+ -- %expect 0
99
99
100
100
%token
101
101
@@ -230,6 +230,7 @@ import qualified Data.List.NonEmpty as N
230
230
default { Spanned (IdentTok " default" ) _ }
231
231
union { Spanned (IdentTok " union" ) _ }
232
232
catch { Spanned (IdentTok " catch" ) _ }
233
+ auto { Spanned (IdentTok " auto" ) _ }
233
234
234
235
-- Comments
235
236
outerDoc { Spanned (Doc _ Outer _) _ }
@@ -276,7 +277,7 @@ import qualified Data.List.NonEmpty as N
276
277
%nonassoc mut DEF EQ ' ::'
277
278
278
279
-- These are all identifiers of sorts (' union' and ' default' are " weak" keywords)
279
- %nonassoc IDENT ntIdent default union catch self
280
+ %nonassoc IDENT ntIdent default union catch self auto
280
281
281
282
-- These are all very low precedence unary operators
282
283
%nonassoc box return break continue IMPLTRAIT LAMBDA
@@ -329,6 +330,7 @@ ident :: { Spanned Ident }
329
330
| union { toIdent $1 }
330
331
| default { toIdent $1 }
331
332
| catch { toIdent $1 }
333
+ | auto { toIdent $1 }
332
334
| IDENT { toIdent $1 }
333
335
334
336
-- This should precede any ' >' token which could be absorbed in a ' >>' , ' >=' , or ' >>=' token. Its
@@ -543,11 +545,18 @@ mod_path :: { Path Span }
543
545
: ntPath { $1 }
544
546
| self_or_ident { Path False [(unspan $1 , NoParameters mempty)] (spanOf $1 ) }
545
547
| ' ::' self_or_ident { Path True [(unspan $2 , NoParameters mempty)] ($1 # $>) }
546
- | mod_path ' ::' ident {
548
+ | mod_path ' ::' self_or_ident {
547
549
let Path g segs _ = $1 in
548
550
Path g (segs |> (unspan $3 , NoParameters mempty)) ($1 # $>)
549
551
}
550
552
553
+ self_or_ident :: { Spanned Ident }
554
+ : ident { $1 }
555
+ | self { Spanned " self" (spanOf $1 ) }
556
+ | Self { Spanned " Self" (spanOf $1 ) }
557
+ | super { Spanned " super" (spanOf $1 ) }
558
+
559
+
551
560
-----------
552
561
-- Types --
553
562
-----------
@@ -1270,7 +1279,7 @@ gen_item(vis) :: { Item Span }
1270
1279
{ ConstItem $1 (unspan $2) (unspan $4) $6 $8 ($1 # $2 # $3 # $>) }
1271
1280
| many(outer_attribute) vis type ident generics where_clause ' =' ty ' ;'
1272
1281
{ TyAlias $1 (unspan $2) (unspan $4) $8 ($5 `withWhere` $6) ($1 # $2 # $3 # $>) }
1273
- | many(outer_attribute) vis use view_path ' ;'
1282
+ | many(outer_attribute) vis use use_tree ' ;'
1274
1283
{ Use $1 (unspan $2) $4 ($1 # $2 # $3 # $>) }
1275
1284
| many(outer_attribute) vis safety extern crate ident ' ;'
1276
1285
{% noSafety $3 (ExternCrate $1 (unspan $2) (unspan $6) Nothing ($1 # $2 # $4 # $>)) }
@@ -1299,9 +1308,15 @@ gen_item(vis) :: { Item Span }
1299
1308
| many(outer_attribute) vis enum ident generics where_clause ' {' sep_byT(enum_def,' ,' ) ' }'
1300
1309
{ Enum $1 (unspan $2) (unspan $4) $8 ($5 `withWhere` $6) ($1 # $2 # $3 # $>) }
1301
1310
| many(outer_attribute) vis safety trait ident generics ' :' sep_by1T(ty_param_bound,' +' ) where_clause ' {' many(trait_item) ' }'
1302
- { Trait $1 (unspan $2) (unspan $5) (unspan $3) ($6 `withWhere` $9) (toList $8) $11 ($1 # $2 # $3 # $4 # $>) }
1311
+ { Trait $1 (unspan $2) (unspan $5) False (unspan $3) ($6 `withWhere` $9) (toList $8) $11 ($1 # $2 # $3 # $4 # $>) }
1303
1312
| many(outer_attribute) vis safety trait ident generics where_clause ' {' many(trait_item) ' }'
1304
- { Trait $1 (unspan $2) (unspan $5) (unspan $3) ($6 `withWhere` $7) [] $9 ($1 # $2 # $3 # $4 # $>) }
1313
+ { Trait $1 (unspan $2) (unspan $5) False (unspan $3) ($6 `withWhere` $7) [] $9 ($1 # $2 # $3 # $4 # $>) }
1314
+ | many(outer_attribute) vis safety auto trait ident generics ' :' sep_by1T(ty_param_bound,' +' ) where_clause ' {' many(trait_item) ' }'
1315
+ { Trait $1 (unspan $2) (unspan $6) True (unspan $3) ($7 `withWhere` $10) (toList $9) $12 ($1 # $2 # $3 # $5 # $>) }
1316
+ | many(outer_attribute) vis safety auto trait ident generics where_clause ' {' many(trait_item) ' }'
1317
+ { Trait $1 (unspan $2) (unspan $6) True (unspan $3) ($7 `withWhere` $8) [] $10 ($1 # $2 # $3 # $5 # $>) }
1318
+ -- | many(outer_attribute) vis trait ident generics ' =' sep_by1T(ty_param_bound,' +' ) ' ;'
1319
+ -- { TraitAlias $1 (unspan $2) (unspan $4) $5 (toNonEmpty $7) ($1 # $2 # $3 # $>) }
1305
1320
| many(outer_attribute) vis safety impl generics ty_prim where_clause ' {' impl_items ' }'
1306
1321
{ Impl ($1 ++ fst $9) (unspan $2) Final (unspan $3) Positive ($5 `withWhere` $7) Nothing $6 (snd $9) ($1 # $2 # $3 # $4 # $5 # $>) }
1307
1322
| many(outer_attribute) vis default safety impl generics ty_prim where_clause ' {' impl_items ' }'
@@ -1320,7 +1335,7 @@ gen_item(vis) :: { Item Span }
1320
1335
{ Impl ($1 ++ fst $12) (unspan $2) Default (unspan $4) Positive ($6 `withWhere` $10) (Just $7) $9 (snd $12) ($1 # $2 # $3 # $4 # $5 # $>) }
1321
1336
| many(outer_attribute) vis safety impl generics trait_ref for ' ..' ' {' ' }'
1322
1337
{% case $5 of
1323
- Generics [] [] _ _ -> pure $ DefaultImpl $1 (unspan $2) (unspan $3) $6 ($1 # $2 # $3 # $4 # $>)
1338
+ Generics [] [] _ _ -> pure $ AutoImpl $1 (unspan $2) (unspan $3) $6 ($1 # $2 # $3 # $4 # $>)
1324
1339
_ -> fail "non-empty generics are no allowed on default implementations"
1325
1340
}
1326
1341
@@ -1409,11 +1424,11 @@ impl_item :: { ImplItem Span }
1409
1424
| many(outer_attribute) vis def const ident ' :' ty ' =' expr ' ;' { ConstI $1 (unspan $2) (unspan $3) (unspan $5) $7 $9 ($1 # $2 # $3 # $4 # $>) }
1410
1425
| many(outer_attribute) def mod_mac { MacroI $1 (unspan $2) $3 ($1 # $2 # $>) }
1411
1426
| many(outer_attribute) vis def const safety fn ident generics fn_decl_with_self_named where_clause inner_attrs_block
1412
- { let methodSig = MethodSig (unspan $5) Const Rust $9 ( $8 `withWhere` $10)
1413
- in MethodI ($1 ++ fst $>) (unspan $2) (unspan $3) (unspan $7) methodSig (snd $>) ($1 # $2 # $3 # $4 # snd $>) }
1427
+ { let methodSig = MethodSig (unspan $5) Const Rust $9; generics = $8 `withWhere` $10
1428
+ in MethodI ($1 ++ fst $>) (unspan $2) (unspan $3) (unspan $7) generics methodSig (snd $>) ($1 # $2 # $3 # $4 # snd $>) }
1414
1429
| many(outer_attribute) vis def safety ext_abi fn ident generics fn_decl_with_self_named where_clause inner_attrs_block
1415
- { let methodSig = MethodSig (unspan $4) NotConst (unspan $5) $9 ( $8 `withWhere` $10)
1416
- in MethodI ($1 ++ fst $>) (unspan $2) (unspan $3) (unspan $7) methodSig (snd $>) ($1 # $2 # $3 # $4 # $5 # $6 # snd $>) }
1430
+ { let methodSig = MethodSig (unspan $4) NotConst (unspan $5) $9; generics = $8 `withWhere` $10
1431
+ in MethodI ($1 ++ fst $>) (unspan $2) (unspan $3) (unspan $7) generics methodSig (snd $>) ($1 # $2 # $3 # $4 # $5 # $6 # snd $>) }
1417
1432
1418
1433
trait_item :: { TraitItem Span }
1419
1434
: ntTraitItem { $1 }
@@ -1426,11 +1441,11 @@ trait_item :: { TraitItem Span }
1426
1441
| many(outer_attribute) type ident ' :' sep_by1T(ty_param_bound_mod,' +' ) ' =' ty ' ;'
1427
1442
{ TypeT $1 (unspan $3) (toList $5) (Just $7) ($1 # $2 # $>) }
1428
1443
| many(outer_attribute) safety ext_abi fn ident generics fn_decl_with_self_general where_clause ' ;'
1429
- { let methodSig = MethodSig (unspan $2) NotConst (unspan $3) $7 ( $6 `withWhere` $8)
1430
- in MethodT $1 (unspan $5) methodSig Nothing ($1 # $2 # $3 # $4 # $>) }
1444
+ { let methodSig = MethodSig (unspan $2) NotConst (unspan $3) $7; generics = $6 `withWhere` $8
1445
+ in MethodT $1 (unspan $5) generics methodSig Nothing ($1 # $2 # $3 # $4 # $>) }
1431
1446
| many(outer_attribute) safety ext_abi fn ident generics fn_decl_with_self_general where_clause inner_attrs_block
1432
- { let methodSig = MethodSig (unspan $2) NotConst (unspan $3) $7 ( $6 `withWhere` $8)
1433
- in MethodT ($1 ++ fst $>) (unspan $5) methodSig (Just (snd $>)) ($1 # $2 # $3 # $4 # snd $>) }
1447
+ { let methodSig = MethodSig (unspan $2) NotConst (unspan $3) $7; generics = $6 `withWhere` $8
1448
+ in MethodT ($1 ++ fst $>) (unspan $5) generics methodSig (Just (snd $>)) ($1 # $2 # $3 # $4 # snd $>) }
1434
1449
1435
1450
safety :: { Spanned Unsafety }
1436
1451
: {- empty -} { pure Normal }
@@ -1452,32 +1467,12 @@ def :: { Spanned Defaultness }
1452
1467
: {- empty -} %prec DEF { pure Final }
1453
1468
| default { Spanned Default (spanOf $1) }
1454
1469
1455
- view_path :: { ViewPath Span }
1456
- : ' ::' sep_by1(self_or_ident,' ::' ) { let (ns,n) = unsnoc (fmap unspan $2) in ViewPathSimple True (toList ns) (PathListItem n Nothing mempty) ($1 # $>) }
1457
- | ' ::' sep_by1(self_or_ident,' ::' ) as ident { let (ns,n) = unsnoc (fmap unspan $2) in ViewPathSimple True (toList ns) (PathListItem n (Just (unspan $>)) mempty) ($1 # $>) }
1458
- | ' ::' ' *' { ViewPathGlob True [] ($1 # $2) }
1459
- | ' ::' sep_by1(self_or_ident,' ::' ) ' ::' ' *' { ViewPathGlob True (fmap unspan (toList $2)) ($1 # $>) }
1460
- | ' ::' sep_by1(self_or_ident,' ::' ) ' ::' ' {' sep_byT(plist,' ,' ) ' }' { ViewPathList True (map unspan (toList $2)) $5 ($1 # $>) }
1461
- | ' ::' ' {' sep_byT(plist,' ,' ) ' }' { ViewPathList True [] $3 ($1 # $>) }
1462
- | sep_by1(self_or_ident,' ::' ) { let (ns,n) = unsnoc (fmap unspan $1) in ViewPathSimple False (toList ns) (PathListItem n Nothing mempty) ($1 # $>) }
1463
- | sep_by1(self_or_ident,' ::' ) as ident { let (ns,n) = unsnoc (fmap unspan $1) in ViewPathSimple False (toList ns) (PathListItem n (Just (unspan $>)) mempty) ($1 # $>) }
1464
- | ' *' { ViewPathGlob False [] (spanOf $1) }
1465
- | sep_by1(self_or_ident,' ::' ) ' ::' ' *' { ViewPathGlob False (fmap unspan (toList $1)) ($1 # $>) }
1466
- | sep_by1(self_or_ident,' ::' ) ' ::' ' {' sep_byT(plist,' ,' ) ' }' { ViewPathList False (map unspan (toList $1)) $4 ($1 # $>) }
1467
- | ' {' sep_byT(plist,' ,' ) ' }' { ViewPathList False [] $2 ($1 # $>) }
1468
-
1469
-
1470
- self_or_ident :: { Spanned Ident }
1471
- : ident { $1 }
1472
- | self { Spanned "self" (spanOf $1) }
1473
- | Self { Spanned "Self" (spanOf $1) }
1474
- | super { Spanned "super" (spanOf $1) }
1475
-
1476
-
1477
- plist :: { PathListItem Span }
1478
- : self_or_ident { PathListItem (unspan $1) Nothing (spanOf $1) }
1479
- | self_or_ident as ident { PathListItem (unspan $1) (Just (unspan $3)) (spanOf $1) }
1480
-
1470
+ use_tree :: { UseTree Span }
1471
+ : mod_path { UseTreeSimple $1 Nothing (spanOf $1) }
1472
+ | mod_path as ident { UseTreeSimple $1 (Just (unspan $3)) ($1 # $3) }
1473
+ | mod_path ' ::' ' *' { UseTreeGlob $1 ($1 # $3) }
1474
+ | mod_path ' ::' ' {' sep_byT(use_tree,' ,' ) ' }' { UseTreeNested (Just $1) $4 ($1 # $>) }
1475
+ | ' {' sep_byT(use_tree,' ,' ) ' }' { UseTreeNested Nothing $2 ($1 # $>) }
1481
1476
1482
1477
-------------------
1483
1478
-- Macro related --
@@ -1630,6 +1625,7 @@ token :: { Spanned Token }
1630
1625
| default { $1 }
1631
1626
| union { $1 }
1632
1627
| catch { $1 }
1628
+ | auto { $1 }
1633
1629
-- Comments
1634
1630
| outerDoc { $1 }
1635
1631
| innerDoc { $1 }
0 commit comments