@@ -58,8 +58,9 @@ const (
5858 ExpressionTokenDuration // duration = [ "duration" ] SQUOTE durationValue SQUOTE
5959 ExpressionTokenGuid // [25] A 128-bit GUID
6060 ExpressionTokenAssignement // The '=' assignement for function arguments.
61- ExpressionTokenGeographyPolygon //
62- ExpressionTokenGeometryPolygon //
61+ ExpressionTokenGeographyPolygon // A polygon with geodetic (ie spherical) coordinates. Parsed Token.Value is '<long> <lat>,<long> <lat>...'
62+ ExpressionTokenGeometryPolygon // A polygon with planar (ie cartesian) coordinates. Parsed Token.Value is '<long> <lat>,<long> <lat>...'
63+ ExpressionTokenGeographyPoint // A geodetic coordinate point. Parsed Token.Value is '<long> <lat>'
6364 expressionTokenLast
6465)
6566
@@ -94,6 +95,7 @@ func (e ExpressionTokenType) String() string {
9495 "ExpressionTokenAssignement" ,
9596 "ExpressionTokenGeographyPolygon" ,
9697 "ExpressionTokenGeometryPolygon" ,
98+ "ExpressionTokenGeographyPoint" ,
9799 "expressionTokenLast" ,
98100 }[e ]
99101}
@@ -178,15 +180,11 @@ func NewExpressionTokenizer() *Tokenizer {
178180 // E.g. ABNF for 'geo.distance':
179181 // distanceMethodCallExpr = "geo.distance" OPEN BWS commonExpr BWS COMMA BWS commonExpr BWS CLOSE
180182 t .Add ("(?i)^(?P<token>(geo.distance|geo.intersects|geo.length))[\\ s(]" , ExpressionTokenFunc )
181- // geographyPolygon = geographyPrefix SQUOTE fullPolygonLiteral SQUOTE
182- // fullPolygonLiteral = sridLiteral polygonLiteral
183- // sridLiteral = "SRID" EQ 1*5DIGIT SEMI
184- // polygonLiteral = "Polygon" polygonData
185- // polygonData = OPEN ringLiteral *( COMMA ringLiteral ) CLOSE
186- // Example: geography'SRID=0;Polygon((-122.031577 47.578581, -122.031577 47.678581, -122.131577 47.678581))'
187- t .Add (`^geography'SRID=[0-9]{1,5};Polygon\(\((-?[0-9]+\.[0-9]+\s+-?[0-9]+\.[0-9]+)(,\s-?[0-9]+\.[0-9]+\s+-?[0-9]+\.[0-9]+)*\)\)'` , ExpressionTokenGeographyPolygon )
188- // geometryPolygon = geometryPrefix SQUOTE fullPolygonLiteral SQUOTE
189- t .Add (`^geometry'SRID=[0-9]{1,5};Polygon\(\((-?[0-9]+\.[0-9]+\s+-?[0-9]+\.[0-9]+)(,\s-?[0-9]+\.[0-9]+\s+-?[0-9]+\.[0-9]+)*\)\)'` , ExpressionTokenGeometryPolygon )
183+ // Example: geography'POLYGON((-122.031577 47.578581, -122.031577 47.678581, -122.131577 47.678581))'
184+ t .Add (`(?i)^geography'(?:SRID=(\d{1,5});)?POLYGON\s*\(\(\s*(?P<subtoken>-?\d+(\.\d+)?\s+-?\d+(\.\d+)?(?:\s*,\s*-?\d+(\.\d+)?\s+-?\d+(\.\d+)?)*?)\s*\)\)'` , ExpressionTokenGeographyPolygon )
185+ t .Add (`(?i)^geometry'(?:SRID=(\d{1,5});)?POLYGON\s*\(\(\s*(?P<subtoken>-?\d+(\.\d+)?\s+-?\d+(\.\d+)?(?:\s*,\s*-?\d+(\.\d+)?\s+-?\d+(\.\d+)?)*?)\s*\)\)'` , ExpressionTokenGeometryPolygon )
186+ // Example: geography'POINT(-122.131577 47.678581)'
187+ t .Add (`(?i)^geography'POINT\s*\(\s*(?P<subtoken>-?\d+(\.\d+)?\s+-?\d+(\.\d+)?)\s*\)'` , ExpressionTokenGeographyPoint )
190188 // According to ODATA ABNF notation, functions must be followed by a open parenthesis with no space
191189 // between the function name and the open parenthesis.
192190 // However, we are leniently allowing space characters between the function and the open parenthesis.
@@ -315,7 +313,7 @@ func NewExpressionParser() *ExpressionParser {
315313 // Edm.Boolean geo.intersects(Edm.GeometryPoint,Edm.GeometryPolygon)
316314 // The geo.intersects function returns true if the specified point lies within the interior
317315 // or on the boundary of the specified polygon, otherwise it returns false.
318- parser .DefineFunction ("geo.intersects" , []int {2 }, false )
316+ parser .DefineFunction ("geo.intersects" , []int {2 }, true )
319317 // The geo.length function has the following signatures:
320318 // Edm.Double geo.length(Edm.GeographyLineString)
321319 // Edm.Double geo.length(Edm.GeometryLineString)
@@ -329,7 +327,7 @@ func NewExpressionParser() *ExpressionParser {
329327 parser .DefineFunction ("all" , []int {2 }, true )
330328 // Define 'case' as a function accepting 1-10 arguments. Each argument is a pair of expressions separated by a colon.
331329 // See https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html#sec_case
332- parser .DefineFunction ("case" , []int {1 ,2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 }, true )
330+ parser .DefineFunction ("case" , []int {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 }, true )
333331
334332 return parser
335333}
0 commit comments