This commit is contained in:
elvis
2025-09-17 00:34:18 +02:00
parent d458787a81
commit 83923b80e5
10 changed files with 116 additions and 80 deletions

View File

@ -1,8 +1,9 @@
use execution::presets;
use lalrpop_util::ParseError;
use std::fmt::Display; use std::fmt::Display;
use grammar::grammar;
use ::grammar::user_error::{UserError, UserErrorTypes}; use ::grammar::user_error::{UserError, UserErrorTypes};
use execution::presets;
use grammar::grammar;
use lalrpop_util::ParseError;
pub struct Parsers {} pub struct Parsers {}
@ -124,9 +125,10 @@ where
T: Display, T: Display,
{ {
match e { match e {
| ParseError::ExtraToken { token: (l, t, r) } => | ParseError::ExtraToken { token: (l, t, r) } => Err(format!(
Err(format!("Unexpected extra token \"{t}\" between positions {l} \ "Unexpected extra token \"{t}\" between positions {l} \
and {r}.")), and {r}."
)),
| ParseError::UnrecognizedEof { | ParseError::UnrecognizedEof {
location: _, location: _,
expected: _, expected: _,
@ -136,13 +138,13 @@ where
| ParseError::UnrecognizedToken { | ParseError::UnrecognizedToken {
token: (l, t, r), token: (l, t, r),
expected, expected,
} => { } => create_error(input_str, l, t, r, Some(expected), None),
create_error(input_str, l, t, r, Some(expected), None)
},
| ParseError::User { | ParseError::User {
error: UserError { token: (l, t, r), error } error:
} => { UserError {
create_error(input_str, l, t, r, None, Some(error)) token: (l, t, r),
error,
}, },
} => create_error(input_str, l, t, r, None, Some(error)),
} }
} }

View File

@ -3,9 +3,8 @@
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
use std::fmt; use std::fmt;
use rsprocess::translator::{ use rsprocess::translator::{Formatter, PrintableWithTranslator, Translator};
Formatter, PrintableWithTranslator, Translator,
};
use super::dsl::*; use super::dsl::*;
impl<S> fmt::Debug for Assert<S> impl<S> fmt::Debug for Assert<S>

View File

@ -1,8 +1,9 @@
use std::collections::HashMap; use std::collections::HashMap;
use super::dsl::*;
use rsprocess::{graph, label, set, system, translator};
use rsprocess::translator::PrintableWithTranslator; use rsprocess::translator::PrintableWithTranslator;
use rsprocess::{graph, label, set, system, translator};
use super::dsl::*;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Specific Assert Implementation // Specific Assert Implementation

View File

@ -1,4 +1,5 @@
use rsprocess::{environment, label, process, set, system, translator}; use rsprocess::{environment, label, process, set, system, translator};
use super::dsl::*; use super::dsl::*;
use super::rsassert::*; use super::rsassert::*;

View File

@ -1,8 +1,8 @@
use rsprocess::translator; use petgraph::{Directed, Graph};
use rsprocess::system::System;
use rsprocess::label::Label;
use rsprocess::graph::SystemGraph; use rsprocess::graph::SystemGraph;
use petgraph::{Graph, Directed}; use rsprocess::label::Label;
use rsprocess::system::System;
use rsprocess::translator;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// helper functions // helper functions
@ -19,10 +19,7 @@ where
&self, &self,
edge_map: &assert::relabel::Assert, edge_map: &assert::relabel::Assert,
translator: &mut translator::Translator, translator: &mut translator::Translator,
) -> Result< ) -> Result<Graph<System, assert::relabel::AssertReturnValue, Ty, Ix>, String>;
Graph<System, assert::relabel::AssertReturnValue, Ty, Ix>,
String,
>;
} }
impl<'a> MapEdges<'a, System, Label, Directed, u32> for SystemGraph { impl<'a> MapEdges<'a, System, Label, Directed, u32> for SystemGraph {

View File

@ -5,13 +5,13 @@ use std::rc::Rc;
use std::{env, fs, io}; use std::{env, fs, io};
use petgraph::Graph; use petgraph::Graph;
use crate::data::MapEdges;
use rsprocess::set::Set; use rsprocess::set::Set;
use rsprocess::system::ExtensionsSystem; use rsprocess::system::ExtensionsSystem;
use rsprocess::translator::Translator; use rsprocess::translator::Translator;
use rsprocess::*; use rsprocess::*;
use crate::data::MapEdges;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
pub trait FileParsers { pub trait FileParsers {
@ -163,16 +163,23 @@ impl EvaluatedSystem {
pub fn from_graph( pub fn from_graph(
graph: graph::SystemGraph, graph: graph::SystemGraph,
translator: Translator
) -> Self {
Self { sys: None, graph: Some(graph), positive: None, translator }
}
pub fn from_sys(
sys: system::System,
translator: Translator, translator: Translator,
) -> Self { ) -> Self {
Self { sys: Some(sys), graph: None, positive: None, translator } Self {
sys: None,
graph: Some(graph),
positive: None,
translator,
}
}
pub fn from_sys(sys: system::System, translator: Translator) -> Self {
Self {
sys: Some(sys),
graph: None,
positive: None,
translator,
}
} }
} }
@ -269,7 +276,7 @@ pub fn stats(system: &EvaluatedSystem) -> Result<String, String> {
/// Equivalent to main_do(target, E) /// Equivalent to main_do(target, E)
pub fn target( pub fn target(
system: &EvaluatedSystem, system: &EvaluatedSystem,
limit: Option<usize> limit: Option<usize>,
) -> Result<String, String> { ) -> Result<String, String> {
if let Some(sys) = &system.sys { if let Some(sys) = &system.sys {
let res = if let Some(limit) = limit { let res = if let Some(limit) = limit {
@ -318,7 +325,7 @@ pub fn target(
/// equivalent to main_do(run,Es) /// equivalent to main_do(run,Es)
pub fn traversed( pub fn traversed(
system: &EvaluatedSystem, system: &EvaluatedSystem,
limit: Option<usize> limit: Option<usize>,
) -> Result<String, String> { ) -> Result<String, String> {
let mut output = String::new(); let mut output = String::new();
@ -492,7 +499,7 @@ pub fn limit_freq<F>(
parser_experiment: F, parser_experiment: F,
) -> Result<String, String> ) -> Result<String, String>
where where
F: Fn(&mut Translator, String) -> Result<(Vec<u32>, Vec<Set>), String> F: Fn(&mut Translator, String) -> Result<(Vec<u32>, Vec<Set>), String>,
{ {
use frequency::BasicFrequency; use frequency::BasicFrequency;
@ -568,7 +575,7 @@ pub fn fast_freq<F>(
parser_experiment: F, parser_experiment: F,
) -> Result<String, String> ) -> Result<String, String>
where where
F: Fn(&mut Translator, String) -> Result<(Vec<u32>, Vec<Set>), String> F: Fn(&mut Translator, String) -> Result<(Vec<u32>, Vec<Set>), String>,
{ {
use frequency::BasicFrequency; use frequency::BasicFrequency;
@ -623,10 +630,14 @@ where
/// Computes the LTS. /// Computes the LTS.
/// equivalent to main_do(digraph, Arcs) or to main_do(advdigraph, Arcs) /// equivalent to main_do(digraph, Arcs) or to main_do(advdigraph, Arcs)
pub fn digraph(system: &mut EvaluatedSystem) -> Result<(), String> { pub fn digraph(system: &mut EvaluatedSystem) -> Result<(), String> {
if let Some(sys) = &system.sys && system.graph.is_none() { if let Some(sys) = &system.sys
&& system.graph.is_none()
{
let graph = sys.digraph()?; let graph = sys.digraph()?;
system.graph = Some(graph); system.graph = Some(graph);
} else if let Some(positive) = &system.positive && system.graph.is_none() { } else if let Some(positive) = &system.positive
&& system.graph.is_none()
{
let _graph = positive.digraph()?; let _graph = positive.digraph()?;
todo!() todo!()
} }
@ -694,20 +705,21 @@ pub fn bisimilar<F>(
system_a: &mut EvaluatedSystem, system_a: &mut EvaluatedSystem,
edge_relabeler: &assert::relabel::Assert, edge_relabeler: &assert::relabel::Assert,
system_b: String, system_b: String,
parser_instructions: F parser_instructions: F,
) -> Result<String, String> ) -> Result<String, String>
where where
F: Fn(&mut Translator, String) -> Result<Instructions, String> F: Fn(&mut Translator, String) -> Result<Instructions, String>,
{ {
use assert::relabel::AssertReturnValue; use assert::relabel::AssertReturnValue;
let system_b = read_file(&mut system_a.translator, let system_b = read_file(
&mut system_a.translator,
system_b.to_string(), system_b.to_string(),
parser_instructions)?; parser_instructions,
)?;
let mut system_b = system_b let mut system_b =
.system system_b.system.compute(system_a.get_translator().clone())?;
.compute(system_a.get_translator().clone())?;
if system_b.translator != system_a.translator { if system_b.translator != system_a.translator {
return Err("Bisimilarity not implemented for systems with different \ return Err("Bisimilarity not implemented for systems with different \
@ -720,11 +732,16 @@ where
// since we ran digraph on both they have to have valid graphs // since we ran digraph on both they have to have valid graphs
let a: Graph<system::System, AssertReturnValue> = let a: Graph<system::System, AssertReturnValue> = system_a
system_a.graph.as_ref().unwrap() .graph
.as_ref()
.unwrap()
.map_edges(edge_relabeler, &mut system_a.translator)?; .map_edges(edge_relabeler, &mut system_a.translator)?;
let b: Graph<system::System, AssertReturnValue> = let b: Graph<system::System, AssertReturnValue> =
system_b.graph.unwrap().map_edges(edge_relabeler, &mut system_b.translator)?; system_b
.graph
.unwrap()
.map_edges(edge_relabeler, &mut system_b.translator)?;
Ok(format!( Ok(format!(
"{}", "{}",
// bisimilarity::bisimilarity_kanellakis_smolka::bisimilarity(& // bisimilarity::bisimilarity_kanellakis_smolka::bisimilarity(&
@ -897,10 +914,16 @@ fn execute<P: FileParsers>(
save_options!(freq(system)?, so); save_options!(freq(system)?, so);
}, },
| Instruction::LimitFrequency { experiment, so } => { | Instruction::LimitFrequency { experiment, so } => {
save_options!(limit_freq(system, experiment, P::parse_experiment)?, so); save_options!(
limit_freq(system, experiment, P::parse_experiment)?,
so
);
}, },
| Instruction::FastFrequency { experiment, so } => { | Instruction::FastFrequency { experiment, so } => {
save_options!(fast_freq(system, experiment, P::parse_experiment)?, so); save_options!(
fast_freq(system, experiment, P::parse_experiment)?,
so
);
}, },
| Instruction::Digraph { group, gso } => { | Instruction::Digraph { group, gso } => {
digraph(system)?; digraph(system)?;
@ -940,7 +963,15 @@ fn execute<P: FileParsers>(
so, so,
} => { } => {
edge_relabeler.typecheck()?; edge_relabeler.typecheck()?;
save_options!(bisimilar(system, &edge_relabeler, system_b, P::parse_instructions)?, so); save_options!(
bisimilar(
system,
&edge_relabeler,
system_b,
P::parse_instructions
)?,
so
);
}, },
} }
Ok(()) Ok(())
@ -948,17 +979,13 @@ fn execute<P: FileParsers>(
/// Interprets file at supplied path, then executes the code specified as /// Interprets file at supplied path, then executes the code specified as
/// instructions inside the file. /// instructions inside the file.
pub fn run<P: FileParsers>( pub fn run<P: FileParsers>(path: String) -> Result<(), String> {
path: String,
) -> Result<(), String> {
let mut translator = Translator::new(); let mut translator = Translator::new();
let Instructions { let Instructions {
system, system,
instructions, instructions,
} = read_file(&mut translator, } = read_file(&mut translator, path, P::parse_instructions)?;
path,
P::parse_instructions)?;
let mut system = system.compute(translator)?; let mut system = system.compute(translator)?;

View File

@ -8,13 +8,18 @@ pub enum UserErrorTypes {
impl Display for UserErrorTypes { impl Display for UserErrorTypes {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self { match self {
Self::NumberTooBigUsize => | Self::NumberTooBigUsize => write!(
write!(f, "Specified number is too big (greater than {})", f,
usize::MAX), "Specified number is too big (greater than {})",
Self::NumberTooBigi64 => usize::MAX
write!(f, "Specified number is too big (lesser than {} or \ ),
| Self::NumberTooBigi64 => write!(
f,
"Specified number is too big (lesser than {} or \
greater than {})", greater than {})",
i64::MIN, i64::MAX), i64::MIN,
i64::MAX
),
} }
} }
} }

View File

@ -5,6 +5,7 @@ pub mod user_error {
} }
lalrpop_util::lalrpop_mod!( lalrpop_util::lalrpop_mod!(
#[allow(clippy::uninlined_format_args)] pub grammar, // name of module #[allow(clippy::uninlined_format_args)]
#[allow(clippy::type_complexity)] pub grammar, // name of module
"/grammar.rs" // location of parser "/grammar.rs" // location of parser
); );

View File

@ -94,7 +94,6 @@ common_label!(
.intersection(&acc) .intersection(&acc)
); );
// Nodes ----------------------------------------------------------------------- // Nodes -----------------------------------------------------------------------
/// Helper structure that specifies what information to display for nodes. /// Helper structure that specifies what information to display for nodes.

View File

@ -83,7 +83,7 @@ pub trait ExtensionsSystem: BasicSystem {
#[allow(clippy::type_complexity)] #[allow(clippy::type_complexity)]
fn run_separated_limit( fn run_separated_limit(
&self, &self,
limit: usize limit: usize,
) -> Result<Vec<(Self::Set, Self::Set, Self::Set)>, String>; ) -> Result<Vec<(Self::Set, Self::Set, Self::Set)>, String>;
fn traces(self, n: usize) -> Result<Vec<Trace<Self::Label, Self>>, String>; fn traces(self, n: usize) -> Result<Vec<Trace<Self::Label, Self>>, String>;
@ -177,7 +177,9 @@ impl<T: BasicSystem> ExtensionsSystem for T {
} }
let mut n = 1; let mut n = 1;
let mut current = current.unwrap().1; let mut current = current.unwrap().1;
while let Some((_, next)) = current.one_transition()? && n < limit { while let Some((_, next)) = current.one_transition()?
&& n < limit
{
current = next; current = next;
n += 1; n += 1;
} }
@ -208,7 +210,7 @@ impl<T: BasicSystem> ExtensionsSystem for T {
/// see smartOneRunECT, smartRunECT /// see smartOneRunECT, smartRunECT
fn run_separated_limit( fn run_separated_limit(
&self, &self,
limit: usize limit: usize,
) -> Result<Vec<(Self::Set, Self::Set, Self::Set)>, String> { ) -> Result<Vec<(Self::Set, Self::Set, Self::Set)>, String> {
let mut limit = limit; let mut limit = limit;
let mut res = vec![]; let mut res = vec![];
@ -220,7 +222,9 @@ impl<T: BasicSystem> ExtensionsSystem for T {
let (available_entities, context, t) = current.0.get_context(); let (available_entities, context, t) = current.0.get_context();
res.push((available_entities.clone(), context.clone(), t.clone())); res.push((available_entities.clone(), context.clone(), t.clone()));
let mut current = current.1; let mut current = current.1;
while let Some((label, next)) = current.one_transition()? && limit > 1 { while let Some((label, next)) = current.one_transition()?
&& limit > 1
{
limit -= 1; limit -= 1;
current = next; current = next;
let (available_entities, context, t) = label.get_context(); let (available_entities, context, t) = label.get_context();