59#define LEXRES_BACKSLASH 2
62#define ECHO psqlscan_emit(cur_state, yytext, yyleng)
69%option never-interactive
75%option prefix="psql_yy"
81%option extra-type="PsqlScanState"
150non_newline_space [ \t\f\v]
154comment ("--"{non_newline}*)
156whitespace ({space}+|{comment})
165special_whitespace ({space}+|{comment}{newline})
166non_newline_whitespace ({non_newline_space}|{comment})
167whitespace_with_newline ({non_newline_whitespace}*{newline}{special_whitespace}*)
171quotecontinue {whitespace_with_newline}{quote}
180quotecontinuefail {whitespace}*"-"?
205xeoctesc [\\][0-7]{1,3}
206xehexesc [\\]x[0-9A-Fa-f]{1,2}
207xeunicode [\\](u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})
208xeunicodefail [\\](u[0-9A-Fa-f]{0,3}|U[0-9A-Fa-f]{0,7})
214xqdouble {quote}{quote}
226dolq_start [A-Za-z\200-\377_]
227dolq_cont [A-Za-z\200-\377_0-9]
228dolqdelim \$({dolq_start}{dolq_cont}*)?\$
229dolqfailed \${dolq_start}{dolq_cont}*
238xddouble {dquote}{dquote}
242xuistart [uU]&{dquote}
269xcstart \/\*{op_chars}*
273ident_start [A-Za-z\200-\377_]
274ident_cont [A-Za-z\200-\377_0-9\$]
276identifier {ident_start}{ident_cont}*
307self [,()\[\].;\:\+\-\*\/\%\^<>\=]
308op_chars [\~\!\@\#\^\&\|\`\?\+\-\*\/\%<>\=]
327decinteger {decdigit}(_?{decdigit})*
328hexinteger 0[xX](_?{hexdigit})+
329octinteger 0[oO](_?{octdigit})+
330bininteger 0[bB](_?{bindigit})+
336numeric (({decinteger}\.{decinteger}?)|(\.{decinteger}))
337numericfail {decinteger}\.\.
339real ({decinteger}|{numeric})[Ee][-+]?{decinteger}
340realfail ({decinteger}|{numeric})[Ee][-+]
362integer_junk {decinteger}{identifier}
363numeric_junk {numeric}{identifier}
364real_junk {real}{identifier}
365param_junk \${decdigit}+{identifier}
368variable_char [A-Za-z\200-\377_0-9]
389 PsqlScanState cur_state =
yyextra;
390 PQExpBuffer output_buf = cur_state->output_buf;
399 BEGIN(cur_state->start_state);
410 if (output_buf->len > 0)
415 cur_state->xcdepth = 0;
424 cur_state->xcdepth++;
431 if (cur_state->xcdepth <= 0)
434 cur_state->xcdepth--;
477 if (cur_state->std_strings)
492<xb,xh,xq,xe,xus>{quote} {
501 cur_state->state_before_str_stop = YYSTATE;
505<xqs>{quotecontinue} {
511 BEGIN(cur_state->state_before_str_stop);
514<xqs>{quotecontinuefail} |
526<xq,xe,xus>{xqdouble} {
556 cur_state->dolqstart =
pg_strdup(yytext);
char * pg_strdup(const char *in)
566 if (strcmp(yytext, cur_state->dolqstart) == 0)
568 free(cur_state->dolqstart);
569 cur_state->dolqstart = NULL;
662 cur_state->paren_depth++;
667 if (cur_state->paren_depth > 0)
668 cur_state->paren_depth--;
674 if (cur_state->paren_depth == 0 && cur_state->begin_depth == 0)
677 cur_state->start_state = YY_START;
678 cur_state->identifier_count = 0;
691 if (yytext[1] ==
';')
692 cur_state->identifier_count = 0;
void psqlscan_emit(PsqlScanState state, const char *txt, int len)
697 cur_state->start_state = YY_START;
709 if (cur_state->callbacks->get_variable)
710 value = cur_state->callbacks->get_variable(varname,
712 cur_state->cb_passthrough);
#define pg_log_warning(...)
char * psqlscan_extract_substring(PsqlScanState state, const char *txt, int len)
void psqlscan_push_new_buffer(PsqlScanState state, const char *newstr, const char *varname)
bool psqlscan_var_is_current_source(PsqlScanState state, const char *varname)
void psqlscan_escape_variable(PsqlScanState state, const char *txt, int len, PsqlScanQuoteType quote)
752:\"{variable_char}+\" {
757:\{\?{variable_char}+\} {
void psqlscan_test_variable(PsqlScanState state, const char *txt, int len)
778:\{\?{variable_char}* {
805 char *slashstar = strstr(yytext,
"/*");
806 char *dashdash = strstr(yytext,
"--");
808 if (slashstar && dashdash)
811 if (slashstar > dashdash)
812 slashstar = dashdash;
815 slashstar = dashdash;
817 nchars = slashstar - yytext;
828 (yytext[nchars - 1] ==
'+' ||
829 yytext[nchars - 1] ==
'-'))
833 for (ic = nchars - 2; ic >= 0; ic--)
836 if (
c ==
'~' ||
c ==
'!' ||
c ==
'@' ||
837 c ==
'#' ||
c ==
'^' ||
c ==
'&' ||
838 c ==
'|' ||
c ==
'`' ||
c ==
'?' ||
850 }
while (nchars > 1 &&
851 (yytext[nchars - 1] ==
'+' ||
852 yytext[nchars - 1] ==
'-'));
928 if (cur_state->identifier_count == 0)
929 memset(cur_state->identifiers, 0,
sizeof(cur_state->identifiers));
937 if (cur_state->identifier_count <
sizeof(cur_state->identifiers))
938 cur_state->identifiers[cur_state->identifier_count] =
pg_tolower((
unsigned char) yytext[0]);
941 cur_state->identifier_count++;
943 if (cur_state->identifiers[0] ==
'c' &&
944 (cur_state->identifiers[1] ==
'f' || cur_state->identifiers[1] ==
'p' ||
945 (cur_state->identifiers[1] ==
'o' && cur_state->identifiers[2] ==
'r' &&
946 (cur_state->identifiers[3] ==
'f' || cur_state->identifiers[3] ==
'p'))) &&
947 cur_state->paren_depth == 0)
950 cur_state->begin_depth++;
957 if (cur_state->begin_depth >= 1)
958 cur_state->begin_depth++;
962 if (cur_state->begin_depth > 0)
963 cur_state->begin_depth--;
int pg_strcasecmp(const char *s1, const char *s2)
unsigned char pg_tolower(unsigned char ch)
975 if (cur_state->buffer_stack == NULL)
977 cur_state->start_state = YY_START;
void psqlscan_select_top_buffer(PsqlScanState state)
void psqlscan_pop_buffer_stack(PsqlScanState state)
1007 state->callbacks = callbacks;
1009 yylex_init(&
state->scanner);
1028 yylex_destroy(
state->scanner);
1043 state->cb_passthrough = passthrough;
1060 const char *line,
int line_len,
1072 state->std_strings = std_strings;
1077 state->scanline = line;
1128 state->output_buf = query_buf;
1131 if (
state->buffer_stack != NULL)
1132 yy_switch_to_buffer(
state->buffer_stack->buf,
state->scanner);
1134 yy_switch_to_buffer(
state->scanbufhandle,
state->scanner);
1145 switch (
state->start_state)
1149 if (
state->paren_depth > 0)
1154 else if (
state->begin_depth > 0)
1159 else if (query_buf->
len > 0)
1209 fprintf(stderr,
"invalid YY_START\n");
1223 fprintf(stderr,
"invalid yylex result\n");
1243 while (
state->buffer_stack != NULL)
1247 if (
state->scanbufhandle)
1248 yy_delete_buffer(
state->scanbufhandle,
state->scanner);
1249 state->scanbufhandle = NULL;
1252 state->scanbuf = NULL;
1269 state->start_state = INITIAL;
1270 state->paren_depth = 0;
1272 if (
state->dolqstart)
1274 state->dolqstart = NULL;
1275 state->identifier_count = 0;
1276 state->begin_depth = 0;
1297 state->start_state = INITIAL;
1310 return state->start_state != INITIAL &&
1311 state->start_state != xqs;
1321 const char *varname)
1337 if (
state->safe_encoding)
1348 state->buffer_stack = stackelem;
1364 yy_delete_buffer(stackelem->
buf,
state->scanner);
1381 if (stackelem != NULL)
1383 yy_switch_to_buffer(stackelem->
buf,
state->scanner);
1389 yy_switch_to_buffer(
state->scanbufhandle,
state->scanner);
1404 for (stackelem =
state->buffer_stack;
1406 stackelem = stackelem->
next)
1408 if (stackelem->
varname && strcmp(stackelem->
varname, varname) == 0)
1430 newtxt[
len] = newtxt[
len + 1] = YY_END_OF_BUFFER_CHAR;
1432 if (
state->safe_encoding)
1433 memcpy(newtxt, txt,
len);
1446 while (--thislen > 0 &&
i <
len)
1447 newtxt[
i++] = (char) 0xFF;
1451 return yy_scan_buffer(newtxt,
len + 2,
state->scanner);
1467 if (
state->safe_encoding)
1472 const char *reference =
state->refline;
1475 reference += (txt -
state->curline);
1477 for (
i = 0;
i <
len;
i++)
1481 if (ch == (
char) 0xFF)
1499 if (
state->safe_encoding)
1500 memcpy(result, txt,
len);
1504 const char *reference =
state->refline;
1507 reference += (txt -
state->curline);
1509 for (
i = 0;
i <
len;
i++)
1513 if (ch == (
char) 0xFF)
1539 if (
state->callbacks->get_variable)
1540 value =
state->callbacks->get_variable(varname, quote,
1541 state->cb_passthrough);
1566 if (
state->callbacks->get_variable)
1568 state->cb_passthrough);
#define Assert(condition)
#define fprintf(file, fmt, msg)
int PQmblen(const char *s, int encoding)
void * pg_malloc(size_t size)
void * pg_malloc0(size_t size)
#define pg_valid_server_encoding_id
void appendBinaryPQExpBuffer(PQExpBuffer str, const char *data, size_t datalen)
void appendPQExpBufferChar(PQExpBuffer str, char ch)
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
enum _promptStatus promptStatus_t
YY_BUFFER_STATE psqlscan_prepare_buffer(PsqlScanState state, const char *txt, int len, char **txtcopy)
void psql_scan_reset(PsqlScanState state)
void psql_scan_destroy(PsqlScanState state)
PsqlScanResult psql_scan(PsqlScanState state, PQExpBuffer query_buf, promptStatus_t *prompt)
PsqlScanState psql_scan_create(const PsqlScanCallbacks *callbacks)
void psql_scan_set_passthrough(PsqlScanState state, void *passthrough)
void psql_scan_setup(PsqlScanState state, const char *line, int line_len, int encoding, bool std_strings)
int yylex(YYSTYPE *yylval_param, yyscan_t yyscanner)
void psql_scan_reselect_sql_lexer(PsqlScanState state)
bool psql_scan_in_quote(PsqlScanState state)
void psql_scan_finish(PsqlScanState state)
struct yy_buffer_state * YY_BUFFER_STATE