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 ## [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 ## [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 * [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 // separator is required
replaced.push_str(" "); replaced.push_str(" ");
// remove leading whitespace
replaced = String::from(replaced.trim_start());
let (replaced, new_defines) = let (replaced, new_defines) =
preprocess_str(&replaced, path.as_ref(), &defines, include_paths)?; preprocess_str(&replaced, path.as_ref(), &defines, include_paths)?;
@ -614,7 +616,7 @@ endmodule
module a (); 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##" r##"
module a (); 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 ; ; end end ;
endmodule endmodule
@ -648,8 +650,8 @@ endmodule
initial begin initial begin
$display("`HI, world"); $display("`HI, world");
$display( "`HI, world" ); $display("`HI, world" );
$display( "Hello, x" ); $display("Hello, x" );
end end
endmodule endmodule
"## "##
@ -666,7 +668,7 @@ endmodule
module a; module a;
initial begin initial begin
$display( "left side: \"right side\"" ); $display("left side: \"right side\"" );
end end
endmodule endmodule
"## "##

View File

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