2004-04-27 17:46:46 +00:00
|
|
|
/*
|
|
|
|
* Written by Ralph Mason ralph.mason<at>telogis.com
|
|
|
|
*
|
|
|
|
* Copyright Telogis 2004
|
|
|
|
* www.telogis.com
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
%{
|
|
|
|
#include "wktparse.h"
|
2005-01-18 09:30:57 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
2004-04-27 17:46:46 +00:00
|
|
|
|
2004-10-05 16:28:34 +00:00
|
|
|
void set_zm(char z, char m);
|
2005-01-10 09:47:14 +00:00
|
|
|
int lwg_parse_yylex(void);
|
2004-04-27 17:46:46 +00:00
|
|
|
%}
|
|
|
|
|
|
|
|
%start geometry
|
|
|
|
|
2008-09-08 20:16:04 +00:00
|
|
|
%locations
|
|
|
|
|
2004-04-27 17:46:46 +00:00
|
|
|
%union {
|
|
|
|
double value;
|
|
|
|
const char* wkb;
|
|
|
|
}
|
|
|
|
|
2006-12-01 22:16:44 +00:00
|
|
|
%token POINT LINESTRING POLYGON MULTIPOINT MULTILINESTRING MULTIPOLYGON GEOMETRYCOLLECTION CIRCULARSTRING COMPOUNDCURVE CURVEPOLYGON MULTICURVE MULTISURFACE
|
|
|
|
%token POINTM LINESTRINGM POLYGONM MULTIPOINTM MULTILINESTRINGM MULTIPOLYGONM GEOMETRYCOLLECTIONM CIRCULARSTRINGM COMPOUNDCURVEM CURVEPOLYGONM MULTICURVEM MULTISURFACEM
|
2004-04-27 17:46:46 +00:00
|
|
|
%token SRID
|
|
|
|
%token EMPTY
|
|
|
|
%token <value> VALUE
|
|
|
|
%token LPAREN RPAREN COMMA EQUALS SEMICOLON
|
|
|
|
%token <wkb> WKB
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
2006-04-18 12:30:08 +00:00
|
|
|
geometry :
|
|
|
|
srid SEMICOLON { alloc_lwgeom(srid); } geometry_int
|
|
|
|
|
|
|
|
|
{ alloc_lwgeom(-1); } geometry_int
|
|
|
|
|
|
|
|
geometry_int :
|
|
|
|
geom_wkb
|
|
|
|
|
|
|
|
|
geom_point
|
|
|
|
|
|
|
|
|
geom_linestring
|
|
|
|
|
|
2006-12-01 22:16:44 +00:00
|
|
|
geom_circularstring
|
|
|
|
|
|
2006-04-18 12:30:08 +00:00
|
|
|
geom_polygon
|
|
|
|
|
|
2006-12-01 22:16:44 +00:00
|
|
|
geom_compoundcurve
|
|
|
|
|
|
|
|
|
geom_curvepolygon
|
|
|
|
|
|
2006-04-18 12:30:08 +00:00
|
|
|
geom_multipoint
|
|
|
|
|
|
|
|
|
geom_multilinestring
|
2006-12-01 22:16:44 +00:00
|
|
|
|
|
|
|
|
geom_multicurve
|
2006-04-18 12:30:08 +00:00
|
|
|
|
|
|
|
|
geom_multipolygon
|
|
|
|
|
|
2006-12-01 22:16:44 +00:00
|
|
|
geom_multisurface
|
|
|
|
|
|
2006-04-18 12:30:08 +00:00
|
|
|
geom_geometrycollection
|
|
|
|
|
|
|
|
srid :
|
|
|
|
SRID EQUALS VALUE { set_srid($3); }
|
|
|
|
|
|
|
|
geom_wkb :
|
|
|
|
WKB { alloc_wkb($1); }
|
2004-04-27 17:46:46 +00:00
|
|
|
|
|
|
|
|
2006-04-18 12:30:08 +00:00
|
|
|
/* POINT */
|
2004-04-27 17:46:46 +00:00
|
|
|
|
2006-04-18 12:30:08 +00:00
|
|
|
geom_point :
|
|
|
|
POINT point
|
|
|
|
|
|
|
|
|
POINTM { set_zm(0, 1); } point
|
2004-04-27 17:46:46 +00:00
|
|
|
|
2006-04-18 12:30:08 +00:00
|
|
|
point :
|
|
|
|
empty_point
|
|
|
|
|
|
|
|
|
nonempty_point
|
2004-04-27 17:46:46 +00:00
|
|
|
|
2006-04-18 12:30:08 +00:00
|
|
|
empty_point :
|
|
|
|
{ alloc_point(); } empty { pop(); }
|
2004-04-27 17:46:46 +00:00
|
|
|
|
2006-04-18 12:30:08 +00:00
|
|
|
nonempty_point :
|
|
|
|
{ alloc_point(); } point_int { pop(); }
|
2004-04-27 17:46:46 +00:00
|
|
|
|
2006-04-18 12:30:08 +00:00
|
|
|
point_int :
|
|
|
|
LPAREN a_point RPAREN
|
2004-04-27 17:46:46 +00:00
|
|
|
|
|
|
|
/* MULTIPOINT */
|
|
|
|
|
2006-04-18 12:30:08 +00:00
|
|
|
geom_multipoint :
|
|
|
|
MULTIPOINT { alloc_multipoint(); } multipoint { pop(); }
|
|
|
|
|
|
|
|
|
MULTIPOINTM { set_zm(0, 1); alloc_multipoint(); } multipoint {pop(); }
|
2004-04-27 17:46:46 +00:00
|
|
|
|
2006-04-18 12:30:08 +00:00
|
|
|
multipoint :
|
|
|
|
empty
|
|
|
|
|
|
|
|
|
{ alloc_counter(); } LPAREN multipoint_int RPAREN { pop(); }
|
2004-04-27 17:46:46 +00:00
|
|
|
|
2006-04-18 12:30:08 +00:00
|
|
|
multipoint_int :
|
|
|
|
mpoint_element
|
|
|
|
|
|
|
|
|
multipoint_int COMMA mpoint_element
|
2004-04-27 17:46:46 +00:00
|
|
|
|
2006-04-18 12:30:08 +00:00
|
|
|
mpoint_element :
|
|
|
|
nonempty_point
|
|
|
|
|
|
|
|
|
/* this is to allow MULTIPOINT(0 0, 1 1) */
|
|
|
|
{ alloc_point(); } a_point { pop(); }
|
2004-04-27 17:46:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* LINESTRING */
|
|
|
|
|
2006-04-18 12:30:08 +00:00
|
|
|
geom_linestring :
|
|
|
|
LINESTRING linestring
|
|
|
|
|
|
|
|
|
LINESTRINGM { set_zm(0, 1); } linestring
|
|
|
|
|
|
|
|
linestring :
|
|
|
|
empty_linestring
|
|
|
|
|
|
|
|
|
nonempty_linestring
|
|
|
|
|
|
|
|
empty_linestring :
|
|
|
|
{ alloc_linestring(); } empty { pop(); }
|
2004-04-27 17:46:46 +00:00
|
|
|
|
2006-04-18 12:30:08 +00:00
|
|
|
nonempty_linestring :
|
2009-03-10 00:29:32 +00:00
|
|
|
{ alloc_linestring(); } linestring_1 { check_linestring(); pop(); }
|
2004-04-27 17:46:46 +00:00
|
|
|
|
2006-12-01 22:16:44 +00:00
|
|
|
nonempty_linestring_closed :
|
2009-03-10 00:29:32 +00:00
|
|
|
{ alloc_linestring_closed(); } linestring_1 { check_closed_linestring(); pop(); }
|
2006-12-01 22:16:44 +00:00
|
|
|
|
2006-04-18 12:30:08 +00:00
|
|
|
linestring_1 :
|
2009-03-10 00:29:32 +00:00
|
|
|
{ alloc_counter(); } LPAREN linestring_int RPAREN { pop(); }
|
2004-04-27 17:46:46 +00:00
|
|
|
|
2006-04-18 12:30:08 +00:00
|
|
|
linestring_int :
|
|
|
|
a_point
|
|
|
|
|
|
|
|
|
linestring_int COMMA a_point;
|
2004-04-27 17:46:46 +00:00
|
|
|
|
2006-12-01 22:16:44 +00:00
|
|
|
/* CIRCULARSTRING */
|
|
|
|
|
|
|
|
geom_circularstring :
|
|
|
|
CIRCULARSTRING circularstring
|
|
|
|
|
|
|
|
|
CIRCULARSTRINGM {set_zm(0, 1); } circularstring
|
|
|
|
|
|
|
|
geom_circularstring_closed :
|
|
|
|
CIRCULARSTRING circularstring_closed
|
|
|
|
|
|
|
|
|
CIRCULARSTRINGM {set_zm(0, 1); } circularstring_closed
|
|
|
|
|
|
|
|
circularstring :
|
|
|
|
empty_circularstring
|
|
|
|
|
|
|
|
|
nonempty_circularstring
|
|
|
|
|
|
|
|
circularstring_closed :
|
|
|
|
empty_circularstring
|
|
|
|
|
|
|
|
|
nonempty_circularstring_closed
|
|
|
|
|
|
|
|
empty_circularstring :
|
|
|
|
{ alloc_circularstring(); } empty { pop(); }
|
|
|
|
|
|
|
|
nonempty_circularstring :
|
2009-03-10 00:29:32 +00:00
|
|
|
{ alloc_circularstring(); } circularstring_1 { check_circularstring(); pop(); }
|
2006-12-01 22:16:44 +00:00
|
|
|
|
|
|
|
nonempty_circularstring_closed :
|
2009-03-10 00:29:32 +00:00
|
|
|
{ alloc_circularstring_closed(); } circularstring_1 { check_closed_circularstring(); pop(); }
|
2006-12-01 22:16:44 +00:00
|
|
|
|
|
|
|
circularstring_1 :
|
2009-03-10 00:29:32 +00:00
|
|
|
{ alloc_counter(); } LPAREN circularstring_int RPAREN { pop(); }
|
2006-12-01 22:16:44 +00:00
|
|
|
|
|
|
|
circularstring_int :
|
|
|
|
a_point
|
|
|
|
|
|
|
|
|
circularstring_int COMMA a_point;
|
|
|
|
|
|
|
|
/* COMPOUNDCURVE */
|
|
|
|
|
|
|
|
geom_compoundcurve:
|
2009-03-10 00:29:32 +00:00
|
|
|
COMPOUNDCURVE compoundcurve
|
|
|
|
|
|
|
|
|
COMPOUNDCURVEM { set_zm(0, 1); } compoundcurve
|
|
|
|
|
|
|
|
geom_compoundcurve_closed:
|
|
|
|
COMPOUNDCURVE compoundcurve_closed
|
|
|
|
|
|
|
|
|
COMPOUNDCURVEM { set_zm(0, 1); } compoundcurve_closed
|
2006-12-01 22:16:44 +00:00
|
|
|
|
|
|
|
compoundcurve:
|
2009-03-10 00:29:32 +00:00
|
|
|
empty_compoundcurve
|
|
|
|
|
|
|
|
|
nonempty_compoundcurve
|
|
|
|
|
|
|
|
compoundcurve_closed:
|
|
|
|
empty_compoundcurve_closed
|
|
|
|
|
|
|
|
|
nonempty_compoundcurve_closed
|
|
|
|
|
|
|
|
empty_compoundcurve:
|
|
|
|
{ alloc_compoundcurve(); } empty { pop(); }
|
|
|
|
|
|
|
|
empty_compoundcurve_closed:
|
|
|
|
{ alloc_compoundcurve_closed(); } empty { pop(); }
|
|
|
|
|
|
|
|
nonempty_compoundcurve:
|
|
|
|
{ alloc_compoundcurve(); } compoundcurve_1 { check_compoundcurve(); pop(); }
|
|
|
|
|
|
|
|
nonempty_compoundcurve_closed:
|
|
|
|
{ alloc_compoundcurve_closed(); } compoundcurve_1 { check_closed_compoundcurve(); pop(); }
|
|
|
|
|
|
|
|
compoundcurve_1:
|
|
|
|
{ alloc_counter(); } LPAREN compoundcurve_int RPAREN {pop();}
|
2006-12-01 22:16:44 +00:00
|
|
|
|
|
|
|
compoundcurve_int:
|
|
|
|
nonempty_linestring
|
|
|
|
|
|
|
|
|
geom_circularstring
|
|
|
|
|
|
|
|
|
compoundcurve_int COMMA nonempty_linestring
|
|
|
|
|
|
|
|
|
compoundcurve_int COMMA geom_circularstring
|
|
|
|
|
2004-04-27 17:46:46 +00:00
|
|
|
/* MULTILINESTRING */
|
|
|
|
|
2006-04-18 12:30:08 +00:00
|
|
|
geom_multilinestring :
|
|
|
|
MULTILINESTRING { alloc_multilinestring(); }
|
|
|
|
multilinestring { pop(); }
|
|
|
|
|
|
|
|
|
MULTILINESTRINGM { set_zm(0, 1); alloc_multilinestring(); }
|
|
|
|
multilinestring { pop(); }
|
2004-04-27 17:46:46 +00:00
|
|
|
|
2006-04-18 12:30:08 +00:00
|
|
|
multilinestring :
|
|
|
|
empty
|
|
|
|
|
|
|
|
|
{ alloc_counter(); } LPAREN multilinestring_int RPAREN{ pop();}
|
2004-04-27 17:46:46 +00:00
|
|
|
|
2006-04-18 12:30:08 +00:00
|
|
|
multilinestring_int :
|
|
|
|
nonempty_linestring
|
|
|
|
|
|
|
|
|
multilinestring_int COMMA nonempty_linestring
|
2004-04-27 17:46:46 +00:00
|
|
|
|
2006-12-01 22:16:44 +00:00
|
|
|
/* MULTICURVESTRING */
|
|
|
|
|
|
|
|
geom_multicurve :
|
|
|
|
MULTICURVE { alloc_multicurve(); }
|
|
|
|
multicurve { pop(); }
|
|
|
|
|
|
|
|
|
MULTICURVEM { set_zm(0, 1); alloc_multicurve(); }
|
|
|
|
multicurve { pop(); }
|
|
|
|
|
|
|
|
multicurve :
|
|
|
|
empty
|
|
|
|
|
|
|
|
|
{ alloc_counter(); } LPAREN multicurve_int RPAREN { pop(); }
|
|
|
|
|
|
|
|
multicurve_int :
|
|
|
|
nonempty_linestring
|
|
|
|
|
|
|
|
|
geom_circularstring
|
|
|
|
|
|
|
|
|
multicurve_int COMMA nonempty_linestring
|
|
|
|
|
|
|
|
|
multicurve_int COMMA geom_circularstring
|
2004-04-27 17:46:46 +00:00
|
|
|
|
|
|
|
/* POLYGON */
|
|
|
|
|
2006-04-18 12:30:08 +00:00
|
|
|
geom_polygon :
|
|
|
|
POLYGON polygon
|
|
|
|
|
|
|
|
|
POLYGONM { set_zm(0, 1); } polygon
|
2004-04-27 17:46:46 +00:00
|
|
|
|
2006-04-18 12:30:08 +00:00
|
|
|
polygon :
|
|
|
|
empty_polygon
|
|
|
|
|
|
|
|
|
nonempty_polygon
|
2004-04-27 17:46:46 +00:00
|
|
|
|
2006-04-18 12:30:08 +00:00
|
|
|
empty_polygon :
|
|
|
|
{ alloc_polygon(); } empty { pop(); }
|
2004-04-27 17:46:46 +00:00
|
|
|
|
2006-04-18 12:30:08 +00:00
|
|
|
nonempty_polygon :
|
2009-03-10 00:29:32 +00:00
|
|
|
{ alloc_polygon(); } polygon_1 { check_polygon(); pop(); }
|
2006-04-18 12:30:08 +00:00
|
|
|
|
|
|
|
polygon_1 :
|
|
|
|
{ alloc_counter(); } LPAREN polygon_int RPAREN { pop();}
|
|
|
|
|
|
|
|
polygon_int :
|
2009-03-10 00:29:32 +00:00
|
|
|
/* nonempty_linestring_closed */
|
2006-04-18 12:30:08 +00:00
|
|
|
linestring_1
|
|
|
|
|
|
2009-03-10 00:29:32 +00:00
|
|
|
/* polygon_int COMMA nonempty_linestring_closed */
|
2006-04-18 12:30:08 +00:00
|
|
|
polygon_int COMMA linestring_1
|
2006-12-01 22:16:44 +00:00
|
|
|
|
|
|
|
/* CURVEPOLYGON */
|
|
|
|
|
|
|
|
geom_curvepolygon :
|
2009-03-10 00:29:32 +00:00
|
|
|
CURVEPOLYGON { alloc_curvepolygon(); } curvepolygon { check_curvepolygon(); pop(); }
|
2006-12-01 22:16:44 +00:00
|
|
|
|
|
|
|
|
CURVEPOLYGONM { set_zm(0, 1); alloc_curvepolygon(); }
|
2009-03-10 00:29:32 +00:00
|
|
|
curvepolygon { check_curvepolygon(); pop(); }
|
2006-12-01 22:16:44 +00:00
|
|
|
|
|
|
|
curvepolygon :
|
|
|
|
empty
|
|
|
|
|
|
|
|
|
{ alloc_counter(); } LPAREN curvepolygon_int RPAREN { pop(); }
|
|
|
|
|
|
|
|
curvepolygon_int :
|
|
|
|
nonempty_linestring_closed
|
|
|
|
|
|
|
|
|
geom_circularstring_closed
|
|
|
|
|
|
2009-03-10 00:29:32 +00:00
|
|
|
geom_compoundcurve_closed
|
|
|
|
|
|
2006-12-01 22:16:44 +00:00
|
|
|
curvepolygon_int COMMA nonempty_linestring_closed
|
|
|
|
|
|
|
|
|
curvepolygon_int COMMA geom_circularstring_closed
|
2009-03-10 00:29:32 +00:00
|
|
|
|
|
|
|
|
curvepolygon_int COMMA geom_compoundcurve_closed
|
2006-12-01 22:16:44 +00:00
|
|
|
|
2004-04-27 17:46:46 +00:00
|
|
|
/* MULTIPOLYGON */
|
|
|
|
|
2006-04-18 12:30:08 +00:00
|
|
|
geom_multipolygon :
|
|
|
|
MULTIPOLYGON { alloc_multipolygon(); } multipolygon { pop(); }
|
|
|
|
|
|
|
|
|
MULTIPOLYGONM { set_zm(0, 1); alloc_multipolygon(); }
|
|
|
|
multipolygon { pop();}
|
2004-04-27 17:46:46 +00:00
|
|
|
|
2006-04-18 12:30:08 +00:00
|
|
|
multipolygon :
|
|
|
|
empty
|
|
|
|
|
|
|
|
|
{ alloc_counter(); } LPAREN multipolygon_int RPAREN { pop(); }
|
2004-04-27 17:46:46 +00:00
|
|
|
|
2006-04-18 12:30:08 +00:00
|
|
|
multipolygon_int :
|
|
|
|
nonempty_polygon
|
|
|
|
|
|
|
|
|
multipolygon_int COMMA nonempty_polygon
|
2004-04-27 17:46:46 +00:00
|
|
|
|
2006-12-01 22:16:44 +00:00
|
|
|
/* MULTISURFACE */
|
|
|
|
|
|
|
|
geom_multisurface :
|
|
|
|
MULTISURFACE {alloc_multisurface(); } multisurface { pop(); }
|
|
|
|
|
|
|
|
|
MULTISURFACEM { set_zm(0, 1); alloc_multisurface(); }
|
|
|
|
multisurface { pop(); }
|
|
|
|
|
|
|
|
multisurface :
|
|
|
|
empty
|
|
|
|
|
|
|
|
|
{ alloc_counter(); } LPAREN multisurface_int RPAREN { pop(); }
|
|
|
|
|
|
|
|
multisurface_int :
|
|
|
|
nonempty_polygon
|
|
|
|
|
|
|
|
|
geom_curvepolygon
|
|
|
|
|
|
|
|
|
multisurface_int COMMA nonempty_polygon
|
|
|
|
|
|
|
|
|
multisurface_int COMMA geom_curvepolygon
|
2004-04-27 17:46:46 +00:00
|
|
|
|
|
|
|
/* GEOMETRYCOLLECTION */
|
|
|
|
|
2006-04-18 12:30:08 +00:00
|
|
|
geom_geometrycollection :
|
|
|
|
GEOMETRYCOLLECTION { alloc_geomertycollection(); }
|
|
|
|
geometrycollection { pop(); }
|
|
|
|
|
|
|
|
|
GEOMETRYCOLLECTIONM { set_zm(0, 1); alloc_geomertycollection(); }
|
|
|
|
geometrycollection { pop();}
|
|
|
|
|
|
|
|
geometrycollection :
|
|
|
|
empty
|
|
|
|
|
|
|
|
|
{ alloc_counter(); } LPAREN geometrycollection_int RPAREN { pop(); }
|
|
|
|
|
|
|
|
geometrycollection_int :
|
2006-04-18 16:57:10 +00:00
|
|
|
/* to support GEOMETRYCOLLECTION(EMPTY) for backward compatibility */
|
2006-04-18 12:30:08 +00:00
|
|
|
empty
|
|
|
|
|
|
|
|
|
geometry_int
|
|
|
|
|
|
|
|
|
geometrycollection_int COMMA geometry_int
|
|
|
|
|
|
|
|
|
|
|
|
a_point :
|
|
|
|
point_2d
|
|
|
|
|
|
|
|
|
point_3d
|
|
|
|
|
|
|
|
|
point_4d
|
|
|
|
|
|
|
|
point_2d :
|
|
|
|
VALUE VALUE {alloc_point_2d($1,$2); }
|
|
|
|
|
|
|
|
point_3d :
|
|
|
|
VALUE VALUE VALUE {alloc_point_3d($1,$2,$3); }
|
|
|
|
|
|
|
|
point_4d :
|
|
|
|
VALUE VALUE VALUE VALUE {alloc_point_4d($1,$2,$3,$4); }
|
|
|
|
|
|
|
|
empty :
|
|
|
|
EMPTY { alloc_empty(); }
|
2004-04-27 17:46:46 +00:00
|
|
|
%%
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|