use nom::{
combinator::{eof, map},
multi::many0,
sequence::delimited,
IResult,
};
#[cfg(feature = "deserialize")]
use serde::Deserialize;
#[cfg(feature = "serialize")]
use serde::Serialize;
use crate::{
entry::{parse_entry, Entry},
util::{ws, ws_comment},
KconfigInput,
};
#[derive(Debug, Clone, PartialEq, Default)]
#[cfg_attr(feature = "hash", derive(Hash))]
#[cfg_attr(feature = "serialize", derive(Serialize))]
#[cfg_attr(feature = "deserialize", derive(Deserialize))]
pub struct Kconfig {
pub file: String,
pub entries: Vec<Entry>,
}
pub fn parse_kconfig(input: KconfigInput) -> IResult<KconfigInput, Kconfig> {
let file: std::path::PathBuf = input.extra.file.clone();
let (input, result) = map(delimited(ws_comment, many0(parse_entry), ws(eof)), |d| {
Kconfig {
file: file.display().to_string(),
entries: d,
}
})(input)?;
Ok((input, result))
}