forked from gentoo-utils/gentoo-utils
impl profile evaluation
This commit is contained in:
36
src/repo/profile/package_use/parsers.rs
Normal file
36
src/repo/profile/package_use/parsers.rs
Normal file
@@ -0,0 +1,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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user