mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-19 02:55:50 +00:00
Fix f-string regression
This commit is contained in:
parent
fa2e69983f
commit
147187d18d
13 changed files with 37 additions and 24 deletions
|
@ -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 {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
source: parser/src/fstring.rs
|
||||
source: compiler/parser/src/fstring.rs
|
||||
expression: parse_ast
|
||||
---
|
||||
[
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
source: parser/src/fstring.rs
|
||||
source: compiler/parser/src/fstring.rs
|
||||
expression: parse_ast
|
||||
---
|
||||
[
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
source: parser/src/fstring.rs
|
||||
source: compiler/parser/src/fstring.rs
|
||||
expression: parse_ast
|
||||
---
|
||||
[
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
source: parser/src/fstring.rs
|
||||
source: compiler/parser/src/fstring.rs
|
||||
expression: "parse_fstring(\"\").unwrap()"
|
||||
---
|
||||
[]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
source: parser/src/fstring.rs
|
||||
source: compiler/parser/src/fstring.rs
|
||||
expression: parse_ast
|
||||
---
|
||||
[
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
source: parser/src/fstring.rs
|
||||
source: compiler/parser/src/fstring.rs
|
||||
expression: parse_ast
|
||||
---
|
||||
[
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
],
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
source: parser/src/fstring.rs
|
||||
source: compiler/parser/src/fstring.rs
|
||||
expression: parse_ast
|
||||
---
|
||||
[
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
source: parser/src/fstring.rs
|
||||
source: compiler/parser/src/fstring.rs
|
||||
expression: parse_ast
|
||||
---
|
||||
[
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
source: parser/src/fstring.rs
|
||||
source: compiler/parser/src/fstring.rs
|
||||
expression: parse_ast
|
||||
---
|
||||
[
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
source: parser/src/fstring.rs
|
||||
source: compiler/parser/src/fstring.rs
|
||||
expression: parse_ast
|
||||
---
|
||||
[
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
source: parser/src/fstring.rs
|
||||
source: compiler/parser/src/fstring.rs
|
||||
expression: parse_ast
|
||||
---
|
||||
[
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue