mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-08 05:35:22 +00:00
Merge pull request #4405 from harupy/use-drain
Use `drain` to simplify `compiler/parser/src/string_parser.rs`
This commit is contained in:
commit
4a75cc029e
1 changed files with 4 additions and 6 deletions
|
@ -5,7 +5,7 @@ use crate::{
|
|||
parser::parse_expression_located,
|
||||
token::StringKind,
|
||||
};
|
||||
use std::{iter, mem, str};
|
||||
use std::{iter, str};
|
||||
|
||||
/// unicode_name2 does not expose `MAX_NAME_LENGTH`, so we replicate that constant here, fix #3798
|
||||
pub const MAX_UNICODE_NAME: usize = 88;
|
||||
|
@ -365,10 +365,9 @@ impl<'a> StringParser<'a> {
|
|||
'{' => {
|
||||
if !constant_piece.is_empty() {
|
||||
spec_constructor.push(self.expr(ExprKind::Constant {
|
||||
value: constant_piece.to_owned().into(),
|
||||
value: constant_piece.drain(..).collect::<String>().into(),
|
||||
kind: None,
|
||||
}));
|
||||
constant_piece.clear();
|
||||
}
|
||||
let parsed_expr = self.parse_fstring(nested + 1)?;
|
||||
spec_constructor.extend(parsed_expr);
|
||||
|
@ -385,10 +384,9 @@ impl<'a> StringParser<'a> {
|
|||
}
|
||||
if !constant_piece.is_empty() {
|
||||
spec_constructor.push(self.expr(ExprKind::Constant {
|
||||
value: constant_piece.to_owned().into(),
|
||||
value: constant_piece.drain(..).collect::<String>().into(),
|
||||
kind: None,
|
||||
}));
|
||||
constant_piece.clear();
|
||||
}
|
||||
Ok(spec_constructor)
|
||||
}
|
||||
|
@ -418,7 +416,7 @@ impl<'a> StringParser<'a> {
|
|||
}
|
||||
if !content.is_empty() {
|
||||
values.push(self.expr(ExprKind::Constant {
|
||||
value: mem::take(&mut content).into(),
|
||||
value: content.drain(..).collect::<String>().into(),
|
||||
kind: None,
|
||||
}));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue