Skip to content
This repository was archived by the owner on Jul 27, 2023. It is now read-only.

Commit 4574637

Browse files
committed
Use single filter call
1 parent 930324e commit 4574637

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

parser/src/parser.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -415,13 +415,22 @@ pub fn parse_tokens(
415415
) -> Result<ast::Mod, ParseError> {
416416
let lxr = lxr.into_iter();
417417

418-
let lxr =
419-
lxr.filter_ok(|(tok, _)| !matches!(tok, Tok::Comment { .. } | Tok::NonLogicalNewline));
420-
if mode == Mode::Jupyter {
421-
let lxr = lxr.filter_ok(|(tok, _)| !matches!(tok, Tok::MagicCommand { .. }));
422-
parse_filtered_tokens(lxr, mode, source_path)
423-
} else {
424-
parse_filtered_tokens(lxr, mode, source_path)
418+
match mode {
419+
Mode::Module | Mode::Interactive | Mode::Expression => parse_filtered_tokens(
420+
lxr.filter_ok(|(tok, _)| !matches!(tok, Tok::Comment { .. } | Tok::NonLogicalNewline)),
421+
mode,
422+
source_path,
423+
),
424+
Mode::Jupyter => parse_filtered_tokens(
425+
lxr.filter_ok(|(tok, _)| {
426+
!matches!(
427+
tok,
428+
Tok::Comment { .. } | Tok::NonLogicalNewline | Tok::MagicCommand { .. }
429+
)
430+
}),
431+
mode,
432+
source_path,
433+
),
425434
}
426435
}
427436

0 commit comments

Comments
 (0)