summaryrefslogtreecommitdiff
path: root/crates/useflag/src/parsers.rs
diff options
context:
space:
mode:
authorJohn Turner <jturner.usa@gmail.com>2025-12-17 06:45:27 +0000
committerJohn Turner <jturner.usa@gmail.com>2025-12-17 06:45:27 +0000
commitc63c3e8c8c73ed7c036df7511ca190cdb96d92e2 (patch)
tree3262ef318f03388d37ac28493e42c1638c227c27 /crates/useflag/src/parsers.rs
parent0ec856797256b5d9807929e1b32c03756eb43124 (diff)
downloadgentoo-utils-split-into-workspace.tar.gz
Diffstat (limited to 'crates/useflag/src/parsers.rs')
-rw-r--r--crates/useflag/src/parsers.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/crates/useflag/src/parsers.rs b/crates/useflag/src/parsers.rs
new file mode 100644
index 0000000..3007bde
--- /dev/null
+++ b/crates/useflag/src/parsers.rs
@@ -0,0 +1,39 @@
+use parseable::Parseable;
+
+use mon::{Parser, ParserIter, ascii_alphanumeric, one_of, tag};
+
+use crate::{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,
+ }))
+ }
+}