@@ -27,7 +27,7 @@ impl<'a> FStringParser<'a> {
27
27
let mut delims = Vec :: new ( ) ;
28
28
let mut conversion = None ;
29
29
let mut pred_expression_text = String :: new ( ) ;
30
- let mut trailing_seq= String :: new ( ) ;
30
+ let mut trailing_seq = String :: new ( ) ;
31
31
32
32
while let Some ( ch) = self . chars . next ( ) {
33
33
match ch {
@@ -77,7 +77,8 @@ impl<'a> FStringParser<'a> {
77
77
78
78
// match a python 3.8 self documenting expression
79
79
// format '{' PYTHON_EXPRESSION '=' FORMAT_SPECIFIER? '}'
80
- '=' if self . chars . peek ( ) != Some ( & '=' ) => { // check for delims empty?
80
+ '=' if self . chars . peek ( ) != Some ( & '=' ) => {
81
+ // check for delims empty?
81
82
pred_expression_text = expression. to_string ( ) ; // safe expression before = to print it
82
83
}
83
84
@@ -161,28 +162,25 @@ impl<'a> FStringParser<'a> {
161
162
conversion,
162
163
spec,
163
164
} ) ;
164
- }
165
- else {
166
- return Ok ( Joined {
167
- values : vec ! [
168
- Constant {
169
- value: pred_expression_text. to_owned( ) +"="
170
- } ,
171
-
172
- Constant {
173
- value: trailing_seq. to_owned( )
174
- } ,
175
-
176
- FormattedValue {
165
+ } else {
166
+ return Ok ( Joined {
167
+ values : vec ! [
168
+ Constant {
169
+ value: pred_expression_text. to_owned( ) + "=" ,
170
+ } ,
171
+ Constant {
172
+ value: trailing_seq. to_owned( ) ,
173
+ } ,
174
+ FormattedValue {
177
175
value: Box :: new(
178
176
parse_expression( expression. trim( ) )
179
177
. map_err( |e| InvalidExpression ( Box :: new( e. error) ) ) ?,
180
178
) ,
181
179
conversion,
182
- spec, } ,
183
- ]
184
- }
185
- ) ;
180
+ spec,
181
+ } ,
182
+ ] ,
183
+ } ) ;
186
184
}
187
185
}
188
186
'"' | '\'' => {
@@ -360,24 +358,24 @@ mod tests {
360
358
361
359
#[ test]
362
360
fn test_fstring_parse_selfdocumenting_base ( ) {
363
- let src= String :: from ( "{user=}" ) ;
364
- let parse_ast= parse_fstring ( & src) ;
361
+ let src = String :: from ( "{user=}" ) ;
362
+ let parse_ast = parse_fstring ( & src) ;
365
363
366
364
assert ! ( parse_ast. is_ok( ) ) ;
367
365
}
368
366
369
367
#[ test]
370
368
fn test_fstring_parse_selfdocumenting_base_more ( ) {
371
- let src= String :: from ( "mix {user=} with text and {second=}" ) ;
372
- let parse_ast= parse_fstring ( & src) ;
369
+ let src = String :: from ( "mix {user=} with text and {second=}" ) ;
370
+ let parse_ast = parse_fstring ( & src) ;
373
371
374
372
assert ! ( parse_ast. is_ok( ) ) ;
375
373
}
376
374
377
375
#[ test]
378
376
fn test_fstring_parse_selfdocumenting_format ( ) {
379
- let src= String :: from ( "{user=:>10}" ) ;
380
- let parse_ast= parse_fstring ( & src) ;
377
+ let src = String :: from ( "{user=:>10}" ) ;
378
+ let parse_ast = parse_fstring ( & src) ;
381
379
382
380
assert ! ( parse_ast. is_ok( ) ) ;
383
381
}
0 commit comments