@@ -817,7 +817,7 @@ enum InterpolatedStringElementsKind {
817817 /// ```py
818818 /// f"hello {x:.2f} world"
819819 /// ```
820- FormatSpec ,
820+ FormatSpec ( InterpolatedStringKind ) ,
821821}
822822
823823impl InterpolatedStringElementsKind {
@@ -827,7 +827,7 @@ impl InterpolatedStringElementsKind {
827827 // test_ok fstring_format_spec_terminator
828828 // f"hello {x:} world"
829829 // f"hello {x:.3f} world"
830- InterpolatedStringElementsKind :: FormatSpec => TokenKind :: Rbrace ,
830+ InterpolatedStringElementsKind :: FormatSpec ( _ ) => TokenKind :: Rbrace ,
831831 }
832832 }
833833}
@@ -1197,23 +1197,13 @@ impl RecoveryContextKind {
11971197 ) || p. at_name_or_soft_keyword ( )
11981198 }
11991199 RecoveryContextKind :: WithItems ( _) => p. at_expr ( ) ,
1200- RecoveryContextKind :: InterpolatedStringElements ( elements_kind) => {
1201- match elements_kind {
1202- InterpolatedStringElementsKind :: Regular ( interpolated_string_kind) => {
1203- p. current_token_kind ( ) == interpolated_string_kind. middle_token ( )
1204- || p. current_token_kind ( ) == TokenKind :: Lbrace
1205- }
1206- InterpolatedStringElementsKind :: FormatSpec => {
1207- matches ! (
1208- p. current_token_kind( ) ,
1209- // Literal element
1210- TokenKind :: FStringMiddle | TokenKind :: TStringMiddle
1211- // Expression element
1212- | TokenKind :: Lbrace
1213- )
1214- }
1200+ RecoveryContextKind :: InterpolatedStringElements ( elements_kind) => match elements_kind {
1201+ InterpolatedStringElementsKind :: Regular ( interpolated_string_kind)
1202+ | InterpolatedStringElementsKind :: FormatSpec ( interpolated_string_kind) => {
1203+ p. current_token_kind ( ) == interpolated_string_kind. middle_token ( )
1204+ || p. current_token_kind ( ) == TokenKind :: Lbrace
12151205 }
1216- }
1206+ } ,
12171207 }
12181208 }
12191209
@@ -1305,9 +1295,11 @@ impl RecoveryContextKind {
13051295 InterpolatedStringElementsKind :: Regular ( string_kind) => ParseErrorType :: OtherError (
13061296 format ! ( "Expected an element of or the end of the {string_kind}" ) ,
13071297 ) ,
1308- InterpolatedStringElementsKind :: FormatSpec => ParseErrorType :: OtherError (
1309- "Expected an f-string or t-string element or a '}'" . to_string ( ) ,
1310- ) ,
1298+ InterpolatedStringElementsKind :: FormatSpec ( string_kind) => {
1299+ ParseErrorType :: OtherError ( format ! (
1300+ "Expected an {string_kind} element or a '}}'"
1301+ ) )
1302+ }
13111303 } ,
13121304 }
13131305 }
@@ -1345,10 +1337,11 @@ bitflags! {
13451337 const LAMBDA_PARAMETERS = 1 << 24 ;
13461338 const WITH_ITEMS_PARENTHESIZED = 1 << 25 ;
13471339 const WITH_ITEMS_PARENTHESIZED_EXPRESSION = 1 << 26 ;
1348- const WITH_ITEMS_UNPARENTHESIZED = 1 << 28 ;
1349- const F_STRING_ELEMENTS = 1 << 29 ;
1350- const T_STRING_ELEMENTS = 1 << 30 ;
1351- const FT_STRING_ELEMENTS_IN_FORMAT_SPEC = 1 << 31 ;
1340+ const WITH_ITEMS_UNPARENTHESIZED = 1 << 27 ;
1341+ const F_STRING_ELEMENTS = 1 << 28 ;
1342+ const T_STRING_ELEMENTS = 1 << 29 ;
1343+ const F_STRING_ELEMENTS_IN_FORMAT_SPEC = 1 << 30 ;
1344+ const T_STRING_ELEMENTS_IN_FORMAT_SPEC = 1 << 31 ;
13521345 }
13531346}
13541347
@@ -1409,8 +1402,11 @@ impl RecoveryContext {
14091402 RecoveryContext :: T_STRING_ELEMENTS
14101403 }
14111404
1412- InterpolatedStringElementsKind :: FormatSpec => {
1413- RecoveryContext :: FT_STRING_ELEMENTS_IN_FORMAT_SPEC
1405+ InterpolatedStringElementsKind :: FormatSpec ( InterpolatedStringKind :: FString ) => {
1406+ RecoveryContext :: F_STRING_ELEMENTS_IN_FORMAT_SPEC
1407+ }
1408+ InterpolatedStringElementsKind :: FormatSpec ( InterpolatedStringKind :: TString ) => {
1409+ RecoveryContext :: T_STRING_ELEMENTS_IN_FORMAT_SPEC
14141410 }
14151411 } ,
14161412 }
@@ -1485,9 +1481,14 @@ impl RecoveryContext {
14851481 RecoveryContext :: T_STRING_ELEMENTS => RecoveryContextKind :: InterpolatedStringElements (
14861482 InterpolatedStringElementsKind :: Regular ( InterpolatedStringKind :: TString ) ,
14871483 ) ,
1488- RecoveryContext :: FT_STRING_ELEMENTS_IN_FORMAT_SPEC => {
1484+ RecoveryContext :: F_STRING_ELEMENTS_IN_FORMAT_SPEC => {
1485+ RecoveryContextKind :: InterpolatedStringElements (
1486+ InterpolatedStringElementsKind :: FormatSpec ( InterpolatedStringKind :: FString ) ,
1487+ )
1488+ }
1489+ RecoveryContext :: T_STRING_ELEMENTS_IN_FORMAT_SPEC => {
14891490 RecoveryContextKind :: InterpolatedStringElements (
1490- InterpolatedStringElementsKind :: FormatSpec ,
1491+ InterpolatedStringElementsKind :: FormatSpec ( InterpolatedStringKind :: TString ) ,
14911492 )
14921493 }
14931494 _ => return None ,
0 commit comments