fn parse_non_delim_tt_tok(p: &mut Parser) -> TokenTree {
maybe_whole!(deref p, NtTT);
match p.token {
- token::CloseDelim(_) => {
- // This is a conservative error: only report the last unclosed delimiter. The
- // previous unclosed delimiters could actually be closed! The parser just hasn't
- // gotten to them yet.
- match p.open_braces.last() {
- None => {}
- Some(&sp) => p.span_note(sp, "unclosed delimiter"),
- };
- let token_str = p.this_token_to_string();
- p.fatal(format!("incorrect close delimiter: `{}`",
- token_str).index(&FullRange))
- },
- /* we ought to allow different depths of unquotation */
- token::Dollar if p.quote_depth > 0u => {
- p.bump();
- let sp = p.span;
-
- if p.token == token::OpenDelim(token::Paren) {
- let seq = p.parse_seq(
- &token::OpenDelim(token::Paren),
- &token::CloseDelim(token::Paren),
- seq_sep_none(),
- |p| p.parse_token_tree()
- );
- let (sep, repeat) = p.parse_sep_and_kleene_op();
- let seq = match seq {
- Spanned { node, .. } => node,
+ token::CloseDelim(_) => {
+ // This is a conservative error: only report the last unclosed delimiter. The
+ // previous unclosed delimiters could actually be closed! The parser just hasn't
+ // gotten to them yet.
+ match p.open_braces.last() {
+ None => {}
+ Some(&sp) => p.span_note(sp, "unclosed delimiter"),
};
- let name_num = macro_parser::count_names(seq.index(&FullRange));
- TtSequence(mk_sp(sp.lo, p.span.hi),
- Rc::new(SequenceRepetition {
- tts: seq,
- separator: sep,
- op: repeat,
- num_captures: name_num
- }))
- } else if p.token.is_keyword_allow_following_colon(keywords::Crate) {
- p.bump();
- TtToken(sp, SpecialVarNt(SpecialMacroVar::CrateMacroVar))
- } else {
- // A nonterminal that matches or not
- let namep = match p.token { token::Ident(_, p) => p, _ => token::Plain };
- let name = p.parse_ident();
- if p.token == token::Colon && p.look_ahead(1, |t| t.is_ident()) {
- p.bump();
- let kindp = match p.token { token::Ident(_, p) => p, _ => token::Plain };
- let nt_kind = p.parse_ident();
- let m = TtToken(sp, MatchNt(name, nt_kind, namep, kindp));
- m
- } else {
- TtToken(sp, SubstNt(name, namep))
- }
+ let token_str = p.this_token_to_string();
+ p.fatal(format!("incorrect close delimiter: `{}`",
- token_str)[])
++ token_str).index(&FullRange))
+ },
+ /* we ought to allow different depths of unquotation */
+ token::Dollar | token::SubstNt(..) if p.quote_depth > 0u => {
+ p.parse_unquoted()
+ }
+ _ => {
+ TtToken(p.span, p.bump_and_get())
}
- }
- _ => {
- TtToken(p.span, p.bump_and_get())
- }
}
}