diff --git a/CHANGELOG.md b/CHANGELOG.md index 890da9a..9720e1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## [Unreleased](https://github.com/dalance/sv-parser/compare/v0.10.1...Unreleased) - ReleaseDate +* [Fixed] embedded single line comment in macro [#28](https://github.com/dalance/sv-parser/issues/28) + ## [v0.10.1](https://github.com/dalance/sv-parser/compare/v0.10.0...v0.10.1) - 2021-01-05 * [Fixed] Use many_till instead of many0 for accurate error position diff --git a/sv-parser-pp/src/preprocess.rs b/sv-parser-pp/src/preprocess.rs index 8edb6df..29534fb 100644 --- a/sv-parser-pp/src/preprocess.rs +++ b/sv-parser-pp/src/preprocess.rs @@ -588,6 +588,7 @@ fn split_text(s: &str) -> Vec { let mut is_string = false; let mut is_ident = false; let mut is_backquote_prev = false; + let mut is_comment = false; let mut is_ident_prev; let mut x = String::from(""); let mut ret = vec![]; @@ -597,7 +598,12 @@ fn split_text(s: &str) -> Vec { is_ident_prev = is_ident; is_ident = c.is_ascii_alphanumeric() | (c == '_'); - if c == '"' && is_backquote_prev { + if c == '\n' && is_comment { + is_comment = false; + x.push(c); + } else if is_comment { + continue; + } else if c == '"' && is_backquote_prev { x.push(c); ret.push(x); x = String::from(""); @@ -612,7 +618,7 @@ fn split_text(s: &str) -> Vec { x = String::from(""); is_string = false; } else if c == '/' && iter.peek() == Some(&'/') && !is_string { - break; + is_comment = true; } else if !is_string { if is_ident != is_ident_prev { ret.push(x); @@ -1160,6 +1166,30 @@ $display("HELLO" ); $display("HELLO" ); end endmodule +"## + ); + } + + #[test] + fn test17() { + let (ret, _) = preprocess( + get_testcase("test17.sv"), + &HashMap::new(), + &[] as &[String], + false, + false, + ) + .unwrap(); + assert_eq!( + ret.text(), + r##"`define A \ + initial begin // comment \ + end + +module test(); + +initial begin + end endmodule "## ); } diff --git a/sv-parser-pp/testcases/test17.sv b/sv-parser-pp/testcases/test17.sv new file mode 100644 index 0000000..258b0b4 --- /dev/null +++ b/sv-parser-pp/testcases/test17.sv @@ -0,0 +1,9 @@ +`define A \ + initial begin // comment \ + end + +module test(); + +`A + +endmodule