1use nom::{
2 combinator::{eof, map},
3 multi::many0,
4 sequence::delimited,
5 IResult, Parser,
6};
7#[cfg(feature = "deserialize")]
8use serde::Deserialize;
9#[cfg(feature = "serialize")]
10use serde::Serialize;
11use tracing::debug;
12
13use crate::{
14 entry::{parse_entry, Entry},
15 util::{ws, ws_comment},
16 KconfigInput,
17};
18
19#[derive(Debug, Clone, PartialEq, Default)]
22#[cfg_attr(feature = "hash", derive(Hash))]
23#[cfg_attr(feature = "serialize", derive(Serialize))]
24#[cfg_attr(feature = "deserialize", derive(Deserialize))]
25pub struct Kconfig {
26 pub file: String,
27 pub entries: Vec<Entry>,
28}
29
30pub fn parse_kconfig(input: KconfigInput) -> IResult<KconfigInput, Kconfig> {
42 let file: std::path::PathBuf = input.extra.file.clone();
43 debug!("Parsing file '{}'", file.display());
44 let (input, result) = map(delimited(ws_comment, many0(parse_entry), ws(eof)), |d| {
45 Kconfig {
46 file: file.display().to_string(),
47 entries: d,
48 }
49 })
50 .parse(input)?;
51 Ok((input, result))
52}