Fix f-string regression

This commit is contained in:
Charles Marsh 2022-08-21 16:55:06 -04:00
parent fa2e69983f
commit 147187d18d
13 changed files with 37 additions and 24 deletions

View file

@ -4,6 +4,7 @@ use crate::{
error::{FStringError, FStringErrorType, ParseError},
parser::parse_expression,
};
use itertools::Itertools;
use std::{iter, mem, str};
struct FStringParser<'a> {
@ -105,13 +106,16 @@ impl<'a> FStringParser<'a> {
nested -= 1;
if nested == 0 {
formatted_value_piece.push(next);
spec_constructor.extend(
FStringParser::new(
&format!("{{{}}}", formatted_value_piece),
Location::default(),
&self.recurse_lvl + 1,
)
.parse()?,
let values = FStringParser::new(
&formatted_value_piece,
Location::default(),
&self.recurse_lvl + 1,
)
.parse()?;
spec_constructor.push(values
.into_iter()
.exactly_one()
.expect("Expected formatted value to produce exactly one expression.")
);
formatted_value_piece.clear();
} else {

View file

@ -1,5 +1,5 @@
---
source: parser/src/fstring.rs
source: compiler/parser/src/fstring.rs
expression: parse_ast
---
[

View file

@ -1,5 +1,5 @@
---
source: parser/src/fstring.rs
source: compiler/parser/src/fstring.rs
expression: parse_ast
---
[

View file

@ -1,5 +1,5 @@
---
source: parser/src/fstring.rs
source: compiler/parser/src/fstring.rs
expression: parse_ast
---
[

View file

@ -1,5 +1,5 @@
---
source: parser/src/fstring.rs
source: compiler/parser/src/fstring.rs
expression: "parse_fstring(\"\").unwrap()"
---
[]

View file

@ -1,5 +1,5 @@
---
source: parser/src/fstring.rs
source: compiler/parser/src/fstring.rs
expression: parse_ast
---
[

View file

@ -1,5 +1,5 @@
---
source: parser/src/fstring.rs
source: compiler/parser/src/fstring.rs
expression: parse_ast
---
[

View file

@ -1,5 +1,5 @@
---
source: parser/src/fstring.rs
source: compiler/parser/src/fstring.rs
expression: parse_ast
---
[
@ -37,11 +37,20 @@ expression: parse_ast
column: 0,
},
custom: (),
node: Constant {
value: Str(
"{ spec}",
),
kind: None,
node: FormattedValue {
value: Located {
location: Location {
row: 1,
column: 3,
},
custom: (),
node: Name {
id: "spec",
ctx: Load,
},
},
conversion: 0,
format_spec: None,
},
},
],

View file

@ -1,5 +1,5 @@
---
source: parser/src/fstring.rs
source: compiler/parser/src/fstring.rs
expression: parse_ast
---
[

View file

@ -1,5 +1,5 @@
---
source: parser/src/fstring.rs
source: compiler/parser/src/fstring.rs
expression: parse_ast
---
[

View file

@ -1,5 +1,5 @@
---
source: parser/src/fstring.rs
source: compiler/parser/src/fstring.rs
expression: parse_ast
---
[

View file

@ -1,5 +1,5 @@
---
source: parser/src/fstring.rs
source: compiler/parser/src/fstring.rs
expression: parse_ast
---
[

View file

@ -1,5 +1,5 @@
---
source: parser/src/fstring.rs
source: compiler/parser/src/fstring.rs
expression: parse_ast
---
[