1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use nom::{
    bytes::complete::tag,
    combinator::{map, opt},
    sequence::tuple,
    IResult,
};

use crate::{util::wsi, KconfigInput};

use super::{expression::parse_expression, Attribute};

/// Parses a `depends on` attribute.
/// If multiple dependencies are defined, they are connected with '&&'. Dependencies are applied to all other options within this menu entry (which also accept an "if" expression), so these two examples are equivalent:
///
/// # Example
/// ```
/// use nom_kconfig::{
///     assert_parsing_eq,
///     attribute::{
///         parse_depends_on,
///         AndExpression, Atom, Expression, OrExpression, Term,
///     },
///     symbol::Symbol,
///     Attribute
/// };
///
/// assert_parsing_eq!(
///     parse_depends_on,
///     "depends on PCI",
///     Ok((
///         "",
///         Attribute::DependsOn(Expression::Term(AndExpression::Term(
///             Term::Atom(Atom::Symbol(Symbol::Constant("PCI".to_string())))
///         )))
///     ))
/// )
/// ```
pub fn parse_depends_on(input: KconfigInput) -> IResult<KconfigInput, Attribute> {
    map(
        tuple((tag("depends"), wsi(opt(tag("on"))), wsi(parse_expression))),
        |(_, _, e)| Attribute::DependsOn(e),
    )(input)
}