Skip to content

Commit 7d743de

Browse files
fix another edge case
1 parent 400ad80 commit 7d743de

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

parser/src/parser.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ pub enum FStringError {
102102
}
103103

104104
impl From<FStringError> for ParseError<lexer::Location, token::Tok, lexer::LexicalError> {
105-
fn from(err: FStringError) -> Self {
105+
fn from(_err: FStringError) -> Self {
106106
// TODO: we should have our own top-level ParseError to properly propagate f-string (and
107107
// other) syntax errors
108108
ParseError::User {
@@ -126,12 +126,12 @@ pub fn parse_fstring(source: &str) -> Result<ast::StringGroup, FStringError> {
126126
escaped = false;
127127
}
128128
'{' => {
129-
if let Some((_, '{')) = chars.peek() {
130-
escaped = true;
131-
continue;
132-
}
133-
134129
if depth == 0 {
130+
if let Some((_, '{')) = chars.peek() {
131+
escaped = true;
132+
continue;
133+
}
134+
135135
values.push(ast::StringGroup::Constant {
136136
value: mem::replace(&mut content, String::new()),
137137
});
@@ -141,12 +141,12 @@ pub fn parse_fstring(source: &str) -> Result<ast::StringGroup, FStringError> {
141141
depth += 1;
142142
}
143143
'}' => {
144-
if let Some((_, '}')) = chars.peek() {
145-
escaped = true;
146-
continue;
147-
}
148-
149144
if depth == 0 {
145+
if let Some((_, '}')) = chars.peek() {
146+
escaped = true;
147+
continue;
148+
}
149+
150150
return Err(FStringError::UnopenedRbrace);
151151
}
152152

tests/snippets/fstrings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
assert f"foo{foo}foo" == 'foobarfoo'
88
assert f"{{foo}}" == '{foo}'
99
assert f"{ {foo} }" == "{'bar'}"
10+
assert f"{f'{{}}'}" == '{}' # don't include escaped braces in nested f-strings

0 commit comments

Comments
 (0)