2022-09-04 11:33:31 +07:00
|
|
|
%top{
|
2010-11-23 22:27:50 +02:00
|
|
|
/*
|
|
|
|
* A scanner for EMP-style numeric ranges
|
|
|
|
*/
|
2022-09-04 11:33:31 +07:00
|
|
|
#include "postgres.h"
|
|
|
|
|
2022-12-23 09:17:24 -05:00
|
|
|
#include "nodes/miscnodes.h"
|
|
|
|
|
2022-09-04 11:33:31 +07:00
|
|
|
#include "segdata.h"
|
seg: pure parser and reentrant scanner
Use the flex %option reentrant and the bison option %pure-parser to
make the generated scanner and parser pure, reentrant, and
thread-safe.
Make the generated scanner use palloc() etc. instead of malloc() etc.
Previously, we only used palloc() for the buffer, but flex would still
use malloc() for its internal structures. As a result, there could be
some small memory leaks in case of uncaught errors. (We do catch
normal syntax errors as soft errors.) Now, all the memory is under
palloc() control, so there are no more such issues.
Simplify flex scan buffer management: Instead of constructing the
buffer from pieces and then using yy_scan_buffer(), we can just use
yy_scan_string(), which does the same thing internally.
The previous code was necessary because we allocated the buffer with
palloc() and the rest of the state was handled by malloc(). But this
is no longer the case; everything is under palloc() now.
(We could even get rid of the yylex_destroy() call and just let the
memory context cleanup handle everything. But for now, we preserve
the existing behavior.)
Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>
Reviewed-by: Andreas Karlsson <andreas@proxel.se>
Discussion: https://www.postgresql.org/message-id/flat/eb6faeac-2a8a-4b69-9189-c33c520e5b7b@eisentraut.org
2024-12-18 08:47:53 +01:00
|
|
|
#include "segparse.h" /* must be after segdata.h for SEG */
|
2022-09-04 11:33:31 +07:00
|
|
|
}
|
2000-12-11 20:40:33 +00:00
|
|
|
|
2022-09-04 11:33:31 +07:00
|
|
|
%{
|
2017-08-10 23:33:47 -04:00
|
|
|
/* LCOV_EXCL_START */
|
|
|
|
|
2003-09-14 02:18:49 +00:00
|
|
|
/* No reason to constrain amount of data slurped */
|
|
|
|
#define YY_READ_BUF_SIZE 16777216
|
2000-12-11 20:40:33 +00:00
|
|
|
|
2003-05-29 22:30:02 +00:00
|
|
|
/* Avoid exit() on fatal scanner errors (a bit ugly -- see yy_fatal_error) */
|
2005-10-15 20:37:36 +00:00
|
|
|
#undef fprintf
|
Improve handling of ereport(ERROR) and elog(ERROR).
In commit 71450d7fd6c7cf7b3e38ac56e363bff6a681973c, we added code to inform
suitably-intelligent compilers that ereport() doesn't return if the elevel
is ERROR or higher. This patch extends that to elog(), and also fixes a
double-evaluation hazard that the previous commit created in ereport(),
as well as reducing the emitted code size.
The elog() improvement requires the compiler to support __VA_ARGS__, which
should be available in just about anything nowadays since it's required by
C99. But our minimum language baseline is still C89, so add a configure
test for that.
The previous commit assumed that ereport's elevel could be evaluated twice,
which isn't terribly safe --- there are already counterexamples in xlog.c.
On compilers that have __builtin_constant_p, we can use that to protect the
second test, since there's no possible optimization gain if the compiler
doesn't know the value of elevel. Otherwise, use a local variable inside
the macros to prevent double evaluation. The local-variable solution is
inferior because (a) it leads to useless code being emitted when elevel
isn't constant, and (b) it increases the optimization level needed for the
compiler to recognize that subsequent code is unreachable. But it seems
better than not teaching non-gcc compilers about unreachability at all.
Lastly, if the compiler has __builtin_unreachable(), we can use that
instead of abort(), resulting in a noticeable code savings since no
function call is actually emitted. However, it seems wise to do this only
in non-assert builds. In an assert build, continue to use abort(), so that
the behavior will be predictable and debuggable if the "impossible"
happens.
These changes involve making the ereport and elog macros emit do-while
statement blocks not just expressions, which forces small changes in
a few call sites.
Andres Freund, Tom Lane, Heikki Linnakangas
2013-01-13 18:39:20 -05:00
|
|
|
#define fprintf(file, fmt, msg) fprintf_to_ereport(fmt, msg)
|
|
|
|
|
|
|
|
static void
|
|
|
|
fprintf_to_ereport(const char *fmt, const char *msg)
|
|
|
|
{
|
|
|
|
ereport(ERROR, (errmsg_internal("%s", msg)));
|
|
|
|
}
|
2000-12-11 20:40:33 +00:00
|
|
|
%}
|
|
|
|
|
seg: pure parser and reentrant scanner
Use the flex %option reentrant and the bison option %pure-parser to
make the generated scanner and parser pure, reentrant, and
thread-safe.
Make the generated scanner use palloc() etc. instead of malloc() etc.
Previously, we only used palloc() for the buffer, but flex would still
use malloc() for its internal structures. As a result, there could be
some small memory leaks in case of uncaught errors. (We do catch
normal syntax errors as soft errors.) Now, all the memory is under
palloc() control, so there are no more such issues.
Simplify flex scan buffer management: Instead of constructing the
buffer from pieces and then using yy_scan_buffer(), we can just use
yy_scan_string(), which does the same thing internally.
The previous code was necessary because we allocated the buffer with
palloc() and the rest of the state was handled by malloc(). But this
is no longer the case; everything is under palloc() now.
(We could even get rid of the yylex_destroy() call and just let the
memory context cleanup handle everything. But for now, we preserve
the existing behavior.)
Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>
Reviewed-by: Andreas Karlsson <andreas@proxel.se>
Discussion: https://www.postgresql.org/message-id/flat/eb6faeac-2a8a-4b69-9189-c33c520e5b7b@eisentraut.org
2024-12-18 08:47:53 +01:00
|
|
|
%option reentrant
|
|
|
|
%option bison-bridge
|
2002-07-30 16:33:08 +00:00
|
|
|
%option 8bit
|
|
|
|
%option never-interactive
|
2004-02-24 22:06:32 +00:00
|
|
|
%option nodefault
|
2008-08-25 23:12:45 +00:00
|
|
|
%option noinput
|
2002-07-30 16:33:08 +00:00
|
|
|
%option nounput
|
|
|
|
%option noyywrap
|
seg: pure parser and reentrant scanner
Use the flex %option reentrant and the bison option %pure-parser to
make the generated scanner and parser pure, reentrant, and
thread-safe.
Make the generated scanner use palloc() etc. instead of malloc() etc.
Previously, we only used palloc() for the buffer, but flex would still
use malloc() for its internal structures. As a result, there could be
some small memory leaks in case of uncaught errors. (We do catch
normal syntax errors as soft errors.) Now, all the memory is under
palloc() control, so there are no more such issues.
Simplify flex scan buffer management: Instead of constructing the
buffer from pieces and then using yy_scan_buffer(), we can just use
yy_scan_string(), which does the same thing internally.
The previous code was necessary because we allocated the buffer with
palloc() and the rest of the state was handled by malloc(). But this
is no longer the case; everything is under palloc() now.
(We could even get rid of the yylex_destroy() call and just let the
memory context cleanup handle everything. But for now, we preserve
the existing behavior.)
Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>
Reviewed-by: Andreas Karlsson <andreas@proxel.se>
Discussion: https://www.postgresql.org/message-id/flat/eb6faeac-2a8a-4b69-9189-c33c520e5b7b@eisentraut.org
2024-12-18 08:47:53 +01:00
|
|
|
%option noyyalloc
|
|
|
|
%option noyyrealloc
|
|
|
|
%option noyyfree
|
2011-08-25 13:55:57 -04:00
|
|
|
%option warn
|
2003-09-14 02:18:49 +00:00
|
|
|
%option prefix="seg_yy"
|
2002-07-30 16:33:08 +00:00
|
|
|
|
|
|
|
|
2000-12-11 20:40:33 +00:00
|
|
|
range (\.\.)(\.)?
|
|
|
|
plumin (\'\+\-\')|(\(\+\-)\)
|
|
|
|
integer [+-]?[0-9]+
|
|
|
|
real [+-]?[0-9]+\.[0-9]+
|
|
|
|
float ({integer}|{real})([eE]{integer})?
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
seg: pure parser and reentrant scanner
Use the flex %option reentrant and the bison option %pure-parser to
make the generated scanner and parser pure, reentrant, and
thread-safe.
Make the generated scanner use palloc() etc. instead of malloc() etc.
Previously, we only used palloc() for the buffer, but flex would still
use malloc() for its internal structures. As a result, there could be
some small memory leaks in case of uncaught errors. (We do catch
normal syntax errors as soft errors.) Now, all the memory is under
palloc() control, so there are no more such issues.
Simplify flex scan buffer management: Instead of constructing the
buffer from pieces and then using yy_scan_buffer(), we can just use
yy_scan_string(), which does the same thing internally.
The previous code was necessary because we allocated the buffer with
palloc() and the rest of the state was handled by malloc(). But this
is no longer the case; everything is under palloc() now.
(We could even get rid of the yylex_destroy() call and just let the
memory context cleanup handle everything. But for now, we preserve
the existing behavior.)
Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>
Reviewed-by: Andreas Karlsson <andreas@proxel.se>
Discussion: https://www.postgresql.org/message-id/flat/eb6faeac-2a8a-4b69-9189-c33c520e5b7b@eisentraut.org
2024-12-18 08:47:53 +01:00
|
|
|
{range} yylval->text = yytext; return RANGE;
|
|
|
|
{plumin} yylval->text = yytext; return PLUMIN;
|
|
|
|
{float} yylval->text = yytext; return SEGFLOAT;
|
|
|
|
\< yylval->text = "<"; return EXTENSION;
|
|
|
|
\> yylval->text = ">"; return EXTENSION;
|
|
|
|
\~ yylval->text = "~"; return EXTENSION;
|
Handle \v as a whitespace character in parsers
This commit comes as a continuation of the discussion that has led to
d522b05, as \v was handled inconsistently when parsing array values or
anything going through the parsers, and changing a parser behavior in
stable branches is a scary thing to do. The parsing of array values now
uses the more central scanner_isspace() and array_isspace() is removed.
As pointing out by Peter Eisentraut, fix a confusing reference to
horizontal space in the parsers with the term "horiz_space". \f was
included in this set since 3cfdd8f from 2000, but it is not horizontal.
"horiz_space" is renamed to "non_newline_space", to refer to all
whitespace characters except newlines.
The changes impact the parsers for the backend, psql, seg, cube, ecpg
and replication commands. Note that JSON should not escape \v, as per
RFC 7159, so these are not touched.
Reviewed-by: Peter Eisentraut, Tom Lane
Discussion: https://postgr.es/m/ZJKcjNwWHHvw9ksQ@paquier.xyz
2023-07-06 08:16:24 +09:00
|
|
|
[ \t\n\r\f\v]+ /* discard spaces */
|
2000-12-11 20:40:33 +00:00
|
|
|
. return yytext[0]; /* alert parser of the garbage */
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
2017-08-10 23:33:47 -04:00
|
|
|
/* LCOV_EXCL_STOP */
|
|
|
|
|
2015-03-11 14:19:54 +01:00
|
|
|
void
|
seg: pure parser and reentrant scanner
Use the flex %option reentrant and the bison option %pure-parser to
make the generated scanner and parser pure, reentrant, and
thread-safe.
Make the generated scanner use palloc() etc. instead of malloc() etc.
Previously, we only used palloc() for the buffer, but flex would still
use malloc() for its internal structures. As a result, there could be
some small memory leaks in case of uncaught errors. (We do catch
normal syntax errors as soft errors.) Now, all the memory is under
palloc() control, so there are no more such issues.
Simplify flex scan buffer management: Instead of constructing the
buffer from pieces and then using yy_scan_buffer(), we can just use
yy_scan_string(), which does the same thing internally.
The previous code was necessary because we allocated the buffer with
palloc() and the rest of the state was handled by malloc(). But this
is no longer the case; everything is under palloc() now.
(We could even get rid of the yylex_destroy() call and just let the
memory context cleanup handle everything. But for now, we preserve
the existing behavior.)
Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>
Reviewed-by: Andreas Karlsson <andreas@proxel.se>
Discussion: https://www.postgresql.org/message-id/flat/eb6faeac-2a8a-4b69-9189-c33c520e5b7b@eisentraut.org
2024-12-18 08:47:53 +01:00
|
|
|
seg_yyerror(SEG *result, struct Node *escontext, yyscan_t yyscanner, const char *message)
|
2003-09-14 02:18:49 +00:00
|
|
|
{
|
seg: pure parser and reentrant scanner
Use the flex %option reentrant and the bison option %pure-parser to
make the generated scanner and parser pure, reentrant, and
thread-safe.
Make the generated scanner use palloc() etc. instead of malloc() etc.
Previously, we only used palloc() for the buffer, but flex would still
use malloc() for its internal structures. As a result, there could be
some small memory leaks in case of uncaught errors. (We do catch
normal syntax errors as soft errors.) Now, all the memory is under
palloc() control, so there are no more such issues.
Simplify flex scan buffer management: Instead of constructing the
buffer from pieces and then using yy_scan_buffer(), we can just use
yy_scan_string(), which does the same thing internally.
The previous code was necessary because we allocated the buffer with
palloc() and the rest of the state was handled by malloc(). But this
is no longer the case; everything is under palloc() now.
(We could even get rid of the yylex_destroy() call and just let the
memory context cleanup handle everything. But for now, we preserve
the existing behavior.)
Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>
Reviewed-by: Andreas Karlsson <andreas@proxel.se>
Discussion: https://www.postgresql.org/message-id/flat/eb6faeac-2a8a-4b69-9189-c33c520e5b7b@eisentraut.org
2024-12-18 08:47:53 +01:00
|
|
|
struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; /* needed for yytext
|
|
|
|
* macro */
|
|
|
|
|
2022-12-23 09:17:24 -05:00
|
|
|
/* if we already reported an error, don't overwrite it */
|
|
|
|
if (SOFT_ERROR_OCCURRED(escontext))
|
|
|
|
return;
|
|
|
|
|
2003-09-14 02:18:49 +00:00
|
|
|
if (*yytext == YY_END_OF_BUFFER_CHAR)
|
|
|
|
{
|
2022-12-23 09:17:24 -05:00
|
|
|
errsave(escontext,
|
2003-09-14 02:18:49 +00:00
|
|
|
(errcode(ERRCODE_SYNTAX_ERROR),
|
|
|
|
errmsg("bad seg representation"),
|
|
|
|
/* translator: %s is typically "syntax error" */
|
|
|
|
errdetail("%s at end of input", message)));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-12-23 09:17:24 -05:00
|
|
|
errsave(escontext,
|
2003-09-14 02:18:49 +00:00
|
|
|
(errcode(ERRCODE_SYNTAX_ERROR),
|
|
|
|
errmsg("bad seg representation"),
|
|
|
|
/* translator: first %s is typically "syntax error" */
|
|
|
|
errdetail("%s at or near \"%s\"", message, yytext)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called before any actual parsing is done
|
|
|
|
*/
|
|
|
|
void
|
seg: pure parser and reentrant scanner
Use the flex %option reentrant and the bison option %pure-parser to
make the generated scanner and parser pure, reentrant, and
thread-safe.
Make the generated scanner use palloc() etc. instead of malloc() etc.
Previously, we only used palloc() for the buffer, but flex would still
use malloc() for its internal structures. As a result, there could be
some small memory leaks in case of uncaught errors. (We do catch
normal syntax errors as soft errors.) Now, all the memory is under
palloc() control, so there are no more such issues.
Simplify flex scan buffer management: Instead of constructing the
buffer from pieces and then using yy_scan_buffer(), we can just use
yy_scan_string(), which does the same thing internally.
The previous code was necessary because we allocated the buffer with
palloc() and the rest of the state was handled by malloc(). But this
is no longer the case; everything is under palloc() now.
(We could even get rid of the yylex_destroy() call and just let the
memory context cleanup handle everything. But for now, we preserve
the existing behavior.)
Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>
Reviewed-by: Andreas Karlsson <andreas@proxel.se>
Discussion: https://www.postgresql.org/message-id/flat/eb6faeac-2a8a-4b69-9189-c33c520e5b7b@eisentraut.org
2024-12-18 08:47:53 +01:00
|
|
|
seg_scanner_init(const char *str, yyscan_t *yyscannerp)
|
2003-09-14 02:18:49 +00:00
|
|
|
{
|
seg: pure parser and reentrant scanner
Use the flex %option reentrant and the bison option %pure-parser to
make the generated scanner and parser pure, reentrant, and
thread-safe.
Make the generated scanner use palloc() etc. instead of malloc() etc.
Previously, we only used palloc() for the buffer, but flex would still
use malloc() for its internal structures. As a result, there could be
some small memory leaks in case of uncaught errors. (We do catch
normal syntax errors as soft errors.) Now, all the memory is under
palloc() control, so there are no more such issues.
Simplify flex scan buffer management: Instead of constructing the
buffer from pieces and then using yy_scan_buffer(), we can just use
yy_scan_string(), which does the same thing internally.
The previous code was necessary because we allocated the buffer with
palloc() and the rest of the state was handled by malloc(). But this
is no longer the case; everything is under palloc() now.
(We could even get rid of the yylex_destroy() call and just let the
memory context cleanup handle everything. But for now, we preserve
the existing behavior.)
Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>
Reviewed-by: Andreas Karlsson <andreas@proxel.se>
Discussion: https://www.postgresql.org/message-id/flat/eb6faeac-2a8a-4b69-9189-c33c520e5b7b@eisentraut.org
2024-12-18 08:47:53 +01:00
|
|
|
yyscan_t yyscanner;
|
|
|
|
|
|
|
|
if (yylex_init(yyscannerp) != 0)
|
|
|
|
elog(ERROR, "yylex_init() failed: %m");
|
|
|
|
|
|
|
|
yyscanner = *yyscannerp;
|
|
|
|
|
|
|
|
yy_scan_string(str, yyscanner);
|
2003-09-14 02:18:49 +00:00
|
|
|
}
|
|
|
|
|
2000-12-11 20:40:33 +00:00
|
|
|
|
2003-09-14 02:18:49 +00:00
|
|
|
/*
|
|
|
|
* Called after parsing is done to clean up after seg_scanner_init()
|
|
|
|
*/
|
|
|
|
void
|
seg: pure parser and reentrant scanner
Use the flex %option reentrant and the bison option %pure-parser to
make the generated scanner and parser pure, reentrant, and
thread-safe.
Make the generated scanner use palloc() etc. instead of malloc() etc.
Previously, we only used palloc() for the buffer, but flex would still
use malloc() for its internal structures. As a result, there could be
some small memory leaks in case of uncaught errors. (We do catch
normal syntax errors as soft errors.) Now, all the memory is under
palloc() control, so there are no more such issues.
Simplify flex scan buffer management: Instead of constructing the
buffer from pieces and then using yy_scan_buffer(), we can just use
yy_scan_string(), which does the same thing internally.
The previous code was necessary because we allocated the buffer with
palloc() and the rest of the state was handled by malloc(). But this
is no longer the case; everything is under palloc() now.
(We could even get rid of the yylex_destroy() call and just let the
memory context cleanup handle everything. But for now, we preserve
the existing behavior.)
Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>
Reviewed-by: Andreas Karlsson <andreas@proxel.se>
Discussion: https://www.postgresql.org/message-id/flat/eb6faeac-2a8a-4b69-9189-c33c520e5b7b@eisentraut.org
2024-12-18 08:47:53 +01:00
|
|
|
seg_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)
|
2003-09-14 02:18:49 +00:00
|
|
|
{
|
seg: pure parser and reentrant scanner
Use the flex %option reentrant and the bison option %pure-parser to
make the generated scanner and parser pure, reentrant, and
thread-safe.
Make the generated scanner use palloc() etc. instead of malloc() etc.
Previously, we only used palloc() for the buffer, but flex would still
use malloc() for its internal structures. As a result, there could be
some small memory leaks in case of uncaught errors. (We do catch
normal syntax errors as soft errors.) Now, all the memory is under
palloc() control, so there are no more such issues.
Simplify flex scan buffer management: Instead of constructing the
buffer from pieces and then using yy_scan_buffer(), we can just use
yy_scan_string(), which does the same thing internally.
The previous code was necessary because we allocated the buffer with
palloc() and the rest of the state was handled by malloc(). But this
is no longer the case; everything is under palloc() now.
(We could even get rid of the yylex_destroy() call and just let the
memory context cleanup handle everything. But for now, we preserve
the existing behavior.)
Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>
Reviewed-by: Andreas Karlsson <andreas@proxel.se>
Discussion: https://www.postgresql.org/message-id/flat/eb6faeac-2a8a-4b69-9189-c33c520e5b7b@eisentraut.org
2024-12-18 08:47:53 +01:00
|
|
|
if (ptr)
|
|
|
|
pfree(ptr);
|
2000-12-11 20:40:33 +00:00
|
|
|
}
|