cargo fmt, additional operations for dsl on context
This commit is contained in:
@ -110,6 +110,27 @@ pub enum QualifierSystem {
|
||||
Context,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Serialize, Deserialize, Hash)]
|
||||
pub enum QualifierContext {
|
||||
IsNill,
|
||||
IsIdentifier,
|
||||
IsSet,
|
||||
IsGuarded,
|
||||
IsRepeated,
|
||||
IsSummation,
|
||||
IsNondeterministicChoice,
|
||||
|
||||
GetIdentifier,
|
||||
GetSet,
|
||||
GetGuardReactants,
|
||||
GetGuardInhibitors,
|
||||
GetGuardProducts,
|
||||
GetRepeatedCounter,
|
||||
GetRepeatedProcess,
|
||||
|
||||
GetNextProcesses,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Serialize, Deserialize, Hash)]
|
||||
pub enum QualifierEdge {
|
||||
Source,
|
||||
@ -126,6 +147,7 @@ pub enum QualifierNode {
|
||||
#[derive(Clone, Copy, Serialize, Deserialize, Hash)]
|
||||
pub enum Qualifier {
|
||||
System(QualifierSystem),
|
||||
Context(QualifierContext),
|
||||
Label(QualifierLabel),
|
||||
Restricted(QualifierRestricted),
|
||||
Edge(QualifierEdge),
|
||||
@ -171,6 +193,7 @@ pub(super) enum AssertionTypes {
|
||||
RangeInteger,
|
||||
RangeSet,
|
||||
RangeNeighbours,
|
||||
RangeContexts,
|
||||
|
||||
Node,
|
||||
Edge,
|
||||
@ -189,6 +212,7 @@ pub enum AssertReturnValue {
|
||||
Neighbours(petgraph::graph::NodeIndex),
|
||||
System(system::System),
|
||||
Context(process::Process),
|
||||
RangeContext(process::Process),
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@ -264,6 +288,123 @@ impl QualifierSystem {
|
||||
}
|
||||
}
|
||||
|
||||
impl QualifierContext {
|
||||
pub(super) fn get(&self, l: &process::Process) -> AssertReturnValue {
|
||||
use process::Process::*;
|
||||
match self {
|
||||
| Self::IsNill => AssertReturnValue::Boolean(matches!(l, Nill)),
|
||||
| Self::IsIdentifier =>
|
||||
AssertReturnValue::Boolean(matches!(l, RecursiveIdentifier {
|
||||
identifier: _,
|
||||
})),
|
||||
| Self::IsSet =>
|
||||
AssertReturnValue::Boolean(matches!(l, EntitySet {
|
||||
entities: _,
|
||||
next_process: _,
|
||||
})),
|
||||
| Self::IsGuarded =>
|
||||
AssertReturnValue::Boolean(matches!(l, Guarded {
|
||||
reaction: _,
|
||||
next_process: _,
|
||||
})),
|
||||
| Self::IsRepeated =>
|
||||
AssertReturnValue::Boolean(matches!(l, WaitEntity {
|
||||
repeat: _,
|
||||
repeated_process: _,
|
||||
next_process: _,
|
||||
})),
|
||||
| Self::IsSummation =>
|
||||
AssertReturnValue::Boolean(matches!(l, Summation {
|
||||
children: _,
|
||||
})),
|
||||
| Self::IsNondeterministicChoice => AssertReturnValue::Boolean(
|
||||
matches!(l, NondeterministicChoice { children: _ }),
|
||||
),
|
||||
|
||||
| Self::GetIdentifier => AssertReturnValue::Element(
|
||||
if let RecursiveIdentifier { identifier } = l {
|
||||
*identifier
|
||||
} else {
|
||||
0
|
||||
},
|
||||
),
|
||||
| Self::GetSet => AssertReturnValue::Set(
|
||||
if let EntitySet {
|
||||
entities,
|
||||
next_process: _,
|
||||
} = l
|
||||
{
|
||||
entities.clone()
|
||||
} else {
|
||||
Default::default()
|
||||
},
|
||||
),
|
||||
| Self::GetGuardReactants => AssertReturnValue::Set(
|
||||
if let Guarded {
|
||||
reaction,
|
||||
next_process: _,
|
||||
} = l
|
||||
{
|
||||
reaction.reactants.clone()
|
||||
} else {
|
||||
Default::default()
|
||||
},
|
||||
),
|
||||
| Self::GetGuardInhibitors => AssertReturnValue::Set(
|
||||
if let Guarded {
|
||||
reaction,
|
||||
next_process: _,
|
||||
} = l
|
||||
{
|
||||
reaction.inhibitors.clone()
|
||||
} else {
|
||||
Default::default()
|
||||
},
|
||||
),
|
||||
| Self::GetGuardProducts => AssertReturnValue::Set(
|
||||
if let Guarded {
|
||||
reaction,
|
||||
next_process: _,
|
||||
} = l
|
||||
{
|
||||
reaction.products.clone()
|
||||
} else {
|
||||
Default::default()
|
||||
},
|
||||
),
|
||||
| Self::GetRepeatedCounter => AssertReturnValue::Integer(
|
||||
if let WaitEntity {
|
||||
repeat,
|
||||
repeated_process: _,
|
||||
next_process: _,
|
||||
} = l
|
||||
{
|
||||
*repeat
|
||||
} else {
|
||||
0
|
||||
},
|
||||
),
|
||||
| Self::GetRepeatedProcess => {
|
||||
AssertReturnValue::Context(
|
||||
if let WaitEntity {
|
||||
repeat: _,
|
||||
repeated_process,
|
||||
next_process: _,
|
||||
} = l
|
||||
{
|
||||
(**repeated_process).clone()
|
||||
} else {
|
||||
Default::default() // nill
|
||||
},
|
||||
)
|
||||
},
|
||||
|
||||
| Self::GetNextProcesses =>
|
||||
AssertReturnValue::RangeContext(l.clone()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Unary {
|
||||
pub(super) fn is_prefix(&self) -> bool {
|
||||
match self {
|
||||
@ -305,12 +446,18 @@ impl Unary {
|
||||
) => Ok(AssertionTypes::Set),
|
||||
| (Self::ToEl, AssertionTypes::String) =>
|
||||
Ok(AssertionTypes::Element),
|
||||
| (Self::Qualifier(Qualifier::Edge(QualifierEdge::Source)), AssertionTypes::Edge) =>
|
||||
Ok(AssertionTypes::Node),
|
||||
| (Self::Qualifier(Qualifier::Edge(QualifierEdge::Target)), AssertionTypes::Edge) =>
|
||||
Ok(AssertionTypes::Node),
|
||||
| (Self::Qualifier(Qualifier::Edge(QualifierEdge::Label)), AssertionTypes::Edge) =>
|
||||
Ok(AssertionTypes::Label),
|
||||
| (
|
||||
Self::Qualifier(Qualifier::Edge(QualifierEdge::Source)),
|
||||
AssertionTypes::Edge,
|
||||
) => Ok(AssertionTypes::Node),
|
||||
| (
|
||||
Self::Qualifier(Qualifier::Edge(QualifierEdge::Target)),
|
||||
AssertionTypes::Edge,
|
||||
) => Ok(AssertionTypes::Node),
|
||||
| (
|
||||
Self::Qualifier(Qualifier::Edge(QualifierEdge::Label)),
|
||||
AssertionTypes::Edge,
|
||||
) => Ok(AssertionTypes::Label),
|
||||
| (
|
||||
Self::Qualifier(Qualifier::Node(QualifierNode::Neighbours)),
|
||||
AssertionTypes::Node,
|
||||
@ -340,6 +487,90 @@ impl Unary {
|
||||
Self::Qualifier(Qualifier::System(QualifierSystem::Context)),
|
||||
AssertionTypes::System,
|
||||
) => Ok(AssertionTypes::Context),
|
||||
| (
|
||||
Self::Qualifier(Qualifier::Context(QualifierContext::IsNill)),
|
||||
AssertionTypes::Context,
|
||||
) => Ok(AssertionTypes::Boolean),
|
||||
| (
|
||||
Self::Qualifier(Qualifier::Context(
|
||||
QualifierContext::IsIdentifier,
|
||||
)),
|
||||
AssertionTypes::Context,
|
||||
) => Ok(AssertionTypes::Boolean),
|
||||
| (
|
||||
Self::Qualifier(Qualifier::Context(QualifierContext::IsSet)),
|
||||
AssertionTypes::Context,
|
||||
) => Ok(AssertionTypes::Boolean),
|
||||
| (
|
||||
Self::Qualifier(Qualifier::Context(
|
||||
QualifierContext::IsGuarded,
|
||||
)),
|
||||
AssertionTypes::Context,
|
||||
) => Ok(AssertionTypes::Boolean),
|
||||
| (
|
||||
Self::Qualifier(Qualifier::Context(
|
||||
QualifierContext::IsRepeated,
|
||||
)),
|
||||
AssertionTypes::Context,
|
||||
) => Ok(AssertionTypes::Boolean),
|
||||
| (
|
||||
Self::Qualifier(Qualifier::Context(
|
||||
QualifierContext::IsSummation,
|
||||
)),
|
||||
AssertionTypes::Context,
|
||||
) => Ok(AssertionTypes::Boolean),
|
||||
| (
|
||||
Self::Qualifier(Qualifier::Context(
|
||||
QualifierContext::IsNondeterministicChoice,
|
||||
)),
|
||||
AssertionTypes::Context,
|
||||
) => Ok(AssertionTypes::Boolean),
|
||||
| (
|
||||
Self::Qualifier(Qualifier::Context(
|
||||
QualifierContext::GetIdentifier,
|
||||
)),
|
||||
AssertionTypes::Context,
|
||||
) => Ok(AssertionTypes::Element),
|
||||
| (
|
||||
Self::Qualifier(Qualifier::Context(QualifierContext::GetSet)),
|
||||
AssertionTypes::Context,
|
||||
) => Ok(AssertionTypes::Set),
|
||||
| (
|
||||
Self::Qualifier(Qualifier::Context(
|
||||
QualifierContext::GetGuardReactants,
|
||||
)),
|
||||
AssertionTypes::Context,
|
||||
) => Ok(AssertionTypes::Set),
|
||||
| (
|
||||
Self::Qualifier(Qualifier::Context(
|
||||
QualifierContext::GetGuardInhibitors,
|
||||
)),
|
||||
AssertionTypes::Context,
|
||||
) => Ok(AssertionTypes::Set),
|
||||
| (
|
||||
Self::Qualifier(Qualifier::Context(
|
||||
QualifierContext::GetGuardProducts,
|
||||
)),
|
||||
AssertionTypes::Context,
|
||||
) => Ok(AssertionTypes::Set),
|
||||
| (
|
||||
Self::Qualifier(Qualifier::Context(
|
||||
QualifierContext::GetRepeatedCounter,
|
||||
)),
|
||||
AssertionTypes::Context,
|
||||
) => Ok(AssertionTypes::Integer),
|
||||
| (
|
||||
Self::Qualifier(Qualifier::Context(
|
||||
QualifierContext::GetRepeatedProcess,
|
||||
)),
|
||||
AssertionTypes::Context,
|
||||
) => Ok(AssertionTypes::Context),
|
||||
| (
|
||||
Self::Qualifier(Qualifier::Context(
|
||||
QualifierContext::GetNextProcesses,
|
||||
)),
|
||||
AssertionTypes::Context,
|
||||
) => Ok(AssertionTypes::RangeContexts),
|
||||
| (
|
||||
Self::Qualifier(Qualifier::Node(QualifierNode::System)),
|
||||
AssertionTypes::Node,
|
||||
@ -680,6 +911,10 @@ impl TypeContext {
|
||||
self.data.insert(v.clone(), AssertionTypes::Edge);
|
||||
Ok(())
|
||||
},
|
||||
| AssertionTypes::RangeContexts => {
|
||||
self.data.insert(v.clone(), AssertionTypes::Context);
|
||||
Ok(())
|
||||
},
|
||||
| _ => Err(format!("Range has incorrect type {ty:?}.")),
|
||||
}
|
||||
}
|
||||
@ -847,9 +1082,7 @@ impl AssertReturnValue {
|
||||
| (
|
||||
AssertReturnValue::Edge(edge),
|
||||
Unary::Qualifier(Qualifier::Edge(QualifierEdge::Label)),
|
||||
) => Ok(AssertReturnValue::Label(
|
||||
graph[edge].clone()
|
||||
)),
|
||||
) => Ok(AssertReturnValue::Label(graph[edge].clone())),
|
||||
| (
|
||||
AssertReturnValue::Node(node),
|
||||
Unary::Qualifier(Qualifier::Node(QualifierNode::Neighbours)),
|
||||
@ -864,6 +1097,10 @@ impl AssertReturnValue {
|
||||
AssertReturnValue::System(sys),
|
||||
Unary::Qualifier(Qualifier::System(q)),
|
||||
) => Ok(q.get(&sys)),
|
||||
| (
|
||||
AssertReturnValue::Context(c),
|
||||
Unary::Qualifier(Qualifier::Context(q)),
|
||||
) => Ok(q.get(&c)),
|
||||
| (val, u) => Err(format!(
|
||||
"Incompatible unary operation {u:?} on value \
|
||||
{val:?}."
|
||||
@ -1086,6 +1323,8 @@ where
|
||||
| AssertionTypes::Set => Ok(AssertionTypes::RangeSet),
|
||||
| AssertionTypes::RangeNeighbours =>
|
||||
Ok(AssertionTypes::RangeNeighbours),
|
||||
| AssertionTypes::RangeContexts =>
|
||||
Ok(AssertionTypes::RangeContexts),
|
||||
| _ => Err(format!(
|
||||
"Expressions in range is not a set or \
|
||||
neighbours of a node, but is: {type_exp:?}."
|
||||
@ -1175,6 +1414,46 @@ where
|
||||
.map(|x| AssertReturnValue::Edge(x.id()))
|
||||
.collect::<Vec<_>>()
|
||||
.into_iter()),
|
||||
| AssertReturnValue::RangeContext(ctxs) => {
|
||||
use process::Process::*;
|
||||
Ok(match ctxs {
|
||||
| Nill => vec![].into_iter(),
|
||||
| RecursiveIdentifier { identifier: _ } =>
|
||||
vec![].into_iter(),
|
||||
| EntitySet {
|
||||
entities: _,
|
||||
next_process,
|
||||
} => vec![AssertReturnValue::Context(
|
||||
(*next_process).clone(),
|
||||
)]
|
||||
.into_iter(),
|
||||
| Guarded {
|
||||
reaction: _,
|
||||
next_process,
|
||||
} => vec![AssertReturnValue::Context(
|
||||
(*next_process).clone(),
|
||||
)]
|
||||
.into_iter(),
|
||||
| WaitEntity {
|
||||
repeat: _,
|
||||
repeated_process,
|
||||
next_process: _,
|
||||
} => vec![AssertReturnValue::Context(
|
||||
(*repeated_process).clone(),
|
||||
)]
|
||||
.into_iter(),
|
||||
| Summation { children } => children
|
||||
.iter()
|
||||
.map(|c| AssertReturnValue::Context((**c).clone()))
|
||||
.collect::<Vec<_>>()
|
||||
.into_iter(),
|
||||
| NondeterministicChoice { children } => children
|
||||
.iter()
|
||||
.map(|c| AssertReturnValue::Context((**c).clone()))
|
||||
.collect::<Vec<_>>()
|
||||
.into_iter(),
|
||||
})
|
||||
},
|
||||
| _ => Err(format!("{val:?} is not a set in for cycle.")),
|
||||
}
|
||||
},
|
||||
|
||||
@ -176,6 +176,31 @@ impl fmt::Debug for QualifierSystem {
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for QualifierContext {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
| Self::IsNill => write!(f, "isNill"),
|
||||
| Self::IsIdentifier => write!(f, "isIdentifier"),
|
||||
| Self::IsSet => write!(f, "isSet"),
|
||||
| Self::IsGuarded => write!(f, "isGuarded"),
|
||||
| Self::IsRepeated => write!(f, "isRepeated"),
|
||||
| Self::IsSummation => write!(f, "isSummation"),
|
||||
| Self::IsNondeterministicChoice =>
|
||||
write!(f, "isNondeterministicChoice"),
|
||||
|
||||
| Self::GetIdentifier => write!(f, "getIdentifier"),
|
||||
| Self::GetSet => write!(f, "getSet"),
|
||||
| Self::GetGuardReactants => write!(f, "getGuardReactants"),
|
||||
| Self::GetGuardInhibitors => write!(f, "getInhibitors"),
|
||||
| Self::GetGuardProducts => write!(f, "getGuardProducts"),
|
||||
| Self::GetRepeatedCounter => write!(f, "getRepeatedCounter"),
|
||||
| Self::GetRepeatedProcess => write!(f, "getRepeatedProcess"),
|
||||
|
||||
| Self::GetNextProcesses => write!(f, "getNextProcesses"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for QualifierEdge {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
@ -201,6 +226,7 @@ impl fmt::Debug for Qualifier {
|
||||
| Self::Label(q) => write!(f, "{q:?}"),
|
||||
| Self::Restricted(q) => write!(f, "{q:?}"),
|
||||
| Self::System(q) => write!(f, "{q:?}"),
|
||||
| Self::Context(q) => write!(f, "{q:?}"),
|
||||
| Self::Edge(q) => write!(f, "{q:?}"),
|
||||
| Self::Node(q) => write!(f, "{q:?}"),
|
||||
}
|
||||
@ -250,6 +276,7 @@ impl fmt::Debug for AssertReturnValue {
|
||||
},
|
||||
| Self::System(sys) => write!(f, "{{debug: {sys:?}}}"),
|
||||
| Self::Context(ctx) => write!(f, "{{debug: {ctx:?}}}"),
|
||||
| Self::RangeContext(ctx) => write!(f, "{{debug: {ctx:?}}}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -269,6 +296,7 @@ impl fmt::Debug for AssertionTypes {
|
||||
| Self::RangeInteger => write!(f, "range of integers"),
|
||||
| Self::RangeSet => write!(f, "range of set"),
|
||||
| Self::RangeNeighbours => write!(f, "range of edges"),
|
||||
| Self::RangeContexts => write!(f, "range of contexts"),
|
||||
| Self::Edge => write!(f, "edge"),
|
||||
| Self::Node => write!(f, "node"),
|
||||
}
|
||||
@ -523,6 +551,16 @@ impl PrintableWithTranslator for QualifierSystem {
|
||||
}
|
||||
}
|
||||
|
||||
impl PrintableWithTranslator for QualifierContext {
|
||||
fn print(
|
||||
&self,
|
||||
f: &mut fmt::Formatter,
|
||||
_translator: &Translator,
|
||||
) -> fmt::Result {
|
||||
write!(f, "{self:?}")
|
||||
}
|
||||
}
|
||||
|
||||
impl PrintableWithTranslator for QualifierEdge {
|
||||
fn print(
|
||||
&self,
|
||||
@ -557,6 +595,9 @@ impl PrintableWithTranslator for Qualifier {
|
||||
| Self::System(q) => {
|
||||
write!(f, "{}", Formatter::from(translator, q))
|
||||
},
|
||||
| Self::Context(q) => {
|
||||
write!(f, "{}", Formatter::from(translator, q))
|
||||
},
|
||||
| Self::Edge(q) => write!(f, "{}", Formatter::from(translator, q)),
|
||||
| Self::Node(q) => write!(f, "{}", Formatter::from(translator, q)),
|
||||
}
|
||||
@ -601,6 +642,13 @@ impl PrintableWithTranslator for AssertReturnValue {
|
||||
| Self::Context(ctx) => {
|
||||
write!(f, "{}", Formatter::from(translator, ctx))
|
||||
},
|
||||
| Self::RangeContext(ctx) => {
|
||||
write!(
|
||||
f,
|
||||
"{{next processes of: {}}}",
|
||||
Formatter::from(translator, ctx)
|
||||
)
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1013,9 +1013,7 @@ impl PositiveAssertReturnValue {
|
||||
PositiveUnary::Qualifier(PositiveQualifier::Edge(
|
||||
QualifierEdge::Label,
|
||||
)),
|
||||
) => Ok(PositiveAssertReturnValue::Label(
|
||||
graph[edge].clone(),
|
||||
)),
|
||||
) => Ok(PositiveAssertReturnValue::Label(graph[edge].clone())),
|
||||
| (
|
||||
PositiveAssertReturnValue::Node(node),
|
||||
PositiveUnary::Qualifier(PositiveQualifier::Node(
|
||||
|
||||
@ -145,7 +145,8 @@ impl dsl::Assert<EdgeRelablerInput> {
|
||||
.into()),
|
||||
| dsl::AssertionTypes::RangeInteger
|
||||
| dsl::AssertionTypes::RangeSet
|
||||
| dsl::AssertionTypes::RangeNeighbours =>
|
||||
| dsl::AssertionTypes::RangeNeighbours
|
||||
| dsl::AssertionTypes::RangeContexts =>
|
||||
Err(format!("Returned type {ty:?} is not a valid return type.")),
|
||||
}
|
||||
}
|
||||
@ -320,7 +321,8 @@ impl dsl::Assert<NodeRelablerInput> {
|
||||
.into()),
|
||||
| dsl::AssertionTypes::RangeInteger
|
||||
| dsl::AssertionTypes::RangeSet
|
||||
| dsl::AssertionTypes::RangeNeighbours =>
|
||||
| dsl::AssertionTypes::RangeNeighbours
|
||||
| dsl::AssertionTypes::RangeContexts =>
|
||||
Err(format!("Returned type {ty:?} is not a valid return type.")),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user