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

Commit

Permalink
Merge with magic parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Jul 25, 2023
1 parent fcebb0c commit 36e75e1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 39 deletions.
2 changes: 1 addition & 1 deletion ast/src/generic.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![allow(clippy::derive_partial_eq_without_eq)]
use crate::text_size::TextRange;
use crate::text_size::{TextRange, TextSize};
pub(crate) use crate::{builtin::*, ConversionFlag, Node};
use std::fmt::{self, Debug};

Expand Down
9 changes: 6 additions & 3 deletions parser/src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,12 @@ impl<'source> Lexer<'source> {
self.consume_ascii_character(c)
} else if is_unicode_identifier_start(c) {
let identifier = self.lex_identifier(c)?;
self.state = State::Other;

Ok((identifier, self.token_range()))
} else if is_emoji_presentation(c) {
self.state = State::Other;

Ok((
Tok::Name {
name: c.to_string(),
Expand Down Expand Up @@ -1426,9 +1430,8 @@ baz = %matplotlib \

fn assert_no_jupyter_magic(tokens: &[Tok]) {
for tok in tokens {
match tok {
Tok::MagicCommand { .. } => panic!("Unexpected magic command token: {:?}", tok),
_ => {}
if let Tok::MagicCommand { .. } = tok {
panic!("Unexpected magic command token: {:?}", tok)
}
}
}
Expand Down
40 changes: 5 additions & 35 deletions parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,41 +396,11 @@ pub fn parse_tokens(
) -> Result<ast::Mod, ParseError> {
let lxr = lxr.into_iter();

<<<<<<< HEAD
let lxr =
lxr.filter_ok(|(tok, _)| !matches!(tok, Tok::Comment { .. } | Tok::NonLogicalNewline));
parse_filtered_tokens(lxr, mode, source_path)
=======
match mode {
Mode::Module | Mode::Interactive | Mode::Expression => parse_filtered_tokens(
lxr.filter_ok(|(tok, _)| !matches!(tok, Tok::Comment { .. } | Tok::NonLogicalNewline)),
mode,
source_path,
),
Mode::Jupyter => {
let mut after_magic = false;
parse_filtered_tokens(
lxr.filter_ok(|(tok, _)| match tok {
Tok::Comment(..) | Tok::NonLogicalNewline => {
after_magic = false;
false
}
Tok::Newline => !after_magic,
Tok::MagicCommand { .. } => {
after_magic = true;
false
}
_ => {
after_magic = false;
true
}
}),
mode,
source_path,
)
}
}
>>>>>>> 58ac178 (Use single filter call)
parse_filtered_tokens(
lxr.filter_ok(|(tok, _)| !matches!(tok, Tok::Comment { .. } | Tok::NonLogicalNewline)),
mode,
source_path,
)
}

fn parse_filtered_tokens(
Expand Down

0 comments on commit 36e75e1

Please sign in to comment.