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;
11
12use crate::{
13 entry::{parse_entry, Entry},
14 util::{ws, ws_comment},
15 KconfigInput,
16};
17
18#[derive(Debug, Clone, PartialEq, Default)]
21#[cfg_attr(feature = "hash", derive(Hash))]
22#[cfg_attr(feature = "serialize", derive(Serialize))]
23#[cfg_attr(feature = "deserialize", derive(Deserialize))]
24pub struct Kconfig {
25 pub file: String,
26 pub entries: Vec<Entry>,
27}
28
29pub fn parse_kconfig(input: KconfigInput) -> IResult<KconfigInput, Kconfig> {
41 let file: std::path::PathBuf = input.extra.file.clone();
42 let (input, result) = map(delimited(ws_comment, many0(parse_entry), ws(eof)), |d| {
43 Kconfig {
44 file: file.display().to_string(),
45 entries: d,
46 }
47 })
48 .parse(input)?;
49 Ok((input, result))
50}