Skip to content

Commit

Permalink
Fix mis-parsed comment inside PSL directive. Fixes #1129
Browse files Browse the repository at this point in the history
  • Loading branch information
nickg committed Jan 11, 2025
1 parent b5fa5ee commit 2749eba
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
- The `'driving_value` attribute now works correctly with record types.
- Added basic support for `'instance_name`, `'path_name` and `'simple_name`
attributes of generate block labels (from @NikLeberg) (#1125).
- Comments are now parsed correctly inside PSL directives (#1129).
- Several other minor bugs were resolved (#1038, #1057, #1067. #1124).

## Version 1.14.2 - 2024-11-23
Expand Down
16 changes: 13 additions & 3 deletions src/lexer.l
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ static int report_bad_identifier(char *str);

static int last_token = -1;
static int comment_caller = 0;
static bool in_psl_comment = false;

extern loc_t yylloc;
extern yylval_t yylval;
Expand Down Expand Up @@ -352,6 +353,7 @@ BEFORE ?i:before
<PSL,INITIAL>"--" { comment_caller = YY_START; BEGIN(COMMENT); }
<VLOG,UDP>"//" { comment_caller = YY_START; BEGIN(COMMENT); }
{PSL_COMMENT} { if (begin_psl_comment()) {
in_psl_comment = true;
BEGIN(PSL);
TOKEN(tSTARTPSL);
}
Expand All @@ -373,9 +375,13 @@ BEFORE ?i:before
<C_COMMENT>\n { /* Must match a single character */ }
<C_COMMENT>. { }

<PSL>; { TOKEN(tSEMI); }
<PSL>{PSL_CONT} { /* Multi-line PSL comment */ }
<PSL>"--" { comment_caller = YY_START; BEGIN(COMMENT); }
<PSL>; { in_psl_comment = false; TOKEN(tSEMI); }
<PSL>{PSL_CONT} { /* Multi-line PSL comment */
if (!in_psl_comment) {
comment_caller = YY_START;
BEGIN(COMMENT);
}
}

{ENTITY} { TOKEN(tENTITY); }
{IS} { TOKEN(tIS); }
Expand Down Expand Up @@ -1157,6 +1163,10 @@ static void warn_utf8(const char *text)

void reset_scanner(void)
{
last_token = -1;
comment_caller = 0;
in_psl_comment = false;

YY_FLUSH_BUFFER;
BEGIN(INITIAL);
}
Expand Down
23 changes: 23 additions & 0 deletions test/parse/issue1129.vhd
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
entity pragma_test is
end pragma_test;

architecture dummy of pragma_test is -- OK
begin
synerror: assert false
-- pragma translate_off
or true
-- pragma translate_on
report "dummy model found during synthesis" severity failure;

end architecture dummy;


architecture dummy2 of pragma_test is -- generates parsing error
begin
synerror: assert false
-- pragma translate_off
or true
-- pragma translate_on
report "dummy model found during synthesis" severity failure;

end architecture dummy2;
15 changes: 15 additions & 0 deletions test/test_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -7171,6 +7171,20 @@ START_TEST(test_issue1124)
}
END_TEST

START_TEST(test_issue1129)
{
set_standard(STD_08);

input_from_file(TESTDIR "/parse/issue1129.vhd");

parse_and_check(T_ENTITY, T_ARCH, T_ARCH);

fail_unless(parse() == NULL);

fail_if_errors();
}
END_TEST

Suite *get_parse_tests(void)
{
Suite *s = suite_create("parse");
Expand Down Expand Up @@ -7347,6 +7361,7 @@ Suite *get_parse_tests(void)
tcase_add_test(tc_core, test_gensub);
tcase_add_test(tc_core, test_aggregate2);
tcase_add_test(tc_core, test_issue1124);
tcase_add_test(tc_core, test_issue1129);
suite_add_tcase(s, tc_core);

return s;
Expand Down

0 comments on commit 2749eba

Please sign in to comment.