Skip to content

Commit 71ec5c1

Browse files
committed
clean up after review
1 parent 620115d commit 71ec5c1

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

parser/src/fstring.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,22 @@ impl<'a> FStringParser<'a> {
3434
// can be integrated better with the remainign code, but as a starting point ok
3535
// in general I would do here a tokenizing of the fstrings to omit this peeking.
3636
'!' if self.chars.peek() == Some(&'=') => {
37-
expression.push('!');
38-
expression.push('=');
37+
expression.push_str("!=");
3938
self.chars.next();
4039
}
4140

4241
'=' if self.chars.peek() == Some(&'=') => {
43-
expression.push('=');
44-
expression.push('=');
42+
expression.push_str("==");
4543
self.chars.next();
4644
}
4745

4846
'>' if self.chars.peek() == Some(&'=') => {
49-
expression.push('>');
50-
expression.push('=');
47+
expression.push_str(">=");
5148
self.chars.next();
5249
}
5350

5451
'<' if self.chars.peek() == Some(&'=') => {
55-
expression.push('<');
56-
expression.push('=');
52+
expression.push_str("<=");
5753
self.chars.next();
5854
}
5955

@@ -74,8 +70,11 @@ impl<'a> FStringParser<'a> {
7470
}
7571
});
7672

77-
let peek = self.chars.peek();
78-
if peek != Some(&'}') && peek != Some(&':') {
73+
if let Some(&peek) = self.chars.peek() {
74+
if peek != '}' && peek != ':' {
75+
return Err(ExpectedRbrace);
76+
}
77+
} else {
7978
return Err(ExpectedRbrace);
8079
}
8180
}
@@ -197,17 +196,14 @@ impl<'a> FStringParser<'a> {
197196
}
198197
}
199198
}
200-
201199
' ' if !pred_expression_text.is_empty() => {
202200
trailing_seq.push(ch);
203201
}
204-
205202
_ => {
206203
expression.push(ch);
207204
}
208205
}
209206
}
210-
211207
Err(UnclosedLbrace)
212208
}
213209

@@ -391,7 +387,6 @@ mod tests {
391387

392388
assert_eq!(parse_fstring("{5!a1}"), Err(ExpectedRbrace));
393389
assert_eq!(parse_fstring("{5!"), Err(ExpectedRbrace));
394-
395390
assert_eq!(parse_fstring("abc{!a 'cat'}"), Err(EmptyExpression));
396391
assert_eq!(parse_fstring("{!a"), Err(EmptyExpression));
397392
assert_eq!(parse_fstring("{ !a}"), Err(EmptyExpression));

0 commit comments

Comments
 (0)