Fix include with comment error

This commit is contained in:
dalance 2021-01-29 18:35:25 +09:00
parent 3dc1c54615
commit b924dc304c
3 changed files with 48 additions and 0 deletions

View File

@ -2,6 +2,8 @@
## [Unreleased](https://github.com/dalance/sv-parser/compare/v0.10.7...Unreleased) - ReleaseDate ## [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 ## [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 * [Added] get_str_trim to SyntaxTree

View File

@ -13,11 +13,17 @@ pub(crate) fn comment(s: Span) -> IResult<Span, Comment> {
pub(crate) fn one_line_comment(s: Span) -> IResult<Span, Comment> { pub(crate) fn one_line_comment(s: Span) -> IResult<Span, Comment> {
let (s, a) = tag("//")(s)?; let (s, a) = tag("//")(s)?;
let (s, b) = opt(is_not("\n"))(s)?; let (s, b) = opt(is_not("\n"))(s)?;
let (s, c) = opt(tag("\n"))(s)?;
let a = if let Some(b) = b { let a = if let Some(b) = b {
concat(a, b).unwrap() concat(a, b).unwrap()
} else { } else {
a a
}; };
let a = if let Some(c) = c {
concat(a, c).unwrap()
} else {
a
};
Ok(( Ok((
s, s,
Comment { Comment {

View File

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