nom_kconfig/attribute/depends_on.rs
1use nom::{
2 bytes::complete::tag,
3 combinator::{map, opt},
4 sequence::tuple,
5 IResult,
6};
7
8use crate::{util::wsi, KconfigInput};
9
10use super::{expression::parse_expression, Attribute};
11
12/// Parses a `depends on` attribute.
13/// If multiple dependencies are defined, they are connected with '&&'.
14/// Dependencies are applied to all other options within this menu entry (which also accept an "if" expression).
15/// See [https://www.kernel.org/doc/html/next/kbuild/kconfig-language.html#menu-attributes](https://www.kernel.org/doc/html/next/kbuild/kconfig-language.html#menu-attributes) for more information.
16///
17/// # Example
18/// ```
19/// use nom_kconfig::{
20/// assert_parsing_eq,
21/// attribute::{
22/// parse_depends_on,
23/// AndExpression, Atom, Expression, OrExpression, Term,
24/// },
25/// symbol::Symbol,
26/// Attribute
27/// };
28///
29/// assert_parsing_eq!(
30/// parse_depends_on,
31/// "depends on PCI",
32/// Ok((
33/// "",
34/// Attribute::DependsOn(Expression::Term(AndExpression::Term(
35/// Term::Atom(Atom::Symbol(Symbol::Constant("PCI".to_string())))
36/// )))
37/// ))
38/// )
39/// ```
40pub fn parse_depends_on(input: KconfigInput) -> IResult<KconfigInput, Attribute> {
41 map(
42 tuple((tag("depends"), wsi(opt(tag("on"))), wsi(parse_expression))),
43 |(_, _, e)| Attribute::DependsOn(e),
44 )(input)
45}