1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
use crate::model::constraints::{
BooleanSentence, ConstraintSentence, FunctionDef, PredicateValue, QuantifiedSentence,
SequenceOfPredicateValues, SimpleSentence,
};
use crate::model::identifiers::Identifier;
use crate::model::values::SimpleValue;
use crate::model::Span;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
// ------------------------------------------------------------------------------------------------
// Public Macros
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
// Public Types ❱ Formal Constraints ❱ Environments
// ------------------------------------------------------------------------------------------------
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
pub struct EnvironmentDef {
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
span: Option<Span>,
name: Identifier,
body: EnvironmentDefBody,
}
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
pub enum EnvironmentDefBody {
Function(FunctionDef),
Value(PredicateValue),
Sentence(ConstraintSentence),
}
// ------------------------------------------------------------------------------------------------
// Implementations ❱ Formal Constraints ❱ Environments
// ------------------------------------------------------------------------------------------------
impl_has_body_for!(EnvironmentDef, EnvironmentDefBody);
impl_has_name_for!(EnvironmentDef);
impl_has_source_span_for!(EnvironmentDef);
impl EnvironmentDef {
// --------------------------------------------------------------------------------------------
// Constructors
// --------------------------------------------------------------------------------------------
pub const fn new(name: Identifier, body: EnvironmentDefBody) -> Self {
Self {
span: None,
name,
body,
}
}
pub fn new_value<V>(name: Identifier, body: V) -> Self
where
V: Into<PredicateValue>,
{
Self {
span: None,
name,
body: EnvironmentDefBody::Value(body.into()),
}
}
pub fn new_function<V>(name: Identifier, body: V) -> Self
where
V: Into<FunctionDef>,
{
Self {
span: None,
name,
body: EnvironmentDefBody::Function(body.into()),
}
}
pub fn new_sentence<V>(name: Identifier, body: V) -> Self
where
V: Into<ConstraintSentence>,
{
Self {
span: None,
name,
body: EnvironmentDefBody::Sentence(body.into()),
}
}
}
// ------------------------------------------------------------------------------------------------
impl From<FunctionDef> for EnvironmentDefBody {
fn from(v: FunctionDef) -> Self {
Self::Function(v)
}
}
impl From<PredicateValue> for EnvironmentDefBody {
fn from(v: PredicateValue) -> Self {
Self::Value(v)
}
}
impl From<SimpleValue> for EnvironmentDefBody {
fn from(v: SimpleValue) -> Self {
Self::Value(v.into())
}
}
impl From<SequenceOfPredicateValues> for EnvironmentDefBody {
fn from(v: SequenceOfPredicateValues) -> Self {
Self::Value(v.into())
}
}
impl From<ConstraintSentence> for EnvironmentDefBody {
fn from(v: ConstraintSentence) -> Self {
Self::Sentence(v)
}
}
impl From<SimpleSentence> for EnvironmentDefBody {
fn from(v: SimpleSentence) -> Self {
Self::Sentence(v.into())
}
}
impl From<BooleanSentence> for EnvironmentDefBody {
fn from(v: BooleanSentence) -> Self {
Self::Sentence(v.into())
}
}
impl From<QuantifiedSentence> for EnvironmentDefBody {
fn from(v: QuantifiedSentence) -> Self {
Self::Sentence(v.into())
}
}
impl EnvironmentDefBody {
// --------------------------------------------------------------------------------------------
// Variants
// --------------------------------------------------------------------------------------------
is_as_variant!(Value (PredicateValue) => is_value, as_value);
is_as_variant!(Function (FunctionDef) => is_function, as_function);
is_as_variant!(Sentence (ConstraintSentence) => is_sentence, as_sentence);
}
// ------------------------------------------------------------------------------------------------
// Private Functions
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
// Modules
// ------------------------------------------------------------------------------------------------