Fix embedded single line comment in macro #28
This commit is contained in:
parent
c8f8e7e37f
commit
0aaec7e712
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
## [Unreleased](https://github.com/dalance/sv-parser/compare/v0.10.1...Unreleased) - ReleaseDate
|
## [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
|
## [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
|
* [Fixed] Use many_till instead of many0 for accurate error position
|
||||||
|
@ -588,6 +588,7 @@ fn split_text(s: &str) -> Vec<String> {
|
|||||||
let mut is_string = false;
|
let mut is_string = false;
|
||||||
let mut is_ident = false;
|
let mut is_ident = false;
|
||||||
let mut is_backquote_prev = false;
|
let mut is_backquote_prev = false;
|
||||||
|
let mut is_comment = false;
|
||||||
let mut is_ident_prev;
|
let mut is_ident_prev;
|
||||||
let mut x = String::from("");
|
let mut x = String::from("");
|
||||||
let mut ret = vec![];
|
let mut ret = vec![];
|
||||||
@ -597,7 +598,12 @@ fn split_text(s: &str) -> Vec<String> {
|
|||||||
is_ident_prev = is_ident;
|
is_ident_prev = is_ident;
|
||||||
is_ident = c.is_ascii_alphanumeric() | (c == '_');
|
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);
|
x.push(c);
|
||||||
ret.push(x);
|
ret.push(x);
|
||||||
x = String::from("");
|
x = String::from("");
|
||||||
@ -612,7 +618,7 @@ fn split_text(s: &str) -> Vec<String> {
|
|||||||
x = String::from("");
|
x = String::from("");
|
||||||
is_string = false;
|
is_string = false;
|
||||||
} else if c == '/' && iter.peek() == Some(&'/') && !is_string {
|
} else if c == '/' && iter.peek() == Some(&'/') && !is_string {
|
||||||
break;
|
is_comment = true;
|
||||||
} else if !is_string {
|
} else if !is_string {
|
||||||
if is_ident != is_ident_prev {
|
if is_ident != is_ident_prev {
|
||||||
ret.push(x);
|
ret.push(x);
|
||||||
@ -1160,6 +1166,30 @@ $display("HELLO" );
|
|||||||
$display("HELLO" );
|
$display("HELLO" );
|
||||||
end
|
end
|
||||||
endmodule
|
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
|
||||||
"##
|
"##
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
9
sv-parser-pp/testcases/test17.sv
Normal file
9
sv-parser-pp/testcases/test17.sv
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
`define A \
|
||||||
|
initial begin // comment \
|
||||||
|
end
|
||||||
|
|
||||||
|
module test();
|
||||||
|
|
||||||
|
`A
|
||||||
|
|
||||||
|
endmodule
|
Loading…
x
Reference in New Issue
Block a user