impl IUseFlag type

This commit is contained in:
John Turner
2025-10-27 21:58:35 -04:00
parent 4789790733
commit 847e5fc019
2 changed files with 23 additions and 2 deletions

View File

@@ -1,10 +1,18 @@
use core::fmt; use core::fmt;
use get::Get;
pub mod parsers; pub mod parsers;
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
pub struct UseFlag(String); pub struct UseFlag(String);
#[derive(Clone, Debug, PartialEq, Eq, Get)]
pub struct IUseFlag {
default: bool,
flag: UseFlag,
}
impl UseFlag { impl UseFlag {
pub fn get(&self) -> &str { pub fn get(&self) -> &str {
self.0.as_str() self.0.as_str()

View File

@@ -1,6 +1,6 @@
use mon::{Parser, r#if}; use mon::{Parser, r#if, tag};
use crate::useflag::UseFlag; use crate::useflag::{IUseFlag, UseFlag};
pub fn useflag<'a>() -> impl Parser<&'a str, Output = UseFlag> { pub fn useflag<'a>() -> impl Parser<&'a str, Output = UseFlag> {
let start = r#if(|c: &char| c.is_ascii_alphanumeric()); let start = r#if(|c: &char| c.is_ascii_alphanumeric());
@@ -11,3 +11,16 @@ pub fn useflag<'a>() -> impl Parser<&'a str, Output = UseFlag> {
.recognize() .recognize()
.map(|output: &str| UseFlag(output.to_string())) .map(|output: &str| UseFlag(output.to_string()))
} }
pub fn iuseflag<'a>() -> impl Parser<&'a str, Output = IUseFlag> {
useflag()
.preceded_by(tag("+"))
.map(|flag| IUseFlag {
default: true,
flag,
})
.or(useflag().map(|flag| IUseFlag {
default: false,
flag,
}))
}