rustc_ast: Harmonize delimiter naming with proc_macro::Delimiter
This commit is contained in:
parent
0e7915d11f
commit
2733ec1be3
41 changed files with 433 additions and 426 deletions
|
@ -1,5 +1,4 @@
|
|||
pub use BinOpToken::*;
|
||||
pub use DelimToken::*;
|
||||
pub use LitKind::*;
|
||||
pub use Nonterminal::*;
|
||||
pub use TokenKind::*;
|
||||
|
@ -37,18 +36,26 @@ pub enum BinOpToken {
|
|||
Shr,
|
||||
}
|
||||
|
||||
/// A delimiter token.
|
||||
#[derive(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Debug, Copy)]
|
||||
#[derive(HashStable_Generic)]
|
||||
pub enum DelimToken {
|
||||
/// A round parenthesis (i.e., `(` or `)`).
|
||||
Paren,
|
||||
/// A square bracket (i.e., `[` or `]`).
|
||||
Bracket,
|
||||
/// A curly brace (i.e., `{` or `}`).
|
||||
/// Describes how a sequence of token trees is delimited.
|
||||
/// Cannot use `proc_macro::Delimiter` directly because this
|
||||
/// structure should implement some additional traits.
|
||||
/// The `None` variant is also renamed to `Invisible` to be
|
||||
/// less confusing and better convey the semantics.
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
#[derive(Encodable, Decodable, Hash, HashStable_Generic)]
|
||||
pub enum Delimiter {
|
||||
/// `( ... )`
|
||||
Parenthesis,
|
||||
/// `{ ... }`
|
||||
Brace,
|
||||
/// An empty delimiter.
|
||||
NoDelim,
|
||||
/// `[ ... ]`
|
||||
Bracket,
|
||||
/// `Ø ... Ø`
|
||||
/// An invisible delimiter, that may, for example, appear around tokens coming from a
|
||||
/// "macro variable" `$var`. It is important to preserve operator priorities in cases like
|
||||
/// `$var * 3` where `$var` is `1 + 2`.
|
||||
/// Invisible delimiters might not survive roundtrip of a token stream through a string.
|
||||
Invisible,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
|
||||
|
@ -212,9 +219,9 @@ pub enum TokenKind {
|
|||
/// Used by proc macros for representing lifetimes, not generated by lexer right now.
|
||||
SingleQuote,
|
||||
/// An opening delimiter (e.g., `{`).
|
||||
OpenDelim(DelimToken),
|
||||
OpenDelim(Delimiter),
|
||||
/// A closing delimiter (e.g., `}`).
|
||||
CloseDelim(DelimToken),
|
||||
CloseDelim(Delimiter),
|
||||
|
||||
/* Literals */
|
||||
Literal(Lit),
|
||||
|
@ -387,8 +394,8 @@ impl Token {
|
|||
match self.uninterpolate().kind {
|
||||
Ident(name, is_raw) =>
|
||||
ident_can_begin_type(name, self.span, is_raw), // type name or keyword
|
||||
OpenDelim(Paren) | // tuple
|
||||
OpenDelim(Bracket) | // array
|
||||
OpenDelim(Delimiter::Parenthesis) | // tuple
|
||||
OpenDelim(Delimiter::Bracket) | // array
|
||||
Not | // never
|
||||
BinOp(Star) | // raw pointer
|
||||
BinOp(And) | // reference
|
||||
|
@ -405,7 +412,7 @@ impl Token {
|
|||
/// Returns `true` if the token can appear at the start of a const param.
|
||||
pub fn can_begin_const_arg(&self) -> bool {
|
||||
match self.kind {
|
||||
OpenDelim(Brace) => true,
|
||||
OpenDelim(Delimiter::Brace) => true,
|
||||
Interpolated(ref nt) => matches!(**nt, NtExpr(..) | NtBlock(..) | NtLiteral(..)),
|
||||
_ => self.can_begin_literal_maybe_minus(),
|
||||
}
|
||||
|
@ -417,7 +424,7 @@ impl Token {
|
|||
|| self.is_lifetime()
|
||||
|| self.is_keyword(kw::For)
|
||||
|| self == &Question
|
||||
|| self == &OpenDelim(Paren)
|
||||
|| self == &OpenDelim(Delimiter::Parenthesis)
|
||||
}
|
||||
|
||||
/// Returns `true` if the token is any literal.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue