summaryrefslogtreecommitdiff
path: root/src/repo/profile/parsers.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/repo/profile/parsers.rs')
-rw-r--r--src/repo/profile/parsers.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/repo/profile/parsers.rs b/src/repo/profile/parsers.rs
new file mode 100644
index 0000000..44e767e
--- /dev/null
+++ b/src/repo/profile/parsers.rs
@@ -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))
+ }
+}