nom_kconfig/entry/
choice.rs1use nom::{
2 branch::alt,
3 bytes::complete::tag,
4 combinator::map,
5 multi::many0,
6 sequence::{delimited, pair},
7 IResult,
8};
9#[cfg(feature = "deserialize")]
10use serde::Deserialize;
11#[cfg(feature = "serialize")]
12use serde::Serialize;
13
14use crate::{
15 attribute::{optional::parse_optional, parse_attribute, r#type::parse_type, Attribute},
16 util::ws,
17 Entry, KconfigInput,
18};
19
20use super::parse_entry;
21
22#[derive(Debug, Clone, Default, PartialEq)]
28#[cfg_attr(feature = "hash", derive(Hash))]
29#[cfg_attr(feature = "serialize", derive(Serialize))]
30#[cfg_attr(feature = "deserialize", derive(Deserialize))]
31pub struct Choice {
32 pub options: Vec<Attribute>,
33 pub entries: Vec<Entry>,
34}
35
36fn parse_choice_attributes(input: KconfigInput) -> IResult<KconfigInput, Vec<Attribute>> {
37 ws(many0(alt((
38 parse_attribute,
39 parse_type,
40 map(ws(parse_optional), |_| Attribute::Optional),
41 ))))(input)
42}
43
44pub fn parse_choice(input: KconfigInput) -> IResult<KconfigInput, Choice> {
45 map(
46 delimited(
47 tag("choice"),
48 pair(parse_choice_attributes, many0(ws(parse_entry))),
49 ws(tag("endchoice")),
50 ),
51 |(options, entries)| Choice { options, entries },
52 )(input)
53}