@@ -62,26 +62,6 @@ pub enum InvisibleSource {
62
62
// Converted from `proc_macro::Delimiter` in
63
63
// `proc_macro::Delimiter::to_internal`, i.e. returned by a proc macro.
64
64
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
- }
85
65
}
86
66
87
67
// Note that the suffix is *not* considered when deciding the `LitKind` in this
@@ -136,21 +116,8 @@ impl Lit {
136
116
match token. uninterpolate ( ) . kind {
137
117
Ident ( name, false ) if name. is_bool_lit ( ) => Some ( Lit :: new ( Bool , name, None ) ) ,
138
118
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:?}" ) ;
154
121
}
155
122
_ => None ,
156
123
}
@@ -415,8 +382,8 @@ impl Token {
415
382
match self . kind {
416
383
InterpolatedIdent ( _, _, uninterpolated_span)
417
384
| 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 :?}" ) ;
420
387
}
421
388
_ => self . span ,
422
389
}
@@ -473,8 +440,8 @@ impl Token {
473
440
NonterminalKind :: Expr |
474
441
NonterminalKind :: Literal |
475
442
NonterminalKind :: Path
476
- ) ) )
477
- => true ,
443
+ ) ) ) |
444
+ OpenDelim ( Delimiter :: Invisible ( InvisibleSource :: ProcMacro ) ) => true ,
478
445
_ => false ,
479
446
}
480
447
}
@@ -501,7 +468,8 @@ impl Token {
501
468
NonterminalKind :: PatWithOr |
502
469
NonterminalKind :: Path |
503
470
NonterminalKind :: Literal
504
- ) ) ) => true ,
471
+ ) ) ) |
472
+ OpenDelim ( Delimiter :: Invisible ( InvisibleSource :: ProcMacro ) ) => true ,
505
473
_ => false ,
506
474
}
507
475
}
@@ -524,7 +492,8 @@ impl Token {
524
492
OpenDelim ( Delimiter :: Invisible ( InvisibleSource :: MetaVar (
525
493
NonterminalKind :: Ty |
526
494
NonterminalKind :: Path
527
- ) ) ) => true ,
495
+ ) ) ) |
496
+ OpenDelim ( Delimiter :: Invisible ( InvisibleSource :: ProcMacro ) ) => true ,
528
497
_ => false ,
529
498
}
530
499
}
@@ -536,6 +505,7 @@ impl Token {
536
505
OpenDelim ( Delimiter :: Invisible ( InvisibleSource :: MetaVar (
537
506
NonterminalKind :: Block | NonterminalKind :: Expr | NonterminalKind :: Literal ,
538
507
) ) ) => true ,
508
+ OpenDelim ( Delimiter :: Invisible ( InvisibleSource :: ProcMacro ) ) => true ,
539
509
_ => self . can_begin_literal_maybe_minus ( ) ,
540
510
}
541
511
}
@@ -592,7 +562,8 @@ impl Token {
592
562
Ident ( name, false ) if name. is_bool_lit ( ) => true ,
593
563
OpenDelim ( Delimiter :: Invisible ( InvisibleSource :: MetaVar (
594
564
NonterminalKind :: Literal | NonterminalKind :: Expr ,
595
- ) ) ) => true ,
565
+ ) ) )
566
+ | OpenDelim ( Delimiter :: Invisible ( InvisibleSource :: ProcMacro ) ) => true ,
596
567
_ => false ,
597
568
}
598
569
}
@@ -658,6 +629,7 @@ impl Token {
658
629
/// Would `maybe_reparse_metavar_expr` in `parser.rs` return `Ok(..)`?
659
630
/// That is, is this a pre-parsed expression dropped into the token stream
660
631
/// (which happens while parsing the result of macro expansion)?
632
+ // njn: proc macro?
661
633
pub fn is_metavar_expr ( & self ) -> bool {
662
634
matches ! (
663
635
self . is_metavar_seq( ) ,
@@ -672,6 +644,7 @@ impl Token {
672
644
673
645
/// Are we at a block from a metavar (`$b:block`)?
674
646
pub fn is_metavar_block ( & self ) -> bool {
647
+ // njn: handle proc-macro here too?
675
648
matches ! ( self . is_metavar_seq( ) , Some ( NonterminalKind :: Block ) )
676
649
}
677
650
@@ -687,6 +660,7 @@ impl Token {
687
660
pub fn is_path_start ( & self ) -> bool {
688
661
self == & ModSep
689
662
|| self . is_qpath_start ( )
663
+ // njn: proc macro?
690
664
|| matches ! ( self . is_metavar_seq( ) , Some ( NonterminalKind :: Path ) )
691
665
|| self . is_path_segment_keyword ( )
692
666
|| self . is_ident ( ) && !self . is_reserved_ident ( )
@@ -760,6 +734,13 @@ impl Token {
760
734
}
761
735
}
762
736
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
+
763
744
pub fn glue ( & self , joint : & Token ) -> Option < Token > {
764
745
let kind = match self . kind {
765
746
Eq => match joint. kind {
0 commit comments