From e169c907f4634fe0e28e7caa6f2e80385cd5f4ca Mon Sep 17 00:00:00 2001 From: Zachary Snow Date: Mon, 13 Sep 2021 20:46:59 -0400 Subject: [PATCH] fix preprocessing of line comments not preceded by whitespace --- CHANGELOG.md | 2 ++ src/Language/SystemVerilog/Parser/Preprocess.hs | 3 +++ test/lex/comment_no_space.sv | 5 +++++ 3 files changed, 10 insertions(+) create mode 100644 test/lex/comment_no_space.sv diff --git a/CHANGELOG.md b/CHANGELOG.md index a2643e0..bc46ff6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,8 @@ files encoding using Latin-1 with special characters in comments * Support for non-ANSI style port declarations where the port declaration is separate from the corresponding net or variable declaration +* Fix preprocessing of line comments which are neither preceded nor followed by + whitespace except for the newline which terminates the comment ## v0.0.8 diff --git a/src/Language/SystemVerilog/Parser/Preprocess.hs b/src/Language/SystemVerilog/Parser/Preprocess.hs index 8130cb0..0b0fb4e 100644 --- a/src/Language/SystemVerilog/Parser/Preprocess.hs +++ b/src/Language/SystemVerilog/Parser/Preprocess.hs @@ -951,4 +951,7 @@ removeThrough pattern = do let chars = patternIdx + length pattern let (dropped, rest) = splitAt chars str advancePositions dropped + when (pattern == "\n") $ do + pos <- getPosition + pushChar '\n' pos setInput rest diff --git a/test/lex/comment_no_space.sv b/test/lex/comment_no_space.sv new file mode 100644 index 0000000..39e0135 --- /dev/null +++ b/test/lex/comment_no_space.sv @@ -0,0 +1,5 @@ +module top; + initial begin + $display("Hi!"); + end//comment +endmodule