forked from gentoo-utils/gentoo-utils
37 lines
876 B
Rust
37 lines
876 B
Rust
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();
|
|
}
|
|
}
|