82
82
83
83
pub use self :: NamedMatch :: * ;
84
84
pub use self :: ParseResult :: * ;
85
- use self :: TokenTreeOrTokenTreeVec :: * ;
85
+ use self :: TokenTreeOrTokenTreeSlice :: * ;
86
86
87
87
use ast:: Ident ;
88
88
use syntax_pos:: { self , BytePos , Span } ;
@@ -106,12 +106,12 @@ use std::collections::hash_map::Entry::{Occupied, Vacant};
106
106
/// Either a sequence of token trees or a single one. This is used as the representation of the
107
107
/// sequence of tokens that make up a matcher.
108
108
#[ derive( Clone ) ]
109
- enum TokenTreeOrTokenTreeVec {
109
+ enum TokenTreeOrTokenTreeSlice < ' a > {
110
110
Tt ( TokenTree ) ,
111
- TtSeq ( Vec < TokenTree > ) ,
111
+ TtSeq ( & ' a [ TokenTree ] ) ,
112
112
}
113
113
114
- impl TokenTreeOrTokenTreeVec {
114
+ impl < ' a > TokenTreeOrTokenTreeSlice < ' a > {
115
115
/// Returns the number of constituent top-level token trees of `self` (top-level in that it
116
116
/// will not recursively descend into subtrees).
117
117
fn len ( & self ) -> usize {
@@ -135,19 +135,19 @@ impl TokenTreeOrTokenTreeVec {
135
135
/// This is used by `inner_parse_loop` to keep track of delimited submatchers that we have
136
136
/// descended into.
137
137
#[ derive( Clone ) ]
138
- struct MatcherTtFrame {
138
+ struct MatcherTtFrame < ' a > {
139
139
/// The "parent" matcher that we are descending into.
140
- elts : TokenTreeOrTokenTreeVec ,
140
+ elts : TokenTreeOrTokenTreeSlice < ' a > ,
141
141
/// The position of the "dot" in `elts` at the time we descended.
142
142
idx : usize ,
143
143
}
144
144
145
145
/// Represents a single "position" (aka "matcher position", aka "item"), as described in the module
146
146
/// documentation.
147
147
#[ derive( Clone ) ]
148
- struct MatcherPos {
148
+ struct MatcherPos < ' a > {
149
149
/// The token or sequence of tokens that make up the matcher
150
- top_elts : TokenTreeOrTokenTreeVec ,
150
+ top_elts : TokenTreeOrTokenTreeSlice < ' a > ,
151
151
/// The position of the "dot" in this matcher
152
152
idx : usize ,
153
153
/// The beginning position in the source that the beginning of this matcher corresponds to. In
@@ -186,7 +186,7 @@ struct MatcherPos {
186
186
sep : Option < Token > ,
187
187
/// The "parent" matcher position if we are in a repetition. That is, the matcher position just
188
188
/// before we enter the sequence.
189
- up : Option < Box < MatcherPos > > ,
189
+ up : Option < Box < MatcherPos < ' a > > > ,
190
190
191
191
// Specifically used to "unzip" token trees. By "unzip", we mean to unwrap the delimiters from
192
192
// a delimited token tree (e.g. something wrapped in `(` `)`) or to get the contents of a doc
@@ -195,10 +195,10 @@ struct MatcherPos {
195
195
/// pat ) pat`), we need to keep track of the matchers we are descending into. This stack does
196
196
/// that where the bottom of the stack is the outermost matcher.
197
197
// Also, throughout the comments, this "descent" is often referred to as "unzipping"...
198
- stack : Vec < MatcherTtFrame > ,
198
+ stack : Vec < MatcherTtFrame < ' a > > ,
199
199
}
200
200
201
- impl MatcherPos {
201
+ impl < ' a > MatcherPos < ' a > {
202
202
/// Add `m` as a named match for the `idx`-th metavar.
203
203
fn push_match ( & mut self , idx : usize , m : NamedMatch ) {
204
204
let matches = Rc :: make_mut ( & mut self . matches [ idx] ) ;
@@ -241,8 +241,8 @@ fn create_matches(len: usize) -> Vec<Rc<Vec<NamedMatch>>> {
241
241
242
242
/// Generate the top-level matcher position in which the "dot" is before the first token of the
243
243
/// matcher `ms` and we are going to start matching at position `lo` in the source.
244
- fn initial_matcher_pos ( ms : Vec < TokenTree > , lo : BytePos ) -> Box < MatcherPos > {
245
- let match_idx_hi = count_names ( & ms [ .. ] ) ;
244
+ fn initial_matcher_pos ( ms : & [ TokenTree ] , lo : BytePos ) -> Box < MatcherPos > {
245
+ let match_idx_hi = count_names ( ms ) ;
246
246
let matches = create_matches ( match_idx_hi) ;
247
247
Box :: new ( MatcherPos {
248
248
// Start with the top level matcher given to us
@@ -394,12 +394,12 @@ fn token_name_eq(t1: &Token, t2: &Token) -> bool {
394
394
/// # Returns
395
395
///
396
396
/// A `ParseResult`. Note that matches are kept track of through the items generated.
397
- fn inner_parse_loop (
397
+ fn inner_parse_loop < ' a > (
398
398
sess : & ParseSess ,
399
- cur_items : & mut SmallVector < Box < MatcherPos > > ,
400
- next_items : & mut Vec < Box < MatcherPos > > ,
401
- eof_items : & mut SmallVector < Box < MatcherPos > > ,
402
- bb_items : & mut SmallVector < Box < MatcherPos > > ,
399
+ cur_items : & mut SmallVector < Box < MatcherPos < ' a > > > ,
400
+ next_items : & mut Vec < Box < MatcherPos < ' a > > > ,
401
+ eof_items : & mut SmallVector < Box < MatcherPos < ' a > > > ,
402
+ bb_items : & mut SmallVector < Box < MatcherPos < ' a > > > ,
403
403
token : & Token ,
404
404
span : syntax_pos:: Span ,
405
405
) -> ParseResult < ( ) > {
@@ -596,7 +596,7 @@ pub fn parse(
596
596
// processes all of these possible matcher positions and produces posible next positions into
597
597
// `next_items`. After some post-processing, the contents of `next_items` replenish `cur_items`
598
598
// and we start over again.
599
- let mut cur_items = SmallVector :: one ( initial_matcher_pos ( ms. to_owned ( ) , parser. span . lo ( ) ) ) ;
599
+ let mut cur_items = SmallVector :: one ( initial_matcher_pos ( ms, parser. span . lo ( ) ) ) ;
600
600
let mut next_items = Vec :: new ( ) ;
601
601
602
602
loop {
0 commit comments