@@ -39,6 +39,20 @@ pub enum BinOpToken {
3939 Shr ,
4040}
4141
42+ #[ derive( Copy , Clone , Debug , PartialEq , Eq , Encodable , Decodable , Hash , HashStable_Generic ) ]
43+ pub enum InvisibleOrigin {
44+ // From the expansion of a metavariable in a declarative macro.
45+ MetaVar ( NonterminalKind ) ,
46+
47+ // Converted from `proc_macro::Delimiter` in
48+ // `proc_macro::Delimiter::to_internal`, i.e. returned by a proc macro.
49+ ProcMacro ,
50+
51+ // Converted from `TokenKind::Interpolated` in
52+ // `TokenStream::flatten_token`. Treated similarly to `ProcMacro`.
53+ FlattenToken ,
54+ }
55+
4256/// Describes how a sequence of token trees is delimited.
4357/// Cannot use `proc_macro::Delimiter` directly because this
4458/// structure should implement some additional traits.
@@ -56,7 +70,22 @@ pub enum Delimiter {
5670 /// "macro variable" `$var`. It is important to preserve operator priorities in cases like
5771 /// `$var * 3` where `$var` is `1 + 2`.
5872 /// Invisible delimiters might not survive roundtrip of a token stream through a string.
59- Invisible ,
73+ Invisible ( InvisibleOrigin ) ,
74+ }
75+
76+ impl Delimiter {
77+ // Should the parser skip these delimiters? Only happens for certain kinds
78+ // of invisible delimiters. Ideally this function will eventually disappear
79+ // and no invisible delimiters will be skipped.
80+ #[ inline]
81+ pub fn skip ( & self ) -> bool {
82+ use InvisibleOrigin :: * ;
83+ match self {
84+ Delimiter :: Parenthesis | Delimiter :: Bracket | Delimiter :: Brace => false ,
85+ Delimiter :: Invisible ( MetaVar ( _) ) => false ,
86+ Delimiter :: Invisible ( FlattenToken | ProcMacro ) => true ,
87+ }
88+ }
6089}
6190
6291// Note that the suffix is *not* considered when deciding the `LitKind` in this
@@ -869,7 +898,7 @@ pub enum Nonterminal {
869898 NtVis ( P < ast:: Visibility > ) ,
870899}
871900
872- #[ derive( Debug , Copy , Clone , PartialEq , Encodable , Decodable ) ]
901+ #[ derive( Debug , Copy , Clone , PartialEq , Eq , Encodable , Decodable , Hash , HashStable_Generic ) ]
873902pub enum NonterminalKind {
874903 Item ,
875904 Block ,
0 commit comments