From b5765118fead09f3501e99bcb4cc19496912040d Mon Sep 17 00:00:00 2001 From: John Turner Date: Wed, 29 Oct 2025 12:50:07 +0000 Subject: [PATCH] make depend::Expr generic over Parseables --- src/depend/mod.rs | 14 +++++++------- src/depend/parsers.rs | 14 +++++++++----- tests/depend.rs | 3 ++- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/depend/mod.rs b/src/depend/mod.rs index 9a7fb71..1d85005 100644 --- a/src/depend/mod.rs +++ b/src/depend/mod.rs @@ -1,4 +1,4 @@ -use crate::{atom::Atom, useflag::UseFlag}; +use crate::useflag::UseFlag; pub mod parsers; @@ -9,10 +9,10 @@ pub enum Conditional { } #[derive(Clone, Debug)] -pub enum Expr { - Atom(Atom), - AllOf(Vec), - AnyOf(Vec), - OneOf(Vec), - ConditionalGroup(Conditional, Vec), +pub enum Expr { + Element(T), + AllOf(Vec), + AnyOf(Vec), + OneOf(Vec), + ConditionalGroup(Conditional, Vec), } diff --git a/src/depend/parsers.rs b/src/depend/parsers.rs index a17c387..975bbe6 100644 --- a/src/depend/parsers.rs +++ b/src/depend/parsers.rs @@ -2,12 +2,14 @@ use mon::{Parser, tag, whitespace1}; use crate::{ Parseable, - atom::Atom, depend::{Conditional, Expr}, useflag::UseFlag, }; -impl<'a> Parseable<'a, &'a str> for Expr { +impl<'a, T> Parseable<'a, &'a str> for Expr +where + T: Parseable<'a, &'a str>, +{ type Parser = impl Parser<&'a str, Output = Self>; fn parser() -> Self::Parser { @@ -38,8 +40,8 @@ impl<'a> Parseable<'a, &'a str> for Expr { ) .map(|(conditional, exprs)| Expr::ConditionalGroup(conditional, exprs)); - Atom::parser() - .map(|atom| Expr::Atom(atom)) + T::parser() + .map(|e| Expr::Element(e)) .or(conditional_group) .or(any_of_group) .or(all_of_group) @@ -68,13 +70,15 @@ mod test { use mon::input::InputIter; + use crate::atom::Atom; + use super::*; #[test] fn test_expr() { let it = InputIter::new("flag? ( || ( foo/bar foo/bar ) )"); - Expr::parser() + Expr::::parser() .separated_list(whitespace1(), 0..) .check_finished(it) .unwrap(); diff --git a/tests/depend.rs b/tests/depend.rs index 12d6e75..02c59f2 100644 --- a/tests/depend.rs +++ b/tests/depend.rs @@ -1,5 +1,6 @@ use gentoo_utils::{ Parseable, + atom::Atom, depend::{self, Expr}, }; use mon::{Parser, eof, input::InputIter, tag, whitespace1}; @@ -17,7 +18,7 @@ fn parse_md5_cache() { if line.starts_with("DEPEND=") { eprintln!("{line}"); eprintln!(); - Expr::parser() + Expr::::parser() .separated_list(whitespace1(), 0..) .ignore() .or(eof())