diff --git a/vhdl_lang/src/analysis/declarative.rs b/vhdl_lang/src/analysis/declarative.rs index 0fcc3285..b89e63ae 100644 --- a/vhdl_lang/src/analysis/declarative.rs +++ b/vhdl_lang/src/analysis/declarative.rs @@ -42,6 +42,7 @@ impl Declaration { | Use(_) | Package(_) | PackageDeclaration(_) + | PackageBody(_) | Configuration(_) | View(_) ), @@ -63,6 +64,7 @@ impl Declaration { | Use(_) | Package(_) | PackageDeclaration(_) + | PackageBody(_) | View(_) ), // LRM: package_body_declarative_item @@ -89,6 +91,7 @@ impl Declaration { | Use(_) | Package(_) | PackageDeclaration(_) + | PackageBody(_) ), // LRM: package_declarative_item AnyEntKind::Design(Design::Package(..)) => matches!( @@ -104,6 +107,7 @@ impl Declaration { | Use(_) | Package(_) | PackageDeclaration(_) + | PackageBody(_) | View(_) ), _ => { @@ -613,6 +617,9 @@ impl<'a, 't> AnalyzeContext<'a, 't> { Declaration::PackageDeclaration(..) => { // TODO } + Declaration::PackageBody(..) => { + // TODO + } Declaration::Configuration(..) => {} Declaration::View(view) => { if let Some(view) = as_fatal(self.analyze_view_declaration( diff --git a/vhdl_lang/src/analysis/names.rs b/vhdl_lang/src/analysis/names.rs index 649a237e..e90b1e01 100644 --- a/vhdl_lang/src/analysis/names.rs +++ b/vhdl_lang/src/analysis/names.rs @@ -1846,6 +1846,7 @@ impl Declaration { Declaration::Use(_) => "use", Declaration::Package(_) => "package instantiation", Declaration::PackageDeclaration(_) => "package", + Declaration::PackageBody(_) => "package body", Declaration::Configuration(_) => "configuration", Declaration::View(_) => "view", } diff --git a/vhdl_lang/src/ast.rs b/vhdl_lang/src/ast.rs index da0c1a22..7ca92f5f 100644 --- a/vhdl_lang/src/ast.rs +++ b/vhdl_lang/src/ast.rs @@ -853,6 +853,7 @@ pub enum Declaration { Use(UseClause), Package(PackageInstantiation), PackageDeclaration(PackageDeclaration), + PackageBody(PackageBody), Configuration(ConfigurationSpecification), View(ModeViewDeclaration), } diff --git a/vhdl_lang/src/ast/search.rs b/vhdl_lang/src/ast/search.rs index 837fc125..eae3d784 100644 --- a/vhdl_lang/src/ast/search.rs +++ b/vhdl_lang/src/ast/search.rs @@ -1084,6 +1084,10 @@ impl Search for Declaration { return_if_found!(package_instance.search(ctx, searcher)); // @TODO } + Declaration::PackageBody(ref package_instance) => { + return_if_found!(package_instance.search(ctx, searcher)); // @TODO + } + Declaration::Configuration(_) => { // @TODO } diff --git a/vhdl_lang/src/named_entity.rs b/vhdl_lang/src/named_entity.rs index a9cbe28a..0e74d9a7 100644 --- a/vhdl_lang/src/named_entity.rs +++ b/vhdl_lang/src/named_entity.rs @@ -632,6 +632,7 @@ impl HasEntityId for Declaration { Declaration::SubprogramInstantiation(decl) => decl.ent_id(), Declaration::Package(pkg) => pkg.ent_id(), Declaration::PackageDeclaration(_) => None, // @TODO + Declaration::PackageBody(_) => None, // @TODO Declaration::Use(_) => None, Declaration::Configuration(_) => None, Declaration::View(decl) => decl.ent_id(), diff --git a/vhdl_lang/src/syntax/declarative_part.rs b/vhdl_lang/src/syntax/declarative_part.rs index a7c9b884..179ec716 100644 --- a/vhdl_lang/src/syntax/declarative_part.rs +++ b/vhdl_lang/src/syntax/declarative_part.rs @@ -10,7 +10,7 @@ use super::common::ParseResult; use super::component_declaration::parse_component_declaration; use super::configuration::parse_configuration_specification; use super::context::parse_use_clause; -use super::design_unit::parse_package_declaration; +use super::design_unit::{parse_package_declaration, parse_package_body}; use super::names::parse_selected_name; use super::object_declaration::{parse_file_declaration, parse_object_declaration}; use super::subprogram::parse_subprogram; @@ -108,9 +108,12 @@ pub fn parse_declarative_part( Package => { if ctx.stream.next_kinds_are(&[Package, Identifier, Is, New]) { parse_package_instantiation(ctx).map(Declaration::Package)? + } else if ctx.stream.next_kinds_are(&[Package, Body]){ + parse_package_body(ctx).map(Declaration::PackageBody)? } else { parse_package_declaration(ctx).map(Declaration::PackageDeclaration)? } + } For => { parse_configuration_specification(ctx).map(Declaration::Configuration)? diff --git a/vhdl_lang/src/syntax/design_unit.rs b/vhdl_lang/src/syntax/design_unit.rs index a7c04f16..43c72c59 100644 --- a/vhdl_lang/src/syntax/design_unit.rs +++ b/vhdl_lang/src/syntax/design_unit.rs @@ -935,25 +935,38 @@ end entity y; } #[test] - fn parse_package_declaration_in_declarative_part() { + fn parse_package_declaration_and_body_in_declarative_part() { let code = Code::new( "\ +entity ent is +end entity; + architecture arch of ent is package my_pkg is -- ... - end package; + end my_pkg; + package body my_pkg is + -- ... + end package body; begin end arch; ", ); let file = code.design_file(); - let (tokens, _) = &file.design_units[0]; + let (tokens, _) = &file.design_units[1]; assert_eq!(tokens[0].kind, Architecture); - assert_eq!(tokens[1].kind, Identifier); assert_eq!(tokens[5].kind, Package); assert_eq!(tokens[6].kind, Identifier); assert_eq!(tokens[7].kind, Is); assert_eq!(tokens[8].kind, End); - assert_eq!(tokens[9].kind, Package); + assert_eq!(tokens[9].kind, Identifier); + assert_eq!(tokens[10].kind, SemiColon); + assert_eq!(tokens[11].kind, Package); + assert_eq!(tokens[12].kind, Body); + assert_eq!(tokens[13].kind, Identifier); + assert_eq!(tokens[14].kind, Is); + assert_eq!(tokens[15].kind, End); + assert_eq!(tokens[16].kind, Package); + assert_eq!(tokens[17].kind, Body); } }