about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorEric Holk <eric.holk@gmail.com>2012-07-05 23:04:56 -0700
committerEric Holk <eric.holk@gmail.com>2012-07-06 10:42:40 -0700
commitfa4134611dfc54e117f196644d30948a75b7b9eb (patch)
treea53b85b9b44bcdcf80bbe2a55234c80ad0680fac /src/libsyntax
parent6806aa0e66028a218de96edd72b11e0ffa4de4e2 (diff)
downloadrust-fa4134611dfc54e117f196644d30948a75b7b9eb.tar.gz
rust-fa4134611dfc54e117f196644d30948a75b7b9eb.zip
Fixing an infinite type, updating code to match new Early parser, remembering to add protocol parser.
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ext/pipes.rs4
-rw-r--r--src/libsyntax/ext/pipes/parse_proto.rs63
-rw-r--r--src/libsyntax/ext/tt/earley_parser.rs2
-rw-r--r--src/libsyntax/parse/token.rs6
4 files changed, 72 insertions, 3 deletions
diff --git a/src/libsyntax/ext/pipes.rs b/src/libsyntax/ext/pipes.rs
index ce9b0b0a2cf..4ca47254a94 100644
--- a/src/libsyntax/ext/pipes.rs
+++ b/src/libsyntax/ext/pipes.rs
@@ -17,7 +17,9 @@ fn expand_proto(cx: ext_ctxt, _sp: span, id: ast::ident, tt: ast::token_tree)
     let cfg = cx.cfg();
     let body_core = alt tt { tt_delim(tts) { tts } _ {fail}};
     let tt_rdr = new_tt_reader(cx.parse_sess().span_diagnostic,
-                               cx.parse_sess().interner, body_core);
+                               cx.parse_sess().interner,
+                               none,
+                               body_core);
     let rdr = tt_rdr as reader;
     let rust_parser = parser(sess, cfg, rdr.dup(), SOURCE_FILE);
 
diff --git a/src/libsyntax/ext/pipes/parse_proto.rs b/src/libsyntax/ext/pipes/parse_proto.rs
new file mode 100644
index 00000000000..919960f4c82
--- /dev/null
+++ b/src/libsyntax/ext/pipes/parse_proto.rs
@@ -0,0 +1,63 @@
+// Parsing pipes protocols from token trees.
+
+import parse::parser;
+import ast::ident;
+import parse::token;
+
+import pipec::*;
+
+impl proto_parser for parser {
+    fn parse_proto(id: ident) -> protocol {
+        let proto = protocol(id);
+
+        self.expect(token::LBRACE);
+
+        while self.token != token::RBRACE {
+            self.parse_state(proto);
+        }
+
+        ret proto;
+    }
+
+    fn parse_state(proto: protocol) {
+        let id = self.parse_ident();
+        self.expect(token::COLON);
+        let dir = alt copy self.token {
+          token::IDENT(n, _) {
+            self.get_str(n)
+          }
+          _ { fail }
+        };
+        self.bump();
+        let dir = alt dir {
+          @"send" { send }
+          @"recv" { recv }
+          _ { fail }
+        };
+
+        let state = proto.add_state(id, dir);
+        // TODO: add typarams too.
+
+        self.expect(token::LBRACE);
+
+        while self.token != token::RBRACE {
+            let mname = self.parse_ident();
+
+            // TODO: parse data
+
+            self.expect(token::RARROW);
+
+            let next = self.parse_ident();
+            // TODO: parse next types
+
+            state.add_message(mname, ~[], next, ~[]);
+
+            alt copy self.token {
+              token::COMMA { self.bump() }
+              token::RBRACE { }
+              _ { fail }
+            }
+        }
+        self.bump();
+    }
+}
diff --git a/src/libsyntax/ext/tt/earley_parser.rs b/src/libsyntax/ext/tt/earley_parser.rs
index 731d79573e7..191da586ce5 100644
--- a/src/libsyntax/ext/tt/earley_parser.rs
+++ b/src/libsyntax/ext/tt/earley_parser.rs
@@ -272,7 +272,7 @@ fn parse_nt(p: parser, name: str) -> whole_nt {
                       + token::to_str(*p.reader.interner(), copy p.token)) }
       } }
       "path" { token::w_path(p.parse_path_with_tps(false)) }
-      "tt" { token::w_tt(p.parse_token_tree()) }
+      "tt" { token::w_tt(@p.parse_token_tree()) }
       _ { p.fatal("Unsupported builtin nonterminal parser: " + name)}
     }
 }
diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs
index ef1d0f4bc47..dbc1e8b34e3 100644
--- a/src/libsyntax/parse/token.rs
+++ b/src/libsyntax/parse/token.rs
@@ -96,7 +96,10 @@ enum whole_nt {
     w_ty(  @ast::ty),
     w_ident(str_num, bool),
     w_path(@ast::path),
-    w_tt(ast::token_tree),
+    // TODO: this seems to cause infinite recursion in
+    // type_structually_contains if it's not an @-box. We should at least get
+    // failure instead.
+    w_tt(@ast::token_tree),
 }
 
 fn binop_to_str(o: binop) -> str {
@@ -190,6 +193,7 @@ fn to_str(in: interner<@str>, t: token) -> str {
               w_stmt(*) { "statement" } w_pat(*) { "pattern" }
               w_expr(*) { "expression" } w_ty(*) { "type" }
               w_ident(*) { "identifier" } w_path(*) { "path" }
+              w_tt(*) { "tt" }
         }
       }
     }