diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2020-02-22 16:22:38 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2020-02-22 17:28:10 +0300 |
| commit | 4356d18e4ab262a6703fa3a901c7cf00e9d27cc7 (patch) | |
| tree | e604b17252d82279f31436f2962c68ae3b17454b /src/libsyntax | |
| parent | 03d2f5cd6c634b1fdcd26b036009aa4dce37fdfc (diff) | |
| download | rust-4356d18e4ab262a6703fa3a901c7cf00e9d27cc7.tar.gz rust-4356d18e4ab262a6703fa3a901c7cf00e9d27cc7.zip | |
parser: Cleanup `Parser::bump_with` and its uses
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/token.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/libsyntax/token.rs b/src/libsyntax/token.rs index 862934300e0..6eeee498815 100644 --- a/src/libsyntax/token.rs +++ b/src/libsyntax/token.rs @@ -270,6 +270,39 @@ impl TokenKind { Literal(Lit::new(kind, symbol, suffix)) } + // An approximation to proc-macro-style single-character operators used by rustc parser. + // If the operator token can be broken into two tokens, the first of which is single-character, + // then this function performs that operation, otherwise it returns `None`. + pub fn break_two_token_op(&self) -> Option<(TokenKind, TokenKind)> { + Some(match *self { + Le => (Lt, Eq), + EqEq => (Eq, Eq), + Ne => (Not, Eq), + Ge => (Gt, Eq), + AndAnd => (BinOp(And), BinOp(And)), + OrOr => (BinOp(Or), BinOp(Or)), + BinOp(Shl) => (Lt, Lt), + BinOp(Shr) => (Gt, Gt), + BinOpEq(Plus) => (BinOp(Plus), Eq), + BinOpEq(Minus) => (BinOp(Minus), Eq), + BinOpEq(Star) => (BinOp(Star), Eq), + BinOpEq(Slash) => (BinOp(Slash), Eq), + BinOpEq(Percent) => (BinOp(Percent), Eq), + BinOpEq(Caret) => (BinOp(Caret), Eq), + BinOpEq(And) => (BinOp(And), Eq), + BinOpEq(Or) => (BinOp(Or), Eq), + BinOpEq(Shl) => (Lt, Le), + BinOpEq(Shr) => (Gt, Ge), + DotDot => (Dot, Dot), + DotDotDot => (Dot, DotDot), + ModSep => (Colon, Colon), + RArrow => (BinOp(Minus), Gt), + LArrow => (Lt, BinOp(Minus)), + FatArrow => (Eq, Gt), + _ => return None, + }) + } + /// Returns tokens that are likely to be typed accidentally instead of the current token. /// Enables better error recovery when the wrong token is found. pub fn similar_tokens(&self) -> Option<Vec<TokenKind>> { |
