Skip to content

Commit

Permalink
Add package declaration in declarative part
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris44442 committed May 30, 2024
1 parent 805ab71 commit dba05d4
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 1 deletion.
7 changes: 7 additions & 0 deletions vhdl_lang/src/analysis/declarative.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ impl Declaration {
| SubprogramBody(_)
| Use(_)
| Package(_)
| PackageDeclaration(_)
| Configuration(_)
| View(_)
),
Expand All @@ -61,6 +62,7 @@ impl Declaration {
| SubprogramBody(_)
| Use(_)
| Package(_)
| PackageDeclaration(_)
| View(_)
),
// LRM: package_body_declarative_item
Expand All @@ -86,6 +88,7 @@ impl Declaration {
| SubprogramBody(_)
| Use(_)
| Package(_)
| PackageDeclaration(_)
),
// LRM: package_declarative_item
AnyEntKind::Design(Design::Package(..)) => matches!(
Expand All @@ -100,6 +103,7 @@ impl Declaration {
| SubprogramInstantiation(_)
| Use(_)
| Package(_)
| PackageDeclaration(_)
| View(_)
),
_ => {
Expand Down Expand Up @@ -606,6 +610,9 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
scope.add(ent, diagnostics);
}
}
Declaration::PackageDeclaration(..) => {
// 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 @@ -1845,6 +1845,7 @@ impl Declaration {
Declaration::SubprogramBody(_) => "subprogram body",
Declaration::Use(_) => "use",
Declaration::Package(_) => "package instantiation",
Declaration::PackageDeclaration(_) => "package",
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 @@ -852,6 +852,7 @@ pub enum Declaration {
SubprogramBody(SubprogramBody),
Use(UseClause),
Package(PackageInstantiation),
PackageDeclaration(PackageDeclaration),
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 @@ -1080,6 +1080,10 @@ impl Search for Declaration {
return_if_found!(package_instance.search(ctx, searcher));
}

Declaration::PackageDeclaration(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 @@ -631,6 +631,7 @@ impl HasEntityId for Declaration {
Declaration::SubprogramBody(body) => body.ent_id(),
Declaration::SubprogramInstantiation(decl) => decl.ent_id(),
Declaration::Package(pkg) => pkg.ent_id(),
Declaration::PackageDeclaration(_) => None, // @TODO
Declaration::Use(_) => None,
Declaration::Configuration(_) => None,
Declaration::View(decl) => decl.ent_id(),
Expand Down
9 changes: 8 additions & 1 deletion vhdl_lang/src/syntax/declarative_part.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +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::names::parse_selected_name;
use super::object_declaration::{parse_file_declaration, parse_object_declaration};
use super::subprogram::parse_subprogram;
Expand Down Expand Up @@ -104,7 +105,13 @@ pub fn parse_declarative_part(
Type | Subtype => parse_type_declaration(ctx).map(Declaration::Type)?,
Component => parse_component_declaration(ctx).map(Declaration::Component)?,
Impure | Pure | Function | Procedure => parse_subprogram(ctx)?,
Package => parse_package_instantiation(ctx).map(Declaration::Package)?,
Package => {
if ctx.stream.next_kinds_are(&[Package, Identifier, Is, New]) {
parse_package_instantiation(ctx).map(Declaration::Package)?
} else {
parse_package_declaration(ctx).map(Declaration::PackageDeclaration)?
}
}
For => {
parse_configuration_specification(ctx).map(Declaration::Configuration)?
}
Expand Down
23 changes: 23 additions & 0 deletions vhdl_lang/src/syntax/design_unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -933,4 +933,27 @@ end entity y;
assert_eq!(tok.kind, Context);
assert_eq!(tok.pos, code.s1("context").pos());
}

#[test]
fn parse_package_declaration_in_declarative_part() {
let code = Code::new(
"\
architecture arch of ent is
package my_pkg is
-- ...
end package;
begin
end arch;
",
);
let file = code.design_file();
let (tokens, _) = &file.design_units[0];
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);
}
}

0 comments on commit dba05d4

Please sign in to comment.