|
1 | 1 | use std::borrow::Cow;
|
2 | 2 | use std::fmt;
|
3 | 3 |
|
| 4 | +pub use BinOpToken::*; |
| 5 | +pub use LitKind::*; |
| 6 | +pub use Nonterminal::*; |
| 7 | +pub use NtExprKind::*; |
| 8 | +pub use NtPatKind::*; |
| 9 | +pub use TokenKind::*; |
4 | 10 | use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
5 | 11 | use rustc_data_structures::sync::Lrc;
|
6 | 12 | use rustc_macros::{Decodable, Encodable, HashStable_Generic};
|
7 | 13 | use rustc_span::edition::Edition;
|
8 |
| -use rustc_span::symbol::{kw, sym}; |
9 | 14 | #[allow(clippy::useless_attribute)] // FIXME: following use of `hidden_glob_reexports` incorrectly triggers `useless_attribute` lint.
|
10 | 15 | #[allow(hidden_glob_reexports)]
|
11 | 16 | use rustc_span::symbol::{Ident, Symbol};
|
12 |
| -use rustc_span::{ErrorGuaranteed, Span, DUMMY_SP}; |
13 |
| -pub use BinOpToken::*; |
14 |
| -pub use LitKind::*; |
15 |
| -pub use Nonterminal::*; |
16 |
| -pub use NtExprKind::*; |
17 |
| -pub use NtPatKind::*; |
18 |
| -pub use TokenKind::*; |
| 17 | +use rustc_span::symbol::{kw, sym}; |
| 18 | +use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span}; |
19 | 19 |
|
20 | 20 | use crate::ast;
|
21 | 21 | use crate::ptr::P;
|
@@ -385,35 +385,41 @@ impl TokenKind {
|
385 | 385 | Literal(Lit::new(kind, symbol, suffix))
|
386 | 386 | }
|
387 | 387 |
|
388 |
| - /// An approximation to proc-macro-style single-character operators used by rustc parser. |
389 |
| - /// If the operator token can be broken into two tokens, the first of which is single-character, |
390 |
| - /// then this function performs that operation, otherwise it returns `None`. |
391 |
| - pub fn break_two_token_op(&self) -> Option<(TokenKind, TokenKind)> { |
392 |
| - Some(match *self { |
393 |
| - Le => (Lt, Eq), |
394 |
| - EqEq => (Eq, Eq), |
395 |
| - Ne => (Not, Eq), |
396 |
| - Ge => (Gt, Eq), |
397 |
| - AndAnd => (BinOp(And), BinOp(And)), |
398 |
| - OrOr => (BinOp(Or), BinOp(Or)), |
399 |
| - BinOp(Shl) => (Lt, Lt), |
400 |
| - BinOp(Shr) => (Gt, Gt), |
401 |
| - BinOpEq(Plus) => (BinOp(Plus), Eq), |
402 |
| - BinOpEq(Minus) => (BinOp(Minus), Eq), |
403 |
| - BinOpEq(Star) => (BinOp(Star), Eq), |
404 |
| - BinOpEq(Slash) => (BinOp(Slash), Eq), |
405 |
| - BinOpEq(Percent) => (BinOp(Percent), Eq), |
406 |
| - BinOpEq(Caret) => (BinOp(Caret), Eq), |
407 |
| - BinOpEq(And) => (BinOp(And), Eq), |
408 |
| - BinOpEq(Or) => (BinOp(Or), Eq), |
409 |
| - BinOpEq(Shl) => (Lt, Le), |
410 |
| - BinOpEq(Shr) => (Gt, Ge), |
411 |
| - DotDot => (Dot, Dot), |
412 |
| - DotDotDot => (Dot, DotDot), |
413 |
| - PathSep => (Colon, Colon), |
414 |
| - RArrow => (BinOp(Minus), Gt), |
415 |
| - LArrow => (Lt, BinOp(Minus)), |
416 |
| - FatArrow => (Eq, Gt), |
| 388 | + /// An approximation to proc-macro-style single-character operators used by |
| 389 | + /// rustc parser. If the operator token can be broken into two tokens, the |
| 390 | + /// first of which has `n` (1 or 2) chars, then this function performs that |
| 391 | + /// operation, otherwise it returns `None`. |
| 392 | + pub fn break_two_token_op(&self, n: u32) -> Option<(TokenKind, TokenKind)> { |
| 393 | + assert!(n == 1 || n == 2); |
| 394 | + Some(match (self, n) { |
| 395 | + (Le, 1) => (Lt, Eq), |
| 396 | + (EqEq, 1) => (Eq, Eq), |
| 397 | + (Ne, 1) => (Not, Eq), |
| 398 | + (Ge, 1) => (Gt, Eq), |
| 399 | + (AndAnd, 1) => (BinOp(And), BinOp(And)), |
| 400 | + (OrOr, 1) => (BinOp(Or), BinOp(Or)), |
| 401 | + (BinOp(Shl), 1) => (Lt, Lt), |
| 402 | + (BinOp(Shr), 1) => (Gt, Gt), |
| 403 | + (BinOpEq(Plus), 1) => (BinOp(Plus), Eq), |
| 404 | + (BinOpEq(Minus), 1) => (BinOp(Minus), Eq), |
| 405 | + (BinOpEq(Star), 1) => (BinOp(Star), Eq), |
| 406 | + (BinOpEq(Slash), 1) => (BinOp(Slash), Eq), |
| 407 | + (BinOpEq(Percent), 1) => (BinOp(Percent), Eq), |
| 408 | + (BinOpEq(Caret), 1) => (BinOp(Caret), Eq), |
| 409 | + (BinOpEq(And), 1) => (BinOp(And), Eq), |
| 410 | + (BinOpEq(Or), 1) => (BinOp(Or), Eq), |
| 411 | + (BinOpEq(Shl), 1) => (Lt, Le), // `<` + `<=` |
| 412 | + (BinOpEq(Shl), 2) => (BinOp(Shl), Eq), // `<<` + `=` |
| 413 | + (BinOpEq(Shr), 1) => (Gt, Ge), // `>` + `>=` |
| 414 | + (BinOpEq(Shr), 2) => (BinOp(Shr), Eq), // `>>` + `=` |
| 415 | + (DotDot, 1) => (Dot, Dot), |
| 416 | + (DotDotDot, 1) => (Dot, DotDot), // `.` + `..` |
| 417 | + (DotDotDot, 2) => (DotDot, Dot), // `..` + `.` |
| 418 | + (DotDotEq, 2) => (DotDot, Eq), |
| 419 | + (PathSep, 1) => (Colon, Colon), |
| 420 | + (RArrow, 1) => (BinOp(Minus), Gt), |
| 421 | + (LArrow, 1) => (Lt, BinOp(Minus)), |
| 422 | + (FatArrow, 1) => (Eq, Gt), |
417 | 423 | _ => return None,
|
418 | 424 | })
|
419 | 425 | }
|
|
0 commit comments