From eca8714de776b963f2edfbd9b51557966885f9ca Mon Sep 17 00:00:00 2001 From: Zachary Snow Date: Tue, 7 Mar 2023 23:52:43 -0500 Subject: [PATCH] skip start of block before looking for its end --- CHANGELOG.md | 3 +++ src/Language/SystemVerilog/Parser/Preprocess.hs | 5 ++++- test/lex/block_comment.sv | 7 +++++++ test/lex/block_comment.v | 3 +++ 4 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 test/lex/block_comment.sv create mode 100644 test/lex/block_comment.v diff --git a/CHANGELOG.md b/CHANGELOG.md index 208b3ac..de6ac44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ static prefixes, which could cause deep recursion and run out of memory on some designs * Fixed unneeded scoping of constant function calls used in type lookups +* `/*/` is no longer interpreted as a self-closing block comment, e.g., + `$display("a"/*/,"b"/* */);` previously printed "ab", but now prints "a" + ### New Features diff --git a/src/Language/SystemVerilog/Parser/Preprocess.hs b/src/Language/SystemVerilog/Parser/Preprocess.hs index 0b0fb4e..d42eed0 100644 --- a/src/Language/SystemVerilog/Parser/Preprocess.hs +++ b/src/Language/SystemVerilog/Parser/Preprocess.hs @@ -545,7 +545,10 @@ preprocessInput = do macroStack <- getMacroStack case str of '/' : '/' : _ -> removeThrough "\n" - '/' : '*' : _ -> removeThrough "*/" + '/' : '*' : _ -> + -- prevent treating `/*/` as self-closing + takeChar >> takeChar >> + removeThrough "*/" '`' : '"' : _ -> handleBacktickString '"' : _ -> handleString '/' : '`' : '`' : '*' : _ -> diff --git a/test/lex/block_comment.sv b/test/lex/block_comment.sv new file mode 100644 index 0000000..16bf1ce --- /dev/null +++ b/test/lex/block_comment.sv @@ -0,0 +1,7 @@ +module top; + /*test*/ + /*/test*/ + /*test/*/ + /*/test/*/ + initial $display("foo"/*/,"bar"/*/); +endmodule diff --git a/test/lex/block_comment.v b/test/lex/block_comment.v new file mode 100644 index 0000000..61c19cf --- /dev/null +++ b/test/lex/block_comment.v @@ -0,0 +1,3 @@ +module top; + initial $display("foo"); +endmodule