From e47bbb10486cf38a629aa0d493201af545340db2 Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Mon, 11 Feb 2019 17:17:03 +0000 Subject: [PATCH] Add lex initialization References #4017 git-svn-id: http://svn.osgeo.org/postgis/trunk@17234 b70326c6-7e19-0410-871a-916f4a2858ee --- liblwgeom/lwin_wkt_lex.l | 43 ++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/liblwgeom/lwin_wkt_lex.l b/liblwgeom/lwin_wkt_lex.l index 234b64bbc..9ea931ed2 100644 --- a/liblwgeom/lwin_wkt_lex.l +++ b/liblwgeom/lwin_wkt_lex.l @@ -8,12 +8,12 @@ #include "lwin_wkt_parse.h" #include "lwgeom_log.h" -static YY_BUFFER_STATE wkt_yy_buf_state; +static YY_BUFFER_STATE wkt_yy_buf_state; /* * Handle errors due to unexpected junk in WKT strings. */ -static void wkt_lexer_unknown() +static void wkt_lexer_unknown() { /* Set the global error state */ global_parser_result.errcode = PARSER_ERROR_OTHER; @@ -21,8 +21,8 @@ static void wkt_lexer_unknown() global_parser_result.errlocation = wkt_yylloc.last_column; } -/* -* This macro is magically run after a rule is found but before the main +/* +* This macro is magically run after a rule is found but before the main * action is run. We use it to update the parse location information * so we can report on where things fail. Also optionally to dump * debugging info. @@ -34,7 +34,7 @@ static void wkt_lexer_unknown() LWDEBUGF(5,"lex: %s", wkt_yytext); \ } while (0); - + %} %option prefix="wkt_yy" @@ -52,13 +52,13 @@ static void wkt_lexer_unknown() LWDEBUG(5,"DOUBLE"); wkt_yylval.doublevalue = atof(wkt_yytext); yyless(wkt_yyleng-1); - return DOUBLE_TOK; + return DOUBLE_TOK; } -SRID=-?[0-9]+ { +SRID=-?[0-9]+ { LWDEBUG(5,"SRID"); - wkt_yylval.integervalue = wkt_lexer_read_srid(wkt_yytext); - return SRID_TOK; + wkt_yylval.integervalue = wkt_lexer_read_srid(wkt_yytext); + return SRID_TOK; } GEOMETRYCOLLECTION { return COLLECTION_TOK; } @@ -78,10 +78,10 @@ TIN { return TIN_TOK; } POINT { return POINT_TOK; } EMPTY { return EMPTY_TOK; } -Z|M|ZM { +Z|M|ZM { LWDEBUG(5,"DIMENSIONALITY"); wkt_yylval.stringvalue = wkt_yytext; - return DIMENSIONALITY_TOK; + return DIMENSIONALITY_TOK; } \( { LWDEBUG(5,"LBRACKET"); return LBRACKET_TOK; } @@ -92,9 +92,9 @@ Z|M|ZM { [ \t\n\r]+ { /* ignore whitespace */ LWDEBUG(5,"WHITESPACE"); } . { /* Error out and stop parsing on unknown/unexpected characters */ - LWDEBUG(5,"UNKNOWN"); + LWDEBUG(5,"UNKNOWN"); wkt_lexer_unknown(); - yyterminate(); + yyterminate(); } %% @@ -117,16 +117,17 @@ void wkt_yyfree (void * ptr ) /* * Set up the lexer! */ -void wkt_lexer_init(char *src) -{ - wkt_yy_buf_state = wkt_yy_scan_string(src); -} +void wkt_lexer_init(char *src) +{ + yy_init_globals(); + wkt_yy_buf_state = wkt_yy_scan_string(src); +} /* * Clean up the lexer! */ -void wkt_lexer_close() -{ - wkt_yy_delete_buffer(wkt_yy_buf_state); -} +void wkt_lexer_close() +{ + wkt_yy_delete_buffer(wkt_yy_buf_state); +} -- 2.40.0