summaryrefslogtreecommitdiff
path: root/src/repo/profile/package_use/parsers.rs
blob: f7bc801517cb3fbc95f59f36790aade86f58e2cc (plain)
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
use mon::{Parser, ParserIter, ascii_whitespace, ascii_whitespace1, tag};

use crate::{
    Parseable,
    atom::Atom,
    repo::profile::{FlagOperation, package_use::Expr},
};

impl<'a> Parseable<'a, &'a str> for Expr {
    type Parser = impl Parser<&'a str, Output = Self>;

    fn parser() -> Self::Parser {
        Atom::parser()
            .followed_by(ascii_whitespace1())
            .and(
                FlagOperation::parser()
                    .separated_by(ascii_whitespace().and_not(tag("\n")).repeated().at_least(1))
                    .at_least(1),
            )
            .map(|(atom, operations)| Expr(atom, operations))
    }
}

#[cfg(test)]
mod test {
    use mon::input::InputIter;

    use super::*;

    #[test]
    fn test_parse_expr() {
        let it = InputIter::new("foo/bar a -b");

        Expr::parser().check_finished(it).unwrap();
    }
}