diff --git a/Cargo.toml b/Cargo.toml index 9f9b914..7624c7c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,21 +1,7 @@ -[package] -name = "reactionsystems" -version = "0.1.0" -edition = "2024" +[workspace] +resolver = "3" +members = [ "analysis", "assert", "bisimilarity", "execution","grammar", "rsprocess"] exclude = ["*.system", "*.experiment", "/testing/", "*.serial", "*.dot", "*.trace", "*.svg"] -[build-dependencies] -lalrpop = "0.22" - -[dependencies] -rand = { version = "*" } -colored = { version = "*" } -regex = { version = "1", features = ["unicode-bool"] } -lalrpop-util = { version = "*", features = ["lexer", "unicode"] } -petgraph = { version = "*", features = ["serde-1"] } -petgraph-graphml = { version = "5" } -serde = { version = "1", features = ["derive", "rc"] } -serde_cbor_2 = { version = "*" } - [profile.dev] split-debuginfo = "unpacked" diff --git a/analysis/Cargo.toml b/analysis/Cargo.toml new file mode 100644 index 0000000..781b0f7 --- /dev/null +++ b/analysis/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "analysis" +version = "0.1.0" +edition = "2024" + +[dependencies] +rsprocess = { path = "../rsprocess/" } +execution = { path = "../execution/" } +grammar = { path = "../grammar/" } +colored = { version = "*" } +lalrpop-util = { version = "*", features = ["lexer", "unicode"] } diff --git a/analysis/src/helper.rs b/analysis/src/helper.rs new file mode 100644 index 0000000..9e33a8e --- /dev/null +++ b/analysis/src/helper.rs @@ -0,0 +1,113 @@ +use execution::presets; +use lalrpop_util::ParseError; +use std::fmt::Display; +use grammar::grammar; + +pub struct Parsers {} + +impl presets::FileParsers for Parsers { + fn parse_experiment( + translator: &mut rsprocess::translator::Translator, + contents: String, + ) -> Result<(Vec, Vec), String> { + match grammar::ExperimentParser::new().parse(translator, &contents) { + | Ok(sys) => Ok(sys), + | Err(e) => reformat_error(e, &contents), + } + } + + fn parse_instructions( + translator: &mut rsprocess::translator::Translator, + contents: String, + ) -> Result { + match grammar::RunParser::new().parse(translator, &contents) { + | Ok(sys) => Ok(sys), + | Err(e) => reformat_error(e, &contents), + } + } +} + +fn reformat_error( + e: ParseError, + input_str: &str, +) -> Result +where + T: Display, +{ + match e { + | ParseError::ExtraToken { token: (l, t, r) } => Err(format!( + "Unexpected token \"{t}\" between positions {l} and {r}." + )), + | ParseError::UnrecognizedEof { + location: _, + expected: _, + } => Err("End of file encountered while parsing.".into()), + | ParseError::InvalidToken { location } => + Err(format!("Invalid token at position {location}.")), + | ParseError::UnrecognizedToken { + token: (l, t, r), + expected, + } => { + use colored::Colorize; + + let mut err = format!( + "Unrecognized token {}{}{} \ + between positions {l} and {r}.", + "\"".red(), + t.to_string().red(), + "\"".red(), + ); + + // Temporary debug. + err.push_str("\nExpected: "); + let mut it = expected.iter().peekable(); + while let Some(s) = it.next() { + err.push('('); + err.push_str(&format!("{}", s.green())); + err.push(')'); + if it.peek().is_some() { + err.push(','); + err.push(' '); + } + } + let right_new_line = input_str[l..] + .find("\n") + .map(|pos| pos + l) + .unwrap_or(input_str.len()); + let left_new_line = input_str[..r] + .rfind("\n") + .map(|pos| pos + 1) + .unwrap_or_default(); + + let line_number = input_str[..l].match_indices('\n').count() + 1; + let pre_no_color = format!("{line_number} |"); + let pre = format!("{}", pre_no_color.blue()); + + let line_pos_l = l - left_new_line; + let line_pos_r = r - left_new_line; + + err.push_str(&format!( + "\nLine {} position {} to {}:\n{}{}{}{}", + line_number, + line_pos_l, + line_pos_r, + &pre, + &input_str[left_new_line..l].green(), + &input_str[l..r].red(), + &input_str[r..right_new_line], + )); + err.push('\n'); + err.push_str(&" ".repeat(pre_no_color.len() - 1)); + err.push_str(&format!("{}", "|".blue())); + err.push_str(&" ".repeat(l - left_new_line)); + err.push_str(&format!("{}", &"↑".red())); + if r - l > 2 { + err.push_str(&" ".repeat(r - l - 2)); + err.push_str(&format!("{}", &"↑".red())); + } + + Err(err) + }, + | ParseError::User { error } => Err(error.to_string()), + } +} diff --git a/src/main.rs b/analysis/src/main.rs similarity index 77% rename from src/main.rs rename to analysis/src/main.rs index b394916..06d49b3 100644 --- a/src/main.rs +++ b/analysis/src/main.rs @@ -1,5 +1,7 @@ +mod helper; + fn main() { - use reactionsystems::rsprocess::presets; + use execution::presets; let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); @@ -7,7 +9,7 @@ fn main() { let now = std::time::Instant::now(); - match presets::run(input) { + match presets::run::(input) { | Ok(()) => {}, | Err(e) => println!("{e}"), } diff --git a/assert/Cargo.toml b/assert/Cargo.toml new file mode 100644 index 0000000..ddecf5b --- /dev/null +++ b/assert/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "assert" +version = "0.1.0" +edition = "2024" + +[dependencies] +rand = { version = "*" } +rsprocess = { path = "../rsprocess/" } +petgraph = { version = "*", features = ["serde-1"] } +petgraph-graphml = { version = "*" } diff --git a/src/rsprocess/assert/dsl.rs b/assert/src/dsl.rs similarity index 99% rename from src/rsprocess/assert/dsl.rs rename to assert/src/dsl.rs index 2b7e428..38e20f5 100644 --- a/src/rsprocess/assert/dsl.rs +++ b/assert/src/dsl.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; -use super::super::set::BasicSet; -use super::super::{element, graph, label, process, set, system, translator}; +use rsprocess::set::BasicSet; +use rsprocess::{element, graph, label, process, set, system, translator}; /// If changing IntegerType in assert.rs, also change from Num to another /// similar parser with different return type in grammar.lalrpop in diff --git a/src/rsprocess/assert/fmt.rs b/assert/src/fmt.rs similarity index 99% rename from src/rsprocess/assert/fmt.rs rename to assert/src/fmt.rs index 9501c7b..1a6f32d 100644 --- a/src/rsprocess/assert/fmt.rs +++ b/assert/src/fmt.rs @@ -3,7 +3,7 @@ // ----------------------------------------------------------------------------- use std::fmt; -use super::super::translator::{ +use rsprocess::translator::{ Formatter, PrintableWithTranslator, Translator, }; use super::dsl::*; diff --git a/src/rsprocess/assert/mod.rs b/assert/src/lib.rs similarity index 100% rename from src/rsprocess/assert/mod.rs rename to assert/src/lib.rs diff --git a/src/rsprocess/assert/rsassert.rs b/assert/src/rsassert.rs similarity index 98% rename from src/rsprocess/assert/rsassert.rs rename to assert/src/rsassert.rs index db6236e..16926a3 100644 --- a/src/rsprocess/assert/rsassert.rs +++ b/assert/src/rsassert.rs @@ -1,8 +1,8 @@ use std::collections::HashMap; -use super::super::{graph, label, set, system, translator}; use super::dsl::*; -use crate::rsprocess::translator::PrintableWithTranslator; +use rsprocess::{graph, label, set, system, translator}; +use rsprocess::translator::PrintableWithTranslator; // ---------------------------------------------------------------------------- // Specific Assert Implementation diff --git a/src/rsprocess/assert/tests.rs b/assert/src/tests.rs similarity index 99% rename from src/rsprocess/assert/tests.rs rename to assert/src/tests.rs index 38ca9ac..8f58f98 100644 --- a/src/rsprocess/assert/tests.rs +++ b/assert/src/tests.rs @@ -1,4 +1,4 @@ -use super::super::{environment, label, process, set, system, translator}; +use rsprocess::{environment, label, process, set, system, translator}; use super::dsl::*; use super::rsassert::*; diff --git a/bisimilarity/Cargo.toml b/bisimilarity/Cargo.toml new file mode 100644 index 0000000..b1a15ad --- /dev/null +++ b/bisimilarity/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "bisimilarity" +version = "0.1.0" +edition = "2024" + +[dependencies] +petgraph = { version = "0.8", features = ["serde-1"] } diff --git a/src/rsprocess/bisimilarity/bisimilarity_kanellakis_smolka.rs b/bisimilarity/src/bisimilarity_kanellakis_smolka.rs similarity index 100% rename from src/rsprocess/bisimilarity/bisimilarity_kanellakis_smolka.rs rename to bisimilarity/src/bisimilarity_kanellakis_smolka.rs diff --git a/src/rsprocess/bisimilarity/bisimilarity_paige_tarkan.rs b/bisimilarity/src/bisimilarity_paige_tarkan.rs similarity index 100% rename from src/rsprocess/bisimilarity/bisimilarity_paige_tarkan.rs rename to bisimilarity/src/bisimilarity_paige_tarkan.rs diff --git a/src/rsprocess/bisimilarity/mod.rs b/bisimilarity/src/lib.rs similarity index 100% rename from src/rsprocess/bisimilarity/mod.rs rename to bisimilarity/src/lib.rs diff --git a/src/rsprocess/bisimilarity/test_kenallakis_smolka.rs b/bisimilarity/src/test_kenallakis_smolka.rs similarity index 100% rename from src/rsprocess/bisimilarity/test_kenallakis_smolka.rs rename to bisimilarity/src/test_kenallakis_smolka.rs diff --git a/src/rsprocess/bisimilarity/test_paige_tarjan.rs b/bisimilarity/src/test_paige_tarjan.rs similarity index 100% rename from src/rsprocess/bisimilarity/test_paige_tarjan.rs rename to bisimilarity/src/test_paige_tarjan.rs diff --git a/build.rs b/build.rs index 7e68f91..cea3401 100644 --- a/build.rs +++ b/build.rs @@ -1,3 +1,3 @@ fn main() { - lalrpop::process_src().unwrap(); + // lalrpop::process_src().unwrap(); } diff --git a/execution/Cargo.toml b/execution/Cargo.toml new file mode 100644 index 0000000..5288773 --- /dev/null +++ b/execution/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "execution" +version = "0.1.0" +edition = "2024" + +[dependencies] +rsprocess = { path = "../rsprocess/" } +assert = { path = "../assert/" } +bisimilarity = { path = "../bisimilarity/" } +colored = { version = "*" } +petgraph = { version = "0.8", features = ["serde-1"] } +petgraph-graphml = { version = "*" } +lalrpop-util = { version = "*", features = ["lexer", "unicode"] } diff --git a/execution/src/data.rs b/execution/src/data.rs new file mode 100644 index 0000000..83f87d7 --- /dev/null +++ b/execution/src/data.rs @@ -0,0 +1,63 @@ +use rsprocess::translator; +use rsprocess::system::System; +use rsprocess::label::Label; +use rsprocess::graph::SystemGraph; +use petgraph::{Graph, Directed}; + +// ----------------------------------------------------------------------------- +// helper functions +// ----------------------------------------------------------------------------- + +/// Very inelegant way to provide our graph with a map method where the edges +/// are mapped until the first error. +pub trait MapEdges<'a, N: 'a, E, Ty, Ix> +where + Ty: petgraph::EdgeType, + Ix: petgraph::graph::IndexType, +{ + fn map_edges( + &self, + edge_map: &assert::relabel::Assert, + translator: &mut translator::Translator, + ) -> Result< + Graph, + String, + >; +} + +impl<'a> MapEdges<'a, System, Label, Directed, u32> for SystemGraph { + fn map_edges( + &self, + edge_map: &assert::relabel::Assert, + translator: &mut translator::Translator, + ) -> Result< + Graph, + String, + > { + use petgraph::graph::EdgeIndex; + + let mut g = Graph::with_capacity(self.node_count(), self.edge_count()); + let nodes = self.raw_nodes(); + let edges = self.raw_edges(); + + let edges = edges + .iter() + .enumerate() + .map(|(i, edge)| { + match edge_map.execute(self, &EdgeIndex::new(i), translator) { + | Err(e) => Err(e), + | Ok(val) => Ok((edge.source(), edge.target(), val)), + } + }) + .collect::, _>>()?; + nodes.iter().for_each(|node| { + g.add_node(node.weight.clone()); + }); + + edges.into_iter().for_each(|(source, target, v)| { + g.add_edge(source, target, v); + }); + + Ok(g) + } +} diff --git a/execution/src/lib.rs b/execution/src/lib.rs new file mode 100644 index 0000000..9527caf --- /dev/null +++ b/execution/src/lib.rs @@ -0,0 +1,2 @@ +pub mod data; +pub mod presets; diff --git a/src/rsprocess/presets.rs b/execution/src/presets.rs similarity index 85% rename from src/rsprocess/presets.rs rename to execution/src/presets.rs index 02f7115..bf9ac04 100644 --- a/src/rsprocess/presets.rs +++ b/execution/src/presets.rs @@ -1,20 +1,30 @@ //! Module that holds useful presets for interacting with other modules. - use std::collections::HashMap; -use std::fmt::Display; use std::io::prelude::*; use std::rc::Rc; use std::{env, fs, io}; -use lalrpop_util::ParseError; use petgraph::Graph; -use super::super::grammar; -use super::graph::MapEdges; -use super::set::Set; -use super::system::ExtensionsSystem; -use super::translator::Translator; -use super::*; +use crate::data::MapEdges; +use rsprocess::set::Set; +use rsprocess::system::ExtensionsSystem; +use rsprocess::translator::Translator; +use rsprocess::*; + +// ----------------------------------------------------------------------------- + +pub trait FileParsers { + fn parse_experiment( + translator: &mut Translator, + contents: String, + ) -> Result<(Vec, Vec), String>; + + fn parse_instructions( + translator: &mut Translator, + contents: String, + ) -> Result; +} // ----------------------------------------------------------------------------- // Structures @@ -207,112 +217,6 @@ where Ok(result) } -fn reformat_error( - e: ParseError, - input_str: &str, -) -> Result -where - T: Display, -{ - match e { - | ParseError::ExtraToken { token: (l, t, r) } => Err(format!( - "Unexpected token \"{t}\" \ - between positions {l} and {r}." - )), - | ParseError::UnrecognizedEof { - location: _, - expected: _, - } => Err("End of file encountered while parsing.".into()), - | ParseError::InvalidToken { location } => - Err(format!("Invalid token at position {location}.")), - | ParseError::UnrecognizedToken { - token: (l, t, r), - expected, - } => { - use colored::Colorize; - - let mut err = format!( - "Unrecognized token {}{}{} \ - between positions {l} and {r}.", - "\"".red(), - t.to_string().red(), - "\"".red(), - ); - - // Temporary debug. - err.push_str("\nExpected: "); - let mut it = expected.iter().peekable(); - while let Some(s) = it.next() { - err.push('('); - err.push_str(&format!("{}", s.green())); - err.push(')'); - if it.peek().is_some() { - err.push(','); - err.push(' '); - } - } - let right_new_line = input_str[l..] - .find("\n") - .map(|pos| pos + l) - .unwrap_or(input_str.len()); - let left_new_line = input_str[..r] - .rfind("\n") - .map(|pos| pos + 1) - .unwrap_or_default(); - - let line_number = input_str[..l].match_indices('\n').count() + 1; - let pre_no_color = format!("{line_number} |"); - let pre = format!("{}", pre_no_color.blue()); - - let line_pos_l = l - left_new_line; - let line_pos_r = r - left_new_line; - - err.push_str(&format!( - "\nLine {} position {} to {}:\n{}{}{}{}", - line_number, - line_pos_l, - line_pos_r, - &pre, - &input_str[left_new_line..l].green(), - &input_str[l..r].red(), - &input_str[r..right_new_line], - )); - err.push('\n'); - err.push_str(&" ".repeat(pre_no_color.len() - 1)); - err.push_str(&format!("{}", "|".blue())); - err.push_str(&" ".repeat(l - left_new_line)); - err.push_str(&format!("{}", &"↑".red())); - if r - l > 2 { - err.push_str(&" ".repeat(r - l - 2)); - err.push_str(&format!("{}", &"↑".red())); - } - - Err(err) - }, - | ParseError::User { error } => Err(error.to_string()), - } -} - -fn parser_experiment( - translator: &mut Translator, - contents: String, -) -> Result<(Vec, Vec), String> { - match grammar::ExperimentParser::new().parse(translator, &contents) { - | Ok(sys) => Ok(sys), - | Err(e) => reformat_error(e, &contents), - } -} - -fn parser_instructions( - translator: &mut Translator, - contents: String, -) -> Result { - match grammar::RunParser::new().parse(translator, &contents) { - | Ok(sys) => Ok(sys), - | Err(e) => reformat_error(e, &contents), - } -} - fn save_file(contents: &String, path_string: String) -> Result<(), String> { // relative path let mut path = match env::current_dir() { @@ -475,10 +379,14 @@ pub fn freq(system: &EvaluatedSystem) -> Result { /// Finds the frequency of each entity in the limit loop of a nonterminating /// Reaction System whose context has the form Q1 ... Q1.Q2 ... Q2 ... Qn ... /// equivalent to main_do(limitfreq, PairList) -pub fn limit_freq( +pub fn limit_freq( system: &mut EvaluatedSystem, experiment: String, -) -> Result { + parser_experiment: F, +) -> Result +where + F: Fn(&mut Translator, String) -> Result<(Vec, Vec), String> +{ use frequency::BasicFrequency; let (sys, translator): (&system::System, &mut Translator) = match system { @@ -515,10 +423,14 @@ pub fn limit_freq( /// Q1 ... Q1.Q2 ... Q2 ... Qn ... Qn.nil and each Qi is repeated Wi times /// read from a corresponding file. /// equivalent to main_do(fastfreq, PairList) -pub fn fast_freq( +pub fn fast_freq( system: &mut EvaluatedSystem, experiment: String, -) -> Result { + parser_experiment: F, +) -> Result +where + F: Fn(&mut Translator, String) -> Result<(Vec, Vec), String> +{ use frequency::BasicFrequency; let (sys, translator): (&system::System, &mut Translator) = match system { @@ -618,11 +530,15 @@ pub fn grouping( } /// Computes bisimularity of two provided systems -pub fn bisimilar( +pub fn bisimilar( system_a: &mut EvaluatedSystem, edge_relabeler: &assert::relabel::Assert, system_b: String, -) -> Result { + parser_instructions: F +) -> Result +where + F: Fn(&mut Translator, String) -> Result +{ use assert::relabel::AssertReturnValue; let system_b = read_file( @@ -834,7 +750,7 @@ macro_rules! save_options { }; } -fn execute( +fn execute( instruction: Instruction, system: &mut EvaluatedSystem, ) -> Result<(), String> { @@ -855,10 +771,10 @@ fn execute( save_options!(freq(system)?, so); }, | Instruction::LimitFrequency { experiment, so } => { - save_options!(limit_freq(system, experiment)?, so); + save_options!(limit_freq(system, experiment, P::parse_experiment)?, so); }, | Instruction::FastFrequency { experiment, so } => { - save_options!(fast_freq(system, experiment)?, so); + save_options!(fast_freq(system, experiment, P::parse_experiment)?, so); }, | Instruction::Digraph { group, gso } => { digraph(system)?; @@ -898,7 +814,7 @@ fn execute( so, } => { edge_relabeler.typecheck()?; - save_options!(bisimilar(system, &edge_relabeler, system_b)?, so); + save_options!(bisimilar(system, &edge_relabeler, system_b, P::parse_instructions)?, so); }, } Ok(()) @@ -906,18 +822,22 @@ fn execute( /// Interprets file at supplied path, then executes the code specified as /// instructions inside the file. -pub fn run(path: String) -> Result<(), String> { +pub fn run( + path: String, +) -> Result<(), String> { let mut translator = Translator::new(); let Instructions { system, instructions, - } = read_file(&mut translator, path, parser_instructions)?; + } = read_file(&mut translator, + path, + P::parse_instructions)?; let mut system = system.compute(translator)?; for instr in instructions { - execute(instr, &mut system)?; + execute::

(instr, &mut system)?; } Ok(()) diff --git a/grammar/Cargo.toml b/grammar/Cargo.toml new file mode 100644 index 0000000..6fc219d --- /dev/null +++ b/grammar/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "grammar" +version = "0.1.0" +edition = "2024" + +[build-dependencies] +lalrpop = "*" + +[dependencies] +rsprocess = { path = "../rsprocess/" } +assert = { path = "../assert/" } +execution = { path = "../execution/" } +regex = { version = "*", features = ["unicode-bool"] } +lalrpop-util = { version = "*", features = ["lexer", "unicode"] } diff --git a/grammar/build.rs b/grammar/build.rs new file mode 100644 index 0000000..7e68f91 --- /dev/null +++ b/grammar/build.rs @@ -0,0 +1,3 @@ +fn main() { + lalrpop::process_src().unwrap(); +} diff --git a/src/rsprocess/grammar.lalrpop b/grammar/src/grammar.lalrpop similarity index 99% rename from src/rsprocess/grammar.lalrpop rename to grammar/src/grammar.lalrpop index d6cb5cd..ba370af 100644 --- a/src/rsprocess/grammar.lalrpop +++ b/grammar/src/grammar.lalrpop @@ -1,12 +1,13 @@ use std::rc::Rc; use std::str::FromStr; use lalrpop_util::ParseError; -use crate::rsprocess::{set, reaction, process, environment, system, label}; -use crate::rsprocess::element::IdType; -use crate::rsprocess::translator::Translator; -use crate::rsprocess::presets; -use crate::rsprocess::assert::{relabel, grouping}; -use crate::rsprocess::graph; + +use assert::{relabel, grouping}; +use rsprocess::{set, reaction, process, environment, system, label}; +use rsprocess::element::IdType; +use rsprocess::translator::Translator; +use execution::presets; +use rsprocess::graph; grammar(translator: &mut Translator); diff --git a/src/lib.rs b/grammar/src/lib.rs similarity index 54% rename from src/lib.rs rename to grammar/src/lib.rs index e942550..343b94a 100644 --- a/src/lib.rs +++ b/grammar/src/lib.rs @@ -1,8 +1,4 @@ -//! Module root - -pub mod rsprocess; - lalrpop_util::lalrpop_mod!( #[allow(clippy::uninlined_format_args)] pub grammar, // name of module - "/rsprocess/grammar.rs" // location of parser + "/grammar.rs" // location of parser ); diff --git a/rsprocess/Cargo.toml b/rsprocess/Cargo.toml new file mode 100644 index 0000000..844e8a5 --- /dev/null +++ b/rsprocess/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "rsprocess" +version = "0.1.0" +edition = "2024" + +[dependencies] +petgraph = { version = "*", features = ["serde-1"] } +petgraph-graphml = { version = "*" } +serde = { version = "*", features = ["derive", "rc"] } +serde_cbor_2 = { version = "*" } diff --git a/src/rsprocess/choices.rs b/rsprocess/src/choices.rs similarity index 100% rename from src/rsprocess/choices.rs rename to rsprocess/src/choices.rs diff --git a/src/rsprocess/dot.rs b/rsprocess/src/dot.rs similarity index 100% rename from src/rsprocess/dot.rs rename to rsprocess/src/dot.rs diff --git a/src/rsprocess/element.rs b/rsprocess/src/element.rs similarity index 100% rename from src/rsprocess/element.rs rename to rsprocess/src/element.rs diff --git a/src/rsprocess/environment.rs b/rsprocess/src/environment.rs similarity index 100% rename from src/rsprocess/environment.rs rename to rsprocess/src/environment.rs diff --git a/src/rsprocess/format_helpers.rs b/rsprocess/src/format_helpers.rs similarity index 100% rename from src/rsprocess/format_helpers.rs rename to rsprocess/src/format_helpers.rs diff --git a/src/rsprocess/frequency.rs b/rsprocess/src/frequency.rs similarity index 100% rename from src/rsprocess/frequency.rs rename to rsprocess/src/frequency.rs diff --git a/src/rsprocess/graph.rs b/rsprocess/src/graph.rs similarity index 91% rename from src/rsprocess/graph.rs rename to rsprocess/src/graph.rs index e040966..60a5c51 100644 --- a/src/rsprocess/graph.rs +++ b/rsprocess/src/graph.rs @@ -94,63 +94,6 @@ common_label!( .intersection(&acc) ); -// ----------------------------------------------------------------------------- -// helper functions -// ----------------------------------------------------------------------------- - -/// Very inelegant way to provide our graph with a map method where the edges -/// are mapped until the first error. -pub trait MapEdges<'a, N: 'a, E, Ty, Ix> -where - Ty: petgraph::EdgeType, - Ix: petgraph::graph::IndexType, -{ - fn map_edges( - &self, - edge_map: &super::assert::relabel::Assert, - translator: &mut super::translator::Translator, - ) -> Result< - Graph, - String, - >; -} - -impl<'a> MapEdges<'a, System, Label, Directed, u32> for SystemGraph { - fn map_edges( - &self, - edge_map: &super::assert::relabel::Assert, - translator: &mut super::translator::Translator, - ) -> Result< - Graph, - String, - > { - use petgraph::graph::EdgeIndex; - - let mut g = Graph::with_capacity(self.node_count(), self.edge_count()); - let nodes = self.raw_nodes(); - let edges = self.raw_edges(); - - let edges = edges - .iter() - .enumerate() - .map(|(i, edge)| { - match edge_map.execute(self, &EdgeIndex::new(i), translator) { - | Err(e) => Err(e), - | Ok(val) => Ok((edge.source(), edge.target(), val)), - } - }) - .collect::, _>>()?; - nodes.iter().for_each(|node| { - g.add_node(node.weight.clone()); - }); - - edges.into_iter().for_each(|(source, target, v)| { - g.add_edge(source, target, v); - }); - - Ok(g) - } -} // Nodes ----------------------------------------------------------------------- diff --git a/src/rsprocess/label.rs b/rsprocess/src/label.rs similarity index 100% rename from src/rsprocess/label.rs rename to rsprocess/src/label.rs diff --git a/src/rsprocess/mod.rs b/rsprocess/src/lib.rs similarity index 86% rename from src/rsprocess/mod.rs rename to rsprocess/src/lib.rs index 2141fea..51b0f13 100644 --- a/src/rsprocess/mod.rs +++ b/rsprocess/src/lib.rs @@ -12,12 +12,9 @@ pub mod reaction; pub mod set; pub mod system; -pub mod assert; -pub mod bisimilarity; pub mod dot; pub mod frequency; pub mod graph; -pub mod presets; pub mod serialize; pub mod transitions; diff --git a/src/rsprocess/process.rs b/rsprocess/src/process.rs similarity index 100% rename from src/rsprocess/process.rs rename to rsprocess/src/process.rs diff --git a/src/rsprocess/reaction.rs b/rsprocess/src/reaction.rs similarity index 100% rename from src/rsprocess/reaction.rs rename to rsprocess/src/reaction.rs diff --git a/src/rsprocess/serialize.rs b/rsprocess/src/serialize.rs similarity index 100% rename from src/rsprocess/serialize.rs rename to rsprocess/src/serialize.rs diff --git a/src/rsprocess/set.rs b/rsprocess/src/set.rs similarity index 100% rename from src/rsprocess/set.rs rename to rsprocess/src/set.rs diff --git a/src/rsprocess/set_test.rs b/rsprocess/src/set_test.rs similarity index 100% rename from src/rsprocess/set_test.rs rename to rsprocess/src/set_test.rs diff --git a/src/rsprocess/system.rs b/rsprocess/src/system.rs similarity index 100% rename from src/rsprocess/system.rs rename to rsprocess/src/system.rs diff --git a/src/rsprocess/system_test.rs b/rsprocess/src/system_test.rs similarity index 99% rename from src/rsprocess/system_test.rs rename to rsprocess/src/system_test.rs index 204ff3f..61b9159 100644 --- a/src/rsprocess/system_test.rs +++ b/rsprocess/src/system_test.rs @@ -1,5 +1,5 @@ -use crate::rsprocess::set::PositiveSet; -use crate::rsprocess::system::BasicSystem; +use super::set::PositiveSet; +use super::system::BasicSystem; #[test] fn one_transition() { diff --git a/src/rsprocess/transitions.rs b/rsprocess/src/transitions.rs similarity index 100% rename from src/rsprocess/transitions.rs rename to rsprocess/src/transitions.rs diff --git a/src/rsprocess/translator.rs b/rsprocess/src/translator.rs similarity index 100% rename from src/rsprocess/translator.rs rename to rsprocess/src/translator.rs