2022-11-27 11:15:06 +00:00
|
|
|
|
//! Characters and their corresponding confusables were collected from
|
|
|
|
|
//! <https://www.unicode.org/Public/security/10.0.0/confusables.txt>
|
2015-11-15 02:37:49 +05:30
|
|
|
|
|
|
|
|
|
use super::StringReader;
|
2022-04-26 15:40:14 +03:00
|
|
|
|
use crate::token::{self, Delimiter};
|
2022-01-23 20:41:46 +00:00
|
|
|
|
use rustc_errors::{Applicability, Diagnostic};
|
2019-12-31 20:15:40 +03:00
|
|
|
|
use rustc_span::{symbol::kw, BytePos, Pos, Span};
|
2015-11-15 02:37:49 +05:30
|
|
|
|
|
2019-07-02 11:06:01 +03:00
|
|
|
|
#[rustfmt::skip] // for line breaks
|
2021-09-09 17:05:03 +00:00
|
|
|
|
pub(crate) const UNICODE_ARRAY: &[(char, &str, char)] = &[
|
2017-08-06 17:36:50 +02:00
|
|
|
|
('
', "Line Separator", ' '),
|
|
|
|
|
('
', "Paragraph Separator", ' '),
|
|
|
|
|
(' ', "Ogham Space mark", ' '),
|
2016-04-21 20:05:47 +08:00
|
|
|
|
(' ', "En Quad", ' '),
|
|
|
|
|
(' ', "Em Quad", ' '),
|
|
|
|
|
(' ', "En Space", ' '),
|
|
|
|
|
(' ', "Em Space", ' '),
|
|
|
|
|
(' ', "Three-Per-Em Space", ' '),
|
|
|
|
|
(' ', "Four-Per-Em Space", ' '),
|
|
|
|
|
(' ', "Six-Per-Em Space", ' '),
|
|
|
|
|
(' ', "Punctuation Space", ' '),
|
|
|
|
|
(' ', "Thin Space", ' '),
|
|
|
|
|
(' ', "Hair Space", ' '),
|
|
|
|
|
(' ', "Medium Mathematical Space", ' '),
|
2017-08-06 17:36:50 +02:00
|
|
|
|
(' ', "No-Break Space", ' '),
|
|
|
|
|
(' ', "Figure Space", ' '),
|
|
|
|
|
(' ', "Narrow No-Break Space", ' '),
|
2016-04-21 20:05:47 +08:00
|
|
|
|
(' ', "Ideographic Space", ' '),
|
2017-08-06 17:36:50 +02:00
|
|
|
|
|
2015-11-15 02:37:49 +05:30
|
|
|
|
('ߺ', "Nko Lajanyalan", '_'),
|
|
|
|
|
('﹍', "Dashed Low Line", '_'),
|
|
|
|
|
('﹎', "Centreline Low Line", '_'),
|
|
|
|
|
('﹏', "Wavy Low Line", '_'),
|
2017-08-06 18:34:36 +02:00
|
|
|
|
('_', "Fullwidth Low Line", '_'),
|
2017-08-06 17:36:50 +02:00
|
|
|
|
|
2015-11-15 02:37:49 +05:30
|
|
|
|
('‐', "Hyphen", '-'),
|
|
|
|
|
('‑', "Non-Breaking Hyphen", '-'),
|
|
|
|
|
('‒', "Figure Dash", '-'),
|
|
|
|
|
('–', "En Dash", '-'),
|
2016-04-21 17:51:47 +08:00
|
|
|
|
('—', "Em Dash", '-'),
|
2015-11-15 02:37:49 +05:30
|
|
|
|
('﹘', "Small Em Dash", '-'),
|
2017-08-06 17:36:50 +02:00
|
|
|
|
('۔', "Arabic Full Stop", '-'),
|
2015-11-15 02:37:49 +05:30
|
|
|
|
('⁃', "Hyphen Bullet", '-'),
|
|
|
|
|
('˗', "Modifier Letter Minus Sign", '-'),
|
|
|
|
|
('−', "Minus Sign", '-'),
|
2017-08-06 17:36:50 +02:00
|
|
|
|
('➖', "Heavy Minus Sign", '-'),
|
|
|
|
|
('Ⲻ', "Coptic Letter Dialect-P Ni", '-'),
|
2016-04-21 17:51:47 +08:00
|
|
|
|
('ー', "Katakana-Hiragana Prolonged Sound Mark", '-'),
|
2017-08-06 17:36:50 +02:00
|
|
|
|
('-', "Fullwidth Hyphen-Minus", '-'),
|
|
|
|
|
('―', "Horizontal Bar", '-'),
|
|
|
|
|
('─', "Box Drawings Light Horizontal", '-'),
|
|
|
|
|
('━', "Box Drawings Heavy Horizontal", '-'),
|
|
|
|
|
('㇐', "CJK Stroke H", '-'),
|
2019-07-21 07:49:26 -07:00
|
|
|
|
('ꟷ', "Latin Epigraphic Letter Sideways I", '-'),
|
2017-08-06 17:36:50 +02:00
|
|
|
|
('ᅳ', "Hangul Jungseong Eu", '-'),
|
|
|
|
|
('ㅡ', "Hangul Letter Eu", '-'),
|
|
|
|
|
('一', "CJK Unified Ideograph-4E00", '-'),
|
|
|
|
|
('⼀', "Kangxi Radical One", '-'),
|
|
|
|
|
|
|
|
|
|
('؍', "Arabic Date Separator", ','),
|
2015-11-15 02:37:49 +05:30
|
|
|
|
('٫', "Arabic Decimal Separator", ','),
|
|
|
|
|
('‚', "Single Low-9 Quotation Mark", ','),
|
2017-08-06 17:36:50 +02:00
|
|
|
|
('¸', "Cedilla", ','),
|
2015-11-15 02:37:49 +05:30
|
|
|
|
('ꓹ', "Lisu Letter Tone Na Po", ','),
|
2016-04-21 17:51:47 +08:00
|
|
|
|
(',', "Fullwidth Comma", ','),
|
2017-08-06 17:36:50 +02:00
|
|
|
|
|
2015-11-15 02:37:49 +05:30
|
|
|
|
(';', "Greek Question Mark", ';'),
|
2016-04-21 17:51:47 +08:00
|
|
|
|
(';', "Fullwidth Semicolon", ';'),
|
2017-08-06 17:36:50 +02:00
|
|
|
|
('︔', "Presentation Form For Vertical Semicolon", ';'),
|
|
|
|
|
|
2015-11-15 02:37:49 +05:30
|
|
|
|
('ः', "Devanagari Sign Visarga", ':'),
|
|
|
|
|
('ઃ', "Gujarati Sign Visarga", ':'),
|
|
|
|
|
(':', "Fullwidth Colon", ':'),
|
|
|
|
|
('։', "Armenian Full Stop", ':'),
|
|
|
|
|
('܃', "Syriac Supralinear Colon", ':'),
|
|
|
|
|
('܄', "Syriac Sublinear Colon", ':'),
|
2017-08-09 13:52:43 -07:00
|
|
|
|
('᛬', "Runic Multiple Punctuation", ':'),
|
2015-11-15 02:37:49 +05:30
|
|
|
|
('︰', "Presentation Form For Vertical Two Dot Leader", ':'),
|
|
|
|
|
('᠃', "Mongolian Full Stop", ':'),
|
|
|
|
|
('᠉', "Mongolian Manchu Full Stop", ':'),
|
|
|
|
|
('⁚', "Two Dot Punctuation", ':'),
|
|
|
|
|
('׃', "Hebrew Punctuation Sof Pasuq", ':'),
|
|
|
|
|
('˸', "Modifier Letter Raised Colon", ':'),
|
|
|
|
|
('꞉', "Modifier Letter Colon", ':'),
|
|
|
|
|
('∶', "Ratio", ':'),
|
|
|
|
|
('ː', "Modifier Letter Triangular Colon", ':'),
|
|
|
|
|
('ꓽ', "Lisu Letter Tone Mya Jeu", ':'),
|
2017-08-06 17:36:50 +02:00
|
|
|
|
('︓', "Presentation Form For Vertical Colon", ':'),
|
|
|
|
|
|
2015-11-15 02:37:49 +05:30
|
|
|
|
('!', "Fullwidth Exclamation Mark", '!'),
|
|
|
|
|
('ǃ', "Latin Letter Retroflex Click", '!'),
|
2017-08-06 17:36:50 +02:00
|
|
|
|
('ⵑ', "Tifinagh Letter Tuareg Yang", '!'),
|
|
|
|
|
('︕', "Presentation Form For Vertical Exclamation Mark", '!'),
|
|
|
|
|
|
2015-11-15 02:37:49 +05:30
|
|
|
|
('ʔ', "Latin Letter Glottal Stop", '?'),
|
2017-08-06 17:36:50 +02:00
|
|
|
|
('Ɂ', "Latin Capital Letter Glottal Stop", '?'),
|
2015-11-15 02:37:49 +05:30
|
|
|
|
('ॽ', "Devanagari Letter Glottal Stop", '?'),
|
|
|
|
|
('Ꭾ', "Cherokee Letter He", '?'),
|
2017-08-06 17:36:50 +02:00
|
|
|
|
('ꛫ', "Bamum Letter Ntuu", '?'),
|
2016-04-21 17:51:47 +08:00
|
|
|
|
('?', "Fullwidth Question Mark", '?'),
|
2017-08-06 17:36:50 +02:00
|
|
|
|
('︖', "Presentation Form For Vertical Question Mark", '?'),
|
|
|
|
|
|
2015-11-15 02:37:49 +05:30
|
|
|
|
('𝅭', "Musical Symbol Combining Augmentation Dot", '.'),
|
|
|
|
|
('․', "One Dot Leader", '.'),
|
|
|
|
|
('܁', "Syriac Supralinear Full Stop", '.'),
|
|
|
|
|
('܂', "Syriac Sublinear Full Stop", '.'),
|
|
|
|
|
('꘎', "Vai Full Stop", '.'),
|
|
|
|
|
('𐩐', "Kharoshthi Punctuation Dot", '.'),
|
|
|
|
|
('٠', "Arabic-Indic Digit Zero", '.'),
|
|
|
|
|
('۰', "Extended Arabic-Indic Digit Zero", '.'),
|
|
|
|
|
('ꓸ', "Lisu Letter Tone Mya Ti", '.'),
|
2017-08-06 17:36:50 +02:00
|
|
|
|
('·', "Middle Dot", '.'),
|
2016-04-21 17:51:47 +08:00
|
|
|
|
('・', "Katakana Middle Dot", '.'),
|
2017-08-06 17:36:50 +02:00
|
|
|
|
('・', "Halfwidth Katakana Middle Dot", '.'),
|
|
|
|
|
('᛫', "Runic Single Punctuation", '.'),
|
|
|
|
|
('·', "Greek Ano Teleia", '.'),
|
|
|
|
|
('⸱', "Word Separator Middle Dot", '.'),
|
|
|
|
|
('𐄁', "Aegean Word Separator Dot", '.'),
|
|
|
|
|
('•', "Bullet", '.'),
|
|
|
|
|
('‧', "Hyphenation Point", '.'),
|
|
|
|
|
('∙', "Bullet Operator", '.'),
|
|
|
|
|
('⋅', "Dot Operator", '.'),
|
|
|
|
|
('ꞏ', "Latin Letter Sinological Dot", '.'),
|
|
|
|
|
('ᐧ', "Canadian Syllabics Final Middle Dot", '.'),
|
|
|
|
|
('ᐧ', "Canadian Syllabics Final Middle Dot", '.'),
|
|
|
|
|
('.', "Fullwidth Full Stop", '.'),
|
|
|
|
|
('。', "Ideographic Full Stop", '.'),
|
|
|
|
|
('︒', "Presentation Form For Vertical Ideographic Full Stop", '.'),
|
|
|
|
|
|
2015-11-15 02:37:49 +05:30
|
|
|
|
('՝', "Armenian Comma", '\''),
|
|
|
|
|
(''', "Fullwidth Apostrophe", '\''),
|
|
|
|
|
('‘', "Left Single Quotation Mark", '\''),
|
|
|
|
|
('’', "Right Single Quotation Mark", '\''),
|
|
|
|
|
('‛', "Single High-Reversed-9 Quotation Mark", '\''),
|
|
|
|
|
('′', "Prime", '\''),
|
|
|
|
|
('‵', "Reversed Prime", '\''),
|
|
|
|
|
('՚', "Armenian Apostrophe", '\''),
|
|
|
|
|
('׳', "Hebrew Punctuation Geresh", '\''),
|
2017-10-12 14:53:26 +08:00
|
|
|
|
('`', "Grave Accent", '\''),
|
2015-11-15 02:37:49 +05:30
|
|
|
|
('`', "Greek Varia", '\''),
|
|
|
|
|
('`', "Fullwidth Grave Accent", '\''),
|
2017-08-06 17:36:50 +02:00
|
|
|
|
('´', "Acute Accent", '\''),
|
2015-11-15 02:37:49 +05:30
|
|
|
|
('΄', "Greek Tonos", '\''),
|
|
|
|
|
('´', "Greek Oxia", '\''),
|
|
|
|
|
('᾽', "Greek Koronis", '\''),
|
|
|
|
|
('᾿', "Greek Psili", '\''),
|
|
|
|
|
('῾', "Greek Dasia", '\''),
|
|
|
|
|
('ʹ', "Modifier Letter Prime", '\''),
|
|
|
|
|
('ʹ', "Greek Numeral Sign", '\''),
|
2017-08-06 17:36:50 +02:00
|
|
|
|
('ˈ', "Modifier Letter Vertical Line", '\''),
|
2015-11-15 02:37:49 +05:30
|
|
|
|
('ˊ', "Modifier Letter Acute Accent", '\''),
|
|
|
|
|
('ˋ', "Modifier Letter Grave Accent", '\''),
|
|
|
|
|
('˴', "Modifier Letter Middle Grave Accent", '\''),
|
|
|
|
|
('ʻ', "Modifier Letter Turned Comma", '\''),
|
|
|
|
|
('ʽ', "Modifier Letter Reversed Comma", '\''),
|
|
|
|
|
('ʼ', "Modifier Letter Apostrophe", '\''),
|
|
|
|
|
('ʾ', "Modifier Letter Right Half Ring", '\''),
|
|
|
|
|
('ꞌ', "Latin Small Letter Saltillo", '\''),
|
|
|
|
|
('י', "Hebrew Letter Yod", '\''),
|
|
|
|
|
('ߴ', "Nko High Tone Apostrophe", '\''),
|
|
|
|
|
('ߵ', "Nko Low Tone Apostrophe", '\''),
|
2017-08-06 17:36:50 +02:00
|
|
|
|
('ᑊ', "Canadian Syllabics West-Cree P", '\''),
|
|
|
|
|
('ᛌ', "Runic Letter Short-Twig-Sol S", '\''),
|
|
|
|
|
('𖽑', "Miao Sign Aspiration", '\''),
|
|
|
|
|
('𖽒', "Miao Sign Reformed Voicing", '\''),
|
|
|
|
|
|
|
|
|
|
('᳓', "Vedic Sign Nihshvasa", '"'),
|
2015-11-18 10:32:43 +11:00
|
|
|
|
('"', "Fullwidth Quotation Mark", '"'),
|
|
|
|
|
('“', "Left Double Quotation Mark", '"'),
|
|
|
|
|
('”', "Right Double Quotation Mark", '"'),
|
|
|
|
|
('‟', "Double High-Reversed-9 Quotation Mark", '"'),
|
|
|
|
|
('″', "Double Prime", '"'),
|
|
|
|
|
('‶', "Reversed Double Prime", '"'),
|
|
|
|
|
('〃', "Ditto Mark", '"'),
|
|
|
|
|
('״', "Hebrew Punctuation Gershayim", '"'),
|
|
|
|
|
('˝', "Double Acute Accent", '"'),
|
|
|
|
|
('ʺ', "Modifier Letter Double Prime", '"'),
|
|
|
|
|
('˶', "Modifier Letter Middle Double Acute Accent", '"'),
|
|
|
|
|
('˵', "Modifier Letter Middle Double Grave Accent", '"'),
|
|
|
|
|
('ˮ', "Modifier Letter Double Apostrophe", '"'),
|
|
|
|
|
('ײ', "Hebrew Ligature Yiddish Double Yod", '"'),
|
|
|
|
|
('❞', "Heavy Double Comma Quotation Mark Ornament", '"'),
|
|
|
|
|
('❝', "Heavy Double Turned Comma Quotation Mark Ornament", '"'),
|
2017-08-06 17:36:50 +02:00
|
|
|
|
|
|
|
|
|
('(', "Fullwidth Left Parenthesis", '('),
|
2015-11-15 02:37:49 +05:30
|
|
|
|
('❨', "Medium Left Parenthesis Ornament", '('),
|
|
|
|
|
('﴾', "Ornate Left Parenthesis", '('),
|
2017-08-06 17:36:50 +02:00
|
|
|
|
|
|
|
|
|
(')', "Fullwidth Right Parenthesis", ')'),
|
2015-11-15 02:37:49 +05:30
|
|
|
|
('❩', "Medium Right Parenthesis Ornament", ')'),
|
|
|
|
|
('﴿', "Ornate Right Parenthesis", ')'),
|
2017-08-06 17:36:50 +02:00
|
|
|
|
|
2016-04-21 20:09:26 +08:00
|
|
|
|
('[', "Fullwidth Left Square Bracket", '['),
|
|
|
|
|
('❲', "Light Left Tortoise Shell Bracket Ornament", '['),
|
2016-04-21 20:17:51 +08:00
|
|
|
|
('「', "Left Corner Bracket", '['),
|
|
|
|
|
('『', "Left White Corner Bracket", '['),
|
|
|
|
|
('【', "Left Black Lenticular Bracket", '['),
|
2016-04-21 20:09:26 +08:00
|
|
|
|
('〔', "Left Tortoise Shell Bracket", '['),
|
2016-04-21 20:17:51 +08:00
|
|
|
|
('〖', "Left White Lenticular Bracket", '['),
|
|
|
|
|
('〘', "Left White Tortoise Shell Bracket", '['),
|
|
|
|
|
('〚', "Left White Square Bracket", '['),
|
2017-08-06 17:36:50 +02:00
|
|
|
|
|
2016-04-21 20:09:26 +08:00
|
|
|
|
(']', "Fullwidth Right Square Bracket", ']'),
|
|
|
|
|
('❳', "Light Right Tortoise Shell Bracket Ornament", ']'),
|
2016-04-21 20:17:51 +08:00
|
|
|
|
('」', "Right Corner Bracket", ']'),
|
|
|
|
|
('』', "Right White Corner Bracket", ']'),
|
|
|
|
|
('】', "Right Black Lenticular Bracket", ']'),
|
2016-04-21 20:09:26 +08:00
|
|
|
|
('〕', "Right Tortoise Shell Bracket", ']'),
|
2016-04-21 20:17:51 +08:00
|
|
|
|
('〗', "Right White Lenticular Bracket", ']'),
|
|
|
|
|
('〙', "Right White Tortoise Shell Bracket", ']'),
|
|
|
|
|
('〛', "Right White Square Bracket", ']'),
|
2017-08-06 17:36:50 +02:00
|
|
|
|
|
2015-11-15 02:37:49 +05:30
|
|
|
|
('❴', "Medium Left Curly Bracket Ornament", '{'),
|
2017-08-06 17:36:50 +02:00
|
|
|
|
('𝄔', "Musical Symbol Brace", '{'),
|
|
|
|
|
('{', "Fullwidth Left Curly Bracket", '{'),
|
|
|
|
|
|
2015-11-15 02:37:49 +05:30
|
|
|
|
('❵', "Medium Right Curly Bracket Ornament", '}'),
|
2017-08-06 17:36:50 +02:00
|
|
|
|
('}', "Fullwidth Right Curly Bracket", '}'),
|
|
|
|
|
|
2015-11-15 02:37:49 +05:30
|
|
|
|
('⁎', "Low Asterisk", '*'),
|
|
|
|
|
('٭', "Arabic Five Pointed Star", '*'),
|
|
|
|
|
('∗', "Asterisk Operator", '*'),
|
2017-08-06 17:36:50 +02:00
|
|
|
|
('𐌟', "Old Italic Letter Ess", '*'),
|
|
|
|
|
('*', "Fullwidth Asterisk", '*'),
|
|
|
|
|
|
2015-11-15 02:37:49 +05:30
|
|
|
|
('᜵', "Philippine Single Punctuation", '/'),
|
|
|
|
|
('⁁', "Caret Insertion Point", '/'),
|
|
|
|
|
('∕', "Division Slash", '/'),
|
|
|
|
|
('⁄', "Fraction Slash", '/'),
|
|
|
|
|
('╱', "Box Drawings Light Diagonal Upper Right To Lower Left", '/'),
|
|
|
|
|
('⟋', "Mathematical Rising Diagonal", '/'),
|
|
|
|
|
('⧸', "Big Solidus", '/'),
|
2017-08-06 17:36:50 +02:00
|
|
|
|
('𝈺', "Greek Instrumental Notation Symbol-47", '/'),
|
|
|
|
|
('㇓', "CJK Stroke Sp", '/'),
|
2015-11-15 02:37:49 +05:30
|
|
|
|
('〳', "Vertical Kana Repeat Mark Upper Half", '/'),
|
2017-08-06 17:36:50 +02:00
|
|
|
|
('Ⳇ', "Coptic Capital Letter Old Coptic Esh", '/'),
|
|
|
|
|
('ノ', "Katakana Letter No", '/'),
|
|
|
|
|
('丿', "CJK Unified Ideograph-4E3F", '/'),
|
2015-11-15 02:37:49 +05:30
|
|
|
|
('⼃', "Kangxi Radical Slash", '/'),
|
2017-08-06 17:36:50 +02:00
|
|
|
|
('/', "Fullwidth Solidus", '/'),
|
|
|
|
|
|
2015-11-15 02:37:49 +05:30
|
|
|
|
('\', "Fullwidth Reverse Solidus", '\\'),
|
|
|
|
|
('﹨', "Small Reverse Solidus", '\\'),
|
|
|
|
|
('∖', "Set Minus", '\\'),
|
|
|
|
|
('⟍', "Mathematical Falling Diagonal", '\\'),
|
|
|
|
|
('⧵', "Reverse Solidus Operator", '\\'),
|
|
|
|
|
('⧹', "Big Reverse Solidus", '\\'),
|
2017-08-06 17:36:50 +02:00
|
|
|
|
('⧹', "Greek Vocal Notation Symbol-16", '\\'),
|
|
|
|
|
('⧹', "Greek Instrumental Symbol-48", '\\'),
|
|
|
|
|
('㇔', "CJK Stroke D", '\\'),
|
|
|
|
|
('丶', "CJK Unified Ideograph-4E36", '\\'),
|
|
|
|
|
('⼂', "Kangxi Radical Dot", '\\'),
|
2016-04-21 17:51:47 +08:00
|
|
|
|
('、', "Ideographic Comma", '\\'),
|
|
|
|
|
('ヽ', "Katakana Iteration Mark", '\\'),
|
2017-08-06 17:36:50 +02:00
|
|
|
|
|
2015-11-15 02:37:49 +05:30
|
|
|
|
('ꝸ', "Latin Small Letter Um", '&'),
|
2017-08-06 17:36:50 +02:00
|
|
|
|
('&', "Fullwidth Ampersand", '&'),
|
|
|
|
|
|
2017-08-09 19:23:05 -05:00
|
|
|
|
('᛭', "Runic Cross Punctuation", '+'),
|
2017-08-06 17:36:50 +02:00
|
|
|
|
('➕', "Heavy Plus Sign", '+'),
|
|
|
|
|
('𐊛', "Lycian Letter H", '+'),
|
2015-11-15 02:37:49 +05:30
|
|
|
|
('﬩', "Hebrew Letter Alternative Plus Sign", '+'),
|
2017-08-06 17:36:50 +02:00
|
|
|
|
('+', "Fullwidth Plus Sign", '+'),
|
|
|
|
|
|
2015-11-15 02:37:49 +05:30
|
|
|
|
('‹', "Single Left-Pointing Angle Quotation Mark", '<'),
|
|
|
|
|
('❮', "Heavy Left-Pointing Angle Quotation Mark Ornament", '<'),
|
|
|
|
|
('˂', "Modifier Letter Left Arrowhead", '<'),
|
2017-08-06 17:36:50 +02:00
|
|
|
|
('𝈶', "Greek Instrumental Symbol-40", '<'),
|
|
|
|
|
('ᐸ', "Canadian Syllabics Pa", '<'),
|
|
|
|
|
('ᚲ', "Runic Letter Kauna", '<'),
|
|
|
|
|
('❬', "Medium Left-Pointing Angle Bracket Ornament", '<'),
|
|
|
|
|
('⟨', "Mathematical Left Angle Bracket", '<'),
|
|
|
|
|
('〈', "Left-Pointing Angle Bracket", '<'),
|
2016-04-21 17:51:47 +08:00
|
|
|
|
('〈', "Left Angle Bracket", '<'),
|
2017-08-06 17:36:50 +02:00
|
|
|
|
('㇛', "CJK Stroke Pd", '<'),
|
|
|
|
|
('く', "Hiragana Letter Ku", '<'),
|
|
|
|
|
('𡿨', "CJK Unified Ideograph-21FE8", '<'),
|
2016-04-21 17:51:47 +08:00
|
|
|
|
('《', "Left Double Angle Bracket", '<'),
|
2017-08-06 17:36:50 +02:00
|
|
|
|
('<', "Fullwidth Less-Than Sign", '<'),
|
|
|
|
|
|
|
|
|
|
('᐀', "Canadian Syllabics Hyphen", '='),
|
|
|
|
|
('⹀', "Double Hyphen", '='),
|
|
|
|
|
('゠', "Katakana-Hiragana Double Hyphen", '='),
|
2015-11-15 02:37:49 +05:30
|
|
|
|
('꓿', "Lisu Punctuation Full Stop", '='),
|
2017-08-06 17:36:50 +02:00
|
|
|
|
('=', "Fullwidth Equals Sign", '='),
|
|
|
|
|
|
2015-11-15 02:37:49 +05:30
|
|
|
|
('›', "Single Right-Pointing Angle Quotation Mark", '>'),
|
|
|
|
|
('❯', "Heavy Right-Pointing Angle Quotation Mark Ornament", '>'),
|
|
|
|
|
('˃', "Modifier Letter Right Arrowhead", '>'),
|
2017-08-06 17:36:50 +02:00
|
|
|
|
('𝈷', "Greek Instrumental Symbol-42", '>'),
|
|
|
|
|
('ᐳ', "Canadian Syllabics Po", '>'),
|
|
|
|
|
('𖼿', "Miao Letter Archaic Zza", '>'),
|
|
|
|
|
('❭', "Medium Right-Pointing Angle Bracket Ornament", '>'),
|
|
|
|
|
('⟩', "Mathematical Right Angle Bracket", '>'),
|
|
|
|
|
('〉', "Right-Pointing Angle Bracket", '>'),
|
2016-04-21 17:51:47 +08:00
|
|
|
|
('〉', "Right Angle Bracket", '>'),
|
|
|
|
|
('》', "Right Double Angle Bracket", '>'),
|
2019-07-02 11:06:01 +03:00
|
|
|
|
('>', "Fullwidth Greater-Than Sign", '>'),
|
|
|
|
|
];
|
2015-11-15 02:37:49 +05:30
|
|
|
|
|
2019-07-25 11:22:46 -07:00
|
|
|
|
// 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.
|
2019-07-24 16:10:42 -07:00
|
|
|
|
const ASCII_ARRAY: &[(char, &str, Option<token::TokenKind>)] = &[
|
2020-09-01 11:24:52 +02:00
|
|
|
|
(' ', "Space", None),
|
2019-07-25 11:22:46 -07:00
|
|
|
|
('_', "Underscore", Some(token::Ident(kw::Underscore, false))),
|
2019-07-24 16:10:42 -07:00
|
|
|
|
('-', "Minus/Hyphen", Some(token::BinOp(token::Minus))),
|
|
|
|
|
(',', "Comma", Some(token::Comma)),
|
|
|
|
|
(';', "Semicolon", Some(token::Semi)),
|
|
|
|
|
(':', "Colon", Some(token::Colon)),
|
|
|
|
|
('!', "Exclamation Mark", Some(token::Not)),
|
|
|
|
|
('?', "Question Mark", Some(token::Question)),
|
|
|
|
|
('.', "Period", Some(token::Dot)),
|
2022-04-26 15:40:14 +03:00
|
|
|
|
('(', "Left Parenthesis", Some(token::OpenDelim(Delimiter::Parenthesis))),
|
|
|
|
|
(')', "Right Parenthesis", Some(token::CloseDelim(Delimiter::Parenthesis))),
|
|
|
|
|
('[', "Left Square Bracket", Some(token::OpenDelim(Delimiter::Bracket))),
|
|
|
|
|
(']', "Right Square Bracket", Some(token::CloseDelim(Delimiter::Bracket))),
|
|
|
|
|
('{', "Left Curly Brace", Some(token::OpenDelim(Delimiter::Brace))),
|
|
|
|
|
('}', "Right Curly Brace", Some(token::CloseDelim(Delimiter::Brace))),
|
2019-07-24 16:10:42 -07:00
|
|
|
|
('*', "Asterisk", Some(token::BinOp(token::Star))),
|
|
|
|
|
('/', "Slash", Some(token::BinOp(token::Slash))),
|
|
|
|
|
('\\', "Backslash", None),
|
|
|
|
|
('&', "Ampersand", Some(token::BinOp(token::And))),
|
|
|
|
|
('+', "Plus Sign", Some(token::BinOp(token::Plus))),
|
|
|
|
|
('<', "Less-Than Sign", Some(token::Lt)),
|
|
|
|
|
('=', "Equals Sign", Some(token::Eq)),
|
|
|
|
|
('>', "Greater-Than Sign", Some(token::Gt)),
|
2019-07-25 11:22:46 -07:00
|
|
|
|
// 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),
|
2019-07-02 11:06:01 +03:00
|
|
|
|
];
|
|
|
|
|
|
2020-09-03 15:37:03 +02:00
|
|
|
|
pub(super) fn check_for_substitution<'a>(
|
2019-07-02 11:06:01 +03:00
|
|
|
|
reader: &StringReader<'a>,
|
2019-05-06 11:53:40 +03:00
|
|
|
|
pos: BytePos,
|
2019-07-02 11:06:01 +03:00
|
|
|
|
ch: char,
|
2022-01-23 20:41:46 +00:00
|
|
|
|
err: &mut Diagnostic,
|
2023-01-07 16:33:05 +00:00
|
|
|
|
count: usize,
|
2019-07-24 16:10:42 -07:00
|
|
|
|
) -> Option<token::TokenKind> {
|
2022-04-27 08:51:33 +01:00
|
|
|
|
let &(_u_char, u_name, ascii_char) = UNICODE_ARRAY.iter().find(|&&(c, _, _)| c == ch)?;
|
2019-07-02 11:06:01 +03:00
|
|
|
|
|
2023-01-07 16:33:05 +00:00
|
|
|
|
let span = Span::with_root_ctxt(pos, pos + Pos::from_usize(ch.len_utf8() * count));
|
2019-07-02 11:06:01 +03:00
|
|
|
|
|
2022-02-19 00:48:49 +01:00
|
|
|
|
let Some((_ascii_char, ascii_name, token)) = ASCII_ARRAY.iter().find(|&&(c, _, _)| c == ascii_char) else {
|
|
|
|
|
let msg = format!("substitution character not found for '{}'", ch);
|
|
|
|
|
reader.sess.span_diagnostic.span_bug_no_panic(span, &msg);
|
|
|
|
|
return None;
|
2019-07-02 11:06:01 +03:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// special help suggestion for "directed" double quotes
|
2019-05-06 11:53:40 +03:00
|
|
|
|
if let Some(s) = peek_delimited(&reader.src[reader.src_index(pos)..], '“', '”') {
|
2019-07-02 11:06:01 +03:00
|
|
|
|
let msg = format!(
|
|
|
|
|
"Unicode characters '“' (Left Double Quotation Mark) and \
|
|
|
|
|
'”' (Right Double Quotation Mark) look like '{}' ({}), but are not",
|
|
|
|
|
ascii_char, ascii_name
|
|
|
|
|
);
|
|
|
|
|
err.span_suggestion(
|
2019-08-11 01:44:55 +03:00
|
|
|
|
Span::with_root_ctxt(
|
2019-05-06 11:53:40 +03:00
|
|
|
|
pos,
|
|
|
|
|
pos + Pos::from_usize('“'.len_utf8() + s.len() + '”'.len_utf8()),
|
2019-07-02 11:06:01 +03:00
|
|
|
|
),
|
|
|
|
|
&msg,
|
|
|
|
|
format!("\"{}\"", s),
|
|
|
|
|
Applicability::MaybeIncorrect,
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
let msg = format!(
|
|
|
|
|
"Unicode character '{}' ({}) looks like '{}' ({}), but it is not",
|
|
|
|
|
ch, u_name, ascii_char, ascii_name
|
|
|
|
|
);
|
2023-01-07 16:33:05 +00:00
|
|
|
|
err.span_suggestion(
|
|
|
|
|
span,
|
|
|
|
|
&msg,
|
|
|
|
|
ascii_char.to_string().repeat(count),
|
|
|
|
|
Applicability::MaybeIncorrect,
|
|
|
|
|
);
|
2019-07-02 11:06:01 +03:00
|
|
|
|
}
|
2019-07-24 16:10:42 -07:00
|
|
|
|
token.clone()
|
2019-07-02 11:06:01 +03:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-06 11:53:40 +03:00
|
|
|
|
/// Extract string if found at current position with given delimiters
|
|
|
|
|
fn peek_delimited(text: &str, from_ch: char, to_ch: char) -> Option<&str> {
|
|
|
|
|
let mut chars = text.chars();
|
|
|
|
|
let first_char = chars.next()?;
|
|
|
|
|
if first_char != from_ch {
|
|
|
|
|
return None;
|
2019-07-02 11:06:01 +03:00
|
|
|
|
}
|
2019-05-06 11:53:40 +03:00
|
|
|
|
let last_char_idx = chars.as_str().find(to_ch)?;
|
|
|
|
|
Some(&chars.as_str()[..last_char_idx])
|
2015-11-15 02:37:49 +05:30
|
|
|
|
}
|