#![allow(clippy::result_large_err)]
use nom_locate::LocatedSpan;
use std::collections::HashMap;
use std::path::PathBuf;
use std::{fs, io};
pub mod attribute;
pub mod entry;
pub mod kconfig;
pub mod string;
pub mod symbol;
pub mod tristate;
pub mod util;
pub use self::attribute::Attribute;
pub use self::entry::Entry;
pub use self::kconfig::{parse_kconfig, Kconfig};
pub use self::symbol::Symbol;
pub type KconfigInput<'a> = LocatedSpan<&'a str, KconfigFile>;
#[derive(Debug, Default, Clone)]
pub struct KconfigFile {
root_dir: PathBuf,
file: PathBuf,
vars: HashMap<String, String>,
}
impl KconfigFile {
pub fn new(root_dir: PathBuf, file: PathBuf) -> Self {
Self {
root_dir,
file,
vars: HashMap::new(),
}
}
pub fn new_with_vars<S: AsRef<str>>(
root_dir: PathBuf,
file: PathBuf,
vars: &HashMap<S, S>,
) -> Self {
Self {
root_dir,
file,
vars: vars
.iter()
.map(|(s1, s2)| (s1.as_ref().to_string(), s2.as_ref().to_string()))
.collect(),
}
}
pub fn full_path(&self) -> PathBuf {
match self.file.is_absolute() {
true => self.file.clone(),
false => self.root_dir.join(&self.file),
}
}
pub fn read_to_string(&self) -> io::Result<String> {
fs::read_to_string(self.full_path())
}
pub fn set_vars<S: AsRef<str>>(&mut self, vars: &[(S, S)]) {
self.vars = vars
.iter()
.map(|(s1, s2)| (s1.as_ref().to_string(), s2.as_ref().to_string()))
.collect();
}
}
#[cfg(test)]
pub mod kconfig_test;
#[cfg(test)]
pub mod lib_test;
mod number;
#[cfg(test)]
pub mod symbol_test;
#[cfg(test)]
pub mod util_test;
#[macro_export]
macro_rules! assert_parsing_eq {
($fn:ident, $input:expr, $expected:expr) => {{
use $crate::KconfigInput;
let res = $fn(KconfigInput::new_extra($input, Default::default()))
.map(|r| (r.0.fragment().to_owned(), r.1));
assert_eq!(res, $expected)
}};
}