From dd40182dce60f1aac2153ad9c915c457f10e7c41 Mon Sep 17 00:00:00 2001
From: Jeff Garzik <jeff@bloq.com>
Date: Fri, 16 Feb 2018 23:53:30 -0500
Subject: [PATCH] Fix missing yyerror arg. Fixes #1

---
 Makefile.am |  7 ++++++-
 fail3.sql   |  2 ++
 fail4.sql   |  2 ++
 ok2.sql     |  1 +
 sql.l       | 18 +++++++++---------
 xfail2.sql  |  1 +
 6 files changed, 21 insertions(+), 10 deletions(-)
 create mode 100644 fail3.sql
 create mode 100644 fail4.sql
 create mode 100644 ok2.sql
 create mode 100644 xfail2.sql

diff --git a/Makefile.am b/Makefile.am
index 96eb063..3d9c288 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -12,7 +12,12 @@ pkgconfig_DATA = libsqlpars.pc
 # noinst_PROGRAMS = $(TESTS)
 EXTRA_DIST = sql.y sql.l \
 	test-ok.sh test-fail.sh \
-	fail1.sql ok1.sql
+	fail1.sql \
+	xfail2.sql \
+	fail3.sql \
+	fail4.sql \
+	ok1.sql \
+	ok2.sql
 
 sql_SOURCES = exec.c sql-parser.h
 nodist_sql_SOURCES = sql.c sql.tab.c sql.tab.h sql.lex.h
diff --git a/fail3.sql b/fail3.sql
new file mode 100644
index 0000000..a775904
--- /dev/null
+++ b/fail3.sql
@@ -0,0 +1,2 @@
+select (`foo
+
diff --git a/fail4.sql b/fail4.sql
new file mode 100644
index 0000000..96197de
--- /dev/null
+++ b/fail4.sql
@@ -0,0 +1,2 @@
+select ('foo
+
diff --git a/ok2.sql b/ok2.sql
new file mode 100644
index 0000000..93726c7
--- /dev/null
+++ b/ok2.sql
@@ -0,0 +1 @@
+select [ab] from d;
diff --git a/sql.l b/sql.l
index 4bcd6f4..30f58df 100644
--- a/sql.l
+++ b/sql.l
@@ -26,7 +26,7 @@
 #include "sql.tab.h"
 #include "sql-parser.h"
 
-void yyerror(YYLTYPE *, struct psql_state *pstate, const char *s, ...);
+void yyerror(YYLTYPE *, yyscan_t scanner, struct psql_state *pstate, const char *s, ...);
 
 int oldstate;
 
@@ -297,8 +297,8 @@ FALSE	{ yylval->intval = 0; return BOOL; }
 '(\\.|''|[^'\n])*'	|
 \"(\\.|\"\"|[^"\n])*\"  { yylval->strval = strdup(yytext); return STRING; }
 
-'(\\.|[^'\n])*$	        { yyerror(yylloc, pstate, "Unterminated string %s", yytext); }
-\"(\\.|[^"\n])*$	{ yyerror(yylloc, pstate, "Unterminated string %s", yytext); }
+'(\\.|[^'\n])*$	        { yyerror(yylloc, pstate->scanner, pstate, "Unterminated string %s", yytext); }
+\"(\\.|[^"\n])*$	{ yyerror(yylloc, pstate->scanner, pstate, "Unterminated string %s", yytext); }
 
    /* hex strings */
 X'[0-9A-F]+' |  
@@ -349,7 +349,7 @@ COUNT    { int c = input(pstate->scanner); unput(c);
                           yylval->strval[yyleng-2] = 0;
                           return NAME; }
 
-`[^`\n]*$               { yyerror(yylloc, pstate, "unterminated quoted name %s", yytext); }
+`[^`\n]*$               { yyerror(yylloc, pstate->scanner, pstate, "unterminated quoted name %s", yytext); }
 
 	/* user variables */
 @[0-9a-z_.$]+ |
@@ -357,9 +357,9 @@ COUNT    { int c = input(pstate->scanner); unput(c);
 @`[^`\n]+` |
 @'[^'\n]+' { yylval->strval = strdup(yytext+1); return USERVAR; }
 
-@\"[^"\n]*$ { yyerror(yylloc, pstate, "unterminated quoted user variable %s", yytext); }
-@`[^`\n]*$ { yyerror(yylloc, pstate, "unterminated quoted user variable %s", yytext); }
-@'[^'\n]*$ { yyerror(yylloc, pstate, "unterminated quoted user variable %s", yytext); }
+@\"[^"\n]*$ { yyerror(yylloc, pstate->scanner, pstate, "unterminated quoted user variable %s", yytext); }
+@`[^`\n]*$ { yyerror(yylloc, pstate->scanner, pstate, "unterminated quoted user variable %s", yytext); }
+@'[^'\n]*$ { yyerror(yylloc, pstate->scanner, pstate, "unterminated quoted user variable %s", yytext); }
 
 
 ":="     { return ASSIGN; }
@@ -372,12 +372,12 @@ COUNT    { int c = input(pstate->scanner); unput(c);
 <COMMENT>"*/"   { BEGIN oldstate; }
 <COMMENT>.   ;
 <COMMENT>\n     { yycolumn = 1; }
-<COMMENT><<EOF>> { yyerror(yylloc, pstate, "unclosed comment"); }
+<COMMENT><<EOF>> { yyerror(yylloc, pstate->scanner, pstate, "unclosed comment"); }
 
 	        /* everything else */
 [ \t]           /* white space */
 \n              { yycolumn = 1; }
-.               { yyerror(yylloc, pstate, "mystery character '%c'", *yytext); }
+.               { yyerror(yylloc, pstate->scanner, pstate, "mystery character '%c'", *yytext); }
 
 %%
 
diff --git a/xfail2.sql b/xfail2.sql
new file mode 100644
index 0000000..33662f5
--- /dev/null
+++ b/xfail2.sql
@@ -0,0 +1 @@
+/*