pub fn try_decl_item<P: Parser>(p: &mut P) -> ReportedResult<Option<ast::DeclItem>> {
    let mut span = p.peek(0).span;
    Ok(match p.peek(0).value {
        // package_decl := "package" ident "is" ...
        // package_body := "package" "body" ident "is" ...
        // package_inst := "package" ident "is" "new" ...
        Keyword(Kw::Package) => {
            if p.peek(1).value == Keyword(Kw::Body) {
                Some(ast::DeclItem::PkgBody(parse_package_body(p)?))
            } else if p.peek(2).value == Keyword(Kw::Is) && p.peek(3).value == Keyword(Kw::New) {
                Some(ast::DeclItem::PkgInst(parse_package_inst(p, true)?))
            } else {
                Some(ast::DeclItem::PkgDecl(parse_package_decl(p)?))
            }
        }
        // type_decl := "type" ...
        Keyword(Kw::Type) => Some(ast::DeclItem::TypeDecl(parse_type_decl(p, true)?)),
        // subtype_decl := "subtype" ...
        Keyword(Kw::Subtype) => Some(ast::DeclItem::SubtypeDecl(parse_subtype_decl(p)?)),
        // constant_decl := "constant" ...
        // signal_decl   := "signal" ...
        // variable_decl := ("variable"|"shared") ...
        // file_decl     := "file" ...
        Keyword(Kw::Constant)
        | Keyword(Kw::Signal)
        | Keyword(Kw::Variable)
        | Keyword(Kw::Shared)
        | Keyword(Kw::File) => Some(ast::DeclItem::ObjDecl(parse_object_decl(p)?)),
        // alias_decl := "alias" ...
        Keyword(Kw::Alias) => Some(ast::DeclItem::AliasDecl(parse_alias_decl(p)?)),
        // use_clause := "use" ...
        Keyword(Kw::Use) => Some(ast::DeclItem::UseClause(span, parse_use_clause(p)?)),
        // subprog_spec := "pure"|"impure"|"procedure"|"function" ...
        Keyword(Kw::Pure)
        | Keyword(Kw::Impure)
        | Keyword(Kw::Procedure)
        | Keyword(Kw::Function) => Some(ast::DeclItem::SubprogDecl(parse_subprog_decl_item(p)?)),
        // component_decl := "component" ...
        Keyword(Kw::Component) => Some(ast::DeclItem::CompDecl(parse_component_decl(p)?)),
        // discon_spec := "disconnect" ...
        Keyword(Kw::Disconnect) => Some(ast::DeclItem::DisconDecl(parse_discon_spec(p)?)),
        // config_spec := "for" ...
        Keyword(Kw::For) => Some(ast::DeclItem::CfgSpec(parse_config_spec(p)?)),
        // attr_decl := "attribute" ...
        Keyword(Kw::Attribute) => Some(ast::DeclItem::AttrDecl(parse_attr_decl(p)?)),
        // generic_clause     := "generic" ...
        // generic_map_aspect := "generic" "map" ...
        Keyword(Kw::Generic) => {
            let pk = Spanned::new(ast::PortgenKind::Generic, p.peek(0).span);
            if p.peek(1).value == Keyword(Kw::Map) {
                let a = try_map_aspect(p, Kw::Generic)?.unwrap();
                require(p, Semicolon)?;
                span.expand(p.last_span());
                Some(ast::DeclItem::PortgenMap(span, pk, a))
            } else {
                let c = try_generic_clause(p)?.unwrap();
                span.expand(p.last_span());
                Some(ast::DeclItem::PortgenClause(span, pk, c))
            }
        }
        // port_clause     := "port" ...
        // port_map_aspect := "port" "map" ...
        Keyword(Kw::Port) => {
            let pk = Spanned::new(ast::PortgenKind::Port, p.peek(0).span);
            if p.peek(1).value == Keyword(Kw::Map) {
                let a = try_map_aspect(p, Kw::Port)?.unwrap();
                require(p, Semicolon)?;
                span.expand(p.last_span());
                Some(ast::DeclItem::PortgenMap(span, pk, a))
            } else {
                let c = try_port_clause(p)?.unwrap();
                span.expand(p.last_span());
                Some(ast::DeclItem::PortgenClause(span, pk, c))
            }
        }
        // group_decl := "group" ...
        Keyword(Kw::Group) => Some(ast::DeclItem::GroupDecl(parse_group_decl(p)?)),
        _ => None,
    })
}
/// Try to parse a declarative item. See IEEE 1076-2008 section 3.2.3.
Try to parse a declarative item.
Try to parse a declarative item .
pub fn try_decl_item<P: Parser>(p: &mut P) -> ReportedResult<Option<ast::DeclItem>> {
    let mut span = p.peek(0).span;
    Ok(match p.peek(0).value {
        // package_decl := "package" ident "is" ...
        // package_body := "package" "body" ident "is" ...
        // package_inst := "package" ident "is" "new" ...
        Keyword(Kw::Package) => {
            if p.peek(1).value == Keyword(Kw::Body) {
                Some(ast::DeclItem::PkgBody(parse_package_body(p)?))
            } else if p.peek(2).value == Keyword(Kw::Is) && p.peek(3).value == Keyword(Kw::New) {
                Some(ast::DeclItem::PkgInst(parse_package_inst(p, true)?))
            } else {
                Some(ast::DeclItem::PkgDecl(parse_package_decl(p)?))
            }
        }
        // type_decl := "type" ...
        Keyword(Kw::Type) => Some(ast::DeclItem::TypeDecl(parse_type_decl(p, true)?)),
        // subtype_decl := "subtype" ...
        Keyword(Kw::Subtype) => Some(ast::DeclItem::SubtypeDecl(parse_subtype_decl(p)?)),
        // constant_decl := "constant" ...
        // signal_decl   := "signal" ...
        // variable_decl := ("variable"|"shared") ...
        // file_decl     := "file" ...
        Keyword(Kw::Constant)
        | Keyword(Kw::Signal)
        | Keyword(Kw::Variable)
        | Keyword(Kw::Shared)
        | Keyword(Kw::File) => Some(ast::DeclItem::ObjDecl(parse_object_decl(p)?)),
        // alias_decl := "alias" ...
        Keyword(Kw::Alias) => Some(ast::DeclItem::AliasDecl(parse_alias_decl(p)?)),
        // use_clause := "use" ...
        Keyword(Kw::Use) => Some(ast::DeclItem::UseClause(span, parse_use_clause(p)?)),
        // subprog_spec := "pure"|"impure"|"procedure"|"function" ...
        Keyword(Kw::Pure)
        | Keyword(Kw::Impure)
        | Keyword(Kw::Procedure)
        | Keyword(Kw::Function) => Some(ast::DeclItem::SubprogDecl(parse_subprog_decl_item(p)?)),
        // component_decl := "component" ...
        Keyword(Kw::Component) => Some(ast::DeclItem::CompDecl(parse_component_decl(p)?)),
        // discon_spec := "disconnect" ...
        Keyword(Kw::Disconnect) => Some(ast::DeclItem::DisconDecl(parse_discon_spec(p)?)),
        // config_spec := "for" ...
        Keyword(Kw::For) => Some(ast::DeclItem::CfgSpec(parse_config_spec(p)?)),
        // attr_decl := "attribute" ...
        Keyword(Kw::Attribute) => Some(ast::DeclItem::AttrDecl(parse_attr_decl(p)?)),
        // generic_clause     := "generic" ...
        // generic_map_aspect := "generic" "map" ...
        Keyword(Kw::Generic) => {
            let pk = Spanned::new(ast::PortgenKind::Generic, p.peek(0).span);
            if p.peek(1).value == Keyword(Kw::Map) {
                let a = try_map_aspect(p, Kw::Generic)?.unwrap();
                require(p, Semicolon)?;
                span.expand(p.last_span());
                Some(ast::DeclItem::PortgenMap(span, pk, a))
            } else {
                let c = try_generic_clause(p)?.unwrap();
                span.expand(p.last_span());
                Some(ast::DeclItem::PortgenClause(span, pk, c))
            }
        }
        // port_clause     := "port" ...
        // port_map_aspect := "port" "map" ...
        Keyword(Kw::Port) => {
            let pk = Spanned::new(ast::PortgenKind::Port, p.peek(0).span);
            if p.peek(1).value == Keyword(Kw::Map) {
                let a = try_map_aspect(p, Kw::Port)?.unwrap();
                require(p, Semicolon)?;
                span.expand(p.last_span());
                Some(ast::DeclItem::PortgenMap(span, pk, a))
            } else {
                let c = try_port_clause(p)?.unwrap();
                span.expand(p.last_span());
                Some(ast::DeclItem::PortgenClause(span, pk, c))
            }
        }
        // group_decl := "group" ...
        Keyword(Kw::Group) => Some(ast::DeclItem::GroupDecl(parse_group_decl(p)?)),
        _ => None,
    })
}
pub fn try_decl_item < P : Parser > ( p : & mut P ) -> ReportedResult < Option < ast :: DeclItem > > { let mut span = p . peek ( 0 ) . span ; Ok ( match p . peek ( 0 ) . value { // package_decl := "package" ident "is" ... // package_body := "package" "body" ident "is" ... // package_inst := "package" ident "is" "new" ... Keyword ( Kw :: Package ) => { if p . peek ( 1 ) . value == Keyword ( Kw :: Body ) { Some ( ast :: DeclItem :: PkgBody ( parse_package_body ( p ) ? ) ) } else if p . peek ( 2 ) . value == Keyword ( Kw :: Is ) && p . peek ( 3 ) . value == Keyword ( Kw :: New ) { Some ( ast :: DeclItem :: PkgInst ( parse_package_inst ( p , true ) ? ) ) } else { Some ( ast :: DeclItem :: PkgDecl ( parse_package_decl ( p ) ? ) ) } } // type_decl := "type" ... Keyword ( Kw :: Type ) => Some ( ast :: DeclItem :: TypeDecl ( parse_type_decl ( p , true ) ? ) ) , // subtype_decl := "subtype" ... Keyword ( Kw :: Subtype ) => Some ( ast :: DeclItem :: SubtypeDecl ( parse_subtype_decl ( p ) ? ) ) , // constant_decl := "constant" ... // signal_decl   := "signal" ... // variable_decl := ("variable"|"shared") ... // file_decl     := "file" ... Keyword ( Kw :: Constant ) | Keyword ( Kw :: Signal ) | Keyword ( Kw :: Variable ) | Keyword ( Kw :: Shared ) | Keyword ( Kw :: File ) => Some ( ast :: DeclItem :: ObjDecl ( parse_object_decl ( p ) ? ) ) , // alias_decl := "alias" ... Keyword ( Kw :: Alias ) => Some ( ast :: DeclItem :: AliasDecl ( parse_alias_decl ( p ) ? ) ) , // use_clause := "use" ... Keyword ( Kw :: Use ) => Some ( ast :: DeclItem :: UseClause ( span , parse_use_clause ( p ) ? ) ) , // subprog_spec := "pure"|"impure"|"procedure"|"function" ... Keyword ( Kw :: Pure ) | Keyword ( Kw :: Impure ) | Keyword ( Kw :: Procedure ) | Keyword ( Kw :: Function ) => Some ( ast :: DeclItem :: SubprogDecl ( parse_subprog_decl_item ( p ) ? ) ) , // component_decl := "component" ... Keyword ( Kw :: Component ) => Some ( ast :: DeclItem :: CompDecl ( parse_component_decl ( p ) ? ) ) , // discon_spec := "disconnect" ... Keyword ( Kw :: Disconnect ) => Some ( ast :: DeclItem :: DisconDecl ( parse_discon_spec ( p ) ? ) ) , // config_spec := "for" ... Keyword ( Kw :: For ) => Some ( ast :: DeclItem :: CfgSpec ( parse_config_spec ( p ) ? ) ) , // attr_decl := "attribute" ... Keyword ( Kw :: Attribute ) => Some ( ast :: DeclItem :: AttrDecl ( parse_attr_decl ( p ) ? ) ) , // generic_clause     := "generic" ... // generic_map_aspect := "generic" "map" ... Keyword ( Kw :: Generic ) => { let pk = Spanned :: new ( ast :: PortgenKind :: Generic , p . peek ( 0 ) . span ) ; if p . peek ( 1 ) . value == Keyword ( Kw :: Map ) { let a = try_map_aspect ( p , Kw :: Generic ) ? . unwrap ( ) ; require ( p , Semicolon ) ? ; span . expand ( p . last_span ( ) ) ; Some ( ast :: DeclItem :: PortgenMap ( span , pk , a ) ) } else { let c = try_generic_clause ( p ) ? . unwrap ( ) ; span . expand ( p . last_span ( ) ) ; Some ( ast :: DeclItem :: PortgenClause ( span , pk , c ) ) } } // port_clause     := "port" ... // port_map_aspect := "port" "map" ... Keyword ( Kw :: Port ) => { let pk = Spanned :: new ( ast :: PortgenKind :: Port , p . peek ( 0 ) . span ) ; if p . peek ( 1 ) . value == Keyword ( Kw :: Map ) { let a = try_map_aspect ( p , Kw :: Port ) ? . unwrap ( ) ; require ( p , Semicolon ) ? ; span . expand ( p . last_span ( ) ) ; Some ( ast :: DeclItem :: PortgenMap ( span , pk , a ) ) } else { let c = try_port_clause ( p ) ? . unwrap ( ) ; span . expand ( p . last_span ( ) ) ; Some ( ast :: DeclItem :: PortgenClause ( span , pk , c ) ) } } // group_decl := "group" ... Keyword ( Kw :: Group ) => Some ( ast :: DeclItem :: GroupDecl ( parse_group_decl ( p ) ? ) ) , _ => None , } ) }
Try to parse a declarative item.
Try to parse a declarative item .
p
&mut P
p
&mut P