summaryrefslogtreecommitdiff
path: root/crates/useflag
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
parent0ec856797256b5d9807929e1b32c03756eb43124 (diff)
downloadgentoo-utils-c63c3e8c8c73ed7c036df7511ca190cdb96d92e2.tar.gz
Diffstat (limited to 'crates/useflag')
-rw-r--r--crates/useflag/Cargo.toml9
-rw-r--r--crates/useflag/src/lib.rs29
-rw-r--r--crates/useflag/src/meson.build1
-rw-r--r--crates/useflag/src/parsers.rs39
4 files changed, 78 insertions, 0 deletions
diff --git a/crates/useflag/Cargo.toml b/crates/useflag/Cargo.toml
new file mode 100644
index 0000000..16c8c34
--- /dev/null
+++ b/crates/useflag/Cargo.toml
@@ -0,0 +1,9 @@
+[package]
+name = "useflag"
+version = "0.1.0"
+edition = "2024"
+
+[dependencies]
+mon = { workspace = true }
+get = { workspace = true }
+parseable = { path = "../parseable" } \ No newline at end of file
diff --git a/crates/useflag/src/lib.rs b/crates/useflag/src/lib.rs
new file mode 100644
index 0000000..75c40eb
--- /dev/null
+++ b/crates/useflag/src/lib.rs
@@ -0,0 +1,29 @@
+#![deny(clippy::pedantic, unused_imports)]
+#![allow(
+ dead_code,
+ unstable_name_collisions,
+ clippy::missing_errors_doc,
+ clippy::missing_panics_doc
+)]
+#![feature(impl_trait_in_assoc_type)]
+
+use core::fmt;
+
+use get::Get;
+
+mod parsers;
+
+#[derive(Clone, Debug, PartialEq, Eq, Hash, Get)]
+pub struct UseFlag(#[get(method = "name", kind = "deref")] String);
+
+#[derive(Clone, Debug, PartialEq, Eq, Hash, Get)]
+pub struct IUseFlag {
+ default: bool,
+ flag: UseFlag,
+}
+
+impl fmt::Display for UseFlag {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ write!(f, "{}", self.0)
+ }
+}
diff --git a/crates/useflag/src/meson.build b/crates/useflag/src/meson.build
new file mode 100644
index 0000000..a7331a8
--- /dev/null
+++ b/crates/useflag/src/meson.build
@@ -0,0 +1 @@
+sources += files('mod.rs', 'parsers.rs')
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,
+ }))
+ }
+}