Allow replacement fields in format specs

This commit is contained in:
Padraic Fanning
2022-02-01 20:20:11 -05:00
parent 04886d825d
commit a1dffe671e
2 changed files with 39 additions and 14 deletions

View File

@@ -100,16 +100,19 @@ impl<'a> FStringParser<'a> {
'{' if in_nested => return Err(ExpressionNestedTooDeeply),
'}' if in_nested => {
in_nested = false;
spec_constructor.push(self.expr(ExprKind::FormattedValue {
value:
Box::new(
parse_fstring_expr(&formatted_value_piece).map_err(
|e| InvalidExpression(Box::new(e.error)),
)?,
spec_constructor.push(
self.expr(ExprKind::FormattedValue {
value: Box::new(
FStringParser::new(
&format!("{{{}}}", formatted_value_piece),
Location::default(),
)
.parse()?,
),
conversion: None,
format_spec: None,
}));
conversion: None,
format_spec: None,
}),
);
formatted_value_piece.clear();
}
_ if in_nested => {

View File

@@ -61,13 +61,35 @@ Located {
node: FormattedValue {
value: Located {
location: Location {
row: 1,
column: 2,
row: 0,
column: 0,
},
custom: (),
node: Name {
id: "spec",
ctx: Load,
node: JoinedStr {
values: [
Located {
location: Location {
row: 0,
column: 0,
},
custom: (),
node: FormattedValue {
value: Located {
location: Location {
row: 1,
column: 2,
},
custom: (),
node: Name {
id: "spec",
ctx: Load,
},
},
conversion: None,
format_spec: None,
},
},
],
},
},
conversion: None,