Skip to content

Commit

Permalink
Add package body in declarative part
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris44442 committed May 30, 2024
1 parent dba05d4 commit ee9a1af
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 6 deletions.
7 changes: 7 additions & 0 deletions vhdl_lang/src/analysis/declarative.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ impl Declaration {
| Use(_)
| Package(_)
| PackageDeclaration(_)
| PackageBody(_)
| Configuration(_)
| View(_)
),
Expand All @@ -63,6 +64,7 @@ impl Declaration {
| Use(_)
| Package(_)
| PackageDeclaration(_)
| PackageBody(_)
| View(_)
),
// LRM: package_body_declarative_item
Expand All @@ -89,6 +91,7 @@ impl Declaration {
| Use(_)
| Package(_)
| PackageDeclaration(_)
| PackageBody(_)
),
// LRM: package_declarative_item
AnyEntKind::Design(Design::Package(..)) => matches!(
Expand All @@ -104,6 +107,7 @@ impl Declaration {
| Use(_)
| Package(_)
| PackageDeclaration(_)
| PackageBody(_)
| View(_)
),
_ => {
Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions vhdl_lang/src/analysis/names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
Expand Down
1 change: 1 addition & 0 deletions vhdl_lang/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,7 @@ pub enum Declaration {
Use(UseClause),
Package(PackageInstantiation),
PackageDeclaration(PackageDeclaration),
PackageBody(PackageBody),
Configuration(ConfigurationSpecification),
View(ModeViewDeclaration),
}
Expand Down
4 changes: 4 additions & 0 deletions vhdl_lang/src/ast/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions vhdl_lang/src/named_entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
5 changes: 4 additions & 1 deletion vhdl_lang/src/syntax/declarative_part.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)?
Expand Down
23 changes: 18 additions & 5 deletions vhdl_lang/src/syntax/design_unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit ee9a1af

Please sign in to comment.