Use less DRY in cook_lexer_token
.
This is a case where a small amount of repetition results in code that is faster and easier to read.
This commit is contained in:
parent
aa6bfaf04b
commit
ceb25d125f
1 changed files with 19 additions and 19 deletions
|
@ -201,28 +201,28 @@ impl<'a> StringReader<'a> {
|
||||||
self.cook_doc_comment(content_start, content, CommentKind::Block, doc_style)
|
self.cook_doc_comment(content_start, content, CommentKind::Block, doc_style)
|
||||||
}
|
}
|
||||||
rustc_lexer::TokenKind::Whitespace => return None,
|
rustc_lexer::TokenKind::Whitespace => return None,
|
||||||
rustc_lexer::TokenKind::Ident
|
rustc_lexer::TokenKind::Ident => {
|
||||||
| rustc_lexer::TokenKind::RawIdent
|
let sym = nfc_normalize(self.str_from(start));
|
||||||
| rustc_lexer::TokenKind::UnknownPrefix => {
|
let span = self.mk_sp(start, self.pos);
|
||||||
let is_raw_ident = token == rustc_lexer::TokenKind::RawIdent;
|
self.sess.symbol_gallery.insert(sym, span);
|
||||||
let is_unknown_prefix = token == rustc_lexer::TokenKind::UnknownPrefix;
|
token::Ident(sym, false)
|
||||||
let mut ident_start = start;
|
}
|
||||||
if is_raw_ident {
|
rustc_lexer::TokenKind::RawIdent => {
|
||||||
ident_start = ident_start + BytePos(2);
|
let sym = nfc_normalize(self.str_from(start + BytePos(2)));
|
||||||
}
|
|
||||||
if is_unknown_prefix {
|
|
||||||
self.report_unknown_prefix(start);
|
|
||||||
}
|
|
||||||
let sym = nfc_normalize(self.str_from(ident_start));
|
|
||||||
let span = self.mk_sp(start, self.pos);
|
let span = self.mk_sp(start, self.pos);
|
||||||
self.sess.symbol_gallery.insert(sym, span);
|
self.sess.symbol_gallery.insert(sym, span);
|
||||||
if is_raw_ident {
|
|
||||||
if !sym.can_be_raw() {
|
if !sym.can_be_raw() {
|
||||||
self.err_span(span, &format!("`{}` cannot be a raw identifier", sym));
|
self.err_span(span, &format!("`{}` cannot be a raw identifier", sym));
|
||||||
}
|
}
|
||||||
self.sess.raw_identifier_spans.borrow_mut().push(span);
|
self.sess.raw_identifier_spans.borrow_mut().push(span);
|
||||||
|
token::Ident(sym, true)
|
||||||
}
|
}
|
||||||
token::Ident(sym, is_raw_ident)
|
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)
|
||||||
}
|
}
|
||||||
rustc_lexer::TokenKind::InvalidIdent
|
rustc_lexer::TokenKind::InvalidIdent
|
||||||
// Do not recover an identifier with emoji if the codepoint is a confusable
|
// Do not recover an identifier with emoji if the codepoint is a confusable
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue