Files
gentoo-utils/src/useflag/parsers.rs
2025-11-20 23:27:41 +00:00

41 lines
1002 B
Rust

use mon::{Parser, ParserIter, ascii_alphanumeric, one_of, tag};
use crate::{
Parseable,
useflag::{IUseFlag, UseFlag},
};
impl<'a> Parseable<'a, &'a str> for UseFlag {
type Parser = impl Parser<&'a str, Output = Self>;
fn parser() -> Self::Parser {
let start = ascii_alphanumeric();
let rest = ascii_alphanumeric()
.or(one_of("+_@-".chars()))
.repeated()
.many();
start
.and(rest)
.recognize()
.map(|output: &str| UseFlag(output.to_string()))
}
}
impl<'a> Parseable<'a, &'a str> for IUseFlag {
type Parser = impl Parser<&'a str, Output = Self>;
fn parser() -> Self::Parser {
UseFlag::parser()
.preceded_by(tag("+"))
.map(|flag| IUseFlag {
default: true,
flag,
})
.or(UseFlag::parser().map(|flag| IUseFlag {
default: false,
flag,
}))
}
}