#include <unistd.h>
#include "parser/gramparse.h"
-#include "parser/parser.h" /* only needed for GUC variables */
+#include "parser/parser.h" /* only needed for GUC variables */
#include "parser/scansup.h"
#include "mb/pg_wchar.h"
}
* But we shall have to live with it as a short-term thing until the switch
* to SQL-standard string syntax is complete.
*/
-int backslash_quote = BACKSLASH_QUOTE_SAFE_ENCODING;
-bool escape_string_warning = true;
-bool standard_conforming_strings = true;
+int backslash_quote = BACKSLASH_QUOTE_SAFE_ENCODING;
+bool escape_string_warning = true;
+bool standard_conforming_strings = true;
/*
* Set the type of YYSTYPE.
*/
#define ADVANCE_YYLLOC(delta) ( *(yylloc) += (delta) )
-#define startlit() ( yyextra->literallen = 0 )
+#define startlit() ( yyextra->literallen = 0 )
static void addlit(char *ytext, int yleng, core_yyscan_t yyscanner);
static void addlitchar(unsigned char ychar, core_yyscan_t yyscanner);
static char *litbufdup(core_yyscan_t yyscanner);
* instead we pass it separately to parser. there it gets
* coerced via doNegate() -- Leon aug 20 1999
*
-* {decimalfail} is used because we would like "1..10" to lex as 1, dot_dot, 10.
-*
+ * {decimalfail} is used because we would like "1..10" to lex as 1, dot_dot, 10.
+ *
* {realfail1} and {realfail2} are added to prevent the need for scanner
* backup when the {real} rule fails to match completely.
*/
const ScanKeyword *keyword;
SET_YYLLOC();
- yyless(1); /* eat only 'n' this time */
+ yyless(1); /* eat only 'n' this time */
keyword = ScanKeywordLookup("nchar",
yyextra->keywords,
/* xusend state looks for possible UESCAPE */
BEGIN(xusend);
}
-<xusend>{whitespace} { /* stay in xusend state over whitespace */ }
+<xusend>{whitespace} {
+ /* stay in xusend state over whitespace */
+ }
+<xusend><<EOF>> |
<xusend>{other} |
-<xusend>{xustop1} |
-<xusend><<EOF>> {
+<xusend>{xustop1} {
/* no UESCAPE after the quote, throw back everything */
yyless(0);
BEGIN(INITIAL);
<xusend>{xustop2} {
/* found UESCAPE after the end quote */
BEGIN(INITIAL);
- if (!check_uescapechar(yytext[yyleng-2]))
+ if (!check_uescapechar(yytext[yyleng - 2]))
{
SET_YYLLOC();
- ADVANCE_YYLLOC(yyleng-2);
+ ADVANCE_YYLLOC(yyleng - 2);
yyerror("invalid Unicode escape character");
}
- yylval->str = litbuf_udeescape(yytext[yyleng-2], yyscanner);
+ yylval->str = litbuf_udeescape(yytext[yyleng - 2],
+ yyscanner);
return SCONST;
}
<xq,xe,xus>{xqdouble} {
addlit(yytext, yyleng, yyscanner);
}
<xe>{xeunicode} {
- pg_wchar c = strtoul(yytext+2, NULL, 16);
+ pg_wchar c = strtoul(yytext + 2, NULL, 16);
check_escape_warning(yyscanner);
addunicode(c, yyscanner);
}
<xeu>{xeunicode} {
- pg_wchar c = strtoul(yytext+2, NULL, 16);
+ pg_wchar c = strtoul(yytext + 2, NULL, 16);
if (!is_utf16_surrogate_second(c))
yyerror("invalid Unicode surrogate pair");
<xeu>\n { yyerror("invalid Unicode surrogate pair"); }
<xeu><<EOF>> { yyerror("invalid Unicode surrogate pair"); }
<xe,xeu>{xeunicodefail} {
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_ESCAPE_SEQUENCE),
- errmsg("invalid Unicode escape"),
- errhint("Unicode escapes must be \\uXXXX or \\UXXXXXXXX."),
- lexer_errposition()));
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_ESCAPE_SEQUENCE),
+ errmsg("invalid Unicode escape"),
+ errhint("Unicode escapes must be \\uXXXX or \\UXXXXXXXX."),
+ lexer_errposition()));
}
<xe>{xeescape} {
if (yytext[1] == '\'')
yyscanner);
}
<xe>{xeoctesc} {
- unsigned char c = strtoul(yytext+1, NULL, 8);
+ unsigned char c = strtoul(yytext + 1, NULL, 8);
check_escape_warning(yyscanner);
addlitchar(c, yyscanner);
yyextra->saw_non_ascii = true;
}
<xe>{xehexesc} {
- unsigned char c = strtoul(yytext+2, NULL, 16);
+ unsigned char c = strtoul(yytext + 2, NULL, 16);
check_escape_warning(yyscanner);
addlitchar(c, yyscanner);
* the $... part to the output, but put back the final
* $ for rescanning. Consider $delim$...$junk$delim$
*/
- addlit(yytext, yyleng-1, yyscanner);
- yyless(yyleng-1);
+ addlit(yytext, yyleng - 1, yyscanner);
+ yyless(yyleng - 1);
}
}
<xdolq>{dolqinside} {
startlit();
}
<xd>{xdstop} {
- char *ident;
+ char *ident;
BEGIN(INITIAL);
if (yyextra->literallen == 0)
/* xuiend state looks for possible UESCAPE */
BEGIN(xuiend);
}
-<xuiend>{whitespace} { /* stay in xuiend state over whitespace */ }
+<xuiend>{whitespace} {
+ /* stay in xuiend state over whitespace */
+ }
+<xuiend><<EOF>> |
<xuiend>{other} |
-<xuiend>{xustop1} |
-<xuiend><<EOF>> {
+<xuiend>{xustop1} {
/* no UESCAPE after the quote, throw back everything */
char *ident;
int identlen;
BEGIN(INITIAL);
if (yyextra->literallen == 0)
yyerror("zero-length delimited identifier");
- if (!check_uescapechar(yytext[yyleng-2]))
+ if (!check_uescapechar(yytext[yyleng - 2]))
{
SET_YYLLOC();
- ADVANCE_YYLLOC(yyleng-2);
+ ADVANCE_YYLLOC(yyleng - 2);
yyerror("invalid Unicode escape character");
}
ident = litbuf_udeescape(yytext[yyleng - 2], yyscanner);
<xd,xui><<EOF>> { yyerror("unterminated quoted identifier"); }
{xufailed} {
- char *ident;
+ char *ident;
SET_YYLLOC();
/* throw back all but the initial u/U */
return COLON_EQUALS;
}
-{equals_greater} {
+{equals_greater} {
SET_YYLLOC();
return EQUALS_GREATER;
}
* Note that slash-star or dash-dash at the first
* character will match a prior rule, not this one.
*/
- int nchars = yyleng;
- char *slashstar = strstr(yytext, "/*");
- char *dashdash = strstr(yytext, "--");
+ int nchars = yyleng;
+ char *slashstar = strstr(yytext, "/*");
+ char *dashdash = strstr(yytext, "--");
if (slashstar && dashdash)
{
* sequences of SQL operators.
*/
while (nchars > 1 &&
- (yytext[nchars-1] == '+' ||
- yytext[nchars-1] == '-'))
+ (yytext[nchars - 1] == '+' ||
+ yytext[nchars - 1] == '-'))
{
- int ic;
+ int ic;
- for (ic = nchars-2; ic >= 0; ic--)
+ for (ic = nchars - 2; ic >= 0; ic--)
{
if (strchr("~!@#^&|`?%", yytext[ic]))
break;
}
{decimalfail} {
/* throw back the .., and treat as integer */
- yyless(yyleng-2);
+ yyless(yyleng - 2);
SET_YYLLOC();
return process_integer_literal(yytext, yylval);
}
* but since this case will almost certainly lead to a
* syntax error anyway, we don't bother to distinguish.
*/
- yyless(yyleng-1);
+ yyless(yyleng - 1);
SET_YYLLOC();
yylval->str = pstrdup(yytext);
return FCONST;
}
{realfail2} {
/* throw back the [Ee][+-], and proceed as above */
- yyless(yyleng-2);
+ yyless(yyleng - 2);
SET_YYLLOC();
yylval->str = pstrdup(yytext);
return FCONST;
{identifier} {
const ScanKeyword *keyword;
- char *ident;
+ char *ident;
SET_YYLLOC();
/* Likewise for a couple of other things we need. */
#undef yylloc
-#define yylloc (((struct yyguts_t *) yyscanner)->yylloc_r)
+#define yylloc (((struct yyguts_t *) yyscanner)->yylloc_r)
#undef yyleng
-#define yyleng (((struct yyguts_t *) yyscanner)->yyleng_r)
+#define yyleng (((struct yyguts_t *) yyscanner)->yyleng_r)
/*
int
scanner_errposition(int location, core_yyscan_t yyscanner)
{
- int pos;
+ int pos;
if (location < 0)
return 0; /* no-op if location is unknown */
{
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
- /* translator: %s is typically the translation of "syntax error" */
+ /* translator: %s is typically the translation of "syntax error" */
errmsg("%s at end of input", _(message)),
lexer_errposition()));
}
{
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
- /* translator: first %s is typically the translation of "syntax error" */
+ /* translator: first %s is typically the translation of "syntax error" */
errmsg("%s at or near \"%s\"", _(message), loc),
lexer_errposition()));
}
scanner_finish(core_yyscan_t yyscanner)
{
/*
- * We don't bother to call yylex_destroy(), because all it would do
- * is pfree a small amount of control storage. It's cheaper to leak
- * the storage until the parsing context is destroyed. The amount of
- * space involved is usually negligible compared to the output parse
- * tree anyway.
+ * We don't bother to call yylex_destroy(), because all it would do is
+ * pfree a small amount of control storage. It's cheaper to leak the
+ * storage until the parsing context is destroyed. The amount of space
+ * involved is usually negligible compared to the output parse tree
+ * anyway.
*
* We do bother to pfree the scanbuf and literal buffer, but only if they
* represent a nontrivial amount of space. The 8K cutoff is arbitrary.
/* enlarge buffer if needed */
if ((yyextra->literallen + yleng) >= yyextra->literalalloc)
{
- do {
+ do
+ {
yyextra->literalalloc *= 2;
} while ((yyextra->literallen + yleng) >= yyextra->literalalloc);
yyextra->literalbuf = (char *) repalloc(yyextra->literalbuf,
val = strtol(token, &endptr, 10);
if (*endptr != '\0' || errno == ERANGE
#ifdef HAVE_LONG_INT_64
- /* if long > 32 bits, check for overflow of int4 */
+ /* if long > 32 bits, check for overflow of int4 */
|| val != (long) ((int32) val)
#endif
)
if (c >= 'A' && c <= 'F')
return c - 'A' + 0xA;
elog(ERROR, "invalid hexadecimal digit");
- return 0; /* not reached */
+ return 0; /* not reached */
}
static void
if (c > 0x7F)
{
- ADVANCE_YYLLOC(loc - yyextra->literalbuf + 3); /* 3 for U&" */
+ ADVANCE_YYLLOC(loc - yyextra->literalbuf + 3); /* 3 for U&" */
yyerror("Unicode escape values cannot be used for code point values above 007F when the server encoding is not UTF8");
}
}
static void
addunicode(pg_wchar c, core_yyscan_t yyscanner)
{
- char buf[8];
+ char buf[8];
if (c == 0 || c > 0x10FFFF)
yyerror("invalid Unicode escape value");
static char *
litbuf_udeescape(unsigned char escape, core_yyscan_t yyscanner)
{
- char *new;
- char *litbuf, *in, *out;
- pg_wchar pair_first = 0;
+ char *new;
+ char *litbuf,
+ *in,
+ *out;
+ pg_wchar pair_first = 0;
/* Make literalbuf null-terminated to simplify the scanning loop */
litbuf = yyextra->literalbuf;
litbuf[yyextra->literallen] = '\0';
/*
- * This relies on the subtle assumption that a UTF-8 expansion
- * cannot be longer than its escaped representation.
+ * This relies on the subtle assumption that a UTF-8 expansion cannot be
+ * longer than its escaped representation.
*/
new = palloc(yyextra->literallen + 1);
{
if (pair_first)
{
- ADVANCE_YYLLOC(in - litbuf + 3); /* 3 for U&" */
+ ADVANCE_YYLLOC(in - litbuf + 3); /* 3 for U&" */
yyerror("invalid Unicode surrogate pair");
}
*out++ = escape;
isxdigit((unsigned char) in[3]) &&
isxdigit((unsigned char) in[4]))
{
- pg_wchar unicode;
+ pg_wchar unicode;
unicode = (hexval(in[1]) << 12) +
(hexval(in[2]) << 8) +
}
else
{
- ADVANCE_YYLLOC(in - litbuf + 3); /* 3 for U&" */
+ ADVANCE_YYLLOC(in - litbuf + 3); /* 3 for U&" */
yyerror("invalid Unicode surrogate pair");
}
}
isxdigit((unsigned char) in[6]) &&
isxdigit((unsigned char) in[7]))
{
- pg_wchar unicode;
+ pg_wchar unicode;
unicode = (hexval(in[2]) << 20) +
(hexval(in[3]) << 16) +
}
else
{
- ADVANCE_YYLLOC(in - litbuf + 3); /* 3 for U&" */
+ ADVANCE_YYLLOC(in - litbuf + 3); /* 3 for U&" */
yyerror("invalid Unicode surrogate pair");
}
}
}
else
{
- ADVANCE_YYLLOC(in - litbuf + 3); /* 3 for U&" */
+ ADVANCE_YYLLOC(in - litbuf + 3); /* 3 for U&" */
yyerror("invalid Unicode escape value");
}
}
{
if (pair_first)
{
- ADVANCE_YYLLOC(in - litbuf + 3); /* 3 for U&" */
+ ADVANCE_YYLLOC(in - litbuf + 3); /* 3 for U&" */
yyerror("invalid Unicode surrogate pair");
}
*out++ = *in++;
}
*out = '\0';
+
/*
* We could skip pg_verifymbstr if we didn't process any non-7-bit-ASCII
- * codes; but it's probably not worth the trouble, since this isn't
- * likely to be a performance-critical path.
+ * codes; but it's probably not worth the trouble, since this isn't likely
+ * to be a performance-critical path.
*/
pg_verifymbstr(new, out - new, false);
return new;
ereport(WARNING,
(errcode(ERRCODE_NONSTANDARD_USE_OF_ESCAPE_CHARACTER),
errmsg("nonstandard use of escape in a string literal"),
- errhint("Use the escape string syntax for escapes, e.g., E'\\r\\n'."),
+ errhint("Use the escape string syntax for escapes, e.g., E'\\r\\n'."),
lexer_errposition()));
- yyextra->warn_on_first_escape = false; /* warn only once per string */
+ yyextra->warn_on_first_escape = false; /* warn only once per string */
}
/*
* src/backend/parser/scan.l so far as the flex patterns are concerned.
* The rule bodies are just ECHO as opposed to what the backend does,
* however. (But be sure to duplicate code that affects the lexing process,
- * such as BEGIN().) Also, psqlscan uses a single <<EOF>> rule whereas
- * scan.l has a separate one for each exclusive state.
+ * such as BEGIN() and yyless().) Also, psqlscan uses a single <<EOF>> rule
+ * whereas scan.l has a separate one for each exclusive state.
*/
/*
/*
* Force flex into the state indicated by start_state. This has a
- * couple of purposes: it lets some of the functions below set a
- * new starting state without ugly direct access to flex variables,
- * and it allows us to transition from one flex lexer to another
- * so that we can lex different parts of the source string using
- * separate lexers.
+ * couple of purposes: it lets some of the functions below set a new
+ * starting state without ugly direct access to flex variables, and it
+ * allows us to transition from one flex lexer to another so that we
+ * can lex different parts of the source string using separate lexers.
*/
BEGIN(cur_state->start_state);
%}
<xc>{xcstop} {
if (cur_state->xcdepth <= 0)
- {
BEGIN(INITIAL);
- }
else
cur_state->xcdepth--;
ECHO;
}
{xnstart} {
- yyless(1); /* eat only 'n' this time */
+ yyless(1); /* eat only 'n' this time */
ECHO;
}
}
<xus>{quotestop} |
<xus>{quotefail} {
+ /* throw back all but the quote */
yyless(1);
BEGIN(xusend);
ECHO;
* the $... part to the output, but put back the final
* $ for rescanning. Consider $delim$...$junk$delim$
*/
- yyless(yyleng-1);
+ yyless(yyleng - 1);
}
ECHO;
}
:{variable_char}+ {
/* Possible psql variable substitution */
- char *varname;
- char *value;
+ char *varname;
+ char *value;
varname = psqlscan_extract_substring(cur_state,
yytext + 1,
else
{
/*
- * if the variable doesn't exist we'll copy the
- * string as is
+ * if the variable doesn't exist we'll copy the string
+ * as is
*/
ECHO;
}
* Note that slash-star or dash-dash at the first
* character will match a prior rule, not this one.
*/
- int nchars = yyleng;
- char *slashstar = strstr(yytext, "/*");
- char *dashdash = strstr(yytext, "--");
+ int nchars = yyleng;
+ char *slashstar = strstr(yytext, "/*");
+ char *dashdash = strstr(yytext, "--");
if (slashstar && dashdash)
{
* sequences of SQL operators.
*/
while (nchars > 1 &&
- (yytext[nchars-1] == '+' ||
- yytext[nchars-1] == '-'))
+ (yytext[nchars - 1] == '+' ||
+ yytext[nchars - 1] == '-'))
{
- int ic;
+ int ic;
- for (ic = nchars-2; ic >= 0; ic--)
+ for (ic = nchars - 2; ic >= 0; ic--)
{
if (strchr("~!@#^&|`?%", yytext[ic]))
break;
}
{decimalfail} {
/* throw back the .., and treat as integer */
- yyless(yyleng-2);
+ yyless(yyleng - 2);
ECHO;
}
{real} {
* but since this case will almost certainly lead to a
* syntax error anyway, we don't bother to distinguish.
*/
- yyless(yyleng-1);
+ yyless(yyleng - 1);
ECHO;
}
{realfail2} {
/* throw back the [Ee][+-], and proceed as above */
- yyless(yyleng-2);
+ yyless(yyleng - 2);
ECHO;
}
ECHO;
}
- /*
- * psql uses a single <<EOF>> rule, unlike the backend.
- */
-
<<EOF>> {
if (cur_state->buffer_stack == NULL)
{
cur_state->start_state = YY_START;
- return LEXRES_EOL; /* end of input reached */
+ return LEXRES_EOL; /* end of input reached */
}
/*
stackelem = (StackElem *) pg_malloc(sizeof(StackElem));
/*
- * In current usage, the passed varname points at the current flex
- * input buffer; we must copy it before calling psqlscan_prepare_buffer()
+ * In current usage, the passed varname points at the current flex input
+ * buffer; we must copy it before calling psqlscan_prepare_buffer()
* because that will change the buffer state.
*/
stackelem->varname = varname ? pg_strdup(varname) : NULL;
else
{
/* Gotta do it the hard way */
- int i = 0;
+ int i = 0;
while (i < len)
{
- int thislen = PQmblen(txt + i, state->encoding);
+ int thislen = PQmblen(txt + i, state->encoding);
/* first byte should always be okay... */
newtxt[i] = txt[i];
{
/* Gotta do it the hard way */
const char *reference = state->refline;
- int i;
+ int i;
reference += (txt - state->curline);
for (i = 0; i < len; i++)
{
- char ch = txt[i];
+ char ch = txt[i];
if (ch == (char) 0xFF)
ch = reference[i];
{
/* Gotta do it the hard way */
const char *reference = state->refline;
- int i;
+ int i;
reference += (txt - state->curline);
for (i = 0; i < len; i++)
{
- char ch = txt[i];
+ char ch = txt[i];
if (ch == (char) 0xFF)
ch = reference[i];
*
* If the variable name is found, escape its value using the appropriate
* quoting method and emit the value to output_buf. (Since the result is
- * surely quoted, there is never any reason to rescan it.) If we don't
+ * surely quoted, there is never any reason to rescan it.) If we don't
* find the variable or escaping fails, emit the token as-is.
*/
void