mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Allow replacement fields in format specs
This commit is contained in:
@@ -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 => {
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user