use std::borrow::Cow;
use std::{fmt, mem};
-#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
+#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
+pub enum CommentKind {
+ Line,
+ Block,
+}
+
+#[derive(Clone, PartialEq, Encodable, Decodable, Hash, Debug, Copy)]
#[derive(HashStable_Generic)]
pub enum BinOpToken {
Plus,
}
/// A delimiter token.
-#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
+#[derive(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Debug, Copy)]
#[derive(HashStable_Generic)]
pub enum DelimToken {
/// A round parenthesis (i.e., `(` or `)`).
}
}
-#[derive(Clone, Copy, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
+#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
pub enum LitKind {
Bool, // AST only, must never appear in a `Token`
Byte,
}
/// A literal token.
-#[derive(Clone, Copy, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
+#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
pub struct Lit {
pub kind: LitKind,
pub symbol: Symbol,
.contains(&name)
}
-#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
+#[derive(Clone, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
pub enum TokenKind {
/* Expression-operator symbols. */
Eq,
Interpolated(Lrc<Nonterminal>),
- // Can be expanded into several tokens.
- /// A doc comment.
- DocComment(Symbol),
+ /// A doc comment token.
+ /// `Symbol` is the doc comment's data excluding its "quotes" (`///`, `/**`, etc)
+ /// similarly to symbols in string literal tokens.
+ DocComment(CommentKind, ast::AttrStyle, Symbol),
// Junk. These carry no data because we don't really care about the data
// they *would* carry, and don't really want to allocate a new ident for
#[cfg(target_arch = "x86_64")]
rustc_data_structures::static_assert_size!(TokenKind, 16);
-#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
+#[derive(Clone, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
pub struct Token {
pub kind: TokenKind,
pub span: Span,
}
}
-#[derive(Clone, RustcEncodable, RustcDecodable)]
+#[derive(Clone, Encodable, Decodable)]
/// For interpolation during macro expansion.
pub enum Nonterminal {
NtItem(P<ast::Item>),
#[cfg(target_arch = "x86_64")]
rustc_data_structures::static_assert_size!(Nonterminal, 40);
+#[derive(Debug, Copy, Clone, PartialEq, Encodable, Decodable)]
+pub enum NonterminalKind {
+ Item,
+ Block,
+ Stmt,
+ Pat,
+ Expr,
+ Ty,
+ Ident,
+ Lifetime,
+ Literal,
+ Meta,
+ Path,
+ Vis,
+ TT,
+}
+
+impl NonterminalKind {
+ pub fn from_symbol(symbol: Symbol) -> Option<NonterminalKind> {
+ Some(match symbol {
+ sym::item => NonterminalKind::Item,
+ sym::block => NonterminalKind::Block,
+ sym::stmt => NonterminalKind::Stmt,
+ sym::pat => NonterminalKind::Pat,
+ sym::expr => NonterminalKind::Expr,
+ sym::ty => NonterminalKind::Ty,
+ sym::ident => NonterminalKind::Ident,
+ sym::lifetime => NonterminalKind::Lifetime,
+ sym::literal => NonterminalKind::Literal,
+ sym::meta => NonterminalKind::Meta,
+ sym::path => NonterminalKind::Path,
+ sym::vis => NonterminalKind::Vis,
+ sym::tt => NonterminalKind::TT,
+ _ => return None,
+ })
+ }
+ fn symbol(self) -> Symbol {
+ match self {
+ NonterminalKind::Item => sym::item,
+ NonterminalKind::Block => sym::block,
+ NonterminalKind::Stmt => sym::stmt,
+ NonterminalKind::Pat => sym::pat,
+ NonterminalKind::Expr => sym::expr,
+ NonterminalKind::Ty => sym::ty,
+ NonterminalKind::Ident => sym::ident,
+ NonterminalKind::Lifetime => sym::lifetime,
+ NonterminalKind::Literal => sym::literal,
+ NonterminalKind::Meta => sym::meta,
+ NonterminalKind::Path => sym::path,
+ NonterminalKind::Vis => sym::vis,
+ NonterminalKind::TT => sym::tt,
+ }
+ }
+}
+
+impl fmt::Display for NonterminalKind {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ write!(f, "{}", self.symbol())
+ }
+}
+
impl Nonterminal {
fn span(&self) -> Span {
match self {