lollipop operator, fixed but in grammar-lalrpop for environment parsing

This commit is contained in:
elvis
2025-06-19 23:48:16 +02:00
parent bbff61f71a
commit 732683fd24
7 changed files with 343 additions and 169 deletions

View File

@ -10,7 +10,11 @@ use super::structure::{RSset, RSreaction};
/// Computes the result of a single reaction (if enabled returns the products)
/// otherwise returns None.
pub fn compute_step<'a>(current_state: &'a RSset, reaction: &'a RSreaction) -> Option<&'a RSset> {
// see result
pub fn compute_step<'a>(
current_state: &'a RSset,
reaction: &'a RSreaction
) -> Option<&'a RSset> {
if reaction.enabled(current_state) {
Some(reaction.products())
} else {
@ -20,6 +24,23 @@ pub fn compute_step<'a>(current_state: &'a RSset, reaction: &'a RSreaction) -> O
/// Computes the result of a series of reactions. Returns the union of all
/// products.
pub fn compute_all<'a>(current_state: &'a RSset, reactions: Vec<&'a RSreaction>) -> RSset {
reactions.iter().fold(RSset::new(), |acc, r| acc.union_option(compute_step(current_state, r)))
// see result
pub fn compute_all<'a>(
current_state: &'a RSset,
reactions: Vec<&'a RSreaction>
) -> RSset {
reactions.iter().fold(
RSset::new(),
|acc, r| acc.union_option(compute_step(current_state, r))
)
}
pub fn compute_all_owned<'a>(
current_state: &'a RSset,
reactions: &'a [RSreaction]
) -> RSset {
reactions.iter().fold(
RSset::new(),
|acc, r| acc.union_option(compute_step(current_state, r))
)
}