Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Allow replacement fields in format specs
  • Loading branch information
fanninpm committed Feb 4, 2022
commit a1dffe671e4199f2604d47fefe0516ef317098ef
21 changes: 12 additions & 9 deletions parser/src/fstring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down