From 4a540661e23570d393ac468099496bb89fbb99c9 Mon Sep 17 00:00:00 2001 From: anon Date: Mon, 12 Feb 2024 19:10:08 +0100 Subject: [PATCH] set yyerrno on recoverable error --- main.c | 2 +- sql.y | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index 2517ac8..8ea60fc 100644 --- a/main.c +++ b/main.c @@ -41,7 +41,7 @@ main(int ac, char **av) psql_free(pstate); - if (!res) { + if (!res && !yyerrno) { printf("{\"result\":true}\n"); return 0; } else { diff --git a/sql.y b/sql.y index 350b695..114760c 100644 --- a/sql.y +++ b/sql.y @@ -21,6 +21,7 @@ #include char *filename; +int yyerrno; %} %define api.pure @@ -31,6 +32,7 @@ char *filename; %code requires { extern char *filename; +extern int yyerrno; #include "yyl.h" @@ -327,7 +329,11 @@ void yyerror(YYLTYPE *, yyscan_t scanner, struct psql_state *pstate, const char void lyyerror(YYLTYPE t, const char *s, ...); %} /* free discarded tokens */ -%destructor { printf ("free at %d %s\n",@$.first_line, $$); free($$); } +%destructor { +#if DEBUG +printf ("free at %d %s\n",@$.first_line, $$); free($$); +#endif +} %% @@ -974,7 +980,7 @@ yyerror(YYLTYPE *t, yyscan_t scanner, struct psql_state *pstate, const char *s, t->last_line, t->last_column); vfprintf(stderr, s, ap); fprintf(stderr, "\n"); - + yyerrno = 1; } void @@ -988,5 +994,6 @@ lyyerror(YYLTYPE t, const char *s, ...) t.last_line, t.last_column); vfprintf(stderr, s, ap); fprintf(stderr, "\n"); + yyerrno = 1; }