#define CubeKNNDistanceEuclid 17 /* <-> */
#define CubeKNNDistanceChebyshev 18 /* <=> */
+/* for cubescan.l and cubeparse.y */
+/* All grammar constructs return strings */
+#define YYSTYPE char *
+typedef void *yyscan_t;
+
/* in cubescan.l */
-extern int cube_yylex(void);
+extern int cube_yylex(YYSTYPE *yylval_param, yyscan_t yyscanner);
extern void cube_yyerror(NDBOX **result, Size scanbuflen,
struct Node *escontext,
+ yyscan_t yyscanner,
const char *message);
-extern void cube_scanner_init(const char *str, Size *scanbuflen);
-extern void cube_scanner_finish(void);
+extern void cube_scanner_init(const char *str, Size *scanbuflen, yyscan_t *yyscannerp);
+extern void cube_scanner_finish(yyscan_t yyscanner);
/* in cubeparse.y */
extern int cube_yyparse(NDBOX **result, Size scanbuflen,
- struct Node *escontext);
+ struct Node *escontext,
+ yyscan_t yyscanner);
#include "postgres.h"
#include "cubedata.h"
+#include "cubeparse.h" /* must be after cubedata.h for YYSTYPE and NDBOX */
#include "nodes/miscnodes.h"
#include "utils/float.h"
#include "varatt.h"
-/* All grammar constructs return strings */
-#define YYSTYPE char *
-
-#include "cubeparse.h"
-
-/* silence -Wmissing-variable-declarations */
-extern int cube_yychar;
-extern int cube_yynerrs;
-
/*
* Bison doesn't allocate anything that needs to live across parser calls,
* so we can easily have it use palloc instead of malloc. This prevents
%parse-param {NDBOX **result}
%parse-param {Size scanbuflen}
%parse-param {struct Node *escontext}
+%parse-param {yyscan_t yyscanner}
+%lex-param {yyscan_t yyscanner}
+%pure-parser
%expect 0
%name-prefix="cube_yy"
if (!write_box(dim, $2, $4, result, escontext))
YYABORT;
+
+ (void) yynerrs; /* suppress compiler warning */
}
| paren_list COMMA paren_list
#include "postgres.h"
-/*
- * NB: include cubeparse.h only AFTER defining YYSTYPE (to match cubeparse.y)
- * and cubedata.h for NDBOX.
- */
#include "cubedata.h"
-#define YYSTYPE char *
-#include "cubeparse.h"
+#include "cubeparse.h" /* must be after cubedata.h for YYSTYPE and NDBOX */
}
%{
{
ereport(ERROR, (errmsg_internal("%s", msg)));
}
-
-/* Handles to the buffer that the lexer uses internally */
-static YY_BUFFER_STATE scanbufhandle;
-static char *scanbuf;
%}
+%option reentrant
+%option bison-bridge
%option 8bit
%option never-interactive
%option nodefault
%option noinput
%option nounput
%option noyywrap
+%option noyyalloc
+%option noyyrealloc
+%option noyyfree
%option warn
%option prefix="cube_yy"
%%
-{float} cube_yylval = yytext; return CUBEFLOAT;
-{infinity} cube_yylval = yytext; return CUBEFLOAT;
-{NaN} cube_yylval = yytext; return CUBEFLOAT;
-\[ cube_yylval = "("; return O_BRACKET;
-\] cube_yylval = ")"; return C_BRACKET;
-\( cube_yylval = "("; return O_PAREN;
-\) cube_yylval = ")"; return C_PAREN;
-\, cube_yylval = ","; return COMMA;
+{float} *yylval = yytext; return CUBEFLOAT;
+{infinity} *yylval = yytext; return CUBEFLOAT;
+{NaN} *yylval = yytext; return CUBEFLOAT;
+\[ *yylval = "("; return O_BRACKET;
+\] *yylval = ")"; return C_BRACKET;
+\( *yylval = "("; return O_PAREN;
+\) *yylval = ")"; return C_PAREN;
+\, *yylval = ","; return COMMA;
[ \t\n\r\f\v]+ /* discard spaces */
. return yytext[0]; /* alert parser of the garbage */
void
cube_yyerror(NDBOX **result, Size scanbuflen,
struct Node *escontext,
+ yyscan_t yyscanner,
const char *message)
{
+ struct yyguts_t * yyg = (struct yyguts_t *) yyscanner; /* needed for yytext macro */
+
if (*yytext == YY_END_OF_BUFFER_CHAR)
{
errsave(escontext,
* Called before any actual parsing is done
*/
void
-cube_scanner_init(const char *str, Size *scanbuflen)
+cube_scanner_init(const char *str, Size *scanbuflen, yyscan_t *yyscannerp)
{
Size slen = strlen(str);
+ yyscan_t yyscanner;
- /*
- * Might be left over after ereport()
- */
- if (YY_CURRENT_BUFFER)
- yy_delete_buffer(YY_CURRENT_BUFFER);
+ if (yylex_init(yyscannerp) != 0)
+ elog(ERROR, "yylex_init() failed: %m");
- /*
- * Make a scan buffer with special termination needed by flex.
- */
- *scanbuflen = slen;
- scanbuf = palloc(slen + 2);
- memcpy(scanbuf, str, slen);
- scanbuf[slen] = scanbuf[slen + 1] = YY_END_OF_BUFFER_CHAR;
- scanbufhandle = yy_scan_buffer(scanbuf, slen + 2);
+ yyscanner = *yyscannerp;
- BEGIN(INITIAL);
+ yy_scan_bytes(str, slen, yyscanner);
+ *scanbuflen = slen;
}
* Called after parsing is done to clean up after cube_scanner_init()
*/
void
-cube_scanner_finish(void)
+cube_scanner_finish(yyscan_t yyscanner)
+{
+ yylex_destroy(yyscanner);
+}
+
+/*
+ * Interface functions to make flex use palloc() instead of malloc().
+ * It'd be better to make these static, but flex insists otherwise.
+ */
+
+void *
+yyalloc(yy_size_t size, yyscan_t yyscanner)
+{
+ return palloc(size);
+}
+
+void *
+yyrealloc(void *ptr, yy_size_t size, yyscan_t yyscanner)
+{
+ if (ptr)
+ return repalloc(ptr, size);
+ else
+ return palloc(size);
+}
+
+void
+yyfree(void *ptr, yyscan_t yyscanner)
{
- yy_delete_buffer(scanbufhandle);
- pfree(scanbuf);
+ if (ptr)
+ pfree(ptr);
}