set yyerrno on recoverable error

This commit is contained in:
anon 2024-02-12 19:10:08 +01:00
parent 84b98f93d3
commit 4a540661e2
2 changed files with 10 additions and 3 deletions

2
main.c
View File

@ -41,7 +41,7 @@ main(int ac, char **av)
psql_free(pstate); psql_free(pstate);
if (!res) { if (!res && !yyerrno) {
printf("{\"result\":true}\n"); printf("{\"result\":true}\n");
return 0; return 0;
} else { } else {

11
sql.y
View File

@ -21,6 +21,7 @@
#include <string.h> #include <string.h>
char *filename; char *filename;
int yyerrno;
%} %}
%define api.pure %define api.pure
@ -31,6 +32,7 @@ char *filename;
%code requires { %code requires {
extern char *filename; extern char *filename;
extern int yyerrno;
#include "yyl.h" #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, ...); void lyyerror(YYLTYPE t, const char *s, ...);
%} %}
/* free discarded tokens */ /* free discarded tokens */
%destructor { printf ("free at %d %s\n",@$.first_line, $$); free($$); } <strval> %destructor {
#if DEBUG
printf ("free at %d %s\n",@$.first_line, $$); free($$);
#endif
} <strval>
%% %%
@ -974,7 +980,7 @@ yyerror(YYLTYPE *t, yyscan_t scanner, struct psql_state *pstate, const char *s,
t->last_line, t->last_column); t->last_line, t->last_column);
vfprintf(stderr, s, ap); vfprintf(stderr, s, ap);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
yyerrno = 1;
} }
void void
@ -988,5 +994,6 @@ lyyerror(YYLTYPE t, const char *s, ...)
t.last_line, t.last_column); t.last_line, t.last_column);
vfprintf(stderr, s, ap); vfprintf(stderr, s, ap);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
yyerrno = 1;
} }