Add define option to parse_sv
This commit is contained in:
parent
e80104111a
commit
d18209ce87
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
## [Unreleased](https://github.com/dalance/sv-parser/compare/v0.8.3...Unreleased) - ReleaseDate
|
## [Unreleased](https://github.com/dalance/sv-parser/compare/v0.8.3...Unreleased) - ReleaseDate
|
||||||
|
|
||||||
|
* [Added] define option to parse_sv
|
||||||
* [Added] incomplete option [#19](https://github.com/dalance/sv-parser/issues/19)
|
* [Added] incomplete option [#19](https://github.com/dalance/sv-parser/issues/19)
|
||||||
* [Changed] keep text_macro_definition after preprocess [#19](https://github.com/dalance/sv-parser/issues/19)
|
* [Changed] keep text_macro_definition after preprocess [#19](https://github.com/dalance/sv-parser/issues/19)
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@ sv-parser-syntaxtree = {version = "^0.8.3", path = "../sv-parser-syntaxtree"}
|
|||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
structopt = "0.3.2"
|
structopt = "0.3.2"
|
||||||
criterion = "0.3"
|
criterion = "0.3"
|
||||||
|
enquote = "1.0"
|
||||||
|
|
||||||
[[bench]]
|
[[bench]]
|
||||||
name = "parse_sv_criterion"
|
name = "parse_sv_criterion"
|
||||||
|
@ -5,7 +5,7 @@ use std::io::Read;
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::{cmp, process};
|
use std::{cmp, process};
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
use sv_parser::parse_sv;
|
use sv_parser::{parse_sv, Define, DefineText};
|
||||||
use sv_parser_error::Error;
|
use sv_parser_error::Error;
|
||||||
use sv_parser_pp::preprocess::preprocess;
|
use sv_parser_pp::preprocess::preprocess;
|
||||||
|
|
||||||
@ -29,6 +29,10 @@ struct Opt {
|
|||||||
#[structopt(long = "incomplete")]
|
#[structopt(long = "incomplete")]
|
||||||
pub incomplete: bool,
|
pub incomplete: bool,
|
||||||
|
|
||||||
|
/// Define
|
||||||
|
#[structopt(short = "d", long = "define", multiple = true, number_of_values = 1)]
|
||||||
|
pub defines: Vec<String>,
|
||||||
|
|
||||||
/// Quiet
|
/// Quiet
|
||||||
#[structopt(short = "q", long = "quiet")]
|
#[structopt(short = "q", long = "quiet")]
|
||||||
pub quiet: bool,
|
pub quiet: bool,
|
||||||
@ -36,7 +40,21 @@ struct Opt {
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let opt = Opt::from_args();
|
let opt = Opt::from_args();
|
||||||
|
|
||||||
let mut defines = HashMap::new();
|
let mut defines = HashMap::new();
|
||||||
|
for define in &opt.defines {
|
||||||
|
let mut define = define.splitn(2, '=');
|
||||||
|
let ident = String::from(define.next().unwrap());
|
||||||
|
let text = if let Some(x) = define.next() {
|
||||||
|
let x = enquote::unescape(x, None).unwrap();
|
||||||
|
Some(DefineText::new(x, None))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
let define = Define::new(ident.clone(), vec![], text);
|
||||||
|
defines.insert(ident, Some(define));
|
||||||
|
}
|
||||||
|
|
||||||
let mut exit = 0;
|
let mut exit = 0;
|
||||||
for path in &opt.files {
|
for path in &opt.files {
|
||||||
if opt.pp {
|
if opt.pp {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user