summary refs log tree commit diff
path: root/src/libsyntax/parse
diff options
context:
space:
mode:
authorJames Miller <james@aatch.net>2013-07-05 22:15:21 +1200
committerJames Miller <bladeon@gmail.com>2013-07-07 22:51:09 +1200
commitcd1b6c897911c91167c5a3c5e3c2fa0d9334ad45 (patch)
tree547f2b0e84098a4aeea47dc30fa08b70541f30f6 /src/libsyntax/parse
parenta69eb952336bb3d483dd046373daa8e3948390a7 (diff)
downloadrust-cd1b6c897911c91167c5a3c5e3c2fa0d9334ad45.tar.gz
rust-cd1b6c897911c91167c5a3c5e3c2fa0d9334ad45.zip
De-managed ast::Path
Diffstat (limited to 'src/libsyntax/parse')
-rw-r--r--src/libsyntax/parse/mod.rs20
-rw-r--r--src/libsyntax/parse/parser.rs60
-rw-r--r--src/libsyntax/parse/token.rs2
3 files changed, 45 insertions, 37 deletions
diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs
index 6dd8d4880e3..634efbe165d 100644
--- a/src/libsyntax/parse/mod.rs
+++ b/src/libsyntax/parse/mod.rs
@@ -366,7 +366,7 @@ mod test {
     #[test] fn path_exprs_1 () {
         assert_eq!(string_to_expr(@"a"),
                    @ast::expr{id:1,
-                              node:ast::expr_path(@ast::Path {span:sp(0,1),
+                              node:ast::expr_path(ast::Path {span:sp(0,1),
                                                               global:false,
                                                               idents:~[str_to_ident("a")],
                                                               rp:None,
@@ -378,7 +378,7 @@ mod test {
         assert_eq!(string_to_expr(@"::a::b"),
                    @ast::expr{id:1,
                                node:ast::expr_path(
-                                   @ast::Path {span:sp(0,6),
+                                    ast::Path {span:sp(0,6),
                                                global:true,
                                                idents:strs_to_idents(~["a","b"]),
                                                rp:None,
@@ -428,7 +428,7 @@ mod test {
                               node:ast::expr_ret(
                                   Some(@ast::expr{id:1,
                                                   node:ast::expr_path(
-                                                      @ast::Path{span:sp(7,8),
+                                                       ast::Path{span:sp(7,8),
                                                                  global:false,
                                                                  idents:~[str_to_ident("d")],
                                                                  rp:None,
@@ -444,7 +444,7 @@ mod test {
                        node: ast::stmt_expr(@ast::expr{
                            id: 1,
                            node: ast::expr_path(
-                               @ast::Path{
+                                ast::Path{
                                    span:sp(0,1),
                                    global:false,
                                    idents:~[str_to_ident("b")],
@@ -465,7 +465,7 @@ mod test {
         assert_eq!(parser.parse_pat(),
                    @ast::pat{id:1, // fixme
                              node: ast::pat_ident(ast::bind_infer,
-                                                  @ast::Path{
+                                                   ast::Path{
                                                       span:sp(0,1),
                                                       global:false,
                                                       idents:~[str_to_ident("b")],
@@ -483,7 +483,7 @@ mod test {
                    ast::arg{
                        is_mutbl: false,
                        ty: @ast::Ty{id:3, // fixme
-                                    node: ast::ty_path(@ast::Path{
+                                    node: ast::ty_path(ast::Path{
                                         span:sp(4,4), // this is bizarre...
                                         // check this in the original parser?
                                         global:false,
@@ -494,7 +494,7 @@ mod test {
                                     span:sp(4,7)},
                        pat: @ast::pat{id:1,
                                       node: ast::pat_ident(ast::bind_infer,
-                                                           @ast::Path{
+                                                            ast::Path{
                                                                span:sp(0,1),
                                                                global:false,
                                                                idents:~[str_to_ident("b")],
@@ -520,7 +520,7 @@ mod test {
                                 inputs: ~[ast::arg{
                                     is_mutbl: false,
                                     ty: @ast::Ty{id:3, // fixme
-                                                node: ast::ty_path(@ast::Path{
+                                                node: ast::ty_path(ast::Path{
                                         span:sp(10,13),
                                         global:false,
                                         idents:~[str_to_ident("int")],
@@ -531,7 +531,7 @@ mod test {
                                     pat: @ast::pat{id:1, // fixme
                                                    node: ast::pat_ident(
                                                        ast::bind_infer,
-                                                       @ast::Path{
+                                                       ast::Path{
                                                            span:sp(6,7),
                                                            global:false,
                                                            idents:~[str_to_ident("b")],
@@ -561,7 +561,7 @@ mod test {
                                                 node: ast::stmt_semi(@ast::expr{
                                                     id: 6,
                                                     node: ast::expr_path(
-                                                        @ast::Path{
+                                                          ast::Path{
                                                             span:sp(17,18),
                                                             global:false,
                                                             idents:~[str_to_ident("b")],
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 35c558c5296..00386f611b1 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -130,20 +130,28 @@ The important thing is to make sure that lookahead doesn't balk
 at INTERPOLATED tokens */
 macro_rules! maybe_whole_expr (
     ($p:expr) => (
-        match *($p).token {
-            INTERPOLATED(token::nt_expr(e)) => {
-                $p.bump();
-                return e;
-            }
-            INTERPOLATED(token::nt_path(pt)) => {
-                $p.bump();
-                return $p.mk_expr(
-                    ($p).span.lo,
-                    ($p).span.hi,
-                    expr_path(pt)
-                );
+        {
+            // This horrible convolution is brought to you by
+            // @mut, have a terrible day
+            let ret = match *($p).token {
+                INTERPOLATED(token::nt_expr(e)) => {
+                    Some(e)
+                }
+                INTERPOLATED(token::nt_path(ref pt)) => {
+                    Some($p.mk_expr(
+                        ($p).span.lo,
+                        ($p).span.hi,
+                        expr_path(/* bad */ copy *pt)))
+                }
+                _ => None
+            };
+            match ret {
+                Some(e) => {
+                    $p.bump();
+                    return e;
+                }
+                None => ()
             }
-            _ => ()
         }
     )
 )
@@ -1218,10 +1226,10 @@ impl Parser {
     }
 
     // parse a path that doesn't have type parameters attached
-    pub fn parse_path_without_tps(&self) -> @ast::Path {
+    pub fn parse_path_without_tps(&self) -> ast::Path {
         maybe_whole!(self, nt_path);
         let (ids,is_global,sp) = self.parse_path();
-        @ast::Path { span: sp,
+        ast::Path { span: sp,
                      global: is_global,
                      idents: ids,
                      rp: None,
@@ -1229,7 +1237,7 @@ impl Parser {
     }
 
     pub fn parse_bounded_path_with_tps(&self, colons: bool,
-                                        before_tps: Option<&fn()>) -> @ast::Path {
+                                        before_tps: Option<&fn()>) -> ast::Path {
         debug!("parse_path_with_tps(colons=%b)", colons);
 
         maybe_whole!(self, nt_path);
@@ -1288,22 +1296,22 @@ impl Parser {
             }
         };
 
-        @ast::Path { span: mk_sp(lo, hi),
+        ast::Path { span: mk_sp(lo, hi),
                      rp: rp,
                      types: tps,
-                     .. copy *path }
+                     .. path }
     }
 
     // parse a path optionally with type parameters. If 'colons'
     // is true, then type parameters must be preceded by colons,
     // as in a::t::<t1,t2>
-    pub fn parse_path_with_tps(&self, colons: bool) -> @ast::Path {
+    pub fn parse_path_with_tps(&self, colons: bool) -> ast::Path {
         self.parse_bounded_path_with_tps(colons, None)
     }
 
     // Like the above, but can also parse kind bounds in the case of a
     // path to be used as a type that might be a trait.
-    pub fn parse_type_path(&self) -> (@ast::Path, Option<OptVec<TyParamBound>>) {
+    pub fn parse_type_path(&self) -> (ast::Path, Option<OptVec<TyParamBound>>) {
         let mut bounds = None;
         let path = self.parse_bounded_path_with_tps(false, Some(|| {
             // Note: this closure might not even get called in the case of a
@@ -3557,9 +3565,9 @@ impl Parser {
         let opt_trait = if could_be_trait && self.eat_keyword(keywords::For) {
             // New-style trait. Reinterpret the type as a trait.
             let opt_trait_ref = match ty.node {
-                ty_path(path, @None, node_id) => {
+                ty_path(ref path, @None, node_id) => {
                     Some(@trait_ref {
-                        path: path,
+                        path: /* bad */ copy *path,
                         ref_id: node_id
                     })
                 }
@@ -4558,7 +4566,7 @@ impl Parser {
                 let id = self.parse_ident();
                 path.push(id);
             }
-            let path = @ast::Path { span: mk_sp(lo, self.span.hi),
+            let path = ast::Path { span: mk_sp(lo, self.span.hi),
                                     global: false,
                                     idents: path,
                                     rp: None,
@@ -4588,7 +4596,7 @@ impl Parser {
                         seq_sep_trailing_allowed(token::COMMA),
                         |p| p.parse_path_list_ident()
                     );
-                    let path = @ast::Path { span: mk_sp(lo, self.span.hi),
+                    let path = ast::Path { span: mk_sp(lo, self.span.hi),
                                             global: false,
                                             idents: path,
                                             rp: None,
@@ -4600,7 +4608,7 @@ impl Parser {
                   // foo::bar::*
                   token::BINOP(token::STAR) => {
                     self.bump();
-                    let path = @ast::Path { span: mk_sp(lo, self.span.hi),
+                    let path = ast::Path { span: mk_sp(lo, self.span.hi),
                                             global: false,
                                             idents: path,
                                             rp: None,
@@ -4616,7 +4624,7 @@ impl Parser {
           _ => ()
         }
         let last = path[path.len() - 1u];
-        let path = @ast::Path { span: mk_sp(lo, self.span.hi),
+        let path = ast::Path { span: mk_sp(lo, self.span.hi),
                                 global: false,
                                 idents: path,
                                 rp: None,
diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs
index a50fa416832..0264903076b 100644
--- a/src/libsyntax/parse/token.rs
+++ b/src/libsyntax/parse/token.rs
@@ -106,7 +106,7 @@ pub enum nonterminal {
     nt_expr(@ast::expr),
     nt_ty(  @ast::Ty),
     nt_ident(ast::ident, bool),
-    nt_path(@ast::Path),
+    nt_path( ast::Path),
     nt_tt(  @ast::token_tree), //needs @ed to break a circularity
     nt_matchers(~[ast::matcher])
 }