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); + } }