diff options
Diffstat (limited to 'contrib/pgbench/exprscan.l')
-rw-r--r-- | contrib/pgbench/exprscan.l | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/contrib/pgbench/exprscan.l b/contrib/pgbench/exprscan.l index 6e3331d908e..5331ab778b4 100644 --- a/contrib/pgbench/exprscan.l +++ b/contrib/pgbench/exprscan.l @@ -17,6 +17,13 @@ static int yyline = 0, yycol = 0; static YY_BUFFER_STATE scanbufhandle; static char *scanbuf; static int scanbuflen; + +/* context information for error reporting */ +static char *expr_source = NULL; +static int expr_lineno = 0; +static char *expr_full_line = NULL; +static char *expr_command = NULL; +static int expr_col = 0; %} %option 8bit @@ -56,7 +63,9 @@ space [ \t\r\f] . { yycol += yyleng; - fprintf(stderr, "unexpected character \"%s\"\n", yytext); + syntax_error(expr_source, expr_lineno, expr_full_line, expr_command, + "unexpected character", yytext, expr_col + yycol); + /* dead code, exit is called from syntax_error */ return CHAR_ERROR; } %% @@ -64,20 +73,27 @@ space [ \t\r\f] void yyerror(const char *message) { - /* yyline is always 1 as pgbench calls the parser for each line... - * so the interesting location information is the column number */ - fprintf(stderr, "%s at column %d\n", message, yycol); - /* go on to raise the error from pgbench with more information */ + syntax_error(expr_source, expr_lineno, expr_full_line, expr_command, + message, NULL, expr_col + yycol); } /* * Called before any actual parsing is done */ void -expr_scanner_init(const char *str) +expr_scanner_init(const char *str, const char *source, + const int lineno, const char *line, + const char *cmd, const int ecol) { Size slen = strlen(str); + /* save context informations for error messages */ + expr_source = (char *) source; + expr_lineno = (int) lineno; + expr_full_line = (char *) line; + expr_command = (char *) cmd; + expr_col = (int) ecol; + /* * Might be left over after error */ @@ -105,4 +121,9 @@ expr_scanner_finish(void) { yy_delete_buffer(scanbufhandle); pg_free(scanbuf); + expr_source = NULL; + expr_lineno = 0; + expr_full_line = NULL; + expr_command = NULL; + expr_col = 0; } |