@@ -62,26 +62,6 @@ pub enum InvisibleSource {
6262 // Converted from `proc_macro::Delimiter` in
6363 // `proc_macro::Delimiter::to_internal`, i.e. returned by a proc macro.
6464 ProcMacro ,
65-
66- // Converted from `TokenKind::Interpolated` in
67- // `TokenStream::flatten_token`. Treated similarly to `ProcMacro`.
68- FlattenToken ,
69- }
70-
71- impl Delimiter {
72- // Should the parser skip these delimiters? Only happens for certain kinds
73- // of invisible delimiters. Once all interpolated nonterminals are removed,
74- // the answer should become `false` for all kinds, whereupon this function
75- // can be removed.
76- pub fn skip ( & self ) -> bool {
77- match self {
78- Delimiter :: Invisible ( src) => match src {
79- InvisibleSource :: FlattenToken | InvisibleSource :: ProcMacro => true ,
80- InvisibleSource :: MetaVar ( _) => false ,
81- } ,
82- Delimiter :: Parenthesis | Delimiter :: Bracket | Delimiter :: Brace => false ,
83- }
84- }
8565}
8666
8767// Note that the suffix is *not* considered when deciding the `LitKind` in this
@@ -136,21 +116,8 @@ impl Lit {
136116 match token. uninterpolate ( ) . kind {
137117 Ident ( name, false ) if name. is_bool_lit ( ) => Some ( Lit :: new ( Bool , name, None ) ) ,
138118 Literal ( token_lit) => Some ( token_lit) ,
139- OpenDelim ( Delimiter :: Invisible ( InvisibleSource :: MetaVar ( NonterminalKind :: Literal ) ) ) => {
140- panic ! ( "njn: FROM_TOKEN (1)" ) ;
141- // if let NtExpr(expr) | NtLiteral(expr) = &**nt
142- // && let ast::ExprKind::Lit(token_lit) = expr.kind =>
143- // {
144- // Some(token_lit)
145- // }
146- }
147- OpenDelim ( Delimiter :: Invisible ( InvisibleSource :: MetaVar ( NonterminalKind :: Expr ) ) ) => {
148- panic ! ( "njn: FROM_TOKEN (2)" ) ;
149- // if let NtExpr(expr) | NtLiteral(expr) = &**nt
150- // && let ast::ExprKind::Lit(token_lit) = expr.kind =>
151- // {
152- // Some(token_lit)
153- // }
119+ OpenDelim ( Delimiter :: Invisible ( source) ) => {
120+ panic ! ( "njn: from_token {source:?}" ) ;
154121 }
155122 _ => None ,
156123 }
@@ -415,8 +382,8 @@ impl Token {
415382 match self . kind {
416383 InterpolatedIdent ( _, _, uninterpolated_span)
417384 | InterpolatedLifetime ( _, uninterpolated_span) => uninterpolated_span,
418- OpenDelim ( Delimiter :: Invisible ( InvisibleSource :: MetaVar ( kind ) ) ) => {
419- panic ! ( "njn: uninterpolated_span {kind :?}" ) ;
385+ OpenDelim ( Delimiter :: Invisible ( source ) ) => {
386+ panic ! ( "njn: uninterpolated_span {source :?}" ) ;
420387 }
421388 _ => self . span ,
422389 }
@@ -473,8 +440,8 @@ impl Token {
473440 NonterminalKind :: Expr |
474441 NonterminalKind :: Literal |
475442 NonterminalKind :: Path
476- ) ) )
477- => true ,
443+ ) ) ) |
444+ OpenDelim ( Delimiter :: Invisible ( InvisibleSource :: ProcMacro ) ) => true ,
478445 _ => false ,
479446 }
480447 }
@@ -501,7 +468,8 @@ impl Token {
501468 NonterminalKind :: PatWithOr |
502469 NonterminalKind :: Path |
503470 NonterminalKind :: Literal
504- ) ) ) => true ,
471+ ) ) ) |
472+ OpenDelim ( Delimiter :: Invisible ( InvisibleSource :: ProcMacro ) ) => true ,
505473 _ => false ,
506474 }
507475 }
@@ -524,7 +492,8 @@ impl Token {
524492 OpenDelim ( Delimiter :: Invisible ( InvisibleSource :: MetaVar (
525493 NonterminalKind :: Ty |
526494 NonterminalKind :: Path
527- ) ) ) => true ,
495+ ) ) ) |
496+ OpenDelim ( Delimiter :: Invisible ( InvisibleSource :: ProcMacro ) ) => true ,
528497 _ => false ,
529498 }
530499 }
@@ -536,6 +505,7 @@ impl Token {
536505 OpenDelim ( Delimiter :: Invisible ( InvisibleSource :: MetaVar (
537506 NonterminalKind :: Block | NonterminalKind :: Expr | NonterminalKind :: Literal ,
538507 ) ) ) => true ,
508+ OpenDelim ( Delimiter :: Invisible ( InvisibleSource :: ProcMacro ) ) => true ,
539509 _ => self . can_begin_literal_maybe_minus ( ) ,
540510 }
541511 }
@@ -592,7 +562,8 @@ impl Token {
592562 Ident ( name, false ) if name. is_bool_lit ( ) => true ,
593563 OpenDelim ( Delimiter :: Invisible ( InvisibleSource :: MetaVar (
594564 NonterminalKind :: Literal | NonterminalKind :: Expr ,
595- ) ) ) => true ,
565+ ) ) )
566+ | OpenDelim ( Delimiter :: Invisible ( InvisibleSource :: ProcMacro ) ) => true ,
596567 _ => false ,
597568 }
598569 }
@@ -658,6 +629,7 @@ impl Token {
658629 /// Would `maybe_reparse_metavar_expr` in `parser.rs` return `Ok(..)`?
659630 /// That is, is this a pre-parsed expression dropped into the token stream
660631 /// (which happens while parsing the result of macro expansion)?
632+ // njn: proc macro?
661633 pub fn is_metavar_expr ( & self ) -> bool {
662634 matches ! (
663635 self . is_metavar_seq( ) ,
@@ -672,6 +644,7 @@ impl Token {
672644
673645 /// Are we at a block from a metavar (`$b:block`)?
674646 pub fn is_metavar_block ( & self ) -> bool {
647+ // njn: handle proc-macro here too?
675648 matches ! ( self . is_metavar_seq( ) , Some ( NonterminalKind :: Block ) )
676649 }
677650
@@ -687,6 +660,7 @@ impl Token {
687660 pub fn is_path_start ( & self ) -> bool {
688661 self == & ModSep
689662 || self . is_qpath_start ( )
663+ // njn: proc macro?
690664 || matches ! ( self . is_metavar_seq( ) , Some ( NonterminalKind :: Path ) )
691665 || self . is_path_segment_keyword ( )
692666 || self . is_ident ( ) && !self . is_reserved_ident ( )
@@ -760,6 +734,13 @@ impl Token {
760734 }
761735 }
762736
737+ /// Is this an invisible open delimiter at the start of a token sequence
738+ /// from a proc macro?
739+ // njn: need to use this more
740+ pub fn is_proc_macro_seq ( & self ) -> bool {
741+ matches ! ( self . kind, OpenDelim ( Delimiter :: Invisible ( InvisibleSource :: ProcMacro ) ) )
742+ }
743+
763744 pub fn glue ( & self , joint : & Token ) -> Option < Token > {
764745 let kind = match self . kind {
765746 Eq => match joint. kind {
0 commit comments