]> git.lizzy.rs Git - rust.git/commitdiff
review comments: add FIXME comments and formatting
authorEsteban Küber <esteban@kuber.com.ar>
Thu, 25 Jul 2019 18:22:46 +0000 (11:22 -0700)
committerEsteban Küber <esteban@kuber.com.ar>
Thu, 25 Jul 2019 19:36:51 +0000 (12:36 -0700)
src/libsyntax/parse/lexer/mod.rs
src/libsyntax/parse/lexer/unicode_chars.rs

index 412ed8f04b3432f8eb83f1d0ae7a129e35d96da7..52f65e1b474754b5927eb12c59136fefd4bf03f8 100644 (file)
@@ -389,11 +389,18 @@ fn cook_lexer_token(
                                                           self.pos,
                                                           "unknown start of token",
                                                           c);
-                if let Some(t) = unicode_chars::check_for_substitution(self, start, c, &mut err) {
-                    err.emit();
-                    return Ok(t);
+                // FIXME: the lexer could be used to turn the ASCII version of unicode homoglyphs,
+                // instead of keeping a table in `check_for_substitution`into the token. Ideally,
+                // this should be inside `rustc_lexer`. However, we should first remove compound
+                // tokens like `<<` from `rustc_lexer`, and then add fancier error recovery to it,
+                // as there will be less overall work to do this way.
+                return match unicode_chars::check_for_substitution(self, start, c, &mut err) {
+                    Some(token) => {
+                        err.emit();
+                        Ok(token)
+                    }
+                    None => Err(err),
                 }
-                return Err(err)
             }
         };
         Ok(kind)
index bfa1606a0d2010ce503064623187a453a671ea57..eaa736c6a351741a71ee29675592695bbb92dc67 100644 (file)
@@ -3,7 +3,7 @@
 
 use super::StringReader;
 use errors::{Applicability, DiagnosticBuilder};
-use syntax_pos::{BytePos, Pos, Span, NO_EXPANSION};
+use syntax_pos::{BytePos, Pos, Span, NO_EXPANSION, symbol::kw};
 use crate::parse::token;
 
 #[rustfmt::skip] // for line breaks
     ('>', "Fullwidth Greater-Than Sign", '>'),
 ];
 
+// FIXME: the lexer could be used to turn the ASCII version of unicode homoglyphs, instead of
+// keeping the substitution token in this table. Ideally, this should be inside `rustc_lexer`.
+// However, we should first remove compound tokens like `<<` from `rustc_lexer`, and then add
+// fancier error recovery to it, as there will be less overall work to do this way.
 const ASCII_ARRAY: &[(char, &str, Option<token::TokenKind>)] = &[
     (' ', "Space", Some(token::Whitespace)),
-    ('_', "Underscore", None),
+    ('_', "Underscore", Some(token::Ident(kw::Underscore, false))),
     ('-', "Minus/Hyphen", Some(token::BinOp(token::Minus))),
     (',', "Comma", Some(token::Comma)),
     (';', "Semicolon", Some(token::Semi)),
     ('!', "Exclamation Mark", Some(token::Not)),
     ('?', "Question Mark", Some(token::Question)),
     ('.', "Period", Some(token::Dot)),
-    ('\'', "Single Quote", None),  // Literals are already lexed by this point, so we can't recover
-    ('"', "Quotation Mark", None), // gracefully just by spitting the correct token out.
     ('(', "Left Parenthesis", Some(token::OpenDelim(token::Paren))),
     (')', "Right Parenthesis", Some(token::CloseDelim(token::Paren))),
     ('[', "Left Square Bracket", Some(token::OpenDelim(token::Bracket))),
     ('<', "Less-Than Sign", Some(token::Lt)),
     ('=', "Equals Sign", Some(token::Eq)),
     ('>', "Greater-Than Sign", Some(token::Gt)),
+    // FIXME: Literals are already lexed by this point, so we can't recover gracefully just by
+    // spitting the correct token out.
+    ('\'', "Single Quote", None),
+    ('"', "Quotation Mark", None),
 ];
 
 crate fn check_for_substitution<'a>(