mirror of
https://github.com/supleed2/sv-filelist-parser.git
synced 2024-11-10 01:35:49 +00:00
Changing files and incdirs to PathBuf from String
This commit is contained in:
parent
c962719206
commit
4061408e5c
|
@ -1,6 +1,7 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
use std::path::PathBuf;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
use crate::line_parser;
|
use crate::line_parser;
|
||||||
|
@ -8,8 +9,8 @@ use crate::line_parser::LineType;
|
||||||
|
|
||||||
#[derive(PartialEq, Debug, Default)]
|
#[derive(PartialEq, Debug, Default)]
|
||||||
pub struct Filelist {
|
pub struct Filelist {
|
||||||
pub files: Vec<String>,
|
pub files: Vec<PathBuf>,
|
||||||
pub incdirs: Vec<String>,
|
pub incdirs: Vec<PathBuf>,
|
||||||
pub defines: HashMap<String, Option<String>>,
|
pub defines: HashMap<String, Option<String>>,
|
||||||
pub comments_present: bool,
|
pub comments_present: bool,
|
||||||
}
|
}
|
||||||
|
@ -40,7 +41,7 @@ pub fn parse_file(path: &str) -> Result<Filelist, Box<dyn Error>> {
|
||||||
for line in contents.lines() {
|
for line in contents.lines() {
|
||||||
let line = replace_env_vars(&line);
|
let line = replace_env_vars(&line);
|
||||||
match line_parser::parse_line(&line) {
|
match line_parser::parse_line(&line) {
|
||||||
LineType::File(file) => filelist.files.push(file.to_string()),
|
LineType::File(file) => filelist.files.push(PathBuf::from(file)),
|
||||||
LineType::Define(define_map) => {
|
LineType::Define(define_map) => {
|
||||||
for (d, t) in define_map.into_iter() {
|
for (d, t) in define_map.into_iter() {
|
||||||
match t {
|
match t {
|
||||||
|
@ -51,7 +52,7 @@ pub fn parse_file(path: &str) -> Result<Filelist, Box<dyn Error>> {
|
||||||
},
|
},
|
||||||
LineType::IncDir(incdirs) => {
|
LineType::IncDir(incdirs) => {
|
||||||
for dir in incdirs {
|
for dir in incdirs {
|
||||||
filelist.incdirs.push(dir.to_string());
|
filelist.incdirs.push(PathBuf::from(dir));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LineType::Comment => filelist.comments_present = true,
|
LineType::Comment => filelist.comments_present = true,
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use sv_filelist_parser;
|
use sv_filelist_parser;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn simple_test() {
|
fn simple_test() {
|
||||||
|
@ -12,11 +13,13 @@ fn simple_test() {
|
||||||
defines.insert("RTL".to_string(), None);
|
defines.insert("RTL".to_string(), None);
|
||||||
|
|
||||||
let filelist_exp = sv_filelist_parser::Filelist {
|
let filelist_exp = sv_filelist_parser::Filelist {
|
||||||
files : vec!["testcase/file1.sv".to_string(),
|
files : vec![
|
||||||
"testcase/file2.sv".to_string(),
|
PathBuf::from("testcase/file1.sv"),
|
||||||
"testcase/file3.sv".to_string(),
|
PathBuf::from("testcase/file2.sv"),
|
||||||
"testcase/file4.sv".to_string(),],
|
PathBuf::from("testcase/file3.sv"),
|
||||||
incdirs : vec!["testcase/".to_string()],
|
PathBuf::from("testcase/file4.sv"),
|
||||||
|
],
|
||||||
|
incdirs : vec![PathBuf::from("testcase/")],
|
||||||
defines : defines,
|
defines : defines,
|
||||||
comments_present : true
|
comments_present : true
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue