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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,5 +1,5 @@
--- ---
source: parser/src/fstring.rs source: compiler/parser/src/fstring.rs
expression: parse_ast expression: parse_ast
--- ---
[ [
@ -37,11 +37,20 @@ expression: parse_ast
column: 0, column: 0,
}, },
custom: (), custom: (),
node: Constant { node: FormattedValue {
value: Str( value: Located {
"{ spec}", location: Location {
), row: 1,
kind: None, 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 expression: parse_ast
--- ---
[ [

View file

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

View file

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

View file

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

View file

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