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)?;

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,6 +34,15 @@ 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 {
if opt.pp {
match preprocess(&path, &defines, &opt.includes) {
Ok((preprocessed_text, new_defines)) => {
println!("{}", preprocessed_text.text());
defines = new_defines;
}
_ => (),
}
} else {
match parse_sv(&path, &defines, &opt.includes) { match parse_sv(&path, &defines, &opt.includes) {
Ok((syntax_tree, new_defines)) => { Ok((syntax_tree, new_defines)) => {
if opt.tree { if opt.tree {
@ -53,6 +67,7 @@ fn main() {
} }
} }
} }
}
process::exit(exit); process::exit(exit);
} }