diff options
| author | Daniel Keep <daniel.keep@gmail.com> | 2016-04-25 02:04:01 +1000 |
|---|---|---|
| committer | Alex Burka <alex@alexburka.com> | 2017-04-15 19:06:19 +0000 |
| commit | a2489495d909c43cfbefaeb79db6a77b13908257 (patch) | |
| tree | dbd1690433ffb36b6bad7a56c3923e9313f0529a /src/libsyntax | |
| parent | ae23e65eb8f207d0c9be82e7f2043d98a32d4f57 (diff) | |
| download | rust-a2489495d909c43cfbefaeb79db6a77b13908257.tar.gz rust-a2489495d909c43cfbefaeb79db6a77b13908257.zip | |
Implementation of the `vis` macro matcher.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ext/tt/macro_parser.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/ext/tt/macro_rules.rs | 15 | ||||
| -rw-r--r-- | src/libsyntax/fold.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/parse/token.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 5 |
5 files changed, 23 insertions, 1 deletions
diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index 6cd1fea2e75..eb0b7c29f8d 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -529,6 +529,7 @@ fn parse_nt<'a>(p: &mut Parser<'a>, sp: Span, name: &str) -> Nonterminal { token::NtPath(panictry!(p.parse_path(PathStyle::Type))) }, "meta" => token::NtMeta(panictry!(p.parse_meta_item())), + "vis" => token::NtVis(panictry!(p.parse_visibility(true))), // this is not supposed to happen, since it has been checked // when compiling the macro. _ => p.span_bug(sp, "invalid fragment specifier") diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 93348c8f083..4e197a85ebd 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -790,6 +790,19 @@ fn is_in_follow(tok: "ed::TokenTree, frag: &str) -> Result<bool, (String, &' // harmless Ok(true) }, + "vis" => { + // Explicitly disallow `priv`, on the off chance it comes back. + match *tok { + Comma => Ok(true), + ModSep => Ok(true), + MatchNt(_, ref frag, _, _) => { + let name = frag.name.as_str(); + Ok(name == "ident" || name == "ty") + }, + Ident(i, _) if i.name.as_str() != "priv" => Ok(true), + _ => Ok(false) + } + }, "" => Ok(true), // keywords::Invalid _ => Err((format!("invalid fragment specifier `{}`", frag), "valid fragment specifiers are `ident`, `block`, \ @@ -813,7 +826,7 @@ fn has_legal_fragment_specifier(tok: "ed::TokenTree) -> Result<(), String> { fn is_legal_fragment_specifier(frag: &str) -> bool { match frag { "item" | "block" | "stmt" | "expr" | "pat" | - "path" | "ty" | "ident" | "meta" | "tt" | "" => true, + "path" | "ty" | "ident" | "meta" | "tt" | "vis" | "" => true, _ => false, } } diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index a6ab8e10d9f..f39399a62e8 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -636,6 +636,7 @@ pub fn noop_fold_interpolated<T: Folder>(nt: token::Nonterminal, fld: &mut T) token::NtWhereClause(where_clause) => token::NtWhereClause(fld.fold_where_clause(where_clause)), token::NtArg(arg) => token::NtArg(fld.fold_arg(arg)), + token::NtVis(vis) => token::NtVis(fld.fold_vis(vis)), } } diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 74aa3984a9a..513aa866043 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -371,6 +371,7 @@ pub enum Nonterminal { NtGenerics(ast::Generics), NtWhereClause(ast::WhereClause), NtArg(ast::Arg), + NtVis(ast::Visibility), } impl fmt::Debug for Nonterminal { @@ -392,6 +393,7 @@ impl fmt::Debug for Nonterminal { NtGenerics(..) => f.pad("NtGenerics(..)"), NtWhereClause(..) => f.pad("NtWhereClause(..)"), NtArg(..) => f.pad("NtArg(..)"), + NtVis(..) => f.pad("NtVis(..)"), } } } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 433ba3d3693..2494af2c161 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -293,6 +293,7 @@ pub fn token_to_string(tok: &Token) -> String { token::NtGenerics(ref e) => generics_to_string(&e), token::NtWhereClause(ref e) => where_clause_to_string(&e), token::NtArg(ref e) => arg_to_string(&e), + token::NtVis(ref e) => vis_to_string(&e), } } } @@ -373,6 +374,10 @@ pub fn ident_to_string(id: ast::Ident) -> String { to_string(|s| s.print_ident(id)) } +pub fn vis_to_string(v: &ast::Visibility) -> String { + to_string(|s| s.print_visibility(v)) +} + pub fn fun_to_string(decl: &ast::FnDecl, unsafety: ast::Unsafety, constness: ast::Constness, |
