about summary refs log tree commit diff
path: root/src/libsyntax/ext
diff options
context:
space:
mode:
authorPaul Stansifer <paul.stansifer@gmail.com>2012-07-03 18:39:37 -0700
committerPaul Stansifer <paul.stansifer@gmail.com>2012-07-05 18:09:31 -0700
commit62db5706e668166f7196463bf34939da7d51093d (patch)
treef75b731244e277afc1470cc53ed5fe5cd7a39965 /src/libsyntax/ext
parentf94065372001f5d34b4fde73f2e6dea8aba28212 (diff)
Start letting the parser catch interpolated ASTs.
Diffstat (limited to 'src/libsyntax/ext')
-rw-r--r--src/libsyntax/ext/tt/earley_parser.rs6
-rw-r--r--src/libsyntax/ext/tt/transcribe.rs11
2 files changed, 15 insertions, 2 deletions
diff --git a/src/libsyntax/ext/tt/earley_parser.rs b/src/libsyntax/ext/tt/earley_parser.rs
index 7477969c1e6..df988cd1a73 100644
--- a/src/libsyntax/ext/tt/earley_parser.rs
+++ b/src/libsyntax/ext/tt/earley_parser.rs
@@ -259,7 +259,11 @@ fn parse_nt(p: parser, name: str) -> whole_nt {
       "expr" { token::w_expr(p.parse_expr()) }
       "ty" { token::w_ty(p.parse_ty(false /* no need to disambiguate*/)) }
       // this could be handled like a token, since it is one
-      "ident" { token::w_ident(p.parse_ident()) }
+      "ident" { alt copy p.token {
+          token::IDENT(sn,b) { p.bump(); token::w_ident(sn,b) }
+          _ { p.fatal("expected ident, found "
+                      + token::to_str(*p.reader.interner(), copy p.token)) }
+      } }
       "path" { token::w_path(p.parse_path_with_tps(false)) }
       _ { p.fatal("Unsupported builtin nonterminal parser: " + name)}
     }
diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs
index a9a99fc9b72..2fd29fa28d0 100644
--- a/src/libsyntax/ext/tt/transcribe.rs
+++ b/src/libsyntax/ext/tt/transcribe.rs
@@ -3,7 +3,7 @@ import diagnostic::span_handler;
 import ast::{token_tree,tt_delim,tt_flat,tt_dotdotdot,tt_interpolate,ident};
 import earley_parser::{arb_depth,seq,leaf};
 import codemap::span;
-import parse::token::{EOF,ACTUALLY,token};
+import parse::token::{EOF,ACTUALLY,IDENT,token,w_ident};
 import std::map::{hashmap,box_str_hash};
 
 export tt_reader,  new_tt_reader, dup_tt_reader, tt_next_token;
@@ -193,8 +193,17 @@ fn tt_next_token(&&r: tt_reader) -> {tok: token, sp: span} {
           // TODO: think about span stuff here
           tt_interpolate(sp, ident) {
             alt *lookup_cur_ad(r, ident) {
+              /* sidestep the interpolation tricks for ident because
+              (a) idents can be in lots of places, so it'd be a pain
+              (b) we actually can, since it's a token. */
+              leaf(w_ident(sn,b)) {
+                r.cur_span = sp; r.cur_tok = IDENT(sn,b);
+                r.cur.idx += 1u;
+                ret ret_val;
+              }
               leaf(w_nt) {
                 r.cur_span = sp; r.cur_tok = ACTUALLY(w_nt);
+                r.cur.idx += 1u;
                 ret ret_val;
               }
               seq(*) {