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 44 45 46 47 48 49 50
use nom::{bytes::complete::tag, combinator::map, sequence::tuple, IResult};
#[cfg(feature = "deserialize")]
use serde::Deserialize;
#[cfg(feature = "serialize")]
use serde::Serialize;
use crate::{util::ws, KconfigInput};
use super::expression::{parse_expression, Expression};
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "hash", derive(Hash))]
#[cfg_attr(feature = "serialize", derive(Serialize))]
#[cfg_attr(feature = "deserialize", derive(Deserialize))]
pub struct Requires {
pub symbol: Expression,
}
/// Parses a `requires` attribute.
/// TODO: I think this attribute is deprecated.
///
/// /// Parses a `range` attribute.
/// # Example
/// ```
/// use nom_kconfig::{
/// assert_parsing_eq,
/// attribute::{
/// parse_requires, Requires,
/// AndExpression, Atom, CompareExpression, CompareOperator, Expression, OrExpression, Term},
/// symbol::Symbol,
/// };
///
/// assert_parsing_eq!(
/// parse_requires,
/// " requires KVM",
/// Ok((
/// "",
/// Requires {
/// symbol: Expression::Term(AndExpression::Term(Term::Atom(
/// Atom::Symbol(Symbol::Constant("KVM".to_string())
/// ))))
/// }
/// ))
/// )
/// ```
pub fn parse_requires(input: KconfigInput) -> IResult<KconfigInput, Requires> {
map(
tuple((ws(tag("requires")), ws(parse_expression))),
|(_, s)| Requires { symbol: s },
)(input)
}