impl profile evaluation
This commit is contained in:
35
src/repo/profile/parsers.rs
Normal file
35
src/repo/profile/parsers.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
use mon::{Parser, ParserIter, any, ascii_whitespace1, tag};
|
||||
|
||||
use crate::{
|
||||
Parseable,
|
||||
repo::profile::{FlagOperation, LineBasedFileExpr},
|
||||
useflag::UseFlag,
|
||||
};
|
||||
|
||||
impl<'a, T> Parseable<'a, &'a str> for LineBasedFileExpr<T>
|
||||
where
|
||||
T: Parseable<'a, &'a str>,
|
||||
{
|
||||
type Parser = impl Parser<&'a str, Output = Self>;
|
||||
|
||||
fn parser() -> Self::Parser {
|
||||
let comment = tag("#")
|
||||
.preceded_by(ascii_whitespace1().opt())
|
||||
.followed_by(any().and_not(tag("\n")).repeated().many())
|
||||
.map(|_| LineBasedFileExpr::Comment);
|
||||
let expr = T::parser().map(|expr| LineBasedFileExpr::Expr(expr));
|
||||
|
||||
comment.or(expr)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Parseable<'a, &'a str> for FlagOperation {
|
||||
type Parser = impl Parser<&'a str, Output = Self>;
|
||||
|
||||
fn parser() -> Self::Parser {
|
||||
UseFlag::parser()
|
||||
.preceded_by(tag("-"))
|
||||
.map(FlagOperation::Remove)
|
||||
.or(UseFlag::parser().map(FlagOperation::Add))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user