Skip to content

Commit d260d93

Browse files
committed
Add package body in declarative part
1 parent dba05d4 commit d260d93

File tree

7 files changed

+35
-6
lines changed

7 files changed

+35
-6
lines changed

vhdl_lang/src/analysis/declarative.rs

+7
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ impl Declaration {
4242
| Use(_)
4343
| Package(_)
4444
| PackageDeclaration(_)
45+
| PackageBody(_)
4546
| Configuration(_)
4647
| View(_)
4748
),
@@ -63,6 +64,7 @@ impl Declaration {
6364
| Use(_)
6465
| Package(_)
6566
| PackageDeclaration(_)
67+
| PackageBody(_)
6668
| View(_)
6769
),
6870
// LRM: package_body_declarative_item
@@ -89,6 +91,7 @@ impl Declaration {
8991
| Use(_)
9092
| Package(_)
9193
| PackageDeclaration(_)
94+
| PackageBody(_)
9295
),
9396
// LRM: package_declarative_item
9497
AnyEntKind::Design(Design::Package(..)) => matches!(
@@ -104,6 +107,7 @@ impl Declaration {
104107
| Use(_)
105108
| Package(_)
106109
| PackageDeclaration(_)
110+
| PackageBody(_)
107111
| View(_)
108112
),
109113
_ => {
@@ -613,6 +617,9 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
613617
Declaration::PackageDeclaration(..) => {
614618
// TODO
615619
}
620+
Declaration::PackageBody(..) => {
621+
// TODO
622+
}
616623
Declaration::Configuration(..) => {}
617624
Declaration::View(view) => {
618625
if let Some(view) = as_fatal(self.analyze_view_declaration(

vhdl_lang/src/analysis/names.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1846,6 +1846,7 @@ impl Declaration {
18461846
Declaration::Use(_) => "use",
18471847
Declaration::Package(_) => "package instantiation",
18481848
Declaration::PackageDeclaration(_) => "package",
1849+
Declaration::PackageBody(_) => "package body",
18491850
Declaration::Configuration(_) => "configuration",
18501851
Declaration::View(_) => "view",
18511852
}

vhdl_lang/src/ast.rs

+1
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,7 @@ pub enum Declaration {
853853
Use(UseClause),
854854
Package(PackageInstantiation),
855855
PackageDeclaration(PackageDeclaration),
856+
PackageBody(PackageBody),
856857
Configuration(ConfigurationSpecification),
857858
View(ModeViewDeclaration),
858859
}

vhdl_lang/src/ast/search.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,10 @@ impl Search for Declaration {
10841084
return_if_found!(package_instance.search(ctx, searcher)); // @TODO
10851085
}
10861086

1087+
Declaration::PackageBody(ref package_instance) => {
1088+
return_if_found!(package_instance.search(ctx, searcher)); // @TODO
1089+
}
1090+
10871091
Declaration::Configuration(_) => {
10881092
// @TODO
10891093
}

vhdl_lang/src/named_entity.rs

+1
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,7 @@ impl HasEntityId for Declaration {
632632
Declaration::SubprogramInstantiation(decl) => decl.ent_id(),
633633
Declaration::Package(pkg) => pkg.ent_id(),
634634
Declaration::PackageDeclaration(_) => None, // @TODO
635+
Declaration::PackageBody(_) => None, // @TODO
635636
Declaration::Use(_) => None,
636637
Declaration::Configuration(_) => None,
637638
Declaration::View(decl) => decl.ent_id(),

vhdl_lang/src/syntax/declarative_part.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use super::common::ParseResult;
1010
use super::component_declaration::parse_component_declaration;
1111
use super::configuration::parse_configuration_specification;
1212
use super::context::parse_use_clause;
13-
use super::design_unit::parse_package_declaration;
13+
use super::design_unit::{parse_package_body, parse_package_declaration};
1414
use super::names::parse_selected_name;
1515
use super::object_declaration::{parse_file_declaration, parse_object_declaration};
1616
use super::subprogram::parse_subprogram;
@@ -108,6 +108,8 @@ pub fn parse_declarative_part(
108108
Package => {
109109
if ctx.stream.next_kinds_are(&[Package, Identifier, Is, New]) {
110110
parse_package_instantiation(ctx).map(Declaration::Package)?
111+
} else if ctx.stream.next_kinds_are(&[Package, Body]) {
112+
parse_package_body(ctx).map(Declaration::PackageBody)?
111113
} else {
112114
parse_package_declaration(ctx).map(Declaration::PackageDeclaration)?
113115
}

vhdl_lang/src/syntax/design_unit.rs

+18-5
Original file line numberDiff line numberDiff line change
@@ -935,25 +935,38 @@ end entity y;
935935
}
936936

937937
#[test]
938-
fn parse_package_declaration_in_declarative_part() {
938+
fn parse_package_declaration_and_body_in_declarative_part() {
939939
let code = Code::new(
940940
"\
941+
entity ent is
942+
end entity;
943+
941944
architecture arch of ent is
942945
package my_pkg is
943946
-- ...
944-
end package;
947+
end my_pkg;
948+
package body my_pkg is
949+
-- ...
950+
end package body;
945951
begin
946952
end arch;
947953
",
948954
);
949955
let file = code.design_file();
950-
let (tokens, _) = &file.design_units[0];
956+
let (tokens, _) = &file.design_units[1];
951957
assert_eq!(tokens[0].kind, Architecture);
952-
assert_eq!(tokens[1].kind, Identifier);
953958
assert_eq!(tokens[5].kind, Package);
954959
assert_eq!(tokens[6].kind, Identifier);
955960
assert_eq!(tokens[7].kind, Is);
956961
assert_eq!(tokens[8].kind, End);
957-
assert_eq!(tokens[9].kind, Package);
962+
assert_eq!(tokens[9].kind, Identifier);
963+
assert_eq!(tokens[10].kind, SemiColon);
964+
assert_eq!(tokens[11].kind, Package);
965+
assert_eq!(tokens[12].kind, Body);
966+
assert_eq!(tokens[13].kind, Identifier);
967+
assert_eq!(tokens[14].kind, Is);
968+
assert_eq!(tokens[15].kind, End);
969+
assert_eq!(tokens[16].kind, Package);
970+
assert_eq!(tokens[17].kind, Body);
958971
}
959972
}

0 commit comments

Comments
 (0)