diff --git a/NEWS.md b/NEWS.md index 365188694..8e47ca2c6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/src/lexer.l b/src/lexer.l index eca8a743d..6b17ac232 100644 --- a/src/lexer.l +++ b/src/lexer.l @@ -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; @@ -352,6 +353,7 @@ BEFORE ?i:before "--" { comment_caller = YY_START; BEGIN(COMMENT); } "//" { comment_caller = YY_START; BEGIN(COMMENT); } {PSL_COMMENT} { if (begin_psl_comment()) { + in_psl_comment = true; BEGIN(PSL); TOKEN(tSTARTPSL); } @@ -373,9 +375,13 @@ BEFORE ?i:before \n { /* Must match a single character */ } . { } -; { TOKEN(tSEMI); } -{PSL_CONT} { /* Multi-line PSL comment */ } -"--" { comment_caller = YY_START; BEGIN(COMMENT); } +; { in_psl_comment = false; TOKEN(tSEMI); } +{PSL_CONT} { /* Multi-line PSL comment */ + if (!in_psl_comment) { + comment_caller = YY_START; + BEGIN(COMMENT); + } + } {ENTITY} { TOKEN(tENTITY); } {IS} { TOKEN(tIS); } @@ -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); } diff --git a/test/parse/issue1129.vhd b/test/parse/issue1129.vhd new file mode 100644 index 000000000..ac9a4ff10 --- /dev/null +++ b/test/parse/issue1129.vhd @@ -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; diff --git a/test/test_parse.c b/test/test_parse.c index f8c9f9929..caf98f827 100644 --- a/test/test_parse.c +++ b/test/test_parse.c @@ -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"); @@ -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;