From b23e9079e9b3af9f0bc952f24cd95d270dc1932f Mon Sep 17 00:00:00 2001 From: dalance Date: Fri, 5 Mar 2021 15:06:12 +0900 Subject: [PATCH] Fix include with comment error --- CHANGELOG.md | 2 ++ sv-parser-pp/src/preprocess.rs | 46 +++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9cf3c9a..3a346b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## [Unreleased](https://github.com/dalance/sv-parser/compare/v0.11.0...Unreleased) - ReleaseDate +* [Fixed] include with comment error + ## [v0.11.0](https://github.com/dalance/sv-parser/compare/v0.10.8...v0.11.0) - 2021-03-04 * [Changed] keep directives after preprocess diff --git a/sv-parser-pp/src/preprocess.rs b/sv-parser-pp/src/preprocess.rs index a07d1e1..4e021b0 100644 --- a/sv-parser-pp/src/preprocess.rs +++ b/sv-parser-pp/src/preprocess.rs @@ -247,7 +247,10 @@ pub fn preprocess_str, U: AsRef, V: BuildHasher>( } NodeEvent::Leave(RefNode::SourceDescriptionNotDirective(x)) => { let locate: Locate = x.try_into().unwrap(); - last_item_line = Some(locate.line); + // If the item is whitespace, last_item_line should not be updated + if !locate.str(s).trim().is_empty() { + last_item_line = Some(locate.line); + } } NodeEvent::Leave(RefNode::CompilerDirective(x)) => { let locate: Locate = x.try_into().unwrap(); @@ -1294,4 +1297,45 @@ endmodule ); assert_eq!(ret.origin(70).unwrap().1, 50); } + + #[test] + fn test20() { + let include_paths = [get_testcase("")]; + let (ret, _) = preprocess( + get_testcase("test20.sv"), + &HashMap::new(), + &include_paths, + false, + false, + ) + .unwrap(); + assert_eq!( + ret.text(), + r##"module and_op (a, b, c); + // a + output a; +input b, c; + +and a1 (a,b,c); + + +endmodule +"## + ); + assert_eq!( + ret.origin(10).unwrap().0, + &PathBuf::from(get_testcase("test20.sv")) + ); + assert_eq!(ret.origin(10).unwrap().1, 10); + assert_eq!( + ret.origin(60).unwrap().0, + &PathBuf::from(get_testcase("test2.svh")) + ); + assert_eq!(ret.origin(60).unwrap().1, 74); + assert_eq!( + ret.origin(80).unwrap().0, + &PathBuf::from(get_testcase("test20.sv")) + ); + assert_eq!(ret.origin(80).unwrap().1, 60); + } }