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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
//! SHACL Core constraint components.
use std::fmt;
use iri_rfc3987::Iri;
use crate::{CustomConstraint, ExpressionConstraint, NodeKind, ShaclPath, SparqlConstraint};
/// The default value type used by [`Component`].
pub type DefaultValue = crate::DefaultTerm;
/// A Core, SPARQL, or AF constraint declaration applied to a shape.
///
/// Integer count and length parameters use `Count`, which defaults to the
/// caller's RDF value type. Consumers may instead supply a compiled comparison
/// type without imposing a machine-integer limit on the structural model.
/// Regex flags and patterns use independent `Flags` and `Pattern` types,
/// also defaulting to `Value`. Consumers may retain an RDF reference beside
/// a compiled representation without requiring an owned lexical string.
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
#[serde(
deny_unknown_fields,
bound(
serialize = "Value: serde::Serialize, Count: serde::Serialize, Flags: serde::Serialize, Pattern: serde::Serialize, Named: serde::Serialize",
deserialize = "Value: serde::Deserialize<'de>, Count: serde::Deserialize<'de>, Flags: serde::Deserialize<'de>, Pattern: serde::Deserialize<'de>, Named: serde::Deserialize<'de>"
)
)]
pub enum Component<
Value = DefaultValue,
Count = Value,
Flags = Value,
Pattern = Value,
Named = Iri<String>,
> {
/// `sh:class` — the value must be an instance of the class.
Class(Named),
/// `sh:datatype` — the value must have the given datatype.
Datatype(Named),
/// `sh:nodeKind` — the value must have the given RDF node kind.
NodeKind(NodeKind),
/// `sh:minCount`.
MinCount(Count),
/// `sh:maxCount`.
MaxCount(Count),
/// `sh:minExclusive`.
MinExclusive(Value),
/// `sh:minInclusive`.
MinInclusive(Value),
/// `sh:maxExclusive`.
MaxExclusive(Value),
/// `sh:maxInclusive`.
MaxInclusive(Value),
/// `sh:minLength`.
MinLength(Count),
/// `sh:maxLength`.
MaxLength(Count),
/// `sh:pattern` with optional `sh:flags`.
Pattern {
/// Original RDF pattern value, or a caller-defined compiled representation.
pattern: Pattern,
/// Original RDF flags value, or a caller-defined compiled representation.
flags: Option<Flags>,
},
/// `sh:languageIn`.
LanguageIn(Vec<String>),
/// `sh:uniqueLang`.
UniqueLang(bool),
/// `sh:equals`.
Equals(ShaclPath<Named>),
/// `sh:disjoint`.
Disjoint(ShaclPath<Named>),
/// `sh:lessThan`.
LessThan(ShaclPath<Named>),
/// `sh:lessThanOrEquals`.
LessThanOrEquals(ShaclPath<Named>),
/// `sh:and`.
And(Vec<Value>),
/// `sh:or`.
Or(Vec<Value>),
/// `sh:not`.
Not(Value),
/// `sh:xone`.
Xone(Vec<Value>),
/// `sh:node`.
Node(Value),
/// `sh:qualifiedValueShape` with optional min/max counts.
QualifiedValueShape {
/// The shape to count conforming values against.
shape: Value,
/// Minimum number of conforming values.
min_count: Option<Count>,
/// Maximum number of conforming values.
max_count: Option<Count>,
/// Whether sibling qualified shapes use disjoint value sets.
disjoint: bool,
},
/// `sh:hasValue`.
HasValue(Value),
/// `sh:in`.
In(Vec<Value>),
/// `sh:closed` with `sh:ignoredProperties`.
Closed {
/// Whether the shape is closed.
is_closed: bool,
/// Properties exempt from the closure check.
ignored_properties: Vec<Named>,
},
/// A `sh:sparql` constraint declaration.
Sparql(Box<SparqlConstraint<Value>>),
/// A `sh:expression` constraint declaration.
Expression(Box<ExpressionConstraint<Value, Named>>),
/// A use of a separately declared custom component.
Custom(CustomConstraint<Value, Named>),
/// `sh:singleLine` from the SHACL 1.2 Core 2026-10-14 Working Draft.
///
/// When true, literal values must not contain U+000A through U+000D.
/// False explicitly permits multiline values. This declaration is at risk
/// in the draft; representing it does not implement constraint evaluation.
SingleLine(bool),
/// `sh:memberShape` from the SHACL 1.2 Core 2026-10-14 Working Draft.
///
/// Each value must be a well-formed SHACL list whose members conform to
/// this caller-owned shape reference. The consumer checks and evaluates it.
MemberShape(Value),
/// Draft `sh:minListLength`, using the independent caller-owned count type.
///
/// The consumer checks the non-negative integer parameter and list structure.
MinListLength(Count),
/// Draft `sh:maxListLength`, using the independent caller-owned count type.
///
/// The consumer checks the non-negative integer parameter and list structure.
MaxListLength(Count),
/// Draft `sh:uniqueMembers` — require distinct members when true.
///
/// Both true and false require a well-formed SHACL list. False relaxes only
/// the uniqueness check, not list well-formedness. Evaluation is consumer-owned.
UniqueMembers(bool),
}
impl<Value, Count, Flags, Pattern, Named> Component<Value, Count, Flags, Pattern, Named> {
/// Return the SHACL constraint kind name.
#[must_use]
pub const fn kind_name(&self) -> &'static str {
match self {
Self::Class(_) => "class",
Self::Datatype(_) => "datatype",
Self::NodeKind(_) => "nodeKind",
Self::MinCount(_) => "minCount",
Self::MaxCount(_) => "maxCount",
Self::MinExclusive(_) => "minExclusive",
Self::MinInclusive(_) => "minInclusive",
Self::MaxExclusive(_) => "maxExclusive",
Self::MaxInclusive(_) => "maxInclusive",
Self::MinLength(_) => "minLength",
Self::MaxLength(_) => "maxLength",
Self::Pattern { .. } => "pattern",
Self::LanguageIn(_) => "languageIn",
Self::UniqueLang(_) => "uniqueLang",
Self::Equals(_) => "equals",
Self::Disjoint(_) => "disjoint",
Self::LessThan(_) => "lessThan",
Self::LessThanOrEquals(_) => "lessThanOrEquals",
Self::And(_) => "and",
Self::Or(_) => "or",
Self::Not(_) => "not",
Self::Xone(_) => "xone",
Self::Node(_) => "node",
Self::QualifiedValueShape { .. } => "qualifiedValueShape",
Self::HasValue(_) => "hasValue",
Self::In(_) => "in",
Self::Closed { .. } => "closed",
Self::Sparql(_) => "sparql",
Self::Expression(_) => "expression",
Self::Custom(_) => "custom",
Self::SingleLine(_) => "singleLine",
Self::MemberShape(_) => "memberShape",
Self::MinListLength(_) => "minListLength",
Self::MaxListLength(_) => "maxListLength",
Self::UniqueMembers(_) => "uniqueMembers",
}
}
}
impl<
Value: fmt::Debug,
Count: fmt::Debug,
Flags: fmt::Debug,
Pattern: fmt::Debug,
Named: AsRef<str>,
> Component<Value, Count, Flags, Pattern, Named>
{
/// Return a human-readable display value for this component.
#[must_use]
pub fn display_value(&self) -> String {
match self {
Self::Class(iri) | Self::Datatype(iri) => crate::local_name(iri),
Self::NodeKind(kind) => format!("{kind:?}"),
Self::MinCount(count)
| Self::MaxCount(count)
| Self::MinLength(count)
| Self::MaxLength(count)
| Self::MinListLength(count)
| Self::MaxListLength(count) => format!("{count:?}"),
Self::MinExclusive(value)
| Self::MinInclusive(value)
| Self::MaxExclusive(value)
| Self::MaxInclusive(value)
| Self::HasValue(value)
| Self::Not(value)
| Self::Node(value)
| Self::MemberShape(value) => format!("{value:?}"),
Self::Pattern { pattern, flags } => match flags {
Some(flags) => format!("/{pattern:?}/{flags:?}"),
None => format!("/{pattern:?}/"),
},
Self::LanguageIn(languages) => languages.join(", "),
Self::UniqueLang(value) | Self::SingleLine(value) | Self::UniqueMembers(value) => {
value.to_string()
}
Self::Equals(path)
| Self::Disjoint(path)
| Self::LessThan(path)
| Self::LessThanOrEquals(path) => path.to_string(),
Self::And(iris) | Self::Or(iris) | Self::Xone(iris) => iris
.iter()
.map(|value| format!("{value:?}"))
.collect::<Vec<_>>()
.join(", "),
Self::QualifiedValueShape {
shape,
min_count,
max_count,
..
} => {
let mut parts = vec![format!("{shape:?}")];
if let Some(min) = min_count {
parts.push(format!("min={min:?}"));
}
if let Some(max) = max_count {
parts.push(format!("max={max:?}"));
}
parts.join(", ")
}
Self::In(values) => values
.iter()
.map(|value| format!("{value:?}"))
.collect::<Vec<_>>()
.join(", "),
Self::Closed {
is_closed,
ignored_properties,
} => {
if *is_closed {
if ignored_properties.is_empty() {
"true".to_owned()
} else {
let ignored = ignored_properties
.iter()
.map(crate::local_name)
.collect::<Vec<_>>();
format!("true (ignore: {})", ignored.join(", "))
}
} else {
"false".to_owned()
}
}
Self::Sparql(constraint) => format!("{:?}", constraint.select.text),
Self::Expression(constraint) => format!("{:?}", constraint.expression.node),
Self::Custom(constraint) => crate::local_name(&constraint.component),
}
}
}