]> git.lizzy.rs Git - rust.git/blob - src/libsyntax/ext/tt/macro_parser.rs
Rollup merge of #43011 - qnighy:unsized-tuple-impls, r=aturon
[rust.git] / src / libsyntax / ext / tt / macro_parser.rs
1 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 //! This is an Earley-like parser, without support for in-grammar nonterminals,
12 //! only by calling out to the main rust parser for named nonterminals (which it
13 //! commits to fully when it hits one in a grammar). This means that there are no
14 //! completer or predictor rules, and therefore no need to store one column per
15 //! token: instead, there's a set of current Earley items and a set of next
16 //! ones. Instead of NTs, we have a special case for Kleene star. The big-O, in
17 //! pathological cases, is worse than traditional Earley parsing, but it's an
18 //! easier fit for Macro-by-Example-style rules, and I think the overhead is
19 //! lower. (In order to prevent the pathological case, we'd need to lazily
20 //! construct the resulting `NamedMatch`es at the very end. It'd be a pain,
21 //! and require more memory to keep around old items, but it would also save
22 //! overhead)
23 //!
24 //! Quick intro to how the parser works:
25 //!
26 //! A 'position' is a dot in the middle of a matcher, usually represented as a
27 //! dot. For example `· a $( a )* a b` is a position, as is `a $( · a )* a b`.
28 //!
29 //! The parser walks through the input a character at a time, maintaining a list
30 //! of items consistent with the current position in the input string: `cur_eis`.
31 //!
32 //! As it processes them, it fills up `eof_eis` with items that would be valid if
33 //! the macro invocation is now over, `bb_eis` with items that are waiting on
34 //! a Rust nonterminal like `$e:expr`, and `next_eis` with items that are waiting
35 //! on a particular token. Most of the logic concerns moving the · through the
36 //! repetitions indicated by Kleene stars. It only advances or calls out to the
37 //! real Rust parser when no `cur_eis` items remain
38 //!
39 //! Example:
40 //!
41 //! ```text, ignore
42 //! Start parsing a a a a b against [· a $( a )* a b].
43 //!
44 //! Remaining input: a a a a b
45 //! next_eis: [· a $( a )* a b]
46 //!
47 //! - - - Advance over an a. - - -
48 //!
49 //! Remaining input: a a a b
50 //! cur: [a · $( a )* a b]
51 //! Descend/Skip (first item).
52 //! next: [a $( · a )* a b]  [a $( a )* · a b].
53 //!
54 //! - - - Advance over an a. - - -
55 //!
56 //! Remaining input: a a b
57 //! cur: [a $( a · )* a b]  next: [a $( a )* a · b]
58 //! Finish/Repeat (first item)
59 //! next: [a $( a )* · a b]  [a $( · a )* a b]  [a $( a )* a · b]
60 //!
61 //! - - - Advance over an a. - - - (this looks exactly like the last step)
62 //!
63 //! Remaining input: a b
64 //! cur: [a $( a · )* a b]  next: [a $( a )* a · b]
65 //! Finish/Repeat (first item)
66 //! next: [a $( a )* · a b]  [a $( · a )* a b]  [a $( a )* a · b]
67 //!
68 //! - - - Advance over an a. - - - (this looks exactly like the last step)
69 //!
70 //! Remaining input: b
71 //! cur: [a $( a · )* a b]  next: [a $( a )* a · b]
72 //! Finish/Repeat (first item)
73 //! next: [a $( a )* · a b]  [a $( · a )* a b]
74 //!
75 //! - - - Advance over a b. - - -
76 //!
77 //! Remaining input: ''
78 //! eof: [a $( a )* a b ·]
79 //! ```
80
81 pub use self::NamedMatch::*;
82 pub use self::ParseResult::*;
83 use self::TokenTreeOrTokenTreeVec::*;
84
85 use ast::Ident;
86 use syntax_pos::{self, BytePos, Span};
87 use codemap::Spanned;
88 use errors::FatalError;
89 use ext::tt::quoted::{self, TokenTree};
90 use parse::{Directory, ParseSess};
91 use parse::parser::{PathStyle, Parser};
92 use parse::token::{self, DocComment, Token, Nonterminal};
93 use print::pprust;
94 use symbol::keywords;
95 use tokenstream::TokenStream;
96 use util::small_vector::SmallVector;
97
98 use std::mem;
99 use std::rc::Rc;
100 use std::collections::HashMap;
101 use std::collections::hash_map::Entry::{Vacant, Occupied};
102
103 // To avoid costly uniqueness checks, we require that `MatchSeq` always has
104 // a nonempty body.
105
106 #[derive(Clone)]
107 enum TokenTreeOrTokenTreeVec {
108     Tt(TokenTree),
109     TtSeq(Vec<TokenTree>),
110 }
111
112 impl TokenTreeOrTokenTreeVec {
113     fn len(&self) -> usize {
114         match *self {
115             TtSeq(ref v) => v.len(),
116             Tt(ref tt) => tt.len(),
117         }
118     }
119
120     fn get_tt(&self, index: usize) -> TokenTree {
121         match *self {
122             TtSeq(ref v) => v[index].clone(),
123             Tt(ref tt) => tt.get_tt(index),
124         }
125     }
126 }
127
128 /// an unzipping of `TokenTree`s
129 #[derive(Clone)]
130 struct MatcherTtFrame {
131     elts: TokenTreeOrTokenTreeVec,
132     idx: usize,
133 }
134
135 #[derive(Clone)]
136 struct MatcherPos {
137     stack: Vec<MatcherTtFrame>,
138     top_elts: TokenTreeOrTokenTreeVec,
139     sep: Option<Token>,
140     idx: usize,
141     up: Option<Box<MatcherPos>>,
142     matches: Vec<Rc<Vec<NamedMatch>>>,
143     match_lo: usize,
144     match_cur: usize,
145     match_hi: usize,
146     sp_lo: BytePos,
147 }
148
149 impl MatcherPos {
150     fn push_match(&mut self, idx: usize, m: NamedMatch) {
151         let matches = Rc::make_mut(&mut self.matches[idx]);
152         matches.push(m);
153     }
154 }
155
156 pub type NamedParseResult = ParseResult<HashMap<Ident, Rc<NamedMatch>>>;
157
158 pub fn count_names(ms: &[TokenTree]) -> usize {
159     ms.iter().fold(0, |count, elt| {
160         count + match *elt {
161             TokenTree::Sequence(_, ref seq) => seq.num_captures,
162             TokenTree::Delimited(_, ref delim) => count_names(&delim.tts),
163             TokenTree::MetaVar(..) => 0,
164             TokenTree::MetaVarDecl(..) => 1,
165             TokenTree::Token(..) => 0,
166         }
167     })
168 }
169
170 fn initial_matcher_pos(ms: Vec<TokenTree>, lo: BytePos) -> Box<MatcherPos> {
171     let match_idx_hi = count_names(&ms[..]);
172     let matches = create_matches(match_idx_hi);
173     Box::new(MatcherPos {
174         stack: vec![],
175         top_elts: TtSeq(ms),
176         sep: None,
177         idx: 0,
178         up: None,
179         matches: matches,
180         match_lo: 0,
181         match_cur: 0,
182         match_hi: match_idx_hi,
183         sp_lo: lo
184     })
185 }
186
187 /// `NamedMatch` is a pattern-match result for a single `token::MATCH_NONTERMINAL`:
188 /// so it is associated with a single ident in a parse, and all
189 /// `MatchedNonterminal`s in the `NamedMatch` have the same nonterminal type
190 /// (expr, item, etc). Each leaf in a single `NamedMatch` corresponds to a
191 /// single `token::MATCH_NONTERMINAL` in the `TokenTree` that produced it.
192 ///
193 /// The in-memory structure of a particular `NamedMatch` represents the match
194 /// that occurred when a particular subset of a matcher was applied to a
195 /// particular token tree.
196 ///
197 /// The width of each `MatchedSeq` in the `NamedMatch`, and the identity of
198 /// the `MatchedNonterminal`s, will depend on the token tree it was applied
199 /// to: each `MatchedSeq` corresponds to a single `TTSeq` in the originating
200 /// token tree. The depth of the `NamedMatch` structure will therefore depend
201 /// only on the nesting depth of `ast::TTSeq`s in the originating
202 /// token tree it was derived from.
203
204 #[derive(Debug, Clone)]
205 pub enum NamedMatch {
206     MatchedSeq(Rc<Vec<NamedMatch>>, syntax_pos::Span),
207     MatchedNonterminal(Rc<Nonterminal>)
208 }
209
210 fn nameize<I: Iterator<Item=NamedMatch>>(sess: &ParseSess, ms: &[TokenTree], mut res: I)
211                                              -> NamedParseResult {
212     fn n_rec<I: Iterator<Item=NamedMatch>>(sess: &ParseSess, m: &TokenTree, mut res: &mut I,
213              ret_val: &mut HashMap<Ident, Rc<NamedMatch>>)
214              -> Result<(), (syntax_pos::Span, String)> {
215         match *m {
216             TokenTree::Sequence(_, ref seq) => {
217                 for next_m in &seq.tts {
218                     n_rec(sess, next_m, res.by_ref(), ret_val)?
219                 }
220             }
221             TokenTree::Delimited(_, ref delim) => {
222                 for next_m in &delim.tts {
223                     n_rec(sess, next_m, res.by_ref(), ret_val)?;
224                 }
225             }
226             TokenTree::MetaVarDecl(span, _, id) if id.name == keywords::Invalid.name() => {
227                 if sess.missing_fragment_specifiers.borrow_mut().remove(&span) {
228                     return Err((span, "missing fragment specifier".to_string()));
229                 }
230             }
231             TokenTree::MetaVarDecl(sp, bind_name, _) => {
232                 match ret_val.entry(bind_name) {
233                     Vacant(spot) => {
234                         // FIXME(simulacrum): Don't construct Rc here
235                         spot.insert(Rc::new(res.next().unwrap()));
236                     }
237                     Occupied(..) => {
238                         return Err((sp, format!("duplicated bind name: {}", bind_name)))
239                     }
240                 }
241             }
242             TokenTree::MetaVar(..) | TokenTree::Token(..) => (),
243         }
244
245         Ok(())
246     }
247
248     let mut ret_val = HashMap::new();
249     for m in ms {
250         match n_rec(sess, m, res.by_ref(), &mut ret_val) {
251             Ok(_) => {},
252             Err((sp, msg)) => return Error(sp, msg),
253         }
254     }
255
256     Success(ret_val)
257 }
258
259 pub enum ParseResult<T> {
260     Success(T),
261     /// Arm failed to match. If the second parameter is `token::Eof`, it
262     /// indicates an unexpected end of macro invocation. Otherwise, it
263     /// indicates that no rules expected the given token.
264     Failure(syntax_pos::Span, Token),
265     /// Fatal error (malformed macro?). Abort compilation.
266     Error(syntax_pos::Span, String)
267 }
268
269 pub fn parse_failure_msg(tok: Token) -> String {
270     match tok {
271         token::Eof => "unexpected end of macro invocation".to_string(),
272         _ => format!("no rules expected the token `{}`", pprust::token_to_string(&tok)),
273     }
274 }
275
276 /// Perform a token equality check, ignoring syntax context (that is, an unhygienic comparison)
277 fn token_name_eq(t1 : &Token, t2 : &Token) -> bool {
278     if let (Some(id1), Some(id2)) = (t1.ident(), t2.ident()) {
279         id1.name == id2.name
280     } else if let (&token::Lifetime(id1), &token::Lifetime(id2)) = (t1, t2) {
281         id1.name == id2.name
282     } else {
283         *t1 == *t2
284     }
285 }
286
287 fn create_matches(len: usize) -> Vec<Rc<Vec<NamedMatch>>> {
288     (0..len).into_iter().map(|_| Rc::new(Vec::new())).collect()
289 }
290
291 fn inner_parse_loop(sess: &ParseSess,
292                     cur_eis: &mut SmallVector<Box<MatcherPos>>,
293                     next_eis: &mut Vec<Box<MatcherPos>>,
294                     eof_eis: &mut SmallVector<Box<MatcherPos>>,
295                     bb_eis: &mut SmallVector<Box<MatcherPos>>,
296                     token: &Token,
297                     span: syntax_pos::Span)
298                     -> ParseResult<()> {
299     while let Some(mut ei) = cur_eis.pop() {
300         // When unzipped trees end, remove them
301         while ei.idx >= ei.top_elts.len() {
302             match ei.stack.pop() {
303                 Some(MatcherTtFrame { elts, idx }) => {
304                     ei.top_elts = elts;
305                     ei.idx = idx + 1;
306                 }
307                 None => break
308             }
309         }
310
311         let idx = ei.idx;
312         let len = ei.top_elts.len();
313
314         // at end of sequence
315         if idx >= len {
316             // We are repeating iff there is a parent
317             if ei.up.is_some() {
318                 // Disregarding the separator, add the "up" case to the tokens that should be
319                 // examined.
320                 // (remove this condition to make trailing seps ok)
321                 if idx == len {
322                     let mut new_pos = ei.up.clone().unwrap();
323
324                     // update matches (the MBE "parse tree") by appending
325                     // each tree as a subtree.
326
327                     // Only touch the binders we have actually bound
328                     for idx in ei.match_lo..ei.match_hi {
329                         let sub = ei.matches[idx].clone();
330                         new_pos.push_match(idx, MatchedSeq(sub, Span { lo: ei.sp_lo, ..span }));
331                     }
332
333                     new_pos.match_cur = ei.match_hi;
334                     new_pos.idx += 1;
335                     cur_eis.push(new_pos);
336                 }
337
338                 // Check if we need a separator
339                 if idx == len && ei.sep.is_some() {
340                     // We have a separator, and it is the current token.
341                     if ei.sep.as_ref().map(|sep| token_name_eq(token, sep)).unwrap_or(false) {
342                         ei.idx += 1;
343                         next_eis.push(ei);
344                     }
345                 } else { // we don't need a separator
346                     ei.match_cur = ei.match_lo;
347                     ei.idx = 0;
348                     cur_eis.push(ei);
349                 }
350             } else {
351                 // We aren't repeating, so we must be potentially at the end of the input.
352                 eof_eis.push(ei);
353             }
354         } else {
355             match ei.top_elts.get_tt(idx) {
356                 /* need to descend into sequence */
357                 TokenTree::Sequence(sp, seq) => {
358                     if seq.op == quoted::KleeneOp::ZeroOrMore {
359                         // Examine the case where there are 0 matches of this sequence
360                         let mut new_ei = ei.clone();
361                         new_ei.match_cur += seq.num_captures;
362                         new_ei.idx += 1;
363                         for idx in ei.match_cur..ei.match_cur + seq.num_captures {
364                             new_ei.push_match(idx, MatchedSeq(Rc::new(vec![]), sp));
365                         }
366                         cur_eis.push(new_ei);
367                     }
368
369                     // Examine the case where there is at least one match of this sequence
370                     let matches = create_matches(ei.matches.len());
371                     cur_eis.push(Box::new(MatcherPos {
372                         stack: vec![],
373                         sep: seq.separator.clone(),
374                         idx: 0,
375                         matches: matches,
376                         match_lo: ei.match_cur,
377                         match_cur: ei.match_cur,
378                         match_hi: ei.match_cur + seq.num_captures,
379                         up: Some(ei),
380                         sp_lo: sp.lo,
381                         top_elts: Tt(TokenTree::Sequence(sp, seq)),
382                     }));
383                 }
384                 TokenTree::MetaVarDecl(span, _, id) if id.name == keywords::Invalid.name() => {
385                     if sess.missing_fragment_specifiers.borrow_mut().remove(&span) {
386                         return Error(span, "missing fragment specifier".to_string());
387                     }
388                 }
389                 TokenTree::MetaVarDecl(_, _, id) => {
390                     // Built-in nonterminals never start with these tokens,
391                     // so we can eliminate them from consideration.
392                     if may_begin_with(&*id.name.as_str(), token) {
393                         bb_eis.push(ei);
394                     }
395                 }
396                 seq @ TokenTree::Delimited(..) | seq @ TokenTree::Token(_, DocComment(..)) => {
397                     let lower_elts = mem::replace(&mut ei.top_elts, Tt(seq));
398                     let idx = ei.idx;
399                     ei.stack.push(MatcherTtFrame {
400                         elts: lower_elts,
401                         idx: idx,
402                     });
403                     ei.idx = 0;
404                     cur_eis.push(ei);
405                 }
406                 TokenTree::Token(_, ref t) if token_name_eq(t, token) => {
407                     ei.idx += 1;
408                     next_eis.push(ei);
409                 }
410                 TokenTree::Token(..) | TokenTree::MetaVar(..) => {}
411             }
412         }
413     }
414
415     Success(())
416 }
417
418 pub fn parse(sess: &ParseSess,
419              tts: TokenStream,
420              ms: &[TokenTree],
421              directory: Option<Directory>,
422              recurse_into_modules: bool)
423              -> NamedParseResult {
424     let mut parser = Parser::new(sess, tts, directory, recurse_into_modules, true);
425     let mut cur_eis = SmallVector::one(initial_matcher_pos(ms.to_owned(), parser.span.lo));
426     let mut next_eis = Vec::new(); // or proceed normally
427
428     loop {
429         let mut bb_eis = SmallVector::new(); // black-box parsed by parser.rs
430         let mut eof_eis = SmallVector::new();
431         assert!(next_eis.is_empty());
432
433         match inner_parse_loop(sess, &mut cur_eis, &mut next_eis, &mut eof_eis, &mut bb_eis,
434                                &parser.token, parser.span) {
435             Success(_) => {},
436             Failure(sp, tok) => return Failure(sp, tok),
437             Error(sp, msg) => return Error(sp, msg),
438         }
439
440         // inner parse loop handled all cur_eis, so it's empty
441         assert!(cur_eis.is_empty());
442
443         /* error messages here could be improved with links to orig. rules */
444         if token_name_eq(&parser.token, &token::Eof) {
445             if eof_eis.len() == 1 {
446                 let matches = eof_eis[0].matches.iter_mut().map(|mut dv| {
447                     Rc::make_mut(dv).pop().unwrap()
448                 });
449                 return nameize(sess, ms, matches);
450             } else if eof_eis.len() > 1 {
451                 return Error(parser.span, "ambiguity: multiple successful parses".to_string());
452             } else {
453                 return Failure(parser.span, token::Eof);
454             }
455         } else if (!bb_eis.is_empty() && !next_eis.is_empty()) || bb_eis.len() > 1 {
456             let nts = bb_eis.iter().map(|ei| match ei.top_elts.get_tt(ei.idx) {
457                 TokenTree::MetaVarDecl(_, bind, name) => {
458                     format!("{} ('{}')", name, bind)
459                 }
460                 _ => panic!()
461             }).collect::<Vec<String>>().join(" or ");
462
463             return Error(parser.span, format!(
464                 "local ambiguity: multiple parsing options: {}",
465                 match next_eis.len() {
466                     0 => format!("built-in NTs {}.", nts),
467                     1 => format!("built-in NTs {} or 1 other option.", nts),
468                     n => format!("built-in NTs {} or {} other options.", nts, n),
469                 }
470             ));
471         } else if bb_eis.is_empty() && next_eis.is_empty() {
472             return Failure(parser.span, parser.token);
473         } else if !next_eis.is_empty() {
474             /* Now process the next token */
475             cur_eis.extend(next_eis.drain(..));
476             parser.bump();
477         } else /* bb_eis.len() == 1 */ {
478             let mut ei = bb_eis.pop().unwrap();
479             if let TokenTree::MetaVarDecl(span, _, ident) = ei.top_elts.get_tt(ei.idx) {
480                 let match_cur = ei.match_cur;
481                 ei.push_match(match_cur,
482                     MatchedNonterminal(Rc::new(parse_nt(&mut parser, span, &ident.name.as_str()))));
483                 ei.idx += 1;
484                 ei.match_cur += 1;
485             } else {
486                 unreachable!()
487             }
488             cur_eis.push(ei);
489         }
490
491         assert!(!cur_eis.is_empty());
492     }
493 }
494
495 /// Checks whether a non-terminal may begin with a particular token.
496 ///
497 /// Returning `false` is a *stability guarantee* that such a matcher will *never* begin with that
498 /// token. Be conservative (return true) if not sure.
499 fn may_begin_with(name: &str, token: &Token) -> bool {
500     /// Checks whether the non-terminal may contain a single (non-keyword) identifier.
501     fn may_be_ident(nt: &token::Nonterminal) -> bool {
502         match *nt {
503             token::NtItem(_) | token::NtBlock(_) | token::NtVis(_) => false,
504             _ => true,
505         }
506     }
507
508     match name {
509         "expr" => token.can_begin_expr(),
510         "ty" => token.can_begin_type(),
511         "ident" => token.is_ident(),
512         "vis" => match *token { // The follow-set of :vis + "priv" keyword + interpolated
513             Token::Comma | Token::Ident(_) | Token::Interpolated(_) => true,
514             _ => token.can_begin_type(),
515         },
516         "block" => match *token {
517             Token::OpenDelim(token::Brace) => true,
518             Token::Interpolated(ref nt) => match nt.0 {
519                 token::NtItem(_) |
520                 token::NtPat(_) |
521                 token::NtTy(_) |
522                 token::NtIdent(_) |
523                 token::NtMeta(_) |
524                 token::NtPath(_) |
525                 token::NtVis(_) => false, // none of these may start with '{'.
526                 _ => true,
527             },
528             _ => false,
529         },
530         "path" | "meta" => match *token {
531             Token::ModSep | Token::Ident(_) => true,
532             Token::Interpolated(ref nt) => match nt.0 {
533                 token::NtPath(_) | token::NtMeta(_) => true,
534                 _ => may_be_ident(&nt.0),
535             },
536             _ => false,
537         },
538         "pat" => match *token {
539             Token::Ident(_) |               // box, ref, mut, and other identifiers (can stricten)
540             Token::OpenDelim(token::Paren) |    // tuple pattern
541             Token::OpenDelim(token::Bracket) |  // slice pattern
542             Token::BinOp(token::And) |          // reference
543             Token::BinOp(token::Minus) |        // negative literal
544             Token::AndAnd |                     // double reference
545             Token::Literal(..) |                // literal
546             Token::DotDot |                     // range pattern (future compat)
547             Token::DotDotDot |                  // range pattern (future compat)
548             Token::ModSep |                     // path
549             Token::Lt |                         // path (UFCS constant)
550             Token::BinOp(token::Shl) |          // path (double UFCS)
551             Token::Underscore => true,          // placeholder
552             Token::Interpolated(ref nt) => may_be_ident(&nt.0),
553             _ => false,
554         },
555         _ => match *token {
556             token::CloseDelim(_) => false,
557             _ => true,
558         },
559     }
560 }
561
562 fn parse_nt<'a>(p: &mut Parser<'a>, sp: Span, name: &str) -> Nonterminal {
563     if name == "tt" {
564         return token::NtTT(p.parse_token_tree());
565     }
566     // check at the beginning and the parser checks after each bump
567     p.process_potential_macro_variable();
568     match name {
569         "item" => match panictry!(p.parse_item()) {
570             Some(i) => token::NtItem(i),
571             None => {
572                 p.fatal("expected an item keyword").emit();
573                 panic!(FatalError);
574             }
575         },
576         "block" => token::NtBlock(panictry!(p.parse_block())),
577         "stmt" => match panictry!(p.parse_stmt()) {
578             Some(s) => token::NtStmt(s),
579             None => {
580                 p.fatal("expected a statement").emit();
581                 panic!(FatalError);
582             }
583         },
584         "pat" => token::NtPat(panictry!(p.parse_pat())),
585         "expr" => token::NtExpr(panictry!(p.parse_expr())),
586         "ty" => token::NtTy(panictry!(p.parse_ty())),
587         // this could be handled like a token, since it is one
588         "ident" => match p.token {
589             token::Ident(sn) => {
590                 p.bump();
591                 token::NtIdent(Spanned::<Ident>{node: sn, span: p.prev_span})
592             }
593             _ => {
594                 let token_str = pprust::token_to_string(&p.token);
595                 p.fatal(&format!("expected ident, found {}",
596                                  &token_str[..])).emit();
597                 panic!(FatalError)
598             }
599         },
600         "path" => {
601             token::NtPath(panictry!(p.parse_path(PathStyle::Type)))
602         },
603         "meta" => token::NtMeta(panictry!(p.parse_meta_item())),
604         "vis" => token::NtVis(panictry!(p.parse_visibility(true))),
605         // this is not supposed to happen, since it has been checked
606         // when compiling the macro.
607         _ => p.span_bug(sp, "invalid fragment specifier")
608     }
609 }