Commit 21c8ee79 authored by Tom Lane's avatar Tom Lane

Sync backend/parser/scan.l with bin/psql/psqlscan.l.

Make some minor formatting adjustments to make it easier to diff these
files and see that they indeed implement the same flex rules (at least
to the extent that we want them to be the same).

(Someday it'd be nice to make ecpg's pgc.l more easily diff'able too,
but today is not that day.)

Also run relevant parts of these files and psqlscanslash.l through
pgindent.

No actual behavioral changes here, just obsessive neatnik-ism.
parent 72b1e3a2
This diff is collapsed.
...@@ -78,8 +78,8 @@ extern void psql_yyset_column(int column_no, yyscan_t yyscanner); ...@@ -78,8 +78,8 @@ extern void psql_yyset_column(int column_no, yyscan_t yyscanner);
* src/backend/parser/scan.l so far as the flex patterns are concerned. * 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, * 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, * however. (But be sure to duplicate code that affects the lexing process,
* such as BEGIN().) Also, psqlscan uses a single <<EOF>> rule whereas * such as BEGIN() and yyless().) Also, psqlscan uses a single <<EOF>> rule
* scan.l has a separate one for each exclusive state. * whereas scan.l has a separate one for each exclusive state.
*/ */
/* /*
...@@ -351,11 +351,10 @@ other . ...@@ -351,11 +351,10 @@ other .
/* /*
* Force flex into the state indicated by start_state. This has a * Force flex into the state indicated by start_state. This has a
* couple of purposes: it lets some of the functions below set a * couple of purposes: it lets some of the functions below set a new
* new starting state without ugly direct access to flex variables, * starting state without ugly direct access to flex variables, and it
* and it allows us to transition from one flex lexer to another * allows us to transition from one flex lexer to another so that we
* so that we can lex different parts of the source string using * can lex different parts of the source string using separate lexers.
* separate lexers.
*/ */
BEGIN(cur_state->start_state); BEGIN(cur_state->start_state);
%} %}
...@@ -390,9 +389,7 @@ other . ...@@ -390,9 +389,7 @@ other .
<xc>{xcstop} { <xc>{xcstop} {
if (cur_state->xcdepth <= 0) if (cur_state->xcdepth <= 0)
{
BEGIN(INITIAL); BEGIN(INITIAL);
}
else else
cur_state->xcdepth--; cur_state->xcdepth--;
ECHO; ECHO;
...@@ -447,7 +444,7 @@ other . ...@@ -447,7 +444,7 @@ other .
} }
{xnstart} { {xnstart} {
yyless(1); /* eat only 'n' this time */ yyless(1); /* eat only 'n' this time */
ECHO; ECHO;
} }
...@@ -474,6 +471,7 @@ other . ...@@ -474,6 +471,7 @@ other .
} }
<xus>{quotestop} | <xus>{quotestop} |
<xus>{quotefail} { <xus>{quotefail} {
/* throw back all but the quote */
yyless(1); yyless(1);
BEGIN(xusend); BEGIN(xusend);
ECHO; ECHO;
...@@ -547,7 +545,7 @@ other . ...@@ -547,7 +545,7 @@ other .
* the $... part to the output, but put back the final * the $... part to the output, but put back the final
* $ for rescanning. Consider $delim$...$junk$delim$ * $ for rescanning. Consider $delim$...$junk$delim$
*/ */
yyless(yyleng-1); yyless(yyleng - 1);
} }
ECHO; ECHO;
} }
...@@ -682,8 +680,8 @@ other . ...@@ -682,8 +680,8 @@ other .
:{variable_char}+ { :{variable_char}+ {
/* Possible psql variable substitution */ /* Possible psql variable substitution */
char *varname; char *varname;
char *value; char *value;
varname = psqlscan_extract_substring(cur_state, varname = psqlscan_extract_substring(cur_state,
yytext + 1, yytext + 1,
...@@ -717,8 +715,8 @@ other . ...@@ -717,8 +715,8 @@ other .
else else
{ {
/* /*
* if the variable doesn't exist we'll copy the * if the variable doesn't exist we'll copy the string
* string as is * as is
*/ */
ECHO; ECHO;
} }
...@@ -766,9 +764,9 @@ other . ...@@ -766,9 +764,9 @@ other .
* Note that slash-star or dash-dash at the first * Note that slash-star or dash-dash at the first
* character will match a prior rule, not this one. * character will match a prior rule, not this one.
*/ */
int nchars = yyleng; int nchars = yyleng;
char *slashstar = strstr(yytext, "/*"); char *slashstar = strstr(yytext, "/*");
char *dashdash = strstr(yytext, "--"); char *dashdash = strstr(yytext, "--");
if (slashstar && dashdash) if (slashstar && dashdash)
{ {
...@@ -790,12 +788,12 @@ other . ...@@ -790,12 +788,12 @@ other .
* sequences of SQL operators. * sequences of SQL operators.
*/ */
while (nchars > 1 && 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])) if (strchr("~!@#^&|`?%", yytext[ic]))
break; break;
...@@ -825,7 +823,7 @@ other . ...@@ -825,7 +823,7 @@ other .
} }
{decimalfail} { {decimalfail} {
/* throw back the .., and treat as integer */ /* throw back the .., and treat as integer */
yyless(yyleng-2); yyless(yyleng - 2);
ECHO; ECHO;
} }
{real} { {real} {
...@@ -838,12 +836,12 @@ other . ...@@ -838,12 +836,12 @@ other .
* but since this case will almost certainly lead to a * but since this case will almost certainly lead to a
* syntax error anyway, we don't bother to distinguish. * syntax error anyway, we don't bother to distinguish.
*/ */
yyless(yyleng-1); yyless(yyleng - 1);
ECHO; ECHO;
} }
{realfail2} { {realfail2} {
/* throw back the [Ee][+-], and proceed as above */ /* throw back the [Ee][+-], and proceed as above */
yyless(yyleng-2); yyless(yyleng - 2);
ECHO; ECHO;
} }
...@@ -856,15 +854,11 @@ other . ...@@ -856,15 +854,11 @@ other .
ECHO; ECHO;
} }
/*
* psql uses a single <<EOF>> rule, unlike the backend.
*/
<<EOF>> { <<EOF>> {
if (cur_state->buffer_stack == NULL) if (cur_state->buffer_stack == NULL)
{ {
cur_state->start_state = YY_START; cur_state->start_state = YY_START;
return LEXRES_EOL; /* end of input reached */ return LEXRES_EOL; /* end of input reached */
} }
/* /*
...@@ -1192,8 +1186,8 @@ psqlscan_push_new_buffer(PsqlScanState state, const char *newstr, ...@@ -1192,8 +1186,8 @@ psqlscan_push_new_buffer(PsqlScanState state, const char *newstr,
stackelem = (StackElem *) pg_malloc(sizeof(StackElem)); stackelem = (StackElem *) pg_malloc(sizeof(StackElem));
/* /*
* In current usage, the passed varname points at the current flex * In current usage, the passed varname points at the current flex input
* input buffer; we must copy it before calling psqlscan_prepare_buffer() * buffer; we must copy it before calling psqlscan_prepare_buffer()
* because that will change the buffer state. * because that will change the buffer state.
*/ */
stackelem->varname = varname ? pg_strdup(varname) : NULL; stackelem->varname = varname ? pg_strdup(varname) : NULL;
...@@ -1301,11 +1295,11 @@ psqlscan_prepare_buffer(PsqlScanState state, const char *txt, int len, ...@@ -1301,11 +1295,11 @@ psqlscan_prepare_buffer(PsqlScanState state, const char *txt, int len,
else else
{ {
/* Gotta do it the hard way */ /* Gotta do it the hard way */
int i = 0; int i = 0;
while (i < len) while (i < len)
{ {
int thislen = PQmblen(txt + i, state->encoding); int thislen = PQmblen(txt + i, state->encoding);
/* first byte should always be okay... */ /* first byte should always be okay... */
newtxt[i] = txt[i]; newtxt[i] = txt[i];
...@@ -1337,13 +1331,13 @@ psqlscan_emit(PsqlScanState state, const char *txt, int len) ...@@ -1337,13 +1331,13 @@ psqlscan_emit(PsqlScanState state, const char *txt, int len)
{ {
/* Gotta do it the hard way */ /* Gotta do it the hard way */
const char *reference = state->refline; const char *reference = state->refline;
int i; int i;
reference += (txt - state->curline); reference += (txt - state->curline);
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
{ {
char ch = txt[i]; char ch = txt[i];
if (ch == (char) 0xFF) if (ch == (char) 0xFF)
ch = reference[i]; ch = reference[i];
...@@ -1369,13 +1363,13 @@ psqlscan_extract_substring(PsqlScanState state, const char *txt, int len) ...@@ -1369,13 +1363,13 @@ psqlscan_extract_substring(PsqlScanState state, const char *txt, int len)
{ {
/* Gotta do it the hard way */ /* Gotta do it the hard way */
const char *reference = state->refline; const char *reference = state->refline;
int i; int i;
reference += (txt - state->curline); reference += (txt - state->curline);
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
{ {
char ch = txt[i]; char ch = txt[i];
if (ch == (char) 0xFF) if (ch == (char) 0xFF)
ch = reference[i]; ch = reference[i];
...@@ -1391,7 +1385,7 @@ psqlscan_extract_substring(PsqlScanState state, const char *txt, int len) ...@@ -1391,7 +1385,7 @@ psqlscan_extract_substring(PsqlScanState state, const char *txt, int len)
* *
* If the variable name is found, escape its value using the appropriate * 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 * 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. * find the variable or escaping fails, emit the token as-is.
*/ */
void void
......
...@@ -113,11 +113,10 @@ other . ...@@ -113,11 +113,10 @@ other .
/* /*
* Force flex into the state indicated by start_state. This has a * Force flex into the state indicated by start_state. This has a
* couple of purposes: it lets some of the functions below set a * couple of purposes: it lets some of the functions below set a new
* new starting state without ugly direct access to flex variables, * starting state without ugly direct access to flex variables, and it
* and it allows us to transition from one flex lexer to another * allows us to transition from one flex lexer to another so that we
* so that we can lex different parts of the source string using * can lex different parts of the source string using separate lexers.
* separate lexers.
*/ */
BEGIN(cur_state->start_state); BEGIN(cur_state->start_state);
%} %}
...@@ -228,8 +227,8 @@ other . ...@@ -228,8 +227,8 @@ other .
ECHO; ECHO;
else else
{ {
char *varname; char *varname;
char *value; char *value;
varname = psqlscan_extract_substring(cur_state, varname = psqlscan_extract_substring(cur_state,
yytext + 1, yytext + 1,
...@@ -396,15 +395,11 @@ other . ...@@ -396,15 +395,11 @@ other .
} }
/*
* psql uses a single <<EOF>> rule, unlike the backend.
*/
<<EOF>> { <<EOF>> {
if (cur_state->buffer_stack == NULL) if (cur_state->buffer_stack == NULL)
{ {
cur_state->start_state = YY_START; cur_state->start_state = YY_START;
return LEXRES_EOL; /* end of input reached */ return LEXRES_EOL; /* end of input reached */
} }
/* /*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment