// walks forward over `tts` until all potential FIRST tokens are
// identified.
walks forward over `tts` until all potential FIRST tokens are
identified.
walks forward over ` tts ` until all potential FIRST tokens are identified .
fn first(&self, tts: &[TokenTree]) -> TokenSet {
        let mut first = TokenSet::empty();
        for tt in tts.iter() {
            assert!(first.maybe_empty);
            match *tt {
                TokenTree::Token(sp, ref tok) => {
                    first.add_one((sp, tok.clone()));
                    return first;
                }
                TokenTree::Delimited(_, ref delimited) => {
                    first.add_one((delimited.open_span,
                                   Token::OpenDelim(delimited.delim)));
                    return first;
                }
                TokenTree::Sequence(sp, ref seq_rep) => {
                    match self.first.get(&sp) {
                        Some(&Some(ref subfirst)) => {
                            // If the sequence contents can be empty, then the first
                            // token could be the separator token itself.
                            if let (Some(ref sep), true) = (seq_rep.separator.clone(),
                                                            subfirst.maybe_empty) {
                                first.add_one_maybe((sp, sep.clone()));
                            }
                            assert!(first.maybe_empty);
                            first.add_all(subfirst);
                            if subfirst.maybe_empty ||
                               seq_rep.op == tokenstream::KleeneOp::ZeroOrMore {
                                // continue scanning for more first
                                // tokens, but also make sure we
                                // restore empty-tracking state
                                first.maybe_empty = true;
                                continue;
                            } else {
                                return first;
                            }
                        }
                        Some(&None) => {
                            panic!("assume all sequences have (unique) spans for now");
                        }
                        None => {
                            panic!("We missed a sequence during FirstSets construction");
                        }
                    }
                }
            }
        }
        // we only exit the loop if `tts` was empty or if every
        // element of `tts` matches the empty sequence.
        assert!(first.maybe_empty);
        return first;
    }
fn first ( & self , tts : & [ TokenTree ] ) -> TokenSet { let mut first = TokenSet :: empty ( ) ; for tt in tts . iter ( ) { assert ! ( first maybe_empty ) ; match * tt { TokenTree :: Token ( sp , ref tok ) => { first . add_one ( ( sp , tok . clone ( ) ) ) ; return first ; } TokenTree :: Delimited ( _ , ref delimited ) => { first . add_one ( ( delimited . open_span , Token :: OpenDelim ( delimited . delim ) ) ) ; return first ; } TokenTree :: Sequence ( sp , ref seq_rep ) => { match self . first . get ( & sp ) { Some ( & Some ( ref subfirst ) ) => { // If the sequence contents can be empty, then the first // token could be the separator token itself. if let ( Some ( ref sep ) , true ) = ( seq_rep . separator . clone ( ) , subfirst . maybe_empty ) { first . add_one_maybe ( ( sp , sep . clone ( ) ) ) ; } assert ! ( first maybe_empty ) ; first . add_all ( subfirst ) ; if subfirst . maybe_empty || seq_rep . op == tokenstream :: KleeneOp :: ZeroOrMore { // continue scanning for more first // tokens, but also make sure we // restore empty-tracking state first . maybe_empty = true ; continue ; } else { return first ; } } Some ( & None ) => { panic ! ( " " ) ; } None => { panic ! ( " " ) ; } } } } } // we only exit the loop if `tts` was empty or if every // element of `tts` matches the empty sequence. assert ! ( first maybe_empty ) ; return first ; }
walks forward over `tts` until all potential FIRST tokens are
identified.
walks forward over ` tts ` until all potential FIRST tokens are identified .
&self
tts
&[TokenTree]