@@ -121,23 +121,8 @@ func (p *ExpressionParser) ParseExpressionString(ctx context.Context, expression
121121 if tree == nil || tree .Token == nil {
122122 return nil , BadRequestError ("Expression cannot be nil" )
123123 }
124- if p .ExpectBoolExpr {
125- switch tree .Token .Type {
126- case ExpressionTokenBoolean :
127- // Valid boolean expression
128- case ExpressionTokenLogical :
129- // eq|ne|gt|ge|lt|le|and|or|not|has|in
130- // Valid boolean expression
131- case ExpressionTokenFunc :
132- // We need to know the return type of the function.
133- // TODO
134- case ExpressionTokenLambdaNav :
135- // Lambda Navigation.
136- // Valid boolean expression
137- default :
138- // Not a boolean expression
139- return nil , BadRequestError ("Expression does not return a boolean value" )
140- }
124+ if p .ExpectBoolExpr && ! p .isBooleanExpression (tree .Token ) {
125+ return nil , BadRequestError ("Expression does not return a boolean value" )
141126 }
142127 return & GoDataExpression {tree , expression }, nil
143128}
@@ -288,52 +273,55 @@ func NewExpressionParser() *ExpressionParser {
288273 parser .DefineOperator ("and" , 2 , OpAssociationLeft , 2 )
289274 parser .DefineOperator ("or" , 2 , OpAssociationLeft , 1 )
290275 parser .DefineOperator ("=" , 2 , OpAssociationRight , 0 ) // Function argument assignment. E.g. MyFunc(Arg1='abc')
291- parser .DefineFunction ("contains" , []int {2 })
292- parser .DefineFunction ("endswith" , []int {2 })
293- parser .DefineFunction ("startswith" , []int {2 })
294- parser .DefineFunction ("exists" , []int {2 })
295- parser .DefineFunction ("length" , []int {1 })
296- parser .DefineFunction ("indexof" , []int {2 })
297- parser .DefineFunction ("substring" , []int {2 , 3 })
298- parser .DefineFunction ("substringof" , []int {2 })
299- parser .DefineFunction ("tolower" , []int {1 })
300- parser .DefineFunction ("toupper" , []int {1 })
301- parser .DefineFunction ("trim" , []int {1 })
302- parser .DefineFunction ("concat" , []int {2 })
303- parser .DefineFunction ("year" , []int {1 })
304- parser .DefineFunction ("month" , []int {1 })
305- parser .DefineFunction ("day" , []int {1 })
306- parser .DefineFunction ("hour" , []int {1 })
307- parser .DefineFunction ("minute" , []int {1 })
308- parser .DefineFunction ("second" , []int {1 })
309- parser .DefineFunction ("fractionalseconds" , []int {1 })
310- parser .DefineFunction ("date" , []int {1 })
311- parser .DefineFunction ("time" , []int {1 })
312- parser .DefineFunction ("totaloffsetminutes" , []int {1 })
313- parser .DefineFunction ("now" , []int {0 })
314- parser .DefineFunction ("maxdatetime" , []int {0 })
315- parser .DefineFunction ("mindatetime" , []int {0 })
316- parser .DefineFunction ("totalseconds" , []int {1 })
317- parser .DefineFunction ("round" , []int {1 })
318- parser .DefineFunction ("floor" , []int {1 })
319- parser .DefineFunction ("ceiling" , []int {1 })
320- parser .DefineFunction ("isof" , []int {1 , 2 }) // isof function can take one or two arguments.
321- parser .DefineFunction ("cast" , []int {2 })
322- parser .DefineFunction ("geo.distance" , []int {2 })
276+ parser .DefineFunction ("contains" , []int {2 }, true )
277+ parser .DefineFunction ("endswith" , []int {2 }, true )
278+ parser .DefineFunction ("startswith" , []int {2 }, true )
279+ parser .DefineFunction ("exists" , []int {2 }, true )
280+ parser .DefineFunction ("length" , []int {1 }, false )
281+ parser .DefineFunction ("indexof" , []int {2 }, false )
282+ parser .DefineFunction ("substring" , []int {2 , 3 }, false )
283+ parser .DefineFunction ("substringof" , []int {2 }, false )
284+ parser .DefineFunction ("tolower" , []int {1 }, false )
285+ parser .DefineFunction ("toupper" , []int {1 }, false )
286+ parser .DefineFunction ("trim" , []int {1 }, false )
287+ parser .DefineFunction ("concat" , []int {2 }, false )
288+ parser .DefineFunction ("year" , []int {1 }, false )
289+ parser .DefineFunction ("month" , []int {1 }, false )
290+ parser .DefineFunction ("day" , []int {1 }, false )
291+ parser .DefineFunction ("hour" , []int {1 }, false )
292+ parser .DefineFunction ("minute" , []int {1 }, false )
293+ parser .DefineFunction ("second" , []int {1 }, false )
294+ parser .DefineFunction ("fractionalseconds" , []int {1 }, false )
295+ parser .DefineFunction ("date" , []int {1 }, false )
296+ parser .DefineFunction ("time" , []int {1 }, false )
297+ parser .DefineFunction ("totaloffsetminutes" , []int {1 }, false )
298+ parser .DefineFunction ("now" , []int {0 }, false )
299+ parser .DefineFunction ("maxdatetime" , []int {0 }, false )
300+ parser .DefineFunction ("mindatetime" , []int {0 }, false )
301+ parser .DefineFunction ("totalseconds" , []int {1 }, false )
302+ parser .DefineFunction ("round" , []int {1 }, false )
303+ parser .DefineFunction ("floor" , []int {1 }, false )
304+ parser .DefineFunction ("ceiling" , []int {1 }, false )
305+ parser .DefineFunction ("isof" , []int {1 , 2 }, true ) // isof function can take one or two arguments.
306+ parser .DefineFunction ("cast" , []int {2 }, false )
307+ parser .DefineFunction ("geo.distance" , []int {2 }, false )
323308 // The geo.intersects function has the following signatures:
324309 // Edm.Boolean geo.intersects(Edm.GeographyPoint,Edm.GeographyPolygon)
325310 // Edm.Boolean geo.intersects(Edm.GeometryPoint,Edm.GeometryPolygon)
326311 // The geo.intersects function returns true if the specified point lies within the interior
327312 // or on the boundary of the specified polygon, otherwise it returns false.
328- parser .DefineFunction ("geo.intersects" , []int {2 })
313+ parser .DefineFunction ("geo.intersects" , []int {2 }, false )
329314 // The geo.length function has the following signatures:
330315 // Edm.Double geo.length(Edm.GeographyLineString)
331316 // Edm.Double geo.length(Edm.GeometryLineString)
332317 // The geo.length function returns the total length of its line string parameter
333318 // in the coordinate reference system signified by its SRID.
334- parser .DefineFunction ("geo.length" , []int {1 })
335- parser .DefineFunction ("any" , []int {0 , 2 }) // 'any' can take either zero or one argument.
336- parser .DefineFunction ("all" , []int {2 })
319+ parser .DefineFunction ("geo.length" , []int {1 }, false )
320+ // 'any' can take either zero or two arguments with the later having the form any(d:d/Prop eq 1).
321+ // Godata interprets the colon as an argument delimiter and considers the function to have two arguments.
322+ parser .DefineFunction ("any" , []int {0 , 2 }, true )
323+ // 'all' requires two arguments of a form similar to 'any'.
324+ parser .DefineFunction ("all" , []int {2 }, true )
337325
338326 return parser
339327}
0 commit comments