Skip to content

Commit 3d1db16

Browse files
authored
Merge pull request #288 from Schottkyc137/vhdl2019-simple
Add simple VHDL2019 constructs
2 parents 5af68f9 + f878894 commit 3d1db16

File tree

2 files changed

+57
-3
lines changed

2 files changed

+57
-3
lines changed

vhdl_lang/src/syntax/component_declaration.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crate::ast::WithDecl;
1111
use crate::ast::{ComponentDeclaration, InterfaceDeclaration};
1212
use crate::data::Diagnostic;
1313
use vhdl_lang::syntax::parser::ParsingContext;
14+
use vhdl_lang::VHDLStandard::VHDL2019;
1415

1516
pub fn parse_optional_generic_list(
1617
ctx: &mut ParsingContext<'_>,
@@ -81,7 +82,11 @@ pub fn parse_component_declaration(
8182
let generic_list = parse_optional_generic_list(ctx)?;
8283
let port_list = parse_optional_port_list(ctx)?;
8384
ctx.stream.expect_kind(End)?;
84-
ctx.stream.expect_kind(Component)?;
85+
if ctx.standard < VHDL2019 {
86+
ctx.stream.expect_kind(Component)?;
87+
} else {
88+
ctx.stream.pop_if_kind(Component);
89+
}
8590
let end_ident = ctx.stream.pop_optional_ident();
8691
let end_token = ctx.stream.expect_kind(SemiColon)?;
8792

@@ -101,6 +106,7 @@ mod tests {
101106
use crate::ast::Ident;
102107
use crate::syntax::test::Code;
103108
use crate::SrcPos;
109+
use crate::VHDLStandard::VHDL2019;
104110

105111
fn to_component(
106112
ident: WithDecl<Ident>,
@@ -296,4 +302,34 @@ end
296302
);
297303
assert_eq!(result, Ok(Some(vec![code.s1("foo : natural").port()])),);
298304
}
305+
306+
#[test]
307+
pub fn component_vhdl2019() {
308+
Code::with_standard(
309+
"\
310+
component foo is
311+
end;
312+
",
313+
VHDL2019,
314+
)
315+
.parse_ok_no_diagnostics(parse_component_declaration);
316+
317+
Code::with_standard(
318+
"\
319+
component foo is
320+
end component;
321+
",
322+
VHDL2019,
323+
)
324+
.parse_ok_no_diagnostics(parse_component_declaration);
325+
326+
Code::with_standard(
327+
"\
328+
component foo is
329+
end component foo;
330+
",
331+
VHDL2019,
332+
)
333+
.parse_ok_no_diagnostics(parse_component_declaration);
334+
}
299335
}

vhdl_lang/src/syntax/interface_declaration.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use crate::ast::*;
1717
use crate::data::*;
1818
use vhdl_lang::data::error_codes::ErrorCode;
1919
use vhdl_lang::syntax::parser::ParsingContext;
20+
use vhdl_lang::VHDLStandard::VHDL2019;
2021

2122
pub(crate) fn parse_optional_mode(
2223
ctx: &mut ParsingContext<'_>,
@@ -304,8 +305,8 @@ fn parse_semicolon_separator(ctx: &mut ParsingContext<'_>) -> ParseResult<()> {
304305
peek_token!(
305306
ctx.stream, token,
306307
SemiColon => {
307-
ctx.stream.skip();
308-
if ctx.stream.next_kind_is(RightPar) {
308+
ctx.stream.skip();
309+
if ctx.stream.next_kind_is(RightPar) && ctx.standard < VHDL2019 {
309310
return Err(Diagnostic::syntax_error(&token.pos,
310311
format!("Last interface element may not end with {}",
311312
kinds_str(&[SemiColon]))));
@@ -777,6 +778,23 @@ bar : natural)",
777778
"Last interface element may not end with ';'"
778779
)]
779780
);
781+
782+
let code = Code::with_standard(
783+
"\
784+
(constant foo : std_logic;
785+
bar : natural;
786+
)",
787+
VHDL2019,
788+
);
789+
let result = code.parse_ok_no_diagnostics(parse_generic_interface_list);
790+
791+
assert_eq!(
792+
result,
793+
vec![
794+
code.s1("constant foo : std_logic").generic(),
795+
code.s1("bar : natural").generic()
796+
]
797+
);
780798
}
781799

782800
#[test]

0 commit comments

Comments
 (0)