]> git.lizzy.rs Git - rust.git/commitdiff
Handle interpolated paths in pattern parsing. Fixes #3007.
authorEric Holk <eric.holk@gmail.com>
Mon, 6 Aug 2012 20:09:10 +0000 (13:09 -0700)
committerEric Holk <eric.holk@gmail.com>
Mon, 6 Aug 2012 20:25:34 +0000 (13:25 -0700)
We might need to use is_ident_or_path in a for other places too.

src/libsyntax/ext/tt/macro_rules.rs
src/libsyntax/parse/parser.rs
src/libsyntax/parse/token.rs

index 7655d7c970c868f6ebe85d3a37fb367bf2bc2a7d..b4fc1f5c484b22410ef64a57522f3ac5f3215bb5 100644 (file)
@@ -73,7 +73,8 @@ fn generic_extension(cx: ext_ctxt, sp: span, arg: ~[ast::token_tree],
                                                ~[rhs]);
                     let p = parser(cx.parse_sess(), cx.cfg(),
                                    trncbr as reader, SOURCE_FILE);
-                    return mr_expr(p.parse_expr());
+                    let e = p.parse_expr();
+                    return mr_expr(e);
                   }
                   failure(sp, msg) => if sp.lo >= best_fail_spot.lo {
                     best_fail_spot = sp;
index 71bd87981bc84df3e86aeef186db076fe559e159..4a34b66793704c8c9e47558ca60eb5d5a9554bf1 100644 (file)
@@ -3,7 +3,8 @@
 import result::result;
 import either::{either, left, right};
 import std::map::{hashmap, str_hash};
-import token::{can_begin_expr, is_ident, is_plain_ident, INTERPOLATED};
+import token::{can_begin_expr, is_ident, is_ident_or_path, is_plain_ident,
+               INTERPOLATED};
 import codemap::{span,fss_none};
 import util::interner;
 import ast_util::{spanned, respan, mk_sp, ident_to_path, operator_prec};
@@ -1748,7 +1749,7 @@ fn parse_pat(refutable: bool) -> @pat {
             }
           }
           tok => {
-            if !is_ident(tok) ||
+            if !is_ident_or_path(tok) ||
                     self.is_keyword(~"true") || self.is_keyword(~"false") {
                 let val = self.parse_expr_res(RESTRICT_NO_BAR_OP);
                 if self.eat_keyword(~"to") {
index d69ff7f16683f4213cb9d7ff929eea47a5877769..9e9a3bbca56c63271bde3567fe18fc60284329f3 100644 (file)
@@ -262,6 +262,13 @@ fn is_lit(t: token) -> bool {
     alt t { IDENT(_, _) => true, _ => false }
 }
 
+pure fn is_ident_or_path(t: token) -> bool {
+    alt t {
+      IDENT(_, _) | INTERPOLATED(nt_path(*)) => true,
+      _ => false
+    }
+}
+
 pure fn is_plain_ident(t: token) -> bool {
     alt t { IDENT(_, false) => true, _ => false }
 }