Skip to content

Commit

Permalink
Merge pull request #288 from Schottkyc137/vhdl2019-simple
Browse files Browse the repository at this point in the history
Add simple VHDL2019 constructs
  • Loading branch information
Schottkyc137 authored Apr 14, 2024
2 parents 5af68f9 + f878894 commit 3d1db16
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 deletions.
38 changes: 37 additions & 1 deletion vhdl_lang/src/syntax/component_declaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::ast::WithDecl;
use crate::ast::{ComponentDeclaration, InterfaceDeclaration};
use crate::data::Diagnostic;
use vhdl_lang::syntax::parser::ParsingContext;
use vhdl_lang::VHDLStandard::VHDL2019;

pub fn parse_optional_generic_list(
ctx: &mut ParsingContext<'_>,
Expand Down Expand Up @@ -81,7 +82,11 @@ pub fn parse_component_declaration(
let generic_list = parse_optional_generic_list(ctx)?;
let port_list = parse_optional_port_list(ctx)?;
ctx.stream.expect_kind(End)?;
ctx.stream.expect_kind(Component)?;
if ctx.standard < VHDL2019 {
ctx.stream.expect_kind(Component)?;
} else {
ctx.stream.pop_if_kind(Component);
}
let end_ident = ctx.stream.pop_optional_ident();
let end_token = ctx.stream.expect_kind(SemiColon)?;

Expand All @@ -101,6 +106,7 @@ mod tests {
use crate::ast::Ident;
use crate::syntax::test::Code;
use crate::SrcPos;
use crate::VHDLStandard::VHDL2019;

fn to_component(
ident: WithDecl<Ident>,
Expand Down Expand Up @@ -296,4 +302,34 @@ end
);
assert_eq!(result, Ok(Some(vec![code.s1("foo : natural").port()])),);
}

#[test]
pub fn component_vhdl2019() {
Code::with_standard(
"\
component foo is
end;
",
VHDL2019,
)
.parse_ok_no_diagnostics(parse_component_declaration);

Code::with_standard(
"\
component foo is
end component;
",
VHDL2019,
)
.parse_ok_no_diagnostics(parse_component_declaration);

Code::with_standard(
"\
component foo is
end component foo;
",
VHDL2019,
)
.parse_ok_no_diagnostics(parse_component_declaration);
}
}
22 changes: 20 additions & 2 deletions vhdl_lang/src/syntax/interface_declaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::ast::*;
use crate::data::*;
use vhdl_lang::data::error_codes::ErrorCode;
use vhdl_lang::syntax::parser::ParsingContext;
use vhdl_lang::VHDLStandard::VHDL2019;

pub(crate) fn parse_optional_mode(
ctx: &mut ParsingContext<'_>,
Expand Down Expand Up @@ -304,8 +305,8 @@ fn parse_semicolon_separator(ctx: &mut ParsingContext<'_>) -> ParseResult<()> {
peek_token!(
ctx.stream, token,
SemiColon => {
ctx.stream.skip();
if ctx.stream.next_kind_is(RightPar) {
ctx.stream.skip();
if ctx.stream.next_kind_is(RightPar) && ctx.standard < VHDL2019 {
return Err(Diagnostic::syntax_error(&token.pos,
format!("Last interface element may not end with {}",
kinds_str(&[SemiColon]))));
Expand Down Expand Up @@ -777,6 +778,23 @@ bar : natural)",
"Last interface element may not end with ';'"
)]
);

let code = Code::with_standard(
"\
(constant foo : std_logic;
bar : natural;
)",
VHDL2019,
);
let result = code.parse_ok_no_diagnostics(parse_generic_interface_list);

assert_eq!(
result,
vec![
code.s1("constant foo : std_logic").generic(),
code.s1("bar : natural").generic()
]
);
}

#[test]
Expand Down

0 comments on commit 3d1db16

Please sign in to comment.