From b924dc304c628817eadaa7b233015b01840b0d5e Mon Sep 17 00:00:00 2001 From: dalance Date: Fri, 29 Jan 2021 18:35:25 +0900 Subject: [PATCH] Fix include with comment error --- CHANGELOG.md | 2 ++ sv-parser-parser/src/general/comments.rs | 6 ++++ sv-parser-pp/src/preprocess.rs | 40 ++++++++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e85cdbd..0021b8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## [Unreleased](https://github.com/dalance/sv-parser/compare/v0.10.7...Unreleased) - ReleaseDate +* [Fixed] include with comment error + ## [v0.10.7](https://github.com/dalance/sv-parser/compare/v0.10.6...v0.10.7) - 2021-01-29 * [Added] get_str_trim to SyntaxTree diff --git a/sv-parser-parser/src/general/comments.rs b/sv-parser-parser/src/general/comments.rs index c74eda9..1a0bfc3 100644 --- a/sv-parser-parser/src/general/comments.rs +++ b/sv-parser-parser/src/general/comments.rs @@ -13,11 +13,17 @@ pub(crate) fn comment(s: Span) -> IResult { pub(crate) fn one_line_comment(s: Span) -> IResult { let (s, a) = tag("//")(s)?; let (s, b) = opt(is_not("\n"))(s)?; + let (s, c) = opt(tag("\n"))(s)?; let a = if let Some(b) = b { concat(a, b).unwrap() } else { a }; + let a = if let Some(c) = c { + concat(a, c).unwrap() + } else { + a + }; Ok(( s, Comment { diff --git a/sv-parser-pp/src/preprocess.rs b/sv-parser-pp/src/preprocess.rs index 12ea599..c18da9b 100644 --- a/sv-parser-pp/src/preprocess.rs +++ b/sv-parser-pp/src/preprocess.rs @@ -1214,4 +1214,44 @@ endmodule "## ); } + + #[test] + fn test19() { + let include_paths = [get_testcase("")]; + let (ret, _) = preprocess( + get_testcase("test19.sv"), + &HashMap::new(), + &include_paths, + false, + false, + ) + .unwrap(); + assert_eq!( + ret.text(), + r##"module and_op (a, b, c); +output a; +input b, c; + +and a1 (a,b,c); + + // comment +endmodule +"## + ); + assert_eq!( + ret.origin(10).unwrap().0, + &PathBuf::from(get_testcase("test19.sv")) + ); + assert_eq!(ret.origin(10).unwrap().1, 10); + assert_eq!( + ret.origin(50).unwrap().0, + &PathBuf::from(get_testcase("test2.svh")) + ); + assert_eq!(ret.origin(50).unwrap().1, 73); + assert_eq!( + ret.origin(70).unwrap().0, + &PathBuf::from(get_testcase("test19.sv")) + ); + assert_eq!(ret.origin(70).unwrap().1, 50); + } }