/// Parse a single design unit. IEEE 1076-2008 section 13.1.
///
/// ```text
/// design_unit := {context_item} library_unit
/// library_unit
///   := entity_decl
///   := config_decl
///   := package_decl
///   := package_inst_decl
///   := context_decl
///   := arch_body
///   := package_body
/// ```
Parse a single design unit.
Parse a single design unit .
pub fn parse_design_unit<P: Parser>(p: &mut P) -> RecoveredResult<ast::DesignUnit> {
    let context = repeat(p, try_context_item)?;
    let Spanned {
        value: tkn,
        span: sp,
    } = p.peek(0);
    match match tkn {
        Keyword(Kw::Entity) => parse_entity_decl(p).map(|d| ast::DesignUnitData::EntityDecl(d)),
        Keyword(Kw::Configuration) => parse_config_decl(p).map(|d| ast::DesignUnitData::CfgDecl(d)),
        Keyword(Kw::Package) => {
            if p.peek(1).value == Keyword(Kw::Body) {
                parse_package_body(p).map(|d| ast::DesignUnitData::PkgBody(d))
            } else {
                parse_package_decl(p).map(|d| ast::DesignUnitData::PkgDecl(d))
            }
        }
        Keyword(Kw::Context) => parse_context_decl(p).map(|d| ast::DesignUnitData::CtxDecl(d)),
        Keyword(Kw::Architecture) => parse_arch_body(p).map(|d| ast::DesignUnitData::ArchBody(d)),
        tkn => {
            p.emit(
                DiagBuilder2::error(format!(
                    "Expected a primary or secondary unit, instead found {}",
                    tkn
                ))
                .span(sp)
                .add_note("`entity`, `configuration`, `package`, and `context` are primary units")
                .add_note("`architecture` and `package body` are secondary units"),
            );
            Err(Reported)
        }
    } {
        Ok(x) => Ok(ast::DesignUnit {
            id: Default::default(),
            ctx: context,
            data: x,
        }),
        Err(Reported) => {
            recover(p, &[Keyword(Kw::End)], true);
            recover(p, &[Semicolon], true);
            recover(
                p,
                &[
                    Keyword(Kw::Entity),
                    Keyword(Kw::Configuration),
                    Keyword(Kw::Package),
                    Keyword(Kw::Context),
                    Keyword(Kw::Architecture),
                ],
                false,
            );
            Err(Recovered)
        }
    }
}
pub fn parse_design_unit < P : Parser > ( p : & mut P ) -> RecoveredResult < ast :: DesignUnit > { let context = repeat ( p , try_context_item ) ? ; let Spanned { value : tkn , span : sp , } = p . peek ( 0 ) ; match match tkn { Keyword ( Kw :: Entity ) => parse_entity_decl ( p ) . map ( | d | ast :: DesignUnitData :: EntityDecl ( d ) ) , Keyword ( Kw :: Configuration ) => parse_config_decl ( p ) . map ( | d | ast :: DesignUnitData :: CfgDecl ( d ) ) , Keyword ( Kw :: Package ) => { if p . peek ( 1 ) . value == Keyword ( Kw :: Body ) { parse_package_body ( p ) . map ( | d | ast :: DesignUnitData :: PkgBody ( d ) ) } else { parse_package_decl ( p ) . map ( | d | ast :: DesignUnitData :: PkgDecl ( d ) ) } } Keyword ( Kw :: Context ) => parse_context_decl ( p ) . map ( | d | ast :: DesignUnitData :: CtxDecl ( d ) ) , Keyword ( Kw :: Architecture ) => parse_arch_body ( p ) . map ( | d | ast :: DesignUnitData :: ArchBody ( d ) ) , tkn => { p . emit ( DiagBuilder2 :: error ( format ! ( " " tkn ) ) . span ( sp ) . add_note ( " " ) . add_note ( " " ) , ) ; Err ( Reported ) } } { Ok ( x ) => Ok ( ast :: DesignUnit { id : Default :: default ( ) , ctx : context , data : x , } ) , Err ( Reported ) => { recover ( p , & [ Keyword ( Kw :: End ) ] , true ) ; recover ( p , & [ Semicolon ] , true ) ; recover ( p , & [ Keyword ( Kw :: Entity ) , Keyword ( Kw :: Configuration ) , Keyword ( Kw :: Package ) , Keyword ( Kw :: Context ) , Keyword ( Kw :: Architecture ) , ] , false , ) ; Err ( Recovered ) } } }
Parse a single design unit.
Parse a single design unit .
p
&mut P