nom_config_in/entry/
main_menu_option.rs

1use nom::{
2    branch::alt,
3    bytes::complete::tag,
4    combinator::{eof, map},
5    multi::many0,
6    sequence::{pair, preceded, tuple},
7    IResult,
8};
9use serde::Serialize;
10
11use crate::{
12    util::{ws, wsi},
13    ConfigInInput,
14};
15
16use super::{comment::parse_comment, parse_entry, Entry};
17
18pub fn parse_main_menu_option(input: ConfigInInput) -> IResult<ConfigInInput, MainMenuOption> {
19    map(
20        tuple((
21            preceded(
22                pair(ws(tag("mainmenu_option")), wsi(tag("next_comment"))),
23                ws(parse_comment),
24            ),
25            many0(ws(parse_entry)),
26            alt((
27                ws(tag("endmenu")),
28                //ws(peek(tag("fi"))),
29                //ws(peek(tag("mainmenu_option"))),
30                ws(eof),
31            )),
32        )),
33        |(d, e, _)| MainMenuOption {
34            comment: d,
35            entries: e,
36        },
37    )(input)
38}
39
40#[derive(Debug, Default, Clone, Serialize, PartialEq)]
41pub struct MainMenuOption {
42    pub comment: String,
43    pub entries: Vec<Entry>,
44}