Fix wrong space at define macro usage

This commit is contained in:
dalance 2019-11-28 18:55:26 +09:00
parent 0ae50c97d6
commit 048e39755f
3 changed files with 40 additions and 21 deletions

View File

@ -2,6 +2,8 @@
## [Unreleased](https://github.com/dalance/sv-parser/compare/v0.4.4...Unreleased) - ReleaseDate
* [Fix] wrong space at define macro usage
## [v0.4.4](https://github.com/dalance/sv-parser/compare/v0.4.3...v0.4.4) - 2019-11-22
* [Fix] \`resetall wrongly clear define list

View File

@ -501,6 +501,8 @@ fn resolve_text_macro_usage<T: AsRef<Path>, U: AsRef<Path>>(
}
// separator is required
replaced.push_str(" ");
// remove leading whitespace
replaced = String::from(replaced.trim_start());
let (replaced, new_defines) =
preprocess_str(&replaced, path.as_ref(), &defines, include_paths)?;
@ -614,7 +616,7 @@ endmodule
module a ();
assign a_0__x = a[0].x; assign a_0__y = a[0].y; assign a_1__x = a[1].x; assign a_1__y = a[1].y; endmodule
assign a_0__x = a[0].x; assign a_0__y = a[0].y; assign a_1__x = a[1].x; assign a_1__y = a[1].y; endmodule
"##
);
}
@ -628,7 +630,7 @@ module a ();
r##"
module a ();
always @(posedge clk) begin if (!(!(a[i].b && c[i]))) begin $display ("xxx(()[]]{}}}", a[i].b, c[i])
always @(posedge clk) begin if (!(!(a[i].b && c[i]))) begin $display ("xxx(()[]]{}}}", a[i].b, c[i])
; end end ;
endmodule
@ -648,8 +650,8 @@ endmodule
initial begin
$display("`HI, world");
$display( "`HI, world" );
$display( "Hello, x" );
$display("`HI, world" );
$display("Hello, x" );
end
endmodule
"##
@ -666,7 +668,7 @@ endmodule
module a;
initial begin
$display( "left side: \"right side\"" );
$display("left side: \"right side\"" );
end
endmodule
"##

View File

@ -6,6 +6,7 @@ use std::{cmp, process};
use structopt::StructOpt;
use sv_parser::parse_sv;
use sv_parser_error::ErrorKind;
use sv_parser_pp::preprocess::preprocess;
#[derive(StructOpt)]
struct Opt {
@ -19,6 +20,10 @@ struct Opt {
#[structopt(short = "t", long = "tree")]
pub tree: bool,
/// Show preprocesed text
#[structopt(short = "p", long = "pp")]
pub pp: bool,
/// Quiet
#[structopt(short = "q", long = "quiet")]
pub quiet: bool,
@ -29,27 +34,37 @@ fn main() {
let mut defines = HashMap::new();
let mut exit = 0;
for path in &opt.files {
match parse_sv(&path, &defines, &opt.includes) {
Ok((syntax_tree, new_defines)) => {
if opt.tree {
println!("{}", syntax_tree);
}
defines = new_defines;
if !opt.quiet {
println!("parse succeeded: {:?}", path);
if opt.pp {
match preprocess(&path, &defines, &opt.includes) {
Ok((preprocessed_text, new_defines)) => {
println!("{}", preprocessed_text.text());
defines = new_defines;
}
_ => (),
}
Err(x) => {
match x.kind() {
ErrorKind::Parse(Some((origin_path, origin_pos))) => {
println!("parse failed: {:?}", path);
print_parse_error(origin_path, origin_pos);
} else {
match parse_sv(&path, &defines, &opt.includes) {
Ok((syntax_tree, new_defines)) => {
if opt.tree {
println!("{}", syntax_tree);
}
x => {
println!("parse failed: {:?} ({})", path, x);
defines = new_defines;
if !opt.quiet {
println!("parse succeeded: {:?}", path);
}
}
exit = 1;
Err(x) => {
match x.kind() {
ErrorKind::Parse(Some((origin_path, origin_pos))) => {
println!("parse failed: {:?}", path);
print_parse_error(origin_path, origin_pos);
}
x => {
println!("parse failed: {:?} ({})", path, x);
}
}
exit = 1;
}
}
}
}