use nom::combinator::map;
use crate::parsers::{parse_pref_con_gd, prefix_expr, ParseResult, Span};
use crate::types::ProblemConstraintsDef;
pub fn parse_problem_constraints_def<'a, T: Into<Span<'a>>>(
input: T,
) -> ParseResult<'a, ProblemConstraintsDef> {
map(
prefix_expr(":constraints", parse_pref_con_gd),
ProblemConstraintsDef::new,
)(input.into())
}
impl crate::parsers::Parser for ProblemConstraintsDef {
type Item = ProblemConstraintsDef;
fn parse<'a, S: Into<Span<'a>>>(input: S) -> ParseResult<'a, Self::Item> {
parse_problem_constraints_def(input)
}
}
#[cfg(test)]
mod tests {
use crate::parsers::preamble::*;
use crate::{ConGD, PrefConGDs, ProblemConstraintsDef};
#[test]
fn test_parse() {
let input = "(:constraints (preference test (and)))";
assert!(
ProblemConstraintsDef::parse(input).is_value(ProblemConstraintsDef::new(
PrefConGDs::new_preference(Some("test".into()), ConGD::new_and([]))
))
);
}
}