nom_config_in/entry/
comment.rs1use nom::character::complete::char;
2
3use nom::{
4 branch::alt,
5 bytes::complete::{tag, take_until},
6 combinator::map,
7 sequence::{delimited, tuple},
8 IResult,
9};
10use serde::Serialize;
11
12use crate::util::ws;
13use crate::ConfigInInput;
14
15#[derive(Debug, Clone, Serialize, PartialEq)]
16pub struct Comment {
17 pub prompt: String,
18}
19
20pub fn parse_comment(input: ConfigInInput) -> IResult<ConfigInInput, String> {
21 map(
22 tuple((ws(tag("comment")), ws(parse_prompt_option))),
23 |(_, prompt)| prompt.to_string(),
24 )(input)
25}
26
27pub fn parse_prompt_option(input: ConfigInInput) -> IResult<ConfigInInput, String> {
28 map(
29 alt((
30 delimited(ws(char('"')), take_until("\""), char('"')),
31 delimited(ws(char('\'')), take_until("'"), char('\'')),
32 )),
33 |d: ConfigInInput| d.fragment().to_string(),
34 )(input)
35}