about summary refs log tree commit diff
path: root/src/libsyntax/parse
diff options
context:
space:
mode:
authorEric Holk <eric.holk@gmail.com>2012-07-05 12:10:33 -0700
committerEric Holk <eric.holk@gmail.com>2012-07-06 10:42:40 -0700
commit05cdda3a2c147fdc8caef4e6c662f518ec325e0a (patch)
treefba957706d8588512bfd259d7873edd615854d36 /src/libsyntax/parse
parenta787f4001388a394d5219b74113a718d980e4c90 (diff)
downloadrust-05cdda3a2c147fdc8caef4e6c662f518ec325e0a.tar.gz
rust-05cdda3a2c147fdc8caef4e6c662f518ec325e0a.zip
Plumbing and parsing for item-position macros.
Diffstat (limited to 'src/libsyntax/parse')
-rw-r--r--src/libsyntax/parse/attr.rs1
-rw-r--r--src/libsyntax/parse/common.rs9
-rw-r--r--src/libsyntax/parse/parser.rs17
3 files changed, 25 insertions, 2 deletions
diff --git a/src/libsyntax/parse/attr.rs b/src/libsyntax/parse/attr.rs
index d7ae4995520..e62de46f5db 100644
--- a/src/libsyntax/parse/attr.rs
+++ b/src/libsyntax/parse/attr.rs
@@ -1,7 +1,6 @@
 import either::{either, left, right};
 import ast_util::spanned;
 import common::*; //resolve bug?
-//import common::{parser_common, seq_sep_trailing_disallowed};
 
 export attr_or_ext;
 export parser_attr;
diff --git a/src/libsyntax/parse/common.rs b/src/libsyntax/parse/common.rs
index d4331ee766f..16059b473bb 100644
--- a/src/libsyntax/parse/common.rs
+++ b/src/libsyntax/parse/common.rs
@@ -92,6 +92,15 @@ impl parser_common for parser {
         self.token_is_keyword(word, self.token)
     }
 
+    fn is_any_keyword(tok: token::token) -> bool {
+        alt tok {
+          token::IDENT(sid, false) {
+            self.keywords.contains_key(*self.get_str(sid))
+          }
+          _ { false }
+        }
+    }
+
     fn eat_keyword(word: str) -> bool {
         self.require_keyword(word);
 
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 8bac3e0d751..2f4fe783b49 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -9,7 +9,7 @@ import lexer::reader;
 import prec::{as_prec, token_to_binop};
 import attr::parser_attr;
 import common::{seq_sep_trailing_disallowed, seq_sep_trailing_allowed,
-                seq_sep_none, token_to_str, parser_common};
+                seq_sep_none, token_to_str};
 import dvec::{dvec, extensions};
 import vec::{push};
 import ast::*;
@@ -2595,6 +2595,21 @@ class parser {
             self.parse_item_impl()
         } else if self.eat_keyword("class") {
             self.parse_item_class()
+        } else if !self.is_any_keyword(copy self.token)
+            && self.look_ahead(1) == token::NOT
+        {
+            // item macro.
+            let pth = self.parse_path_without_tps();
+            #error("parsing invocation of %s", *pth.idents[0]);
+            self.expect(token::NOT);
+            let id = self.parse_ident();
+            let tt = self.parse_token_tree();
+            let m = ast::mac_invoc_tt(pth, tt);
+            let m: ast::mac = {node: m,
+                               span: {lo: self.span.lo,
+                                      hi: self.span.hi,
+                                      expn_info: none}};
+            (id, item_mac(m), none)
         } else { ret none; };
         some(self.mk_item(lo, self.last_span.hi, ident, item_, vis,
                           alt extra_attrs {