@@ -453,15 +453,15 @@ qual_path(segs) :: { Spanned (QSelf Span, Path Span) }
453
453
: ' <' qual_path_suf(segs) { let Spanned x _ = $2 in Spanned x ($1 # $2) }
454
454
| lt_ty_qual_path as ty_path ' >' ' ::' segs {
455
455
let Path g segsTy x = $3 in
456
- Spanned (QSelf (unspan $1) (length segsTy), Path g (segsTy <> unspan $6) x) ($1 # $>)
456
+ Spanned (QSelf (unspan $1) (length segsTy), Path g (segsTy <> toList $6) x) ($1 # $>)
457
457
}
458
458
459
459
-- Basically a qualified path, but ignoring the very first ' <' token
460
460
qual_path_suf(segs) :: { Spanned (QSelf Span, Path Span) }
461
- : ty ' >' ' ::' segs { Spanned (QSelf $1 0, Path False (unspan $4) (spanOf $4)) ($1 # $>) }
461
+ : ty ' >' ' ::' segs { Spanned (QSelf $1 0, Path False (toList $4) (spanOf $4)) ($1 # $>) }
462
462
| ty as ty_path ' >' ' ::' segs {
463
463
let Path g segsTy x = $3 in
464
- Spanned (QSelf $1 (length segsTy), Path g (segsTy <> unspan $6) x) ($1 # $>)
464
+ Spanned (QSelf $1 (length segsTy), Path g (segsTy <> toList $6) x) ($1 # $>)
465
465
}
466
466
467
467
-- Usually qual_path_suf is for... type paths! This consumes these but with a starting ' <<' token.
@@ -494,60 +494,62 @@ binding :: { (Ident, Ty Span) }
494
494
-- parse_path(PathStyle::Type)
495
495
ty_path :: { Path Span }
496
496
: ntPath { $1 }
497
- | path_segments_without_colons { Path False (unspan $ 1 ) (spanOf $1 ) }
498
- | ' ::' path_segments_without_colons { Path True (unspan $ 2 ) ($1 # $2 ) }
497
+ | path_segments_without_colons { Path False $ 1 (spanOf $1 ) }
498
+ | ' ::' path_segments_without_colons { Path True $ 2 ($1 # $2 ) }
499
499
500
500
ty_qual_path :: { Spanned (QSelf Span, Path Span) }
501
501
: qual_path(path_segments_without_colons) { $1 }
502
502
503
503
-- parse_path_segments_without_colons()
504
- path_segments_without_colons :: { Spanned ( NonEmpty (Ident, PathParameters Span)) }
505
- : sep_by1(path_segment_without_colons, ' ::' ) %prec SEG { sequence (toNonEmpty $ 1 ) }
504
+ path_segments_without_colons :: { [PathSegment Span] }
505
+ : sep_by1(path_segment_without_colons, ' ::' ) %prec SEG { toList $ 1 }
506
506
507
507
-- No corresponding function - see path_segments_without_colons
508
- path_segment_without_colons :: { Spanned (Ident, PathParameters Span) }
509
- : self_or_ident path_parameter1 { Spanned (unspan $1 , $2 ) ($1 # $>) }
508
+ path_segment_without_colons :: { PathSegment Span }
509
+ : self_or_ident path_parameter { PathSegment (unspan $1 ) $2 ($1 # $>) }
510
510
511
- path_parameter1 :: { PathParameters Span }
512
- : generic_values { let (lts, tys, bds) = unspan $1 in AngleBracketed lts tys bds (spanOf $1 ) }
513
- | ' (' sep_byT(ty,' ,' ) ' )' { Parenthesized $2 Nothing ($1 # $>) }
514
- | ' (' sep_byT(ty,' ,' ) ' )' ' ->' ty_no_plus { Parenthesized $2 (Just $>) ($1 # $>) }
515
- | {- empty -} %prec IDENT { NoParameters mempty }
511
+ path_parameter :: { Maybe (PathParameters Span) }
512
+ : generic_values { let (lts, tys, bds) = unspan $1
513
+ in Just (AngleBracketed lts tys bds (spanOf $1 )) }
514
+ | ' (' sep_byT(ty,' ,' ) ' )' { Just (Parenthesized $2 Nothing ($1 # $>)) }
515
+ | ' (' sep_byT(ty,' ,' ) ' )' ' ->' ty_no_plus { Just (Parenthesized $2 (Just $>) ($1 # $>)) }
516
+ | {- empty -} %prec IDENT { Nothing }
516
517
517
518
518
519
-- Expression related:
519
520
-- parse_path(PathStyle::Expr)
520
521
expr_path :: { Path Span }
521
522
: ntPath { $1 }
522
- | path_segments_with_colons { Path False (unspan $1 ) (spanOf $1 ) }
523
- | ' ::' path_segments_with_colons { Path True (unspan $2 ) ($1 # $2 ) }
523
+ | path_segments_with_colons { Path False (toList $1 ) (spanOf $1 ) }
524
+ | ' ::' path_segments_with_colons { Path True (toList $2 ) ($1 # $2 ) }
524
525
525
526
expr_qual_path :: { Spanned (QSelf Span, Path Span) }
526
527
: qual_path(path_segments_with_colons) { $1 }
527
528
528
529
-- parse_path_segments_with_colons()
529
- path_segments_with_colons :: { Spanned ( NonEmpty (Ident, PathParameters Span) ) }
530
+ path_segments_with_colons :: { Reversed NonEmpty (PathSegment Span) }
530
531
: self_or_ident
531
- { Spanned [ (unspan $1 , NoParameters mempty)] (spanOf $1 ) }
532
+ { [ PathSegment (unspan $1 ) Nothing (spanOf $1 )] }
532
533
| path_segments_with_colons ' ::' self_or_ident
533
- { Spanned (unspan $1 |> (unspan $3 , NoParameters mempty)) ($ 1 # $>) }
534
+ { $1 <> [ PathSegment (unspan $3 ) Nothing (spanOf $ 3 )] }
534
535
| path_segments_with_colons ' ::' generic_values
535
536
{%
536
- case (N.last (unspan $1 ), unspan $3 ) of
537
- ((i, NoParameters{}), (lts, tys, bds)) -> let seg = (i, AngleBracketed lts tys bds (spanOf $3 ))
538
- in pure $ Spanned (N.init (unspan $1 ) |: seg) ($1 # $3 )
537
+ case (unsnoc $1 , unspan $3 ) of
538
+ ((rst, PathSegment i Nothing x), (lts, tys, bds)) ->
539
+ let seg = PathSegment i (Just (AngleBracketed lts tys bds (spanOf $3 ))) (x # $3 )
540
+ in pure $ snoc rst seg
539
541
_ -> fail " invalid path segment in expression path"
540
542
}
541
543
542
544
-- Mod related:
543
545
-- parse_path(PathStyle::Mod)
544
546
mod_path :: { Path Span }
545
547
: ntPath { $1 }
546
- | self_or_ident { Path False [(unspan $1 , NoParameters mempty )] (spanOf $1 ) }
547
- | ' ::' self_or_ident { Path True [(unspan $2 , NoParameters mempty )] ($1 # $>) }
548
+ | self_or_ident { Path False [PathSegment (unspan $1 ) Nothing (spanOf $ 1 )] (spanOf $1 ) }
549
+ | ' ::' self_or_ident { Path True [PathSegment (unspan $2 ) Nothing (spanOf $ 2 )] ($1 # $>) }
548
550
| mod_path ' ::' self_or_ident {
549
551
let Path g segs _ = $1 in
550
- Path g (segs |> (unspan $3 , NoParameters mempty) ) ($1 # $> )
552
+ Path g (segs <> [ PathSegment (unspan $3 ) Nothing (spanOf $ 3 ) ] ) ($1 # $3 )
551
553
}
552
554
553
555
self_or_ident :: { Spanned Ident }
@@ -743,8 +745,8 @@ arg_self_general :: { Arg Span }
743
745
| mut self ' :' ty { SelfExplicit $4 Mutable ($1 # $>) }
744
746
| arg_general {
745
747
case $1 of
746
- Arg Nothing (PathTy Nothing (Path False [( " self" , NoParameters _) ] _) _) x -> SelfValue Immutable x
747
- Arg Nothing (Rptr l m (PathTy Nothing (Path False [( " self" , NoParameters _) ] _) _) _) x -> SelfRegion l m x
748
+ Arg Nothing (PathTy Nothing (Path False [PathSegment " self" Nothing _ ] _) _) x -> SelfValue Immutable x
749
+ Arg Nothing (Rptr l m (PathTy Nothing (Path False [PathSegment " self" Nothing _ ] _) _) _) x -> SelfRegion l m x
748
750
_ -> $1
749
751
}
750
752
@@ -789,8 +791,8 @@ pat :: { Pat Span }
789
791
| ident ' @' pat { IdentP (ByValue Immutable) (unspan $1 ) (Just $3 ) ($1 # $>) }
790
792
| expr_path {
791
793
case $1 of
792
- Path False ((i, NoParameters _) :| []) _ -> IdentP (ByValue Immutable) i Nothing (spanOf $1 )
793
- _ -> PathP Nothing $1 (spanOf $1 )
794
+ Path False [PathSegment i Nothing _] _ -> IdentP (ByValue Immutable) i Nothing (spanOf $1 )
795
+ _ -> PathP Nothing $1 (spanOf $1 )
794
796
}
795
797
| expr_qual_path { PathP (Just (fst (unspan $1 ))) (snd (unspan $1 )) ($1 # $>) }
796
798
| lit_or_path ' ...' lit_or_path { RangeP $1 $3 ($1 # $>) }
@@ -1205,7 +1207,7 @@ vis_union_nonblock_expr :: { Expr Span }
1205
1207
1206
1208
union_expr :: { Expr Span }
1207
1209
: pub_or_inherited union {%
1208
- noVis $1 (PathExpr [] Nothing (Path False [( "union", NoParameters mempty )] (spanOf $1)) (spanOf $1))
1210
+ noVis $1 (PathExpr [] Nothing (Path False [PathSegment "union" Nothing (spanOf $2 )] (spanOf $1)) (spanOf $1))
1209
1211
}
1210
1212
1211
1213
@@ -1460,8 +1462,10 @@ vis :: { Spanned (Visibility Span) }
1460
1462
| pub %prec VIS { Spanned PublicV (spanOf $1) }
1461
1463
| pub ' (' crate ' )' { Spanned CrateV ($1 # $4) }
1462
1464
| pub ' (' in mod_path ' )' { Spanned (RestrictedV $4) ($1 # $5) }
1463
- | pub ' (' super ' )' { Spanned (RestrictedV (Path False [("super", NoParameters mempty)] (spanOf $3))) ($1 # $4) }
1464
- | pub ' (' self ' )' { Spanned (RestrictedV (Path False [("self", NoParameters mempty)] (spanOf $3))) ($1 # $4) }
1465
+ | pub ' (' super ' )' { Spanned (RestrictedV (Path False [PathSegment "super" Nothing (spanOf
1466
+ $3)] (spanOf $3))) ($1 # $4) }
1467
+ | pub ' (' self ' )' { Spanned (RestrictedV (Path False [PathSegment "self" Nothing (spanOf
1468
+ $3)] (spanOf $3))) ($1 # $4) }
1465
1469
1466
1470
def :: { Spanned Defaultness }
1467
1471
: {- empty -} %prec DEF { pure Final }
@@ -1471,8 +1475,11 @@ use_tree :: { UseTree Span }
1471
1475
: mod_path { UseTreeSimple $1 Nothing (spanOf $1) }
1472
1476
| mod_path as ident { UseTreeSimple $1 (Just (unspan $3)) ($1 # $3) }
1473
1477
| 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 # $>) }
1478
+ | ' ::' ' *' { UseTreeGlob (Path True [] (spanOf $1)) ($1 # $2) }
1479
+ | ' *' { UseTreeGlob (Path False [] mempty) (spanOf $1) }
1480
+ | mod_path ' ::' ' {' sep_byT(use_tree,' ,' ) ' }' { UseTreeNested $1 $4 ($1 # $>) }
1481
+ | ' ::' ' {' sep_byT(use_tree,' ,' ) ' }' { UseTreeNested (Path True [] (spanOf $1)) $3 ($1 # $>) }
1482
+ | ' {' sep_byT(use_tree,' ,' ) ' }' { UseTreeNested (Path False [] mempty) $2 ($1 # $>) }
1476
1483
1477
1484
-------------------
1478
1485
-- Macro related --
@@ -1774,7 +1781,7 @@ noSafety _ _ = fail "safety is not allowed here"
1774
1781
1775
1782
-- | Make a macro item, which may be a ' MacroDef'
1776
1783
macroItem :: [Attribute Span] -> (Maybe Ident) -> Mac Span -> Span -> Item Span
1777
- macroItem as (Just i) (Mac (Path False [( " macro_rules" , NoParameters _) ] _) tts _) x = MacroDef as i tts x
1784
+ macroItem as (Just i) (Mac (Path False [PathSegment " macro_rules" Nothing _ ] _) tts _) x = MacroDef as i tts x
1778
1785
macroItem as i mac x = MacItem as i mac x
1779
1786
1780
1787
-- | Add attributes to an expression
0 commit comments