Skip to content

Commit

Permalink
extract common code
Browse files Browse the repository at this point in the history
  • Loading branch information
fee1-dead committed Jul 25, 2023
1 parent 0d9c871 commit a0376e9
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions compiler/rustc_parse/src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,7 @@ impl<'a> StringReader<'a> {
continue;
}
rustc_lexer::TokenKind::Ident => {
let sym = nfc_normalize(self.str_from(start));
let span = self.mk_sp(start, self.pos);
self.sess.symbol_gallery.insert(sym, span);
token::Ident(sym, false)
self.ident(start)
}
rustc_lexer::TokenKind::RawIdent => {
let sym = nfc_normalize(self.str_from(start + BytePos(2)));
Expand All @@ -183,10 +180,7 @@ impl<'a> StringReader<'a> {
}
rustc_lexer::TokenKind::UnknownPrefix => {
self.report_unknown_prefix(start);
let sym = nfc_normalize(self.str_from(start));
let span = self.mk_sp(start, self.pos);
self.sess.symbol_gallery.insert(sym, span);
token::Ident(sym, false)
self.ident(start)
}
rustc_lexer::TokenKind::InvalidIdent
// Do not recover an identifier with emoji if the codepoint is a confusable
Expand Down Expand Up @@ -222,10 +216,8 @@ impl<'a> StringReader<'a> {
self.cursor = Cursor::new(&str_before[prefix_len as usize..]);

self.report_unknown_prefix(start);
let sym = nfc_normalize(self.str_from(start));
let prefix_span = self.mk_sp(start, lit_start);
self.sess.symbol_gallery.insert(sym, prefix_span);
return (Token::new(token::Ident(sym, false), prefix_span), preceded_by_whitespace);
return (Token::new(self.ident(start), prefix_span), preceded_by_whitespace);
}
rustc_lexer::TokenKind::Literal { kind, suffix_start } => {
let suffix_start = start + BytePos(suffix_start);
Expand Down Expand Up @@ -341,6 +333,13 @@ impl<'a> StringReader<'a> {
}
}

fn ident(&self, start: BytePos) -> TokenKind {
let sym = nfc_normalize(self.str_from(start));
let span = self.mk_sp(start, self.pos);
self.sess.symbol_gallery.insert(sym, span);
token::Ident(sym, false)
}

fn struct_fatal_span_char(
&self,
from_pos: BytePos,
Expand Down

0 comments on commit a0376e9

Please sign in to comment.