Update Readme and cargo docs

This commit is contained in:
Raamakrishnan 2020-02-02 13:42:24 +05:30
parent 80f5fd6879
commit ed6065a19d
3 changed files with 66 additions and 4 deletions

View file

@ -1,3 +1,23 @@
# verilog-filelist-parser # Verilog Filelist Parser
A Verilog Filelist parser in Rust A library in Rust to parse a Verilog Filelist and return
a list of files, include directories and defines
# Example
```rust
use verilog_filelist_parser;
let filelist = verilog_filelist_parser::parse_file("testcase/files.f")
.expect("Cannot read filelist");
for file in filelist.files {
println!("{:?}", file);
}
for incdir in filelist.incdirs {
println!("{:?}", incdir);
}
for (d, t) in filelist.defines {
match t {
None => println!("{:?}", d),
Some(te) => println!("{:?}={:?}", d, te),
};
}
```

View file

@ -7,16 +7,23 @@ use std::path::PathBuf;
use crate::line_parser; use crate::line_parser;
use crate::line_parser::LineType; use crate::line_parser::LineType;
/// Represents a Verilog Filelist
#[derive(PartialEq, Debug, Default)] #[derive(PartialEq, Debug, Default)]
pub struct Filelist { pub struct Filelist {
/// List of all files
pub files: Vec<PathBuf>, pub files: Vec<PathBuf>,
/// List of all Include Directories
pub incdirs: Vec<PathBuf>, pub incdirs: Vec<PathBuf>,
/// HashMap of all Defines
pub defines: HashMap<String, Option<String>>, pub defines: HashMap<String, Option<String>>,
/// True if comments are present in the filelist
pub comments_present: bool, pub comments_present: bool,
/// True if unknown arguments are present in the filelist
pub unknowns_present: bool, pub unknowns_present: bool,
} }
impl Filelist { impl Filelist {
/// Returns an empty Filelist
pub fn new() -> Filelist { pub fn new() -> Filelist {
Filelist { Filelist {
files: Vec::new(), files: Vec::new(),
@ -27,6 +34,7 @@ impl Filelist {
} }
} }
/// Adds the elements of the other filelist to the current filelist
pub fn extend(&mut self, other: Filelist) { pub fn extend(&mut self, other: Filelist) {
self.files.extend(other.files); self.files.extend(other.files);
self.incdirs.extend(other.incdirs); self.incdirs.extend(other.incdirs);
@ -36,6 +44,16 @@ impl Filelist {
} }
} }
/// Parses a filelist file
///
/// # Arguments
///
/// * `path` - A string slice that is the path to the filelist file
///
/// # Errors
///
/// Returns an error if the filelist in `path` cannot be read. Also returns
/// error if any of the nested filelists cannot be read.
pub fn parse_file(path: &str) -> Result<Filelist, Box<dyn Error>> { pub fn parse_file(path: &str) -> Result<Filelist, Box<dyn Error>> {
let contents = fs::read_to_string(path)?; let contents = fs::read_to_string(path)?;

View file

@ -1,5 +1,29 @@
pub mod file_parser; //! # Verilog Filelist Parser
pub mod line_parser; //!
//! A library to parse a Verilog Filelist and return
//! a list of files, include directories and defines
//!
//! # Example
//! ```
//! use verilog_filelist_parser;
//! let filelist = verilog_filelist_parser::parse_file("testcase/files.f")
//! .expect("Cannot read filelist");
//! for file in filelist.files {
//! println!("{:?}", file);
//! }
//! for incdir in filelist.incdirs {
//! println!("{:?}", incdir);
//! }
//! for (d, t) in filelist.defines {
//! match t {
//! None => println!("{:?}", d),
//! Some(te) => println!("{:?}={:?}", d, te),
//! };
//! }
//! ```
mod file_parser;
mod line_parser;
pub use file_parser::parse_file; pub use file_parser::parse_file;
pub use file_parser::Filelist; pub use file_parser::Filelist;