2025-05-21 00:03:36 +02:00
|
|
|
use std::rc::Rc;
|
2025-05-14 11:42:19 +02:00
|
|
|
use std::str::FromStr;
|
|
|
|
|
use lalrpop_util::ParseError;
|
2025-07-01 04:04:13 +02:00
|
|
|
use crate::rsprocess::structure::{RSset,
|
|
|
|
|
RSprocess,
|
|
|
|
|
RSenvironment,
|
|
|
|
|
RSassert,
|
|
|
|
|
RSassertOp,
|
|
|
|
|
RSBHML,
|
|
|
|
|
RSsystem,
|
|
|
|
|
RSreaction};
|
2025-06-16 14:46:04 +02:00
|
|
|
use crate::rsprocess::translator::{Translator, IdType};
|
2025-07-11 23:49:59 +02:00
|
|
|
use crate::rsprocess::presets::Instructions;
|
|
|
|
|
use crate::rsprocess::presets;
|
2025-07-12 15:32:21 +02:00
|
|
|
use crate::rsprocess::graph;
|
2025-05-14 11:42:19 +02:00
|
|
|
|
2025-06-16 14:46:04 +02:00
|
|
|
grammar(translator: &mut Translator);
|
2025-05-14 11:42:19 +02:00
|
|
|
|
2025-07-01 04:04:13 +02:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
// Helpers
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
2025-07-03 16:28:28 +02:00
|
|
|
// order
|
|
|
|
|
match {
|
2025-07-11 23:49:59 +02:00
|
|
|
".", ",", ";",
|
2025-07-03 23:44:10 +02:00
|
|
|
"nill",
|
|
|
|
|
"{", "}",
|
|
|
|
|
"[", "]",
|
|
|
|
|
"(", ")",
|
|
|
|
|
"<", ">",
|
|
|
|
|
"r:", "i:", "p:",
|
|
|
|
|
"-", "^",
|
|
|
|
|
"true", "false",
|
2025-07-11 23:49:59 +02:00
|
|
|
"inW", "inR", "inI", "inP",
|
|
|
|
|
"Environment", "Initial Entities", "Context", "Reactions",
|
|
|
|
|
"Weights", "Sets",
|
|
|
|
|
"Print", "Save",
|
|
|
|
|
"Dot", "GraphML", "Serialize",
|
|
|
|
|
"Stats", "Target", "Run", "Loop", "Frequency", "LimitFrequency",
|
|
|
|
|
"FastFrequency", "Digraph",
|
2025-07-12 15:32:21 +02:00
|
|
|
"Deserialize",
|
|
|
|
|
"Hide", "Entities", "MaskEntities", "MaskContext",
|
|
|
|
|
"Products", "MaskProducts", "Union", "MaskUnion",
|
|
|
|
|
"Difference", "MaskDifference",
|
|
|
|
|
"EntitiesDeleted", "MaskEntitiesDeleted",
|
|
|
|
|
"EntitiesAdded", "MaskEntitiesAdded"
|
2025-07-03 23:44:10 +02:00
|
|
|
} else {
|
2025-07-03 16:28:28 +02:00
|
|
|
r"[0-9]+" => NUMBER
|
|
|
|
|
} else {
|
2025-07-12 15:32:21 +02:00
|
|
|
r"([[:alpha:]])([[:word:]])*" => WORD
|
|
|
|
|
// r"(\p{L}|\p{Emoji})(\p{L}|\p{Emoji}|\p{Dash}|\p{N})*" => WORD,
|
2025-07-11 23:49:59 +02:00
|
|
|
} else {
|
2025-07-13 18:14:35 +02:00
|
|
|
r#""[^"]+""# => PATH, // " <- ignore comment, its for the linter in emacs
|
2025-07-03 16:28:28 +02:00
|
|
|
} else {
|
|
|
|
|
_
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-05-14 12:14:13 +02:00
|
|
|
// matches words (letter followed by numbers, letters or _)
|
2025-07-03 16:28:28 +02:00
|
|
|
Literal: String = {
|
|
|
|
|
WORD => <>.to_string()
|
|
|
|
|
};
|
2025-05-14 11:42:19 +02:00
|
|
|
|
2025-05-14 12:14:13 +02:00
|
|
|
// all numbers are i64
|
2025-05-14 11:42:19 +02:00
|
|
|
Num: i64 = {
|
2025-07-03 16:28:28 +02:00
|
|
|
NUMBER =>? i64::from_str(<>)
|
|
|
|
|
.map_err(|_| ParseError::User { error: "Number is too big" })
|
2025-05-14 11:42:19 +02:00
|
|
|
};
|
|
|
|
|
|
2025-07-11 23:49:59 +02:00
|
|
|
Path: String = {
|
|
|
|
|
PATH => <>.trim_end_matches("\"").trim_start_matches("\"").to_string()
|
|
|
|
|
};
|
|
|
|
|
|
2025-05-14 12:14:13 +02:00
|
|
|
// macro for matching sequence of patterns with C as separator
|
2025-07-02 17:27:36 +02:00
|
|
|
Separated<T, C>: Vec<T> = {
|
2025-05-14 11:42:19 +02:00
|
|
|
<mut v:(<T> C)+> <e:T?> => match e {
|
|
|
|
|
None => v,
|
|
|
|
|
Some(e) => {
|
|
|
|
|
v.push(e);
|
|
|
|
|
v
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-07-03 11:09:58 +02:00
|
|
|
Separated_Or<T, C>: Vec<T> = {
|
|
|
|
|
<v: T> => vec![v],
|
|
|
|
|
<v: Separated<T, C>> => v
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-01 04:04:13 +02:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
// SetParser
|
|
|
|
|
// -----------------------------------------------------------------------------
|
2025-06-16 14:46:04 +02:00
|
|
|
pub Set: RSset = {
|
2025-05-14 11:42:19 +02:00
|
|
|
<s: Set_of_entities> => s
|
|
|
|
|
};
|
|
|
|
|
|
2025-06-16 14:46:04 +02:00
|
|
|
Set_of_entities: RSset = {
|
2025-05-19 00:10:23 +02:00
|
|
|
"{" "}" => RSset::from(vec![]),
|
2025-07-03 11:09:58 +02:00
|
|
|
"{" <t: Separated_Or<Literal, ",">> "}" =>
|
2025-07-13 18:14:35 +02:00
|
|
|
RSset::from(t.into_iter().map(|t| translator.encode(t))
|
|
|
|
|
.collect::<Vec<_>>())
|
2025-05-19 00:10:23 +02:00
|
|
|
};
|
|
|
|
|
|
2025-06-12 16:23:39 +02:00
|
|
|
|
2025-07-01 04:04:13 +02:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
// ReactionParser
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
pub Reactions: Vec<RSreaction> = {
|
|
|
|
|
"(" ")" => vec![],
|
2025-07-03 11:09:58 +02:00
|
|
|
"(" <s: Separated_Or<Reaction, ";">> ")" => s
|
2025-07-01 04:04:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Reaction: RSreaction = {
|
|
|
|
|
"[" <r: Set> "," <i: Set> "," <p: Set> "]" => RSreaction::from(r, i, p),
|
2025-07-01 19:22:50 +02:00
|
|
|
"[" "r:" <r: Set> "," "i:" <i: Set> "," "p:" <p: Set> "]" =>
|
|
|
|
|
RSreaction::from(r, i, p),
|
2025-07-01 04:04:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
// ContextParser
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
pub Context: RSprocess = {
|
|
|
|
|
"[" "]" => RSprocess::NondeterministicChoice{ children: vec![] },
|
2025-07-03 11:09:58 +02:00
|
|
|
"[" <t: Separated_Or<Boxed_CTX_process, ",">> "]" =>
|
2025-07-01 04:04:13 +02:00
|
|
|
RSprocess::NondeterministicChoice{ children: t }
|
2025-05-14 11:42:19 +02:00
|
|
|
};
|
|
|
|
|
|
2025-06-16 14:46:04 +02:00
|
|
|
Boxed_CTX_process: Rc<RSprocess> = {
|
2025-05-21 00:03:36 +02:00
|
|
|
<t: CTX_process> => Rc::new(t)
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-16 14:46:04 +02:00
|
|
|
CTX_process: RSprocess = {
|
2025-07-03 23:44:10 +02:00
|
|
|
"nill" => RSprocess::Nill,
|
2025-05-19 00:10:23 +02:00
|
|
|
<c: Set_of_entities> "." <k: CTX_process> =>
|
2025-05-21 00:03:36 +02:00
|
|
|
RSprocess::EntitySet{ entities: c, next_process: Rc::new(k) },
|
2025-05-14 11:42:19 +02:00
|
|
|
"(" <k: CTX_process> ")" => k,
|
2025-07-02 17:27:36 +02:00
|
|
|
"(" <k: Separated<CTX_process, "+">> ")" =>
|
2025-07-01 19:22:50 +02:00
|
|
|
RSprocess::Summation{
|
|
|
|
|
children: k.into_iter().map(Rc::new).collect::<Vec<_>>()
|
|
|
|
|
},
|
2025-05-19 00:10:23 +02:00
|
|
|
"<" <n: Num> <k1: CTX_process> ">" "." <k: CTX_process> =>
|
|
|
|
|
RSprocess::WaitEntity{ repeat: n,
|
2025-05-21 00:03:36 +02:00
|
|
|
repeated_process: Rc::new(k1),
|
2025-07-01 19:22:50 +02:00
|
|
|
next_process: Rc::new(k) },
|
2025-05-19 00:10:23 +02:00
|
|
|
<identifier: Literal> =>
|
2025-07-01 19:22:50 +02:00
|
|
|
RSprocess::RecursiveIdentifier{
|
|
|
|
|
identifier: translator.encode(identifier)
|
|
|
|
|
}
|
2025-05-14 11:42:19 +02:00
|
|
|
};
|
|
|
|
|
|
2025-07-01 04:04:13 +02:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
// EnvironmentParser
|
|
|
|
|
// -----------------------------------------------------------------------------
|
2025-06-16 14:46:04 +02:00
|
|
|
pub Environment: Box<RSenvironment> = {
|
2025-05-14 11:42:19 +02:00
|
|
|
"[" "]" => Box::new(RSenvironment::new()),
|
2025-07-03 11:09:58 +02:00
|
|
|
"[" <t: Separated_Or<Env_term, ",">> "]" => Box::new(RSenvironment::from(t))
|
2025-05-14 11:42:19 +02:00
|
|
|
};
|
|
|
|
|
|
2025-06-16 14:46:04 +02:00
|
|
|
Env_term: (IdType, RSprocess) = {
|
|
|
|
|
<identifier: Literal> "=" <k: CTX_process> =>
|
2025-06-18 11:28:04 +02:00
|
|
|
(translator.encode(identifier), k)
|
2025-05-14 11:42:19 +02:00
|
|
|
};
|
|
|
|
|
|
2025-07-01 04:04:13 +02:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
// AssertParser
|
|
|
|
|
// -----------------------------------------------------------------------------
|
2025-06-16 14:46:04 +02:00
|
|
|
pub Assert: Box<RSassert> = {
|
2025-05-14 11:42:19 +02:00
|
|
|
<f: Formula_Assert> => Box::new(f)
|
|
|
|
|
};
|
|
|
|
|
|
2025-06-16 14:46:04 +02:00
|
|
|
Formula_Assert: RSassert = {
|
2025-05-14 11:42:19 +02:00
|
|
|
"-" <f: Formula_Assert> => RSassert::Not(Box::new(f)),
|
2025-05-19 00:10:23 +02:00
|
|
|
"(" <f1: Formula_Assert> "^" <f2: Formula_Assert> ")" =>
|
|
|
|
|
RSassert::Xor(Box::new(f1), Box::new(f2)),
|
2025-07-02 17:27:36 +02:00
|
|
|
"(" <f: Separated<Formula_Assert, "\\/">> ")" => RSassert::Or(f),
|
|
|
|
|
"(" <f: Separated<Formula_Assert, "/\\">> ")" => RSassert::And(f),
|
2025-05-14 11:42:19 +02:00
|
|
|
<c: Set_of_entities> "inW" => RSassert::Sub(c, RSassertOp::InW),
|
|
|
|
|
<c: Set_of_entities> "inR" => RSassert::Sub(c, RSassertOp::InR),
|
|
|
|
|
<c: Set_of_entities> "inI" => RSassert::Sub(c, RSassertOp::InI),
|
|
|
|
|
<c: Set_of_entities> "inP" => RSassert::Sub(c, RSassertOp::InP),
|
|
|
|
|
"?" "inW" => RSassert::NonEmpty(RSassertOp::InW),
|
|
|
|
|
"?" "inR" => RSassert::NonEmpty(RSassertOp::InR),
|
|
|
|
|
"?" "inI" => RSassert::NonEmpty(RSassertOp::InI),
|
|
|
|
|
"?" "inP" => RSassert::NonEmpty(RSassertOp::InP),
|
|
|
|
|
};
|
|
|
|
|
|
2025-07-01 04:04:13 +02:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
// BHMLParser
|
|
|
|
|
// -----------------------------------------------------------------------------
|
2025-06-16 14:46:04 +02:00
|
|
|
pub BHML: Box<RSBHML> = {
|
2025-05-14 11:42:19 +02:00
|
|
|
<g: Formula_BHML> => Box::new(g)
|
|
|
|
|
};
|
|
|
|
|
|
2025-06-16 14:46:04 +02:00
|
|
|
Formula_BHML: RSBHML = {
|
2025-05-14 11:42:19 +02:00
|
|
|
"true" => RSBHML::True,
|
|
|
|
|
"false" => RSBHML::False,
|
2025-07-02 17:27:36 +02:00
|
|
|
"(" <g: Separated<Formula_BHML, "\\/">> ")" => RSBHML::Or(g),
|
|
|
|
|
"(" <g: Separated<Formula_BHML, "/\\">> ")" => RSBHML::And(g),
|
2025-05-19 00:10:23 +02:00
|
|
|
"<" <f: Formula_Assert> ">" <g: Formula_BHML> =>
|
|
|
|
|
RSBHML::Diamond(Box::new(f), Box::new(g)),
|
|
|
|
|
"[" <f: Formula_Assert> "]" <g: Formula_BHML> =>
|
|
|
|
|
RSBHML::Box(Box::new(f), Box::new(g)),
|
2025-05-14 11:42:19 +02:00
|
|
|
};
|
2025-07-01 04:04:13 +02:00
|
|
|
|
|
|
|
|
|
2025-07-11 23:49:59 +02:00
|
|
|
// ----------------------------------------------------------------------------
|
2025-07-01 04:04:13 +02:00
|
|
|
// File Parsing
|
2025-07-11 23:49:59 +02:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
2025-07-01 04:04:13 +02:00
|
|
|
// system
|
|
|
|
|
// a system is an environment, a set of entities as initial state, a context and
|
|
|
|
|
// a set of reaction rules.
|
|
|
|
|
|
|
|
|
|
pub System: RSsystem = {
|
2025-07-11 23:49:59 +02:00
|
|
|
"Environment" ":" <delta: Environment>
|
|
|
|
|
"Initial Entities" ":" <available_entities: Set>
|
|
|
|
|
"Context" ":" <context_process: Context>
|
|
|
|
|
"Reactions" ":" <reaction_rules: Reactions>
|
2025-07-01 19:22:50 +02:00
|
|
|
=> RSsystem::from(delta.into(),
|
|
|
|
|
available_entities,
|
|
|
|
|
context_process,
|
|
|
|
|
Rc::new(reaction_rules))
|
2025-07-01 04:04:13 +02:00
|
|
|
}
|
2025-07-02 17:27:36 +02:00
|
|
|
|
|
|
|
|
// experiment
|
|
|
|
|
// an experiment is composed by a sequence of weights and a sequence of sets of
|
|
|
|
|
// entities of equal length.
|
|
|
|
|
|
|
|
|
|
pub Experiment: (Vec<u32>, Vec<RSset>) = {
|
2025-07-11 23:49:59 +02:00
|
|
|
"Weights" ":" <w: Separated_Or<Num, ",">>
|
|
|
|
|
"Sets" ":" <s: Separated_Or<Set_of_entities, ",">>
|
2025-07-03 11:09:58 +02:00
|
|
|
=> (w.into_iter().map(|x| x as u32).collect::<Vec<_>>(), s),
|
2025-07-02 17:27:36 +02:00
|
|
|
}
|
2025-07-11 23:49:59 +02:00
|
|
|
|
|
|
|
|
|
2025-07-13 17:28:13 +02:00
|
|
|
// ~~~~~~~~~~~~~~~~~~~
|
2025-07-11 23:49:59 +02:00
|
|
|
// Instruction Parsing
|
2025-07-13 17:28:13 +02:00
|
|
|
// ~~~~~~~~~~~~~~~~~~~
|
2025-07-11 23:49:59 +02:00
|
|
|
|
2025-07-13 17:28:13 +02:00
|
|
|
/// Decides whetherer to print to stdout or to save to file
|
2025-07-11 23:49:59 +02:00
|
|
|
Helper_SO: presets::SaveOptions = {
|
|
|
|
|
"Print" =>
|
|
|
|
|
presets::SaveOptions {print: true, save: None},
|
|
|
|
|
"Save" "(" <p: Path> ")" =>
|
|
|
|
|
presets::SaveOptions {print: false, save: Some(vec![p])}
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-13 17:28:13 +02:00
|
|
|
/// we could need to save to multiple files
|
2025-07-11 23:49:59 +02:00
|
|
|
SaveOptions: presets::SaveOptions = {
|
|
|
|
|
<p: Separated_Or<Helper_SO, ";">> => {
|
2025-07-12 02:42:28 +02:00
|
|
|
p.into_iter()
|
|
|
|
|
.reduce(|mut acc, mut e| {acc.combine(&mut e); acc})
|
|
|
|
|
.unwrap_or_default()
|
2025-07-11 23:49:59 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-13 17:28:13 +02:00
|
|
|
/// Match for strings between nodes formatters
|
2025-07-12 15:32:21 +02:00
|
|
|
LiteralSeparatorNode: presets::NodeDisplay = {
|
|
|
|
|
PATH =>
|
|
|
|
|
presets::NodeDisplay::Separator(
|
|
|
|
|
<>.trim_end_matches("\"").trim_start_matches("\"").to_string()
|
|
|
|
|
)
|
|
|
|
|
};
|
|
|
|
|
|
2025-07-13 17:28:13 +02:00
|
|
|
/// Match for strings between edge formatters
|
2025-07-12 15:32:21 +02:00
|
|
|
LiteralSeparatorEdge: presets::EdgeDisplay = {
|
|
|
|
|
PATH =>
|
|
|
|
|
presets::EdgeDisplay::Separator(
|
|
|
|
|
<>.trim_end_matches("\"").trim_start_matches("\"").to_string()
|
|
|
|
|
)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
NodeDisplay: presets::NodeDisplay = {
|
|
|
|
|
"Hide" => presets::NodeDisplay::Display(graph::GraphMapNodes::Hide),
|
|
|
|
|
"Entities" => presets::NodeDisplay::Display(graph::GraphMapNodes::Entities),
|
|
|
|
|
"MaskEntities" <mask: Set> =>
|
2025-07-13 18:14:35 +02:00
|
|
|
presets::NodeDisplay::Display(graph::GraphMapNodes::MaskEntities{mask}),
|
2025-07-12 15:32:21 +02:00
|
|
|
"Context" => presets::NodeDisplay::Display(graph::GraphMapNodes::Context)
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-13 17:28:13 +02:00
|
|
|
/// Node display formatters separated by arbitrary strings in quotes
|
2025-07-12 15:32:21 +02:00
|
|
|
SeparatorNode: Vec<presets::NodeDisplay> = {
|
|
|
|
|
<v: NodeDisplay> => vec![v],
|
|
|
|
|
<v:(<NodeDisplay> <LiteralSeparatorNode>)+> <e: NodeDisplay?> =>
|
|
|
|
|
match e {
|
2025-07-13 18:14:35 +02:00
|
|
|
None => v.iter().fold(vec![],
|
|
|
|
|
|mut acc, (a, b)| {
|
|
|
|
|
acc.push(a.clone());
|
|
|
|
|
acc.push(b.clone());
|
|
|
|
|
acc.clone()
|
|
|
|
|
}),
|
2025-07-12 15:32:21 +02:00
|
|
|
Some(e) => {
|
2025-07-13 18:14:35 +02:00
|
|
|
let mut v = v.iter().fold(vec![],
|
|
|
|
|
|mut acc, (a, b)| {
|
|
|
|
|
acc.push(a.clone());
|
|
|
|
|
acc.push(b.clone());
|
|
|
|
|
acc.clone()
|
|
|
|
|
});
|
2025-07-12 15:32:21 +02:00
|
|
|
v.push(e);
|
|
|
|
|
v
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EdgeDisplay: presets::EdgeDisplay = {
|
2025-07-13 18:14:35 +02:00
|
|
|
"Hide" =>
|
|
|
|
|
presets::EdgeDisplay::Display(
|
|
|
|
|
graph::GraphMapEdges::Hide
|
|
|
|
|
),
|
|
|
|
|
"Products" =>
|
|
|
|
|
presets::EdgeDisplay::Display(
|
|
|
|
|
graph::GraphMapEdges::Products
|
|
|
|
|
),
|
2025-07-12 15:32:21 +02:00
|
|
|
"MaskProducts" <mask: Set> =>
|
2025-07-13 18:14:35 +02:00
|
|
|
presets::EdgeDisplay::Display(
|
|
|
|
|
graph::GraphMapEdges::MaskEntities{ mask }
|
|
|
|
|
),
|
|
|
|
|
"Entities" =>
|
|
|
|
|
presets::EdgeDisplay::Display(
|
|
|
|
|
graph::GraphMapEdges::Entities
|
|
|
|
|
),
|
|
|
|
|
"MaskEntities" <mask: Set> =>
|
|
|
|
|
presets::EdgeDisplay::Display(
|
|
|
|
|
graph::GraphMapEdges::MaskEntities{ mask }
|
|
|
|
|
),
|
|
|
|
|
"Context" =>
|
|
|
|
|
presets::EdgeDisplay::Display(
|
|
|
|
|
graph::GraphMapEdges::Context
|
|
|
|
|
),
|
|
|
|
|
"MaskContext" <mask: Set> =>
|
|
|
|
|
presets::EdgeDisplay::Display(
|
|
|
|
|
graph::GraphMapEdges::MaskContext{ mask }
|
|
|
|
|
),
|
|
|
|
|
"Union" =>
|
|
|
|
|
presets::EdgeDisplay::Display(
|
|
|
|
|
graph::GraphMapEdges::Union
|
|
|
|
|
),
|
|
|
|
|
"MaskUnion" <mask: Set> =>
|
|
|
|
|
presets::EdgeDisplay::Display(
|
|
|
|
|
graph::GraphMapEdges::MaskUnion{ mask }
|
|
|
|
|
),
|
|
|
|
|
"Difference" =>
|
|
|
|
|
presets::EdgeDisplay::Display(
|
|
|
|
|
graph::GraphMapEdges::Difference
|
|
|
|
|
),
|
|
|
|
|
"MaskDifference" <mask: Set> =>
|
|
|
|
|
presets::EdgeDisplay::Display(
|
|
|
|
|
graph::GraphMapEdges::MaskDifference{ mask }
|
|
|
|
|
),
|
|
|
|
|
"EntitiesDeleted" =>
|
|
|
|
|
presets::EdgeDisplay::Display(
|
|
|
|
|
graph::GraphMapEdges::EntitiesDeleted
|
|
|
|
|
),
|
|
|
|
|
"MaskEntitiesDeleted" <mask: Set> =>
|
|
|
|
|
presets::EdgeDisplay::Display(
|
|
|
|
|
graph::GraphMapEdges::MaskEntitiesDeleted{ mask }
|
|
|
|
|
),
|
|
|
|
|
"EntitiesAdded" =>
|
|
|
|
|
presets::EdgeDisplay::Display(
|
|
|
|
|
graph::GraphMapEdges::EntitiesAdded
|
|
|
|
|
),
|
|
|
|
|
"MaskEntitiesAdded" <mask: Set> =>
|
|
|
|
|
presets::EdgeDisplay::Display(
|
|
|
|
|
graph::GraphMapEdges::MaskEntitiesAdded{ mask }
|
|
|
|
|
),
|
2025-07-12 15:32:21 +02:00
|
|
|
}
|
|
|
|
|
|
2025-07-13 17:28:13 +02:00
|
|
|
/// Edge display formatters separated by arbitrary strings in quotes
|
2025-07-12 15:32:21 +02:00
|
|
|
SeparatorEdge: Vec<presets::EdgeDisplay> = {
|
|
|
|
|
<v: EdgeDisplay> => vec![v],
|
|
|
|
|
<v:(<EdgeDisplay> <LiteralSeparatorEdge>)+> <e: EdgeDisplay?> =>
|
|
|
|
|
match e {
|
2025-07-13 18:14:35 +02:00
|
|
|
None => v.iter().fold(vec![],
|
|
|
|
|
|mut acc, (a, b)| {
|
|
|
|
|
acc.push(a.clone());
|
|
|
|
|
acc.push(b.clone());
|
|
|
|
|
acc.clone()
|
|
|
|
|
}),
|
2025-07-12 15:32:21 +02:00
|
|
|
Some(e) => {
|
2025-07-13 18:14:35 +02:00
|
|
|
let mut v = v.iter().fold(vec![],
|
|
|
|
|
|mut acc, (a, b)| {
|
|
|
|
|
acc.push(a.clone());
|
|
|
|
|
acc.push(b.clone());
|
|
|
|
|
acc.clone()
|
|
|
|
|
});
|
2025-07-12 15:32:21 +02:00
|
|
|
v.push(e);
|
|
|
|
|
v
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-13 18:14:35 +02:00
|
|
|
Operation: graph::OperationType = {
|
|
|
|
|
"==" => graph::OperationType::Equals,
|
|
|
|
|
"=" => graph::OperationType::Equals,
|
|
|
|
|
"<" => graph::OperationType::Subset,
|
|
|
|
|
"⊂" => graph::OperationType::Subset,
|
|
|
|
|
"<=" => graph::OperationType::SubsetEqual,
|
|
|
|
|
"⊆" => graph::OperationType::SubsetEqual,
|
|
|
|
|
">" => graph::OperationType::Superset,
|
|
|
|
|
"⊃" => graph::OperationType::Superset,
|
|
|
|
|
">=" => graph::OperationType::SupersetEqual,
|
|
|
|
|
"⊇" => graph::OperationType::SupersetEqual
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NodeColorConditional: (graph::NodeColorConditional, String) = {
|
|
|
|
|
"Entities" <op: Operation> <set: Set> "?" <color: PATH> =>
|
|
|
|
|
(graph::NodeColorConditional::EntitiesConditional(op, set),
|
|
|
|
|
color.to_string()),
|
|
|
|
|
"Context.Nill" "?" <color: PATH> =>
|
|
|
|
|
(graph::NodeColorConditional::ContextConditional(
|
|
|
|
|
graph::ContextColorConditional::Nill),
|
|
|
|
|
color.to_string()),
|
|
|
|
|
"Context.RecursiveIdentifier" "(" <x: Literal> ")" "?" <color: PATH> =>
|
|
|
|
|
(graph::NodeColorConditional::ContextConditional(
|
|
|
|
|
graph::ContextColorConditional::RecursiveIdentifier(
|
|
|
|
|
translator.encode(x)
|
|
|
|
|
)),
|
|
|
|
|
color.to_string()),
|
|
|
|
|
"Context.EntitySet" <op: Operation> <set: Set> "?" <color: PATH> =>
|
|
|
|
|
(graph::NodeColorConditional::ContextConditional(
|
|
|
|
|
graph::ContextColorConditional::EntitySet(op, set)),
|
|
|
|
|
color.to_string()),
|
|
|
|
|
"Context.NonDeterministicChoice" "?" <color: PATH> =>
|
|
|
|
|
(graph::NodeColorConditional::ContextConditional(
|
|
|
|
|
graph::ContextColorConditional::NonDeterministicChoice),
|
|
|
|
|
color.to_string()),
|
|
|
|
|
"Context.Summation" "?" <color: PATH> =>
|
|
|
|
|
(graph::NodeColorConditional::ContextConditional(
|
|
|
|
|
graph::ContextColorConditional::Summation),
|
|
|
|
|
color.to_string()),
|
|
|
|
|
"Context.WaitEntity" "?" <color: PATH> =>
|
|
|
|
|
(graph::NodeColorConditional::ContextConditional(
|
|
|
|
|
graph::ContextColorConditional::WaitEntity),
|
|
|
|
|
color.to_string()),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Node color formatter
|
|
|
|
|
ColorNode: graph::NodeColor = {
|
|
|
|
|
<conditionals: Separated_Or<NodeColorConditional, "||">>
|
|
|
|
|
"!" <base_color: PATH> =>
|
2025-07-13 19:08:39 +02:00
|
|
|
graph::NodeColor { conditionals,
|
2025-07-13 18:14:35 +02:00
|
|
|
base_color: base_color.to_string() },
|
|
|
|
|
|
|
|
|
|
"!" <base_color: PATH> =>
|
|
|
|
|
graph::NodeColor { conditionals: vec![],
|
|
|
|
|
base_color: base_color.to_string() },
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-13 19:08:39 +02:00
|
|
|
EdgeColorConditional: (graph::EdgeColorConditional, String) = {
|
|
|
|
|
"Entities" <op: Operation> <set: Set> "?" <color: PATH> =>
|
|
|
|
|
(graph::EdgeColorConditional::Entities(op, set),
|
|
|
|
|
color.to_string()),
|
|
|
|
|
"Context" <op: Operation> <set: Set> "?" <color: PATH> =>
|
|
|
|
|
(graph::EdgeColorConditional::Context(op, set),
|
|
|
|
|
color.to_string()),
|
|
|
|
|
"T" <op: Operation> <set: Set> "?" <color: PATH> =>
|
|
|
|
|
(graph::EdgeColorConditional::T(op, set),
|
|
|
|
|
color.to_string()),
|
|
|
|
|
"Reactants" <op: Operation> <set: Set> "?" <color: PATH> =>
|
|
|
|
|
(graph::EdgeColorConditional::Reactants(op, set),
|
|
|
|
|
color.to_string()),
|
|
|
|
|
"AbsentReactants" <op: Operation> <set: Set> "?" <color: PATH> =>
|
|
|
|
|
(graph::EdgeColorConditional::ReactantsAbsent(op, set),
|
|
|
|
|
color.to_string()),
|
|
|
|
|
"Inhibitors" <op: Operation> <set: Set> "?" <color: PATH> =>
|
|
|
|
|
(graph::EdgeColorConditional::Inhibitors(op, set),
|
|
|
|
|
color.to_string()),
|
|
|
|
|
"PresentInhibitors" <op: Operation> <set: Set> "?" <color: PATH> =>
|
|
|
|
|
(graph::EdgeColorConditional::InhibitorsPresent(op, set),
|
|
|
|
|
color.to_string()),
|
|
|
|
|
"Products" <op: Operation> <set: Set> "?" <color: PATH> =>
|
|
|
|
|
(graph::EdgeColorConditional::Products(op, set),
|
|
|
|
|
color.to_string()),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ColorEdge: graph::EdgeColor = {
|
|
|
|
|
<conditionals: Separated_Or<EdgeColorConditional, "||">>
|
|
|
|
|
"!" <base_color: PATH> =>
|
|
|
|
|
graph::EdgeColor { conditionals,
|
|
|
|
|
base_color: base_color.to_string() },
|
|
|
|
|
|
|
|
|
|
"!" <base_color: PATH> =>
|
|
|
|
|
graph::EdgeColor { conditionals: vec![],
|
|
|
|
|
base_color: base_color.to_string() },
|
|
|
|
|
}
|
2025-07-13 18:14:35 +02:00
|
|
|
|
2025-07-12 15:32:21 +02:00
|
|
|
|
2025-07-11 23:49:59 +02:00
|
|
|
GraphSaveOptions: presets::GraphSaveOptions = {
|
2025-07-13 18:14:35 +02:00
|
|
|
"Dot" <s_node: SeparatorNode> "|" <s_edge: SeparatorEdge> "|"
|
2025-07-13 19:08:39 +02:00
|
|
|
<c_node: ColorNode> "|" <c_edge: ColorEdge> ">"
|
2025-07-12 15:32:21 +02:00
|
|
|
<so: SaveOptions> =>
|
|
|
|
|
presets::GraphSaveOptions::Dot { node_display: s_node,
|
|
|
|
|
edge_display: s_edge,
|
2025-07-13 18:14:35 +02:00
|
|
|
node_color: c_node,
|
2025-07-13 19:08:39 +02:00
|
|
|
edge_color: c_edge,
|
2025-07-12 15:32:21 +02:00
|
|
|
so },
|
|
|
|
|
"GraphML" <s_node: SeparatorNode> "|" <s_edge: SeparatorEdge> ">"
|
|
|
|
|
<so: SaveOptions> =>
|
|
|
|
|
presets::GraphSaveOptions::GraphML { node_display: s_node,
|
|
|
|
|
edge_display: s_edge,
|
|
|
|
|
so },
|
2025-07-11 23:49:59 +02:00
|
|
|
"Serialize" "(" <path: Path> ")" =>
|
|
|
|
|
presets::GraphSaveOptions::Serialize { path },
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Instruction: presets::Instruction = {
|
|
|
|
|
"Stats" ">" <so: SaveOptions> =>
|
|
|
|
|
presets::Instruction::Stats { so },
|
|
|
|
|
"Target" ">" <so: SaveOptions> =>
|
|
|
|
|
presets::Instruction::Target { so },
|
|
|
|
|
"Run" ">" <so: SaveOptions> =>
|
|
|
|
|
presets::Instruction::Run { so },
|
|
|
|
|
"Loop" "(" <symbol: Literal> ")" ">" <so: SaveOptions> =>
|
|
|
|
|
presets::Instruction::Loop { symbol, so },
|
2025-07-12 02:42:28 +02:00
|
|
|
"Frequency" ">" <so: SaveOptions> =>
|
|
|
|
|
presets::Instruction::Frequency { so },
|
2025-07-11 23:49:59 +02:00
|
|
|
"LimitFrequency" "(" <p: Path> ")" ">" <so: SaveOptions> =>
|
|
|
|
|
presets::Instruction::LimitFrequency { experiment: p, so },
|
|
|
|
|
"FastFrequency" "(" <p: Path> ")" ">" <so: SaveOptions> =>
|
|
|
|
|
presets::Instruction::FastFrequency { experiment: p, so },
|
|
|
|
|
"Digraph" ">" <gso: Separated_Or<GraphSaveOptions, "|">> =>
|
|
|
|
|
presets::Instruction::Digraph { gso },
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub Run: presets::Instructions = {
|
|
|
|
|
<sys: System> <instr: Separated_Or<Instruction, ",">> =>
|
|
|
|
|
Instructions { system: presets::System::RSsystem { sys },
|
|
|
|
|
instructions: instr },
|
2025-07-13 18:14:35 +02:00
|
|
|
|
|
|
|
|
"Deserialize" "(" <path: Path> ")"
|
|
|
|
|
<instr: Separated_Or<Instruction, ",">> =>
|
2025-07-11 23:49:59 +02:00
|
|
|
Instructions { system: presets::System::Deserialize { path },
|
|
|
|
|
instructions: instr },
|
|
|
|
|
}
|