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