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 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)) } }