@@ -770,7 +770,7 @@ arg_general :: { Arg Span }
770
770
| ' &' ident ' :' ty { Arg (Just (RefP (IdentP (ByValue Immutable) (unspan $2 ) Nothing (spanOf $2 )) Immutable ($1 # $2 ))) $4 ($1 # $4 ) }
771
771
| ' &&' ' _' ' :' ty { Arg (Just (RefP (RefP (WildP (spanOf $2 )) Immutable (nudge 1 0 ($1 # $2 ))) Immutable ($1 # $2 ))) $4 ($1 # $4 ) }
772
772
| ' &&' ident ' :' ty { Arg (Just (RefP (RefP (IdentP (ByValue Immutable) (unspan $2 ) Nothing (spanOf $2 )) Immutable (nudge 1 0 ($1 # $2 ))) Immutable ($1 # $2 ))) $4 ($1 # $4 ) }
773
-
773
+
774
774
-- Self argument (only allowed in trait function signatures)
775
775
arg_self_general :: { Arg Span }
776
776
: mut self { SelfValue Mutable ($1 # $>) }
@@ -812,6 +812,7 @@ lambda_arg :: { Arg Span }
812
812
pat :: { Pat Span }
813
813
: ntPat { $1 }
814
814
| ' _' { WildP (spanOf $1 ) }
815
+ | ' ..' { RestP (spanOf $1 ) }
815
816
| ' &' mut pat { RefP $3 Mutable ($1 # $3 ) }
816
817
| ' &' pat { RefP $2 Immutable ($1 # $2 ) }
817
818
| ' &&' mut pat { RefP (RefP $3 Mutable (nudge 1 0 ($1 # $3 ))) Immutable ($1 # $3 ) }
@@ -832,51 +833,26 @@ pat :: { Pat Span }
832
833
| lit_or_path ' ..=' lit_or_path { RangeP $1 $3 ($1 # $>) }
833
834
| expr_path ' {' ' ..' ' }' { StructP $1 [] True ($1 # $>) }
834
835
| expr_path ' {' pat_fields ' }' { let (fs,b) = $3 in StructP $1 fs b ($1 # $>) }
835
- | expr_path ' (' pat_tup ' )' { let (ps,m,_) = $ 3 in TupleStructP $1 ps m ($1 # $>) }
836
+ | expr_path ' (' sep_byT(pat, ' , ' ) ' )' { TupleStructP $1 $ 3 ($1 # $>) }
836
837
| expr_mac { MacP $1 (spanOf $1 ) }
837
- | ' [' pat_slice ' ]' { let (b,s,a) = $2 in SliceP b s a ($1 # $3 ) }
838
- | ' (' pat_tup ' )' {%
839
- case $2 of
840
- ([p], Nothing, False) -> parseError (CloseDelim Paren)
841
- (ps,m,t) -> pure (TupleP ps m ($1 # $3 ))
838
+ | ' [' sep_byT(pat,' ,' ) ' ]' { SliceP $2 ($1 # $>) }
839
+ | ' (' ' )' { TupleP [] ($1 # $>) }
840
+ | ' (' sep_by1(pat,' ,' ) ' ,' ' )' { TupleP (toList $2 ) ($1 # $>) }
841
+ | ' (' sep_by1(pat,' ,' ) ' )' {
842
+ case toList $2 of
843
+ l @ [RestP _] -> TupleP l ($1 # $>) -- (..) is a tuple pattern
844
+ [p] -> ParenP p ($1 # $>) -- (<pat>) is parenthesis around a pattern
845
+ l -> TupleP l ($1 # $>) -- (<pat1>, <pat2>) is a tuple pattern
842
846
}
843
847
844
-
845
- -- The first element is the spans, the second the position of ' ..' , and the third if there is a
846
- -- trailing comma
847
- pat_tup :: { ([Pat Span], Maybe Int, Bool) }
848
- : sep_by1(pat,' ,' ) ' ,' ' ..' ' ,' sep_by1(pat,' ,' ) { (toList ($1 <> $5 ), Just (length $1 ), False) }
849
- | sep_by1(pat,' ,' ) ' ,' ' ..' ' ,' sep_by1(pat,' ,' ) ' ,' { (toList ($1 <> $5 ), Just (length $1 ), True) }
850
- | sep_by1(pat,' ,' ) ' ,' ' ..' { (toList $1 , Just (length $1 ), False) }
851
- | sep_by1(pat,' ,' ) { (toList $1 , Nothing, False) }
852
- | sep_by1(pat,' ,' ) ' ,' { (toList $1 , Nothing, True) }
853
- | ' ..' ' ,' sep_by1(pat,' ,' ) { (toList $3 , Just 0 , False) }
854
- | ' ..' ' ,' sep_by1(pat,' ,' ) ' ,' { (toList $3 , Just 0 , True) }
855
- | ' ..' { ([], Just 0 , False) }
856
- | {- empty -} { ([], Nothing, False) }
857
-
858
- -- The first element is the patterns at the beginning of the slice, the second the optional binding
859
- -- for the middle slice (' Nothing' if there is no ' ..' and ' Just (WildP mempty) is there is one, but
860
- -- unlabelled), and the third is the patterns at the end of the slice.
861
- pat_slice :: { ([Pat Span], Maybe (Pat Span), [Pat Span]) }
862
- : sep_by1(pat,' ,' ) ' ,' ' ..' ' ,' sep_by1T(pat,' ,' ) { (toList $1, Just (WildP mempty), toList $5) }
863
- | sep_by1(pat,' ,' ) ' ,' ' ..' { (toList $1, Just (WildP mempty), []) }
864
- | sep_by1(pat,' ,' ) ' ..' ' ,' sep_by1T(pat,' ,' ) { let (xs, x) = unsnoc $1 in (toList xs, Just x, toList $4) }
865
- | sep_by1(pat,' ,' ) ' ..' { let (xs, x) = unsnoc $1 in (toList xs, Just x, []) }
866
- | sep_by1T(pat,' ,' ) { (toList $1, Nothing, []) }
867
- | ' ..' ' ,' sep_by1T(pat,' ,' ) { ([], Just (WildP mempty), toList $3) }
868
- | ' ..' { ([], Just (WildP mempty), []) }
869
- | {- empty -} { ([], Nothing, []) }
870
-
871
-
872
848
-- Endpoints of range patterns
873
849
lit_or_path :: { Expr Span }
874
850
: expr_path { PathExpr [] Nothing $1 (spanOf $1 ) }
875
851
| expr_qual_path { PathExpr [] (Just (fst (unspan $1 ))) (snd (unspan $1 )) (spanOf $1 ) }
876
852
| ' -' lit_expr { Unary [] Neg $2 ($1 # $2 ) }
877
853
| lit_expr { $1 }
878
854
879
- -- Used in patterns for tuple and expression patterns
855
+ -- Used in patterns for expression patterns
880
856
pat_fields :: { ([FieldPat Span], Bool) }
881
857
: sep_byT(pat_field,' ,' ) { ($1 , False) }
882
858
| sep_by1(pat_field,' ,' ) ' ,' ' ..' { (toList $1 , True) }
0 commit comments