Files
ReactionSystemsGUI/reaction_systems_gui/src/app_logic.rs

1753 lines
65 KiB
Rust
Raw Normal View History

2025-10-17 21:42:41 +02:00
use std::collections::{HashSet, VecDeque};
use std::rc::Rc;
use egui_node_graph2::*;
use rsprocess::frequency::BasicFrequency;
use rsprocess::system::{ExtensionsSystem, LoopSystem};
use rsprocess::translator::Formatter;
use crate::app::{
2025-10-23 00:17:40 +02:00
BasicDataType, BasicValue, NodeData, NodeInstruction, OutputsCache,
2025-10-17 21:42:41 +02:00
};
use crate::helper;
type MyGraph = Graph<NodeData, BasicDataType, BasicValue>;
/// Recursively evaluates all dependencies of this node, then evaluates the node
/// itself. Except we use a queue so we dont pollute the stack.
pub fn evaluate_node(
graph: &MyGraph,
node_id: NodeId,
outputs_cache: &OutputsCache,
translator: &mut rsprocess::translator::Translator,
ctx: &eframe::egui::Context,
) -> anyhow::Result<BasicValue> {
// generates list of nodes to evaluate and invalidates cache of those nodes
let to_evaluate = generate_to_evaluate(graph, outputs_cache, node_id)?;
let mut to_ret = None;
#[cfg(debug_assertions)]
{
if !to_evaluate.is_empty() {
println!("evaluating nodes {:?}", to_evaluate);
}
}
2025-10-17 21:42:41 +02:00
// for each node to evaluate (in the correct order) finds the output and
// populates the cache
for node_id in to_evaluate {
let node = &graph[node_id];
let output_name = graph[node_id]
.user_data
.template
.output()
.unwrap_or(("".into(), BasicDataType::Error))
.0;
match process_template(
graph,
node_id,
outputs_cache,
&node.user_data.template,
&output_name,
translator,
&mut to_ret,
ctx,
)? {
| None => {},
| Some(val) => return Ok(val),
}
}
if let Some(res) = to_ret.take() {
Ok(res)
} else {
let output_field = graph[node_id]
.user_data
.template
.output()
.map(|el| el.0)
.unwrap_or("".into());
let output_id = graph[node_id].get_output(&output_field)?;
Ok(outputs_cache.retrieve_output(output_id).unwrap())
}
}
fn generate_to_evaluate(
graph: &MyGraph,
outputs_cache: &OutputsCache,
node_id: NodeId,
) -> anyhow::Result<Vec<NodeId>> {
let mut dependencies = vec![];
let mut queue = VecDeque::new();
queue.push_back(node_id);
// first find all possible dependencies
while let Some(n_id) = queue.pop_front() {
dependencies.push(n_id);
for id in graph[n_id].input_ids() {
if let Some(output_id) = graph.connection(id) {
let node = graph.get_output(output_id).node;
queue.push_back(node);
}
}
}
dependencies.reverse();
// then keep only the ones that have an input that is different or not
// cached
let mut res = vec![];
let mut invalid_ids = HashSet::new();
for n_id in dependencies {
let mut input_hashes = vec![];
if let NodeInstruction::SaveString = graph[n_id].user_data.template {
res.push(n_id);
invalid_ids.insert(n_id);
outputs_cache.invalidate_outputs(graph, n_id);
continue;
}
let first_output = if let Some(o) = graph[n_id].output_ids().next() {
o
} else {
continue;
};
let hashes =
if let Some(hashes) = outputs_cache.input_hashes(&first_output) {
hashes
} else {
res.push(n_id);
invalid_ids.insert(n_id);
outputs_cache.invalidate_outputs(graph, n_id);
continue;
};
for (input_id, input_hash) in graph[n_id].input_ids().zip(hashes.iter())
{
if let Some(output_id) = graph.connection(input_id) {
let node = graph.get_output(output_id).node;
if invalid_ids.contains(&node) {
res.push(n_id);
invalid_ids.insert(n_id);
outputs_cache.invalidate_outputs(graph, n_id);
continue;
}
// if we have a connection we assume that the input hasnt
// changed so we add the last known value
input_hashes.push(*input_hash);
} else {
input_hashes
.push(OutputsCache::calculate_hash(&graph[input_id].value));
}
}
for output_id in graph[n_id].output_ids() {
if !outputs_cache.same_hash_inputs(&output_id, &input_hashes) {
res.push(n_id);
invalid_ids.insert(n_id);
outputs_cache.invalidate_outputs(graph, n_id);
continue;
}
}
}
// dedup while preserving order
{
let mut set = HashSet::new();
res.retain(|x| set.insert(*x));
}
Ok(res)
}
2025-10-23 00:17:40 +02:00
// -----------------------------------------------------------------------------
2025-10-17 21:42:41 +02:00
#[allow(clippy::too_many_arguments)]
fn process_template(
graph: &MyGraph,
node_id: NodeId,
outputs_cache: &OutputsCache,
template: &NodeInstruction,
output_name: &str,
translator: &mut rsprocess::translator::Translator,
to_ret: &mut Option<BasicValue>,
ctx: &eframe::egui::Context,
) -> anyhow::Result<Option<BasicValue>> {
2025-10-22 22:17:59 +02:00
// macro that builds a tuple of retrieved values from cache
// same order as in the definition of the inputs
macro_rules! retrieve_from_cache {
(@accum (0) -> ($($body:tt)*))
=> {retrieve_from_cache!(@as_expr ($($body)*))};
(@accum (1) -> ($($body:tt)*))
=> {retrieve_from_cache!(
@accum (0) -> ($($body)*
outputs_cache.retrieve_cache_output(
graph,
node_id,
&graph[node_id]
.user_data
.template
.inputs()[0].0.clone())?,))};
(@accum (2) -> ($($body:tt)*))
=> {retrieve_from_cache!(
@accum (1) -> ($($body)*
outputs_cache.retrieve_cache_output(
graph,
node_id,
&graph[node_id]
.user_data
.template
.inputs()[1].0.clone())?,))};
(@accum (3) -> ($($body:tt)*))
=> {retrieve_from_cache!(
@accum (2) -> ($($body)*
outputs_cache.retrieve_cache_output(
graph,
node_id,
&graph[node_id]
.user_data
.template
.inputs()[2].0.clone())?,))};
(@accum (4) -> ($($body:tt)*))
=> {retrieve_from_cache!(
@accum (3) -> ($($body)*
outputs_cache.retrieve_cache_output(
graph,
node_id,
&graph[node_id]
.user_data
.template
.inputs()[3].0.clone())?,))};
(@accum (5) -> ($($body:tt)*))
=> {retrieve_from_cache!(
@accum (4) -> ($($body)*
outputs_cache.retrieve_cache_output(
graph,
node_id,
&graph[node_id]
.user_data
.template
.inputs()[4].0.clone())?,))};
(@accum (6) -> ($($body:tt)*))
=> {retrieve_from_cache!(
@accum (5) -> ($($body)*
outputs_cache.retrieve_cache_output(
graph,
node_id,
&graph[node_id]
.user_data
.template
.inputs()[5].0.clone())?,))};
(@accum (7) -> ($($body:tt)*))
=> {retrieve_from_cache!(
@accum (6) -> ($($body)*
outputs_cache.retrieve_cache_output(
graph,
node_id,
&graph[node_id]
.user_data
.template
.inputs()[6].0.clone())?,))};
(@accum (8) -> ($($body:tt)*))
=> {retrieve_from_cache!(
@accum (7) -> ($($body)*
outputs_cache.retrieve_cache_output(
graph,
node_id,
&graph[node_id]
.user_data
.template
.inputs()[7].0.clone())?,))};
(@accum (9) -> ($($body:tt)*))
=> {retrieve_from_cache!(
@accum (8) -> ($($body)*
outputs_cache.retrieve_cache_output(
graph,
node_id,
&graph[node_id]
.user_data
.template
.inputs()[8].0.clone())?,))};
(@accum (10) -> ($($body:tt)*))
=> {retrieve_from_cache!(
@accum (9) -> ($($body)*
outputs_cache.retrieve_cache_output(
graph,
node_id,
&graph[node_id]
.user_data
.template
.inputs()[9].0.clone())?,))};
(@as_expr $e:expr) => {$e};
[0] => {
2025-10-23 00:17:40 +02:00
compile_error!("Macro returns a value or a tuple, supply an \
integer greater than 0")
2025-10-22 22:17:59 +02:00
};
[1] => {
outputs_cache.retrieve_cache_output(
2025-10-17 21:42:41 +02:00
graph,
node_id,
2025-10-22 22:17:59 +02:00
&graph[node_id]
.user_data
.template
.inputs().first().unwrap().0.clone())?
};
[$n:tt] => {
{ retrieve_from_cache!(@accum ($n) -> ()) }
};
}
2025-10-23 00:17:40 +02:00
// creates a vector of the hash of the inputs
macro_rules! hash_inputs {
($($i:ident),*) => (vec![$(OutputsCache::calculate_hash(&$i)),*]);
}
2025-10-22 22:17:59 +02:00
match template {
| NodeInstruction::String => {
let s = retrieve_from_cache![1];
2025-10-23 00:17:40 +02:00
let hash_inputs = hash_inputs!(s);
2025-10-17 21:42:41 +02:00
if let BasicValue::String { value: _ } = s {
let res = s;
outputs_cache.populate_output(
graph,
node_id,
output_name,
res,
hash_inputs,
)?;
} else {
anyhow::bail!("Not a string");
}
},
| NodeInstruction::Path => {
2025-10-22 22:17:59 +02:00
let s = retrieve_from_cache![1];
2025-10-23 00:17:40 +02:00
let hash_inputs = hash_inputs!(s);
2025-10-17 21:42:41 +02:00
if let BasicValue::String { value } = s {
let res = BasicValue::Path { value };
outputs_cache.populate_output(
graph,
node_id,
output_name,
res,
hash_inputs,
)?;
} else {
anyhow::bail!("Not a string");
}
},
| NodeInstruction::ReadPath => {
2025-10-22 22:17:59 +02:00
let s = retrieve_from_cache![1];
2025-10-23 00:17:40 +02:00
let hash_inputs = hash_inputs!(s);
2025-10-17 21:42:41 +02:00
if let BasicValue::Path { value } = s {
2025-10-22 22:17:59 +02:00
let file = match std::fs::read_to_string(value) {
2025-10-23 00:17:40 +02:00
| Ok(f) => f,
| Err(e) =>
2025-10-22 22:17:59 +02:00
return Ok(Some(BasicValue::Error {
2025-10-23 00:17:40 +02:00
value: helper::reformat_generic_error(
e.to_string(),
ctx,
),
})),
2025-10-17 21:42:41 +02:00
};
2025-10-23 00:17:40 +02:00
let res = BasicValue::String { value: file };
2025-10-17 21:42:41 +02:00
outputs_cache.populate_output(
graph,
node_id,
output_name,
res,
hash_inputs,
)?;
} else {
anyhow::bail!("Not a path");
}
},
| NodeInstruction::System => {
2025-10-22 22:17:59 +02:00
let s = retrieve_from_cache![1];
2025-10-23 00:17:40 +02:00
let hash_inputs = hash_inputs!(s);
2025-10-22 22:17:59 +02:00
2025-10-17 21:42:41 +02:00
if let BasicValue::String { value } = s {
let res = grammar_separated::grammar::SystemParser::new()
.parse(&mut *translator, &value);
let sys = match res {
| Ok(s) => s,
| Err(parse_error) => {
return Ok(Some(BasicValue::Error {
value: helper::reformat_error(
parse_error,
&value,
ctx,
),
}));
},
};
let res = BasicValue::System { value: sys };
outputs_cache.populate_output(
graph,
node_id,
output_name,
res,
hash_inputs,
)?;
} else {
anyhow::bail!("Not a string");
}
},
| NodeInstruction::Statistics => {
2025-10-22 22:17:59 +02:00
let s = retrieve_from_cache![1];
2025-10-23 00:17:40 +02:00
let hash_inputs = hash_inputs!(s);
2025-10-22 22:17:59 +02:00
2025-10-17 21:42:41 +02:00
if let BasicValue::System { value } = s {
let res = BasicValue::String {
value: value.statistics(translator),
};
outputs_cache.populate_output(
graph,
node_id,
output_name,
res,
hash_inputs,
)?;
} else {
anyhow::bail!("Not a system");
}
},
| NodeInstruction::Target => {
2025-10-22 22:17:59 +02:00
let (s, i) = retrieve_from_cache![2];
2025-10-23 00:17:40 +02:00
let hash_inputs = hash_inputs!(s, i);
2025-10-17 21:42:41 +02:00
match (s, i) {
| (
BasicValue::System { value: s },
BasicValue::PositiveInt { value: i },
) => {
let limit = if i > 0 {
match s.target_limit(i) {
| Ok(l) => l,
| Err(e) => anyhow::bail!(e),
}
} else {
match s.target() {
| Ok(l) => l,
| Err(e) => anyhow::bail!(e),
}
};
let res = BasicValue::String {
value: format!(
"After {} steps arrived at state {}",
limit.0,
Formatter::from(translator, &limit.1)
),
};
outputs_cache.populate_output(
graph,
node_id,
output_name,
res,
hash_inputs,
)?;
},
| (BasicValue::System { value: _ }, _) =>
anyhow::bail!("Not an integer"),
| (_, BasicValue::PositiveInt { value: _ }) =>
anyhow::bail!("Not a system"),
| (_, _) => anyhow::bail!("Inputs all wrong"),
}
},
| NodeInstruction::Run => {
2025-10-22 22:17:59 +02:00
let (s, i) = retrieve_from_cache![2];
2025-10-23 00:17:40 +02:00
let hash_inputs = hash_inputs!(s, i);
2025-10-17 21:42:41 +02:00
match (s, i) {
| (
BasicValue::System { value: s },
BasicValue::PositiveInt { value: i },
) => {
let limit = if i > 0 {
match s.run_separated_limit(i) {
| Ok(l) => l,
| Err(e) => anyhow::bail!(e),
}
} else {
match s.run_separated() {
| Ok(l) => l,
| Err(e) => anyhow::bail!(e),
}
};
let mut output = String::new();
output.push_str(
"The trace is composed by the set of entities: ",
);
for (e, _c, _t) in limit {
output.push_str(&format!(
"{}",
Formatter::from(translator, &e)
));
}
let res = BasicValue::String { value: output };
outputs_cache.populate_output(
graph,
node_id,
output_name,
res,
hash_inputs,
)?;
},
| (BasicValue::System { value: _ }, _) =>
anyhow::bail!("Not an integer"),
| (_, BasicValue::PositiveInt { value: _ }) =>
anyhow::bail!("Not a system"),
| (_, _) => anyhow::bail!("Inputs all wrong"),
}
},
| NodeInstruction::Loop => {
2025-10-22 22:17:59 +02:00
let (s, i) = retrieve_from_cache![2];
2025-10-23 00:17:40 +02:00
let hash_inputs = hash_inputs!(s, i);
2025-10-17 21:42:41 +02:00
match (s, i) {
| (
BasicValue::System { value: sys },
BasicValue::Symbol { value: i },
) => {
let s = match translator.encode_not_mut(i) {
| Some(s) => s,
| None => anyhow::bail!("Symbol not found"),
};
let l = match sys.lollipops_only_loop_named(s) {
| Some(l) => l,
| None => anyhow::bail!("No loop found"),
};
let mut output = String::new();
output.push_str("The loop is composed by the sets: ");
for e in l {
output.push_str(&format!(
"{}",
Formatter::from(translator, &e)
));
}
let res = BasicValue::String { value: output };
outputs_cache.populate_output(
graph,
node_id,
output_name,
res,
hash_inputs,
)?;
},
| (BasicValue::System { value: _ }, _) =>
anyhow::bail!("Not an integer"),
| (_, BasicValue::PositiveInt { value: _ }) =>
anyhow::bail!("Not a system"),
| (_, _) => anyhow::bail!("Inputs all wrong"),
}
},
| NodeInstruction::Symbol => {
2025-10-22 22:17:59 +02:00
let s = retrieve_from_cache![1];
2025-10-23 00:17:40 +02:00
let hash_inputs = hash_inputs!(s);
2025-10-22 22:17:59 +02:00
2025-10-17 21:42:41 +02:00
if let BasicValue::String { value } = s {
let res = BasicValue::Symbol { value };
outputs_cache.populate_output(
graph,
node_id,
output_name,
res,
hash_inputs,
)?;
} else {
anyhow::bail!("Not a string");
}
},
| NodeInstruction::Frequency => {
2025-10-22 22:17:59 +02:00
let s = retrieve_from_cache![1];
2025-10-23 00:17:40 +02:00
let hash_inputs = hash_inputs!(s);
2025-10-17 21:42:41 +02:00
if let BasicValue::System { value } = s {
let res = match rsprocess::frequency::Frequency::naive_frequency(
&value,
) {
| Ok(r) => r,
| Err(e) => anyhow::bail!(e),
};
let output = format!(
"Frequency of encountered symbols:\n{}",
Formatter::from(translator, &res)
);
let res = BasicValue::String { value: output };
outputs_cache.populate_output(
graph,
node_id,
output_name,
res,
hash_inputs,
)?;
} else {
anyhow::bail!("Not a system");
}
},
| NodeInstruction::LimitFrequency => {
2025-10-22 22:17:59 +02:00
let (sys, exp) = retrieve_from_cache![2];
2025-10-23 00:17:40 +02:00
let hash_inputs = hash_inputs!(sys, exp);
2025-10-17 21:42:41 +02:00
match (sys, exp) {
| (
BasicValue::System { value: sys },
BasicValue::Experiment { value: exp },
) => {
let (_, sets) = exp;
let l =
match rsprocess::frequency::Frequency::limit_frequency(
&sets,
&sys.reaction_rules,
&sys.available_entities,
) {
| Some(l) => l,
| None => anyhow::bail!("No loop found"),
};
let res = BasicValue::String {
value: format!(
"Frequency of encountered symbols:\n{}",
Formatter::from(translator, &l)
),
};
outputs_cache.populate_output(
graph,
node_id,
output_name,
res,
hash_inputs,
)?;
},
| (BasicValue::System { value: _ }, _) =>
anyhow::bail!("Not an experiment"),
| (_, BasicValue::Experiment { value: _ }) =>
anyhow::bail!("Not a system"),
| (_, _) => anyhow::bail!("Inputs all wrong"),
}
},
| NodeInstruction::Experiment => {
2025-10-22 22:17:59 +02:00
let s = retrieve_from_cache![1];
2025-10-23 00:17:40 +02:00
let hash_inputs = hash_inputs!(s);
2025-10-22 22:17:59 +02:00
2025-10-17 21:42:41 +02:00
if let BasicValue::String { value } = s {
let value =
match grammar_separated::grammar::ExperimentParser::new()
.parse(translator, &value)
{
| Ok(v) => v,
| Err(e) =>
return Ok(Some(BasicValue::Error {
value: helper::reformat_error(e, &value, ctx),
})),
};
let res = BasicValue::Experiment { value };
outputs_cache.populate_output(
graph,
node_id,
output_name,
res,
hash_inputs,
)?;
} else {
anyhow::bail!("Not a string");
}
},
| NodeInstruction::FastFrequency => {
2025-10-22 22:17:59 +02:00
let (sys, exp) = retrieve_from_cache![2];
2025-10-23 00:17:40 +02:00
let hash_inputs = hash_inputs!(sys, exp);
2025-10-17 21:42:41 +02:00
match (sys, exp) {
| (
BasicValue::System { value: sys },
BasicValue::Experiment { value: exp },
) => {
let (weights, sets) = exp;
let l =
match rsprocess::frequency::Frequency::fast_frequency(
&sets,
&sys.reaction_rules,
&sys.available_entities,
&weights,
) {
| Some(l) => l,
| None => anyhow::bail!("No loop found"),
};
let res = BasicValue::String {
value: format!(
"Frequency of encountered symbols:\n{}",
Formatter::from(translator, &l)
),
};
outputs_cache.populate_output(
graph,
node_id,
output_name,
res,
hash_inputs,
)?;
},
| (BasicValue::System { value: _ }, _) =>
anyhow::bail!("Not an experiment"),
| (_, BasicValue::Experiment { value: _ }) =>
anyhow::bail!("Not a system"),
| (_, _) => anyhow::bail!("Inputs all wrong"),
}
},
| NodeInstruction::BisimilarityKanellakisSmolka => {
2025-10-22 22:17:59 +02:00
let (graph_1, graph_2, grouping) = retrieve_from_cache![3];
2025-10-23 00:17:40 +02:00
let hash_inputs = hash_inputs!(graph_1, graph_2, grouping);
2025-10-17 21:42:41 +02:00
match (graph_1, graph_2, grouping) {
| (
BasicValue::Graph { value: graph_1 },
BasicValue::Graph { value: graph_2 },
BasicValue::GroupingFunction { value: grouping },
) => {
use execution::data::MapEdges;
let graph_1 = match graph_1.map_edges(&grouping, translator)
{
| Ok(g) => g,
| Err(e) => anyhow::bail!(e),
};
let graph_2 = match graph_2.map_edges(&grouping, translator)
{
| Ok(g) => g,
| Err(e) => anyhow::bail!(e),
};
let l = bisimilarity::bisimilarity_kanellakis_smolka::bisimilarity(&&graph_1, &&graph_2);
let res = BasicValue::String {
value: format!("{l}"),
};
outputs_cache.populate_output(
graph,
node_id,
output_name,
res,
hash_inputs,
)?;
},
| (_, _, _) => anyhow::bail!("Invalid inputs to bisimilarity."),
}
},
| NodeInstruction::GroupFunction => {
2025-10-22 22:17:59 +02:00
let s = retrieve_from_cache![1];
2025-10-23 00:17:40 +02:00
let hash_inputs = hash_inputs!(s);
2025-10-17 21:42:41 +02:00
if let BasicValue::String { value } = s {
let res = grammar_separated::assert::AssertParser::new()
.parse(&mut *translator, &value);
let res = match res {
| Ok(s) => s,
| Err(parse_error) => {
return Ok(Some(BasicValue::Error {
value: helper::reformat_error(
parse_error,
&value,
ctx,
),
}));
},
};
let res = BasicValue::GroupingFunction { value: *res };
outputs_cache.populate_output(
graph,
node_id,
output_name,
res,
hash_inputs,
)?;
} else {
anyhow::bail!("Not a string");
}
},
| NodeInstruction::BisimilarityPaigeTarjanNoLabels => {
2025-10-22 22:17:59 +02:00
let (graph_1, graph_2, grouping) = retrieve_from_cache![3];
2025-10-23 00:17:40 +02:00
let hash_inputs = hash_inputs!(graph_1, graph_2, grouping);
2025-10-17 21:42:41 +02:00
match (graph_1, graph_2, grouping) {
| (
BasicValue::Graph { value: graph_1 },
BasicValue::Graph { value: graph_2 },
BasicValue::GroupingFunction { value: grouping },
) => {
use execution::data::MapEdges;
let graph_1 = match graph_1.map_edges(&grouping, translator)
{
| Ok(g) => g,
| Err(e) => anyhow::bail!(e),
};
let graph_2 = match graph_2.map_edges(&grouping, translator)
{
| Ok(g) => g,
| Err(e) => anyhow::bail!(e),
};
let l = bisimilarity::bisimilarity_paige_tarkan::bisimilarity_ignore_labels(&&graph_1, &&graph_2);
let res = BasicValue::String {
value: format!("{l}"),
};
outputs_cache.populate_output(
graph,
node_id,
output_name,
res,
hash_inputs,
)?;
},
| (_, _, _) => anyhow::bail!("Invalid inputs to bisimilarity."),
}
},
| NodeInstruction::BisimilarityPaigeTarjan => {
2025-10-22 22:17:59 +02:00
let (graph_1, graph_2, grouping) = retrieve_from_cache![3];
2025-10-23 00:17:40 +02:00
let hash_inputs = hash_inputs!(graph_1, graph_2, grouping);
2025-10-17 21:42:41 +02:00
match (graph_1, graph_2, grouping) {
| (
BasicValue::Graph { value: graph_1 },
BasicValue::Graph { value: graph_2 },
BasicValue::GroupingFunction { value: grouping },
) => {
use execution::data::MapEdges;
let graph_1 = match graph_1.map_edges(&grouping, translator)
{
| Ok(g) => g,
| Err(e) => anyhow::bail!(e),
};
let graph_2 = match graph_2.map_edges(&grouping, translator)
{
| Ok(g) => g,
| Err(e) => anyhow::bail!(e),
};
let l =
bisimilarity::bisimilarity_paige_tarkan::bisimilarity(
&&graph_1, &&graph_2,
);
let res = BasicValue::String {
value: format!("{l}"),
};
outputs_cache.populate_output(
graph,
node_id,
output_name,
res,
hash_inputs,
)?;
},
| (_, _, _) => anyhow::bail!("Invalid inputs to bisimilarity."),
}
},
| NodeInstruction::SystemGraph => {
2025-10-22 22:17:59 +02:00
let s = retrieve_from_cache![1];
2025-10-23 00:17:40 +02:00
let hash_inputs = hash_inputs!(s);
2025-10-17 21:42:41 +02:00
if let BasicValue::System { value } = s {
let value = match value.digraph() {
| Ok(g) => g,
| Err(e) => anyhow::bail!(e),
};
let res = BasicValue::Graph { value };
outputs_cache.populate_output(
graph,
node_id,
output_name,
res,
hash_inputs,
)?;
} else {
anyhow::bail!("Not a system");
}
},
| NodeInstruction::SaveString => {
2025-10-22 22:17:59 +02:00
let (path, string) = retrieve_from_cache![2];
2025-10-17 21:42:41 +02:00
match (path, string) {
| (
BasicValue::Path { value: path },
BasicValue::String { value },
) => {
*to_ret = Some(BasicValue::SaveString { path, value });
},
| (BasicValue::Path { .. }, _) => {
anyhow::bail!("Not a string");
},
| (_, BasicValue::String { .. }) => {
anyhow::bail!("Not a path");
},
| (_, _) => {
anyhow::bail!("Values of wrong type");
},
}
},
| NodeInstruction::Dot => {
2025-10-23 00:17:40 +02:00
let (
input_graph,
display_node,
display_edge,
color_node,
color_edge,
) = retrieve_from_cache![5];
let hash_inputs = hash_inputs!(
input_graph,
display_node,
display_edge,
color_node,
color_edge
);
2025-10-17 21:42:41 +02:00
match (
input_graph,
display_node,
display_edge,
color_node,
color_edge,
) {
| (
BasicValue::Graph { value: input_graph },
BasicValue::DisplayNode {
value: display_node,
},
BasicValue::DisplayEdge {
value: display_edge,
},
BasicValue::ColorNode { value: color_node },
BasicValue::ColorEdge { value: color_edge },
) => {
use std::rc::Rc;
let rc_translator = Rc::new(translator.clone());
let modified_graph = input_graph.map(
display_node
.generate(Rc::clone(&rc_translator), &input_graph),
display_edge
.generate(Rc::clone(&rc_translator), &input_graph),
);
let input_graph = Rc::new(input_graph.to_owned());
let node_formatter = color_node.generate(
Rc::clone(&input_graph),
translator.encode_not_mut("*"),
);
let edge_formatter =
color_edge.generate(Rc::clone(&input_graph));
let dot = rsprocess::dot::Dot::with_attr_getters(
&modified_graph,
&[],
&edge_formatter,
&node_formatter,
);
let res = BasicValue::String {
value: format!("{dot}"),
};
outputs_cache.populate_output(
graph,
node_id,
output_name,
res,
hash_inputs,
)?;
},
| _ => {
anyhow::bail!("Values of wrong type");
},
}
},
| NodeInstruction::DisplayNode => {
2025-10-22 22:17:59 +02:00
let s = retrieve_from_cache![1];
2025-10-23 00:17:40 +02:00
let hash_inputs = hash_inputs!(s);
2025-10-17 21:42:41 +02:00
if let BasicValue::String { value } = s {
let res =
grammar_separated::instructions::SeparatorNodeParser::new()
.parse(&mut *translator, &value);
let res = match res {
| Ok(s) => s,
| Err(parse_error) => {
return Ok(Some(BasicValue::Error {
value: helper::reformat_error(
parse_error,
&value,
ctx,
),
}));
},
};
let res = BasicValue::DisplayNode { value: res };
outputs_cache.populate_output(
graph,
node_id,
output_name,
res,
hash_inputs,
)?;
} else {
anyhow::bail!("Not a string");
}
},
| NodeInstruction::DisplayEdge => {
2025-10-22 22:17:59 +02:00
let s = retrieve_from_cache![1];
2025-10-23 00:17:40 +02:00
let hash_inputs = hash_inputs!(s);
2025-10-17 21:42:41 +02:00
if let BasicValue::String { value } = s {
let res =
grammar_separated::instructions::SeparatorEdgeParser::new()
.parse(&mut *translator, &value);
let res = match res {
| Ok(s) => s,
| Err(parse_error) => {
return Ok(Some(BasicValue::Error {
value: helper::reformat_error(
parse_error,
&value,
ctx,
),
}));
},
};
let res = BasicValue::DisplayEdge { value: res };
outputs_cache.populate_output(
graph,
node_id,
output_name,
res,
hash_inputs,
)?;
} else {
anyhow::bail!("Not a string");
}
},
| NodeInstruction::ColorNode => {
2025-10-22 22:17:59 +02:00
let s = retrieve_from_cache![1];
2025-10-23 00:17:40 +02:00
let hash_inputs = hash_inputs!(s);
2025-10-17 21:42:41 +02:00
if let BasicValue::String { value } = s {
let res =
grammar_separated::instructions::ColorNodeParser::new()
.parse(&mut *translator, &value);
let res = match res {
| Ok(s) => s,
| Err(parse_error) => {
return Ok(Some(BasicValue::Error {
value: helper::reformat_error(
parse_error,
&value,
ctx,
),
}));
},
};
let res = BasicValue::ColorNode { value: res };
outputs_cache.populate_output(
graph,
node_id,
output_name,
res,
hash_inputs,
)?;
} else {
anyhow::bail!("Not a string");
}
},
| NodeInstruction::ColorEdge => {
2025-10-22 22:17:59 +02:00
let s = retrieve_from_cache![1];
2025-10-23 00:17:40 +02:00
let hash_inputs = hash_inputs!(s);
2025-10-17 21:42:41 +02:00
if let BasicValue::String { value } = s {
let res =
grammar_separated::instructions::ColorEdgeParser::new()
.parse(&mut *translator, &value);
let res = match res {
| Ok(s) => s,
| Err(parse_error) => {
return Ok(Some(BasicValue::Error {
value: helper::reformat_error(
parse_error,
&value,
ctx,
),
}));
},
};
let res = BasicValue::ColorEdge { value: res };
outputs_cache.populate_output(
graph,
node_id,
output_name,
res,
hash_inputs,
)?;
} else {
anyhow::bail!("Not a string");
}
},
| NodeInstruction::GraphML => {
2025-10-23 00:17:40 +02:00
let (input_graph, display_node, display_edge) =
retrieve_from_cache![3];
let hash_inputs =
hash_inputs!(input_graph, display_node, display_edge);
2025-10-17 21:42:41 +02:00
match (input_graph, display_node, display_edge) {
| (
BasicValue::Graph { value: input_graph },
BasicValue::DisplayNode {
value: display_node,
},
BasicValue::DisplayEdge {
value: display_edge,
},
) => {
use std::rc::Rc;
let rc_translator = Rc::new(translator.clone());
let modified_graph = input_graph.map(
display_node
.generate(Rc::clone(&rc_translator), &input_graph),
display_edge.generate(rc_translator, &input_graph),
);
use petgraph_graphml::GraphMl;
let graphml = GraphMl::new(&modified_graph)
.pretty_print(true)
.export_node_weights_display()
.export_edge_weights_display();
let res = BasicValue::String {
value: format!("{graphml}"),
};
outputs_cache.populate_output(
graph,
node_id,
output_name,
res,
hash_inputs,
)?;
},
| _ => {
anyhow::bail!("Values of wrong type");
},
}
},
| NodeInstruction::ComposeSystem => {
2025-10-23 00:17:40 +02:00
let (
input_env,
input_initial_etities,
input_context,
input_reactions,
) = retrieve_from_cache![4];
let hash_inputs = hash_inputs!(
input_env,
input_initial_etities,
input_context,
input_reactions
);
2025-10-17 21:42:41 +02:00
match (
input_env,
input_initial_etities,
input_context,
input_reactions,
) {
| (
BasicValue::Environment { value: env },
BasicValue::Set { value: set },
BasicValue::Context { value: context },
BasicValue::Reactions { value: reactions },
) => {
let res = BasicValue::System {
value: rsprocess::system::System::from(
Rc::new(env),
set,
context,
Rc::new(reactions),
),
};
outputs_cache.populate_output(
graph,
node_id,
output_name,
res,
hash_inputs,
)?;
},
| _ => {
anyhow::bail!("Values of wrong type");
},
}
},
| NodeInstruction::Environment => {
2025-10-22 22:17:59 +02:00
let s = retrieve_from_cache![1];
2025-10-23 00:17:40 +02:00
let hash_inputs = hash_inputs!(s);
2025-10-22 22:17:59 +02:00
2025-10-17 21:42:41 +02:00
if let BasicValue::String { value } = s {
let res = grammar_separated::grammar::EnvironmentParser::new()
.parse(&mut *translator, &value);
let env = match res {
| Ok(s) => s,
| Err(parse_error) => {
return Ok(Some(BasicValue::Error {
value: helper::reformat_error(
parse_error,
&value,
ctx,
),
}));
},
};
let res = BasicValue::Environment { value: *env };
outputs_cache.populate_output(
graph,
node_id,
output_name,
res,
hash_inputs,
)?;
} else {
anyhow::bail!("Not a string");
}
},
| NodeInstruction::Set => {
2025-10-22 22:17:59 +02:00
let s = retrieve_from_cache![1];
2025-10-23 00:17:40 +02:00
let hash_inputs = hash_inputs!(s);
2025-10-22 22:17:59 +02:00
2025-10-17 21:42:41 +02:00
if let BasicValue::String { value } = s {
let res = grammar_separated::grammar::SetParser::new()
.parse(&mut *translator, &value);
let set = match res {
| Ok(s) => s,
| Err(parse_error) => {
return Ok(Some(BasicValue::Error {
value: helper::reformat_error(
parse_error,
&value,
ctx,
),
}));
},
};
let res = BasicValue::Set { value: set };
outputs_cache.populate_output(
graph,
node_id,
output_name,
res,
hash_inputs,
)?;
} else {
anyhow::bail!("Not a string");
}
},
| NodeInstruction::Context => {
2025-10-22 22:17:59 +02:00
let s = retrieve_from_cache![1];
2025-10-23 00:17:40 +02:00
let hash_inputs = hash_inputs!(s);
2025-10-22 22:17:59 +02:00
2025-10-17 21:42:41 +02:00
if let BasicValue::String { value } = s {
let res = grammar_separated::grammar::ContextParser::new()
.parse(&mut *translator, &value);
let context = match res {
| Ok(s) => s,
| Err(parse_error) => {
return Ok(Some(BasicValue::Error {
value: helper::reformat_error(
parse_error,
&value,
ctx,
),
}));
},
};
let res = BasicValue::Context { value: context };
outputs_cache.populate_output(
graph,
node_id,
output_name,
res,
hash_inputs,
)?;
} else {
anyhow::bail!("Not a string");
}
},
| NodeInstruction::Reactions => {
2025-10-22 22:17:59 +02:00
let s = retrieve_from_cache![1];
2025-10-23 00:17:40 +02:00
let hash_inputs = hash_inputs!(s);
2025-10-22 22:17:59 +02:00
2025-10-17 21:42:41 +02:00
if let BasicValue::String { value } = s {
let res = grammar_separated::grammar::ReactionsParser::new()
.parse(&mut *translator, &value);
let reactions = match res {
| Ok(s) => s,
| Err(parse_error) => {
return Ok(Some(BasicValue::Error {
value: helper::reformat_error(
parse_error,
&value,
ctx,
),
}));
},
};
let res = BasicValue::Reactions { value: reactions };
outputs_cache.populate_output(
graph,
node_id,
output_name,
res,
hash_inputs,
)?;
} else {
anyhow::bail!("Not a string");
}
},
| NodeInstruction::PositiveSystem => {
2025-10-22 22:17:59 +02:00
let s = retrieve_from_cache![1];
2025-10-23 00:17:40 +02:00
let hash_inputs = hash_inputs!(s);
2025-10-17 21:42:41 +02:00
if let BasicValue::System { value } = s {
let res = BasicValue::PositiveSystem {
value: value.into(),
};
outputs_cache.populate_output(
graph,
node_id,
output_name,
res,
hash_inputs,
)?;
} else {
anyhow::bail!("Not a system");
}
},
| NodeInstruction::PositiveTarget => {
2025-10-22 22:17:59 +02:00
let (s, i) = retrieve_from_cache![2];
2025-10-23 00:17:40 +02:00
let hash_inputs = hash_inputs!(s, i);
2025-10-17 21:42:41 +02:00
match (s, i) {
| (
BasicValue::PositiveSystem { value: s },
BasicValue::PositiveInt { value: i },
) => {
let limit = if i > 0 {
match s.target_limit(i) {
| Ok(l) => l,
| Err(e) => anyhow::bail!(e),
}
} else {
match s.target() {
| Ok(l) => l,
| Err(e) => anyhow::bail!(e),
}
};
let res = BasicValue::String {
value: format!(
"After {} steps arrived at state {}",
limit.0,
Formatter::from(translator, &limit.1)
),
};
outputs_cache.populate_output(
graph,
node_id,
output_name,
res,
hash_inputs,
)?;
},
| (BasicValue::PositiveSystem { value: _ }, _) =>
anyhow::bail!("Not an integer"),
| (_, BasicValue::PositiveInt { value: _ }) =>
anyhow::bail!("Not a positive system"),
| (_, _) => anyhow::bail!("Inputs all wrong"),
}
},
| NodeInstruction::PositiveRun => {
2025-10-22 22:17:59 +02:00
let (s, i) = retrieve_from_cache![2];
2025-10-23 00:17:40 +02:00
let hash_inputs = hash_inputs!(s, i);
2025-10-17 21:42:41 +02:00
match (s, i) {
| (
BasicValue::PositiveSystem { value: s },
BasicValue::PositiveInt { value: i },
) => {
let limit = if i > 0 {
match s.run_separated_limit(i) {
| Ok(l) => l,
| Err(e) => anyhow::bail!(e),
}
} else {
match s.run_separated() {
| Ok(l) => l,
| Err(e) => anyhow::bail!(e),
}
};
let mut output = String::new();
output.push_str(
"The trace is composed by the set of entities: ",
);
for (e, _c, _t) in limit {
output.push_str(&format!(
"{}",
Formatter::from(translator, &e)
));
}
let res = BasicValue::String { value: output };
outputs_cache.populate_output(
graph,
node_id,
output_name,
res,
hash_inputs,
)?;
},
| (BasicValue::PositiveSystem { value: _ }, _) =>
anyhow::bail!("Not an integer"),
| (_, BasicValue::PositiveInt { value: _ }) =>
anyhow::bail!("Not a positive system"),
| (_, _) => anyhow::bail!("Inputs all wrong"),
}
},
| NodeInstruction::PositiveLoop => {
2025-10-22 22:17:59 +02:00
let (s, i) = retrieve_from_cache![2];
2025-10-23 00:17:40 +02:00
let hash_inputs = hash_inputs!(s, i);
2025-10-17 21:42:41 +02:00
match (s, i) {
| (
BasicValue::PositiveSystem { value: sys },
BasicValue::Symbol { value: i },
) => {
let s = match translator.encode_not_mut(i) {
| Some(s) => s,
| None => anyhow::bail!("Symbol not found"),
};
let l = match sys.lollipops_only_loop_named(s) {
| Some(l) => l,
| None => anyhow::bail!("No loop found"),
};
let mut output = String::new();
output.push_str("The loop is composed by the sets: ");
for e in l {
output.push_str(&format!(
"{}",
Formatter::from(translator, &e)
));
}
let res = BasicValue::String { value: output };
outputs_cache.populate_output(
graph,
node_id,
output_name,
res,
hash_inputs,
)?;
},
| (BasicValue::PositiveSystem { value: _ }, _) =>
anyhow::bail!("Not an integer"),
| (_, BasicValue::PositiveInt { value: _ }) =>
anyhow::bail!("Not a positive system"),
| (_, _) => anyhow::bail!("Inputs all wrong"),
}
},
| NodeInstruction::PositiveFrequency => {
2025-10-22 22:17:59 +02:00
let s = retrieve_from_cache![1];
2025-10-23 00:17:40 +02:00
let hash_inputs = hash_inputs!(s);
2025-10-17 21:42:41 +02:00
if let BasicValue::PositiveSystem { value } = s {
let res = match rsprocess::frequency::PositiveFrequency::naive_frequency(&value) {
Ok(r) => r,
Err(e) => anyhow::bail!(e),
};
let output = format!(
"Frequency of encountered symbols:\n{}",
Formatter::from(translator, &res)
);
let res = BasicValue::String { value: output };
outputs_cache.populate_output(
graph,
node_id,
output_name,
res,
hash_inputs,
)?;
} else {
anyhow::bail!("Not a positive system");
}
},
| NodeInstruction::PositiveLimitFrequency => {
2025-10-22 22:17:59 +02:00
let (sys, exp) = retrieve_from_cache![2];
2025-10-23 00:17:40 +02:00
let hash_inputs = hash_inputs!(sys, exp);
2025-10-17 21:42:41 +02:00
match (sys, exp) {
| (
BasicValue::PositiveSystem { value: sys },
BasicValue::Experiment { value: exp },
) => {
let (_, sets) = exp;
let l = match rsprocess::frequency::PositiveFrequency::limit_frequency(
&sets.into_iter().map(
|e| e.to_positive_set(rsprocess::element::IdState::Positive)
).collect::<Vec<_>>(),
&sys.reaction_rules,
&sys.available_entities,
) {
Some(l) => l,
None => anyhow::bail!("No loop found")
};
let res = BasicValue::String {
value: format!(
"Frequency of encountered symbols:\n{}",
Formatter::from(translator, &l)
),
};
outputs_cache.populate_output(
graph,
node_id,
output_name,
res,
hash_inputs,
)?;
},
| (BasicValue::PositiveSystem { value: _ }, _) =>
anyhow::bail!("Not an experiment"),
| (_, BasicValue::Experiment { value: _ }) =>
anyhow::bail!("Not a positive system"),
| (_, _) => anyhow::bail!("Inputs all wrong"),
}
},
| NodeInstruction::PositiveFastFrequency => {
2025-10-22 22:17:59 +02:00
let (sys, exp) = retrieve_from_cache![2];
2025-10-23 00:17:40 +02:00
let hash_inputs = hash_inputs!(sys, exp);
2025-10-17 21:42:41 +02:00
match (sys, exp) {
| (
BasicValue::PositiveSystem { value: sys },
BasicValue::Experiment { value: exp },
) => {
let (weights, sets) = exp;
let l = match rsprocess::frequency::PositiveFrequency::fast_frequency(
&sets.into_iter().map(
|e| e.to_positive_set(rsprocess::element::IdState::Positive)
).collect::<Vec<_>>(),
&sys.reaction_rules,
&sys.available_entities,
&weights
) {
Some(l) => l,
None => anyhow::bail!("No loop found")
};
let res = BasicValue::String {
value: format!(
"Frequency of encountered symbols:\n{}",
Formatter::from(translator, &l)
),
};
outputs_cache.populate_output(
graph,
node_id,
output_name,
res,
hash_inputs,
)?;
},
| (BasicValue::PositiveSystem { value: _ }, _) =>
anyhow::bail!("Not an experiment"),
| (_, BasicValue::Experiment { value: _ }) =>
anyhow::bail!("Not a system"),
| (_, _) => anyhow::bail!("Inputs all wrong"),
}
},
2025-10-20 17:28:27 +02:00
| NodeInstruction::Trace => {
2025-10-22 22:17:59 +02:00
let (s, limit) = retrieve_from_cache![2];
2025-10-23 00:17:40 +02:00
let hash_inputs = hash_inputs!(s, limit);
2025-10-20 17:28:27 +02:00
match (s, limit) {
2025-10-23 00:17:40 +02:00
| (
BasicValue::System { value: s },
BasicValue::PositiveInt { value: limit },
) => {
2025-10-20 17:28:27 +02:00
let trace = if limit == 0 {
match s.slice_trace() {
2025-10-23 00:17:40 +02:00
| Ok(t) => t,
| Err(e) => anyhow::bail!(e),
2025-10-20 17:28:27 +02:00
}
} else {
match s.slice_trace_limit(limit) {
2025-10-23 00:17:40 +02:00
| Ok(t) => t,
| Err(e) => anyhow::bail!(e),
2025-10-20 17:28:27 +02:00
}
};
2025-10-23 00:17:40 +02:00
let res = BasicValue::Trace { value: trace };
2025-10-20 17:28:27 +02:00
outputs_cache.populate_output(
graph,
node_id,
output_name,
res,
hash_inputs,
)?;
},
| (BasicValue::System { value: _ }, _) =>
anyhow::bail!("Not a positive integer"),
| (_, BasicValue::PositiveInt { value: _ }) =>
anyhow::bail!("Not a system"),
2025-10-23 00:17:40 +02:00
| (_, _) => anyhow::bail!("Inputs all wrong"),
2025-10-20 17:28:27 +02:00
}
},
| NodeInstruction::PositiveTrace => {
2025-10-22 22:17:59 +02:00
let (s, limit) = retrieve_from_cache![2];
2025-10-23 00:17:40 +02:00
let hash_inputs = hash_inputs!(s, limit);
2025-10-20 17:28:27 +02:00
match (s, limit) {
2025-10-23 00:17:40 +02:00
| (
BasicValue::PositiveSystem { value: s },
BasicValue::PositiveInt { value: limit },
) => {
2025-10-20 17:28:27 +02:00
let trace = if limit == 0 {
match s.slice_trace() {
2025-10-23 00:17:40 +02:00
| Ok(t) => t,
| Err(e) => anyhow::bail!(e),
2025-10-20 17:28:27 +02:00
}
} else {
match s.slice_trace_limit(limit) {
2025-10-23 00:17:40 +02:00
| Ok(t) => t,
| Err(e) => anyhow::bail!(e),
2025-10-20 17:28:27 +02:00
}
};
2025-10-23 00:17:40 +02:00
let res = BasicValue::PositiveTrace { value: trace };
2025-10-20 17:28:27 +02:00
outputs_cache.populate_output(
graph,
node_id,
output_name,
res,
hash_inputs,
)?;
},
| (BasicValue::PositiveSystem { value: _ }, _) =>
anyhow::bail!("Not a positive integer"),
| (_, BasicValue::PositiveInt { value: _ }) =>
anyhow::bail!("Not a positive system"),
2025-10-23 00:17:40 +02:00
| (_, _) => anyhow::bail!("Inputs all wrong"),
2025-10-20 17:28:27 +02:00
}
},
| NodeInstruction::SliceTrace => {
2025-10-22 22:17:59 +02:00
let (trace, set) = retrieve_from_cache![2];
2025-10-23 00:17:40 +02:00
let hash_inputs = hash_inputs!(trace, set);
2025-10-20 17:28:27 +02:00
match (trace, set) {
2025-10-23 00:17:40 +02:00
| (
BasicValue::Trace { value: trace },
BasicValue::Set { value: set },
) => {
2025-10-20 17:28:27 +02:00
let new_trace = match trace.slice(set) {
2025-10-23 00:17:40 +02:00
| Ok(t) => t,
| Err(e) => anyhow::bail!(e),
2025-10-20 17:28:27 +02:00
};
2025-10-23 00:17:40 +02:00
let res = BasicValue::Trace { value: new_trace };
2025-10-20 17:28:27 +02:00
outputs_cache.populate_output(
graph,
node_id,
output_name,
res,
hash_inputs,
)?;
},
| (BasicValue::Trace { value: _ }, _) =>
anyhow::bail!("Not a set"),
| (_, BasicValue::Set { value: _ }) =>
anyhow::bail!("Not a trace"),
2025-10-23 00:17:40 +02:00
| (_, _) => anyhow::bail!("Inputs all wrong"),
2025-10-20 17:28:27 +02:00
}
},
| NodeInstruction::PositiveSliceTrace => {
2025-10-22 22:17:59 +02:00
let (trace, set) = retrieve_from_cache![2];
2025-10-23 00:17:40 +02:00
let hash_inputs = hash_inputs!(trace, set);
2025-10-20 17:28:27 +02:00
match (trace, set) {
2025-10-23 00:17:40 +02:00
| (
BasicValue::PositiveTrace { value: trace },
BasicValue::PositiveSet { value: set },
) => {
2025-10-20 17:28:27 +02:00
let new_trace = match trace.slice(set) {
2025-10-23 00:17:40 +02:00
| Ok(t) => t,
| Err(e) => anyhow::bail!(e),
2025-10-20 17:28:27 +02:00
};
2025-10-23 00:17:40 +02:00
let res = BasicValue::PositiveTrace { value: new_trace };
2025-10-20 17:28:27 +02:00
outputs_cache.populate_output(
graph,
node_id,
output_name,
res,
hash_inputs,
)?;
},
| (BasicValue::PositiveTrace { value: _ }, _) =>
anyhow::bail!("Not a set"),
| (_, BasicValue::PositiveSet { value: _ }) =>
anyhow::bail!("Not a trace"),
2025-10-23 00:17:40 +02:00
| (_, _) => anyhow::bail!("Inputs all wrong"),
2025-10-20 17:28:27 +02:00
}
},
| NodeInstruction::PositiveSet => {
2025-10-22 22:17:59 +02:00
let s = retrieve_from_cache![1];
2025-10-23 00:17:40 +02:00
let hash_inputs = hash_inputs!(s);
2025-10-22 22:17:59 +02:00
2025-10-20 17:28:27 +02:00
if let BasicValue::String { value } = s {
let res = grammar_separated::grammar::PositiveSetParser::new()
.parse(&mut *translator, &value);
let set = match res {
| Ok(s) => s,
| Err(parse_error) => {
return Ok(Some(BasicValue::Error {
value: helper::reformat_error(
parse_error,
&value,
ctx,
),
}));
},
};
let res = BasicValue::PositiveSet { value: set };
outputs_cache.populate_output(
graph,
node_id,
output_name,
res,
hash_inputs,
)?;
} else {
anyhow::bail!("Not a string");
}
},
| NodeInstruction::ToPositiveSet => {
2025-10-22 22:17:59 +02:00
let s = retrieve_from_cache![1];
2025-10-23 00:17:40 +02:00
let hash_inputs = hash_inputs!(s);
2025-10-22 22:17:59 +02:00
2025-10-20 17:28:27 +02:00
if let BasicValue::Set { value } = s {
let res = BasicValue::PositiveSet {
2025-10-23 00:17:40 +02:00
value: value
.to_positive_set(rsprocess::element::IdState::Positive),
2025-10-20 17:28:27 +02:00
};
outputs_cache.populate_output(
graph,
node_id,
output_name,
res,
hash_inputs,
)?;
} else {
anyhow::bail!("Not a string");
}
2025-10-23 00:17:40 +02:00
},
2025-10-17 21:42:41 +02:00
}
Ok(None)
}