about summary refs log tree commit diff
path: root/src/libsyntax/ext
diff options
context:
space:
mode:
authorDaniel Keep <daniel.keep@gmail.com>2016-04-25 02:04:01 +1000
committerAlex Burka <alex@alexburka.com>2017-04-15 19:06:19 +0000
commita2489495d909c43cfbefaeb79db6a77b13908257 (patch)
treedbd1690433ffb36b6bad7a56c3923e9313f0529a /src/libsyntax/ext
parentae23e65eb8f207d0c9be82e7f2043d98a32d4f57 (diff)
downloadrust-a2489495d909c43cfbefaeb79db6a77b13908257.tar.gz
rust-a2489495d909c43cfbefaeb79db6a77b13908257.zip
Implementation of the `vis` macro matcher.
Diffstat (limited to 'src/libsyntax/ext')
-rw-r--r--src/libsyntax/ext/tt/macro_parser.rs1
-rw-r--r--src/libsyntax/ext/tt/macro_rules.rs15
2 files changed, 15 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: &quoted::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: &quoted::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,
     }
 }