summaryrefslogtreecommitdiff
path: root/crates/useflag/src/parsers.rs
diff options
context:
space:
mode:
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,
+ }))
+ }
+}