21
21
*/
22
22
23
23
use crate :: {
24
- common:: token:: Predicate ,
24
+ common:: token,
25
25
pattern:: {
26
- Negation , RelationVariableBuilder , RolePlayerConstraint , RuleDeclaration , ThingVariable , TypeVariable ,
27
- TypeVariableBuilder , UnboundVariable , Value , ValueConstraint ,
26
+ Constant , Expression , Function , Negation , PredicateConstraint , RelationVariableBuilder , RolePlayerConstraint ,
27
+ RuleDeclaration , ThingVariable , TypeVariable , TypeVariableBuilder , UnboundConceptVariable ,
28
+ UnboundValueVariable , Value ,
28
29
} ,
29
30
Pattern ,
30
31
} ;
@@ -75,6 +76,42 @@ macro_rules! or {
75
76
} }
76
77
}
77
78
79
+ #[ macro_export]
80
+ macro_rules! max {
81
+ ( $( $arg: expr) ,* $( , ) ?) => { {
82
+ let args = [ $( $arg, ) * ] ;
83
+ $crate:: pattern:: Expression :: Function ( $crate:: pattern:: Function {
84
+ function_name: $crate:: common:: token:: Function :: Max ,
85
+ args: args. into_iter( ) . map( |arg| Box :: new( arg. into( ) ) ) . collect( ) ,
86
+ } )
87
+ } }
88
+ }
89
+
90
+ #[ macro_export]
91
+ macro_rules! min {
92
+ ( $( $arg: expr) ,* $( , ) ?) => { {
93
+ let args = [ $( $arg, ) * ] ;
94
+ $crate:: pattern:: Expression :: Function ( $crate:: pattern:: Function {
95
+ function_name: token:: Function :: Min ,
96
+ args: args. into_iter( ) . map( |arg| Box :: new( arg. into( ) ) ) . collect( ) ,
97
+ } )
98
+ } }
99
+ }
100
+
101
+ #[ macro_export]
102
+ macro_rules! filter {
103
+ ( $( $arg: expr) ,* $( , ) ?) => { {
104
+ [ $( Into :: <$crate:: pattern:: UnboundVariable >:: into( $arg) ) ,* ]
105
+ } }
106
+ }
107
+
108
+ #[ macro_export]
109
+ macro_rules! sort_vars {
110
+ ( $( $arg: expr) ,* ) => { {
111
+ $crate:: query:: Sorting :: new( vec![ $( Into :: <$crate:: query:: sorting:: OrderedVariable >:: into( $arg) , ) * ] )
112
+ } }
113
+ }
114
+
78
115
pub fn not < T : Into < Pattern > > ( pattern : T ) -> Negation {
79
116
Negation :: new ( pattern. into ( ) )
80
117
}
@@ -83,46 +120,70 @@ pub fn rule(name: &str) -> RuleDeclaration {
83
120
RuleDeclaration :: from ( name)
84
121
}
85
122
86
- pub fn var ( var : impl Into < UnboundVariable > ) -> UnboundVariable {
123
+ pub fn cvar ( var : impl Into < UnboundConceptVariable > ) -> UnboundConceptVariable {
124
+ var. into ( )
125
+ }
126
+
127
+ pub fn vvar ( var : impl Into < UnboundValueVariable > ) -> UnboundValueVariable {
87
128
var. into ( )
88
129
}
89
130
131
+ pub fn constant ( constant : impl Into < Constant > ) -> Constant {
132
+ constant. into ( )
133
+ }
134
+
90
135
pub fn type_ ( name : impl Into < String > ) -> TypeVariable {
91
- UnboundVariable :: hidden ( ) . type_ ( name. into ( ) )
136
+ UnboundConceptVariable :: hidden ( ) . type_ ( name. into ( ) )
92
137
}
93
138
94
139
pub fn rel < T : Into < RolePlayerConstraint > > ( value : T ) -> ThingVariable {
95
- UnboundVariable :: hidden ( ) . rel ( value)
140
+ UnboundConceptVariable :: hidden ( ) . rel ( value)
141
+ }
142
+
143
+ pub fn eq < T : Into < Value > > ( value : T ) -> PredicateConstraint {
144
+ PredicateConstraint :: new ( token:: Predicate :: Eq , value. into ( ) )
145
+ }
146
+
147
+ pub fn neq < T : Into < Value > > ( value : T ) -> PredicateConstraint {
148
+ PredicateConstraint :: new ( token:: Predicate :: Neq , value. into ( ) )
149
+ }
150
+
151
+ pub fn lt < T : Into < Value > > ( value : T ) -> PredicateConstraint {
152
+ PredicateConstraint :: new ( token:: Predicate :: Lt , value. into ( ) )
153
+ }
154
+
155
+ pub fn lte < T : Into < Value > > ( value : T ) -> PredicateConstraint {
156
+ PredicateConstraint :: new ( token:: Predicate :: Lte , value. into ( ) )
96
157
}
97
158
98
- pub fn eq < T : Into < Value > > ( value : T ) -> ValueConstraint {
99
- ValueConstraint :: new ( Predicate :: Eq , value. into ( ) )
159
+ pub fn gt < T : Into < Value > > ( value : T ) -> PredicateConstraint {
160
+ PredicateConstraint :: new ( token :: Predicate :: Gt , value. into ( ) )
100
161
}
101
162
102
- pub fn neq < T : Into < Value > > ( value : T ) -> ValueConstraint {
103
- ValueConstraint :: new ( Predicate :: Neq , value. into ( ) )
163
+ pub fn gte < T : Into < Value > > ( value : T ) -> PredicateConstraint {
164
+ PredicateConstraint :: new ( token :: Predicate :: Gte , value. into ( ) )
104
165
}
105
166
106
- pub fn lt < T : Into < Value > > ( value : T ) -> ValueConstraint {
107
- ValueConstraint :: new ( Predicate :: Lt , value. into ( ) )
167
+ pub fn contains < T : Into < String > > ( value : T ) -> PredicateConstraint {
168
+ PredicateConstraint :: new ( token :: Predicate :: Contains , Value :: from ( value. into ( ) ) )
108
169
}
109
170
110
- pub fn lte < T : Into < Value > > ( value : T ) -> ValueConstraint {
111
- ValueConstraint :: new ( Predicate :: Lte , value. into ( ) )
171
+ pub fn like < T : Into < String > > ( value : T ) -> PredicateConstraint {
172
+ PredicateConstraint :: new ( token :: Predicate :: Like , Value :: from ( value. into ( ) ) )
112
173
}
113
174
114
- pub fn gt < T : Into < Value > > ( value : T ) -> ValueConstraint {
115
- ValueConstraint :: new ( Predicate :: Gt , value . into ( ) )
175
+ pub fn abs < T : Into < Expression > > ( arg : T ) -> Function {
176
+ Function { function_name : token :: Function :: Abs , args : vec ! [ Box :: from ( arg . into( ) ) ] }
116
177
}
117
178
118
- pub fn gte < T : Into < Value > > ( value : T ) -> ValueConstraint {
119
- ValueConstraint :: new ( Predicate :: Gte , value . into ( ) )
179
+ pub fn ceil < T : Into < Expression > > ( arg : T ) -> Function {
180
+ Function { function_name : token :: Function :: Ceil , args : vec ! [ Box :: from ( arg . into( ) ) ] }
120
181
}
121
182
122
- pub fn contains < T : Into < String > > ( value : T ) -> ValueConstraint {
123
- ValueConstraint :: new ( Predicate :: Contains , Value :: from ( value . into ( ) ) )
183
+ pub fn floor < T : Into < Expression > > ( arg : T ) -> Function {
184
+ Function { function_name : token :: Function :: Floor , args : vec ! [ Box :: from( arg . into( ) ) ] }
124
185
}
125
186
126
- pub fn like < T : Into < String > > ( value : T ) -> ValueConstraint {
127
- ValueConstraint :: new ( Predicate :: Like , Value :: from ( value . into ( ) ) )
187
+ pub fn round < T : Into < Expression > > ( arg : T ) -> Function {
188
+ Function { function_name : token :: Function :: Round , args : vec ! [ Box :: from( arg . into( ) ) ] }
128
189
}
0 commit comments