Skip to main content

datalog_structural_model/
feature.rs

1//! Exact built-in operation identities used by capability declarations.
2use crate::{BindExpr, BuiltinFilter};
3/// An operation represented by [`BindExpr`], independent of evaluator support.
4#[derive(
5    Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize,
6)]
7pub enum BindingKind {
8    /// The `Term` operation.
9    Term,
10    /// The `Add` operation.
11    Add,
12    /// The `Sub` operation.
13    Sub,
14    /// The `Mul` operation.
15    Mul,
16    /// The `Div` operation.
17    Div,
18    /// The `Neg` operation.
19    Neg,
20    /// The `Abs` operation.
21    Abs,
22    /// The `Ceil` operation.
23    Ceil,
24    /// The `Floor` operation.
25    Floor,
26    /// The `Round` operation.
27    Round,
28    /// The `Str` operation.
29    Str,
30    /// The `StrLen` operation.
31    StrLen,
32    /// The `UCase` operation.
33    UCase,
34    /// The `LCase` operation.
35    LCase,
36    /// The `Concat` operation.
37    Concat,
38    /// The `SubStr` operation.
39    SubStr,
40    /// The `StrBefore` operation.
41    StrBefore,
42    /// The `StrAfter` operation.
43    StrAfter,
44    /// The `Replace` operation.
45    Replace,
46    /// The `EncodeForUri` operation.
47    EncodeForUri,
48    /// The `Md5` operation.
49    Md5,
50    /// The `Sha1` operation.
51    Sha1,
52    /// The `Sha256` operation.
53    Sha256,
54    /// The `Sha384` operation.
55    Sha384,
56    /// The `Sha512` operation.
57    Sha512,
58    /// The `CastInteger` operation.
59    CastInteger,
60    /// The `CastDecimal` operation.
61    CastDecimal,
62    /// The `CastDouble` operation.
63    CastDouble,
64    /// The `CastFloat` operation.
65    CastFloat,
66    /// The `CastString` operation.
67    CastString,
68    /// The `Year` operation.
69    Year,
70    /// The `Month` operation.
71    Month,
72    /// The `Day` operation.
73    Day,
74    /// The `Hours` operation.
75    Hours,
76    /// The `Minutes` operation.
77    Minutes,
78    /// The `Seconds` operation.
79    Seconds,
80    /// The `Timezone` operation.
81    Timezone,
82    /// The `Tz` operation.
83    Tz,
84    /// The `Now` operation.
85    Now,
86    /// The `Lang` operation.
87    Lang,
88    /// The `Iri` operation.
89    Iri,
90    /// The `BNode` operation.
91    BNode,
92}
93impl BindingKind {
94    /// Every operation in this model revision.
95    pub const ALL: &'static [Self] = &[
96        Self::Term,
97        Self::Add,
98        Self::Sub,
99        Self::Mul,
100        Self::Div,
101        Self::Neg,
102        Self::Abs,
103        Self::Ceil,
104        Self::Floor,
105        Self::Round,
106        Self::Str,
107        Self::StrLen,
108        Self::UCase,
109        Self::LCase,
110        Self::Concat,
111        Self::SubStr,
112        Self::StrBefore,
113        Self::StrAfter,
114        Self::Replace,
115        Self::EncodeForUri,
116        Self::Md5,
117        Self::Sha1,
118        Self::Sha256,
119        Self::Sha384,
120        Self::Sha512,
121        Self::CastInteger,
122        Self::CastDecimal,
123        Self::CastDouble,
124        Self::CastFloat,
125        Self::CastString,
126        Self::Year,
127        Self::Month,
128        Self::Day,
129        Self::Hours,
130        Self::Minutes,
131        Self::Seconds,
132        Self::Timezone,
133        Self::Tz,
134        Self::Now,
135        Self::Lang,
136        Self::Iri,
137        Self::BNode,
138    ];
139}
140impl BindExpr {
141    /// Return this expression’s operation identity.
142    #[must_use]
143    pub fn kind(&self) -> BindingKind {
144        match self {
145            Self::Term(..) => BindingKind::Term,
146            Self::Add(..) => BindingKind::Add,
147            Self::Sub(..) => BindingKind::Sub,
148            Self::Mul(..) => BindingKind::Mul,
149            Self::Div(..) => BindingKind::Div,
150            Self::Neg(..) => BindingKind::Neg,
151            Self::Abs(..) => BindingKind::Abs,
152            Self::Ceil(..) => BindingKind::Ceil,
153            Self::Floor(..) => BindingKind::Floor,
154            Self::Round(..) => BindingKind::Round,
155            Self::Str(..) => BindingKind::Str,
156            Self::StrLen(..) => BindingKind::StrLen,
157            Self::UCase(..) => BindingKind::UCase,
158            Self::LCase(..) => BindingKind::LCase,
159            Self::Concat(..) => BindingKind::Concat,
160            Self::SubStr { .. } => BindingKind::SubStr,
161            Self::StrBefore(..) => BindingKind::StrBefore,
162            Self::StrAfter(..) => BindingKind::StrAfter,
163            Self::Replace { .. } => BindingKind::Replace,
164            Self::EncodeForUri(..) => BindingKind::EncodeForUri,
165            Self::Md5(..) => BindingKind::Md5,
166            Self::Sha1(..) => BindingKind::Sha1,
167            Self::Sha256(..) => BindingKind::Sha256,
168            Self::Sha384(..) => BindingKind::Sha384,
169            Self::Sha512(..) => BindingKind::Sha512,
170            Self::CastInteger(..) => BindingKind::CastInteger,
171            Self::CastDecimal(..) => BindingKind::CastDecimal,
172            Self::CastDouble(..) => BindingKind::CastDouble,
173            Self::CastFloat(..) => BindingKind::CastFloat,
174            Self::CastString(..) => BindingKind::CastString,
175            Self::Year(..) => BindingKind::Year,
176            Self::Month(..) => BindingKind::Month,
177            Self::Day(..) => BindingKind::Day,
178            Self::Hours(..) => BindingKind::Hours,
179            Self::Minutes(..) => BindingKind::Minutes,
180            Self::Seconds(..) => BindingKind::Seconds,
181            Self::Timezone(..) => BindingKind::Timezone,
182            Self::Tz(..) => BindingKind::Tz,
183            Self::Now => BindingKind::Now,
184            Self::Lang(..) => BindingKind::Lang,
185            Self::Iri(..) => BindingKind::Iri,
186            Self::BNode(..) => BindingKind::BNode,
187        }
188    }
189}
190/// An operation represented by [`BuiltinFilter`], independent of evaluator support.
191#[derive(
192    Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize,
193)]
194pub enum FilterKind {
195    /// The `Eq` operation.
196    Eq,
197    /// The `Ne` operation.
198    Ne,
199    /// The `Lt` operation.
200    Lt,
201    /// The `Le` operation.
202    Le,
203    /// The `Gt` operation.
204    Gt,
205    /// The `Ge` operation.
206    Ge,
207    /// The `StrStarts` operation.
208    StrStarts,
209    /// The `StrEnds` operation.
210    StrEnds,
211    /// The `Contains` operation.
212    Contains,
213    /// The `RegexMatch` operation.
214    RegexMatch,
215    /// The `IsIri` operation.
216    IsIri,
217    /// The `IsLiteral` operation.
218    IsLiteral,
219    /// The `IsBlank` operation.
220    IsBlank,
221    /// The `IsNumeric` operation.
222    IsNumeric,
223    /// The `LangMatches` operation.
224    LangMatches,
225    /// The `And` operation.
226    And,
227    /// The `Or` operation.
228    Or,
229    /// The `Not` operation.
230    Not,
231}
232impl FilterKind {
233    /// Every operation in this model revision.
234    pub const ALL: &'static [Self] = &[
235        Self::Eq,
236        Self::Ne,
237        Self::Lt,
238        Self::Le,
239        Self::Gt,
240        Self::Ge,
241        Self::StrStarts,
242        Self::StrEnds,
243        Self::Contains,
244        Self::RegexMatch,
245        Self::IsIri,
246        Self::IsLiteral,
247        Self::IsBlank,
248        Self::IsNumeric,
249        Self::LangMatches,
250        Self::And,
251        Self::Or,
252        Self::Not,
253    ];
254}
255impl BuiltinFilter {
256    /// Return this expression’s operation identity.
257    #[must_use]
258    pub fn kind(&self) -> FilterKind {
259        match self {
260            Self::Eq(..) => FilterKind::Eq,
261            Self::Ne(..) => FilterKind::Ne,
262            Self::Lt(..) => FilterKind::Lt,
263            Self::Le(..) => FilterKind::Le,
264            Self::Gt(..) => FilterKind::Gt,
265            Self::Ge(..) => FilterKind::Ge,
266            Self::StrStarts(..) => FilterKind::StrStarts,
267            Self::StrEnds(..) => FilterKind::StrEnds,
268            Self::Contains(..) => FilterKind::Contains,
269            Self::RegexMatch { .. } => FilterKind::RegexMatch,
270            Self::IsIri(..) => FilterKind::IsIri,
271            Self::IsLiteral(..) => FilterKind::IsLiteral,
272            Self::IsBlank(..) => FilterKind::IsBlank,
273            Self::IsNumeric(..) => FilterKind::IsNumeric,
274            Self::LangMatches(..) => FilterKind::LangMatches,
275            Self::And(..) => FilterKind::And,
276            Self::Or(..) => FilterKind::Or,
277            Self::Not(..) => FilterKind::Not,
278        }
279    }
280}