add support for Filelists in file parser.

This commit is contained in:
Raamakrishnan 2020-01-26 22:22:39 +05:30
parent 90bd07ebf1
commit a97a6a3468
2 changed files with 34 additions and 3 deletions

View file

@ -5,12 +5,11 @@ use std::fs;
use crate::line_parser; use crate::line_parser;
use crate::line_parser::LineType; use crate::line_parser::LineType;
#[derive(Debug)] #[derive(PartialEq, Debug, Default)]
pub struct Filelist { pub struct Filelist {
pub files: Vec<String>, pub files: Vec<String>,
pub incdirs: Vec<String>, pub incdirs: Vec<String>,
pub defines: HashMap<String, String>, pub defines: HashMap<String, String>,
pub comments_present: bool, pub comments_present: bool,
} }
@ -23,6 +22,13 @@ impl Filelist {
comments_present: false, comments_present: false,
} }
} }
pub fn extend(&mut self, other: Filelist) {
self.files.extend(other.files);
self.incdirs.extend(other.incdirs);
self.defines.extend(other.defines);
self.comments_present |= other.comments_present;
}
} }
pub fn parse_file(path: &str) -> Result<Filelist, Box<dyn Error>> { pub fn parse_file(path: &str) -> Result<Filelist, Box<dyn Error>> {
@ -44,7 +50,9 @@ pub fn parse_file(path: &str) -> Result<Filelist, Box<dyn Error>> {
} }
} }
LineType::Comment => filelist.comments_present = true, LineType::Comment => filelist.comments_present = true,
_ => {} LineType::Filelist(path) => {
filelist.extend(parse_file(path)?);
},
} }
} }
Ok(filelist) Ok(filelist)

View file

@ -0,0 +1,23 @@
extern crate sv_filelist_parser;
use std::collections::HashMap;
#[test]
fn simple_test() {
let mut defines = HashMap::new();
defines.insert("a".to_string(), "bad".to_string());
defines.insert("e".to_string(), "f".to_string());
defines.insert("c".to_string(), "d".to_string());
let filelist_exp = sv_filelist_parser::file_parser::Filelist {
files : vec!["testcase/file1.sv".to_string(),
"testcase/file2.sv".to_string(),
"testcase/file3.sv".to_string(),
"testcase/file4.sv".to_string(),],
incdirs : vec!["testcase/".to_string()],
defines : defines,
comments_present : true
};
let filelist = sv_filelist_parser::parse("testcase/files.f")
.expect("Error parsing");
assert_eq!(filelist_exp, filelist);
}