fn parse_pat_fields(&mut self) -> PResult<'a, (Vec<codemap::Spanned<ast::FieldPat>> , bool)> {
        let mut fields = Vec::new();
        let mut etc = false;
        let mut first = true;
        while self.token != token::CloseDelim(token::Brace) {
            if first {
                first = false;
            } else {
                try!(self.expect(&token::Comma));
                // accept trailing commas
                if self.check(&token::CloseDelim(token::Brace)) { break }
            }

            let lo = self.span.lo;
            let hi;

            if self.check(&token::DotDot) {
                self.bump();
                if self.token != token::CloseDelim(token::Brace) {
                    let token_str = self.this_token_to_string();
                    return Err(self.fatal(&format!("expected `{}`, found `{}`", "}",
                                       token_str)))
                }
                etc = true;
                break;
            }

            // Check if a colon exists one ahead. This means we're parsing a fieldname.
            let (subpat, fieldname, is_shorthand) = if self.look_ahead(1, |t| t == &token::Colon) {
                // Parsing a pattern of the form "fieldname: pat"
                let fieldname = try!(self.parse_ident());
                self.bump();
                let pat = try!(self.parse_pat());
                hi = pat.span.hi;
                (pat, fieldname, false)
            } else {
                // Parsing a pattern of the form "(box) (ref) (mut) fieldname"
                let is_box = self.eat_keyword(keywords::Box);
                let boxed_span_lo = self.span.lo;
                let is_ref = self.eat_keyword(keywords::Ref);
                let is_mut = self.eat_keyword(keywords::Mut);
                let fieldname = try!(self.parse_ident());
                hi = self.last_span.hi;

                let bind_type = match (is_ref, is_mut) {
                    (true, true) => BindingMode::ByRef(Mutability::Mutable),
                    (true, false) => BindingMode::ByRef(Mutability::Immutable),
                    (false, true) => BindingMode::ByValue(Mutability::Mutable),
                    (false, false) => BindingMode::ByValue(Mutability::Immutable),
                };
                let fieldpath = codemap::Spanned{span:self.last_span, node:fieldname};
                let fieldpat = P(ast::Pat{
                    id: ast::DUMMY_NODE_ID,
                    node: PatKind::Ident(bind_type, fieldpath, None),
                    span: mk_sp(boxed_span_lo, hi),
                });

                let subpat = if is_box {
                    P(ast::Pat{
                        id: ast::DUMMY_NODE_ID,
                        node: PatKind::Box(fieldpat),
                        span: mk_sp(lo, hi),
                    })
                } else {
                    fieldpat
                };
                (subpat, fieldname, true)
            };

            fields.push(codemap::Spanned { span: mk_sp(lo, hi),
                                           node: ast::FieldPat { ident: fieldname,
                                                                 pat: subpat,
                                                                 is_shorthand: is_shorthand }});
        }
        return Ok((fields, etc));
    }
/// Parse the fields of a struct-like pattern
Parse the fields of a struct-like pattern
Parse the fields of a struct - like pattern
fn parse_pat_fields(&mut self) -> PResult<'a, (Vec<codemap::Spanned<ast::FieldPat>> , bool)> {
        let mut fields = Vec::new();
        let mut etc = false;
        let mut first = true;
        while self.token != token::CloseDelim(token::Brace) {
            if first {
                first = false;
            } else {
                try!(self.expect(&token::Comma));
                // accept trailing commas
                if self.check(&token::CloseDelim(token::Brace)) { break }
            }
            let lo = self.span.lo;
            let hi;
            if self.check(&token::DotDot) {
                self.bump();
                if self.token != token::CloseDelim(token::Brace) {
                    let token_str = self.this_token_to_string();
                    return Err(self.fatal(&format!("expected `{}`, found `{}`", "}",
                                       token_str)))
                }
                etc = true;
                break;
            }
            // Check if a colon exists one ahead. This means we're parsing a fieldname.
            let (subpat, fieldname, is_shorthand) = if self.look_ahead(1, |t| t == &token::Colon) {
                // Parsing a pattern of the form "fieldname: pat"
                let fieldname = try!(self.parse_ident());
                self.bump();
                let pat = try!(self.parse_pat());
                hi = pat.span.hi;
                (pat, fieldname, false)
            } else {
                // Parsing a pattern of the form "(box) (ref) (mut) fieldname"
                let is_box = self.eat_keyword(keywords::Box);
                let boxed_span_lo = self.span.lo;
                let is_ref = self.eat_keyword(keywords::Ref);
                let is_mut = self.eat_keyword(keywords::Mut);
                let fieldname = try!(self.parse_ident());
                hi = self.last_span.hi;
                let bind_type = match (is_ref, is_mut) {
                    (true, true) => BindingMode::ByRef(Mutability::Mutable),
                    (true, false) => BindingMode::ByRef(Mutability::Immutable),
                    (false, true) => BindingMode::ByValue(Mutability::Mutable),
                    (false, false) => BindingMode::ByValue(Mutability::Immutable),
                };
                let fieldpath = codemap::Spanned{span:self.last_span, node:fieldname};
                let fieldpat = P(ast::Pat{
                    id: ast::DUMMY_NODE_ID,
                    node: PatKind::Ident(bind_type, fieldpath, None),
                    span: mk_sp(boxed_span_lo, hi),
                });
                let subpat = if is_box {
                    P(ast::Pat{
                        id: ast::DUMMY_NODE_ID,
                        node: PatKind::Box(fieldpat),
                        span: mk_sp(lo, hi),
                    })
                } else {
                    fieldpat
                };
                (subpat, fieldname, true)
            };
            fields.push(codemap::Spanned { span: mk_sp(lo, hi),
                                           node: ast::FieldPat { ident: fieldname,
                                                                 pat: subpat,
                                                                 is_shorthand: is_shorthand }});
        }
        return Ok((fields, etc));
    }
fn parse_pat_fields ( & mut self ) -> PResult < ' a , ( Vec < codemap :: Spanned < ast :: FieldPat > > , bool ) > { let mut fields = Vec :: new ( ) ; let mut etc = false ; let mut first = true ; while self . token != token :: CloseDelim ( token :: Brace ) { if first { first = false ; } else { try ! ( self expect ( token Comma ) ) ; // accept trailing commas if self . check ( & token :: CloseDelim ( token :: Brace ) ) { break } } let lo = self . span . lo ; let hi ; if self . check ( & token :: DotDot ) { self . bump ( ) ; if self . token != token :: CloseDelim ( token :: Brace ) { let token_str = self . this_token_to_string ( ) ; return Err ( self . fatal ( & format ! ( " " " " token_str ) ) ) } etc = true ; break ; } // Check if a colon exists one ahead. This means we're parsing a fieldname. let ( subpat , fieldname , is_shorthand ) = if self . look_ahead ( 1 , | t | t == & token :: Colon ) { // Parsing a pattern of the form "fieldname: pat" let fieldname = try ! ( self parse_ident ( ) ) ; self . bump ( ) ; let pat = try ! ( self parse_pat ( ) ) ; hi = pat . span . hi ; ( pat , fieldname , false ) } else { // Parsing a pattern of the form "(box) (ref) (mut) fieldname" let is_box = self . eat_keyword ( keywords :: Box ) ; let boxed_span_lo = self . span . lo ; let is_ref = self . eat_keyword ( keywords :: Ref ) ; let is_mut = self . eat_keyword ( keywords :: Mut ) ; let fieldname = try ! ( self parse_ident ( ) ) ; hi = self . last_span . hi ; let bind_type = match ( is_ref , is_mut ) { ( true , true ) => BindingMode :: ByRef ( Mutability :: Mutable ) , ( true , false ) => BindingMode :: ByRef ( Mutability :: Immutable ) , ( false , true ) => BindingMode :: ByValue ( Mutability :: Mutable ) , ( false , false ) => BindingMode :: ByValue ( Mutability :: Immutable ) , } ; let fieldpath = codemap :: Spanned { span : self . last_span , node : fieldname } ; let fieldpat = P ( ast :: Pat { id : ast :: DUMMY_NODE_ID , node : PatKind :: Ident ( bind_type , fieldpath , None ) , span : mk_sp ( boxed_span_lo , hi ) , } ) ; let subpat = if is_box { P ( ast :: Pat { id : ast :: DUMMY_NODE_ID , node : PatKind :: Box ( fieldpat ) , span : mk_sp ( lo , hi ) , } ) } else { fieldpat } ; ( subpat , fieldname , true ) } ; fields . push ( codemap :: Spanned { span : mk_sp ( lo , hi ) , node : ast :: FieldPat { ident : fieldname , pat : subpat , is_shorthand : is_shorthand } } ) ; } return Ok ( ( fields , etc ) ) ; }
Parse the fields of a struct-like pattern
Parse the fields of a struct - like pattern
&mut self
&mut self