Files
gentoo-utils-gitea/src/repo/profile/parsers.rs
2025-12-11 02:13:12 +00:00

36 lines
980 B
Rust

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