better error reporting with location.
parent
32fa2d1df9
commit
77080fe875
|
@ -511,7 +511,14 @@ static yyconst flex_int16_t yy_chk[253] =
|
|||
#include <string.h>
|
||||
#include "query_types.h"
|
||||
#include "y.tab.h"
|
||||
#line 515 "lex.yy.c"
|
||||
|
||||
#define YY_USER_ACTION \
|
||||
do { \
|
||||
yylloc_param->first_line = yylloc->last_line = yylineno; \
|
||||
yylloc_param->first_column = yycolumn; yylloc_param->last_column = yycolumn+yyleng-1; \
|
||||
yycolumn += yyleng; \
|
||||
} while(0);
|
||||
#line 522 "lex.yy.c"
|
||||
|
||||
#define INITIAL 0
|
||||
|
||||
|
@ -561,6 +568,8 @@ struct yyguts_t
|
|||
|
||||
YYSTYPE * yylval_r;
|
||||
|
||||
YYLTYPE * yylloc_r;
|
||||
|
||||
}; /* end struct yyguts_t */
|
||||
|
||||
static int yy_init_globals (yyscan_t yyscanner );
|
||||
|
@ -569,6 +578,8 @@ static int yy_init_globals (yyscan_t yyscanner );
|
|||
* from bison output in section 1.*/
|
||||
# define yylval yyg->yylval_r
|
||||
|
||||
# define yylloc yyg->yylloc_r
|
||||
|
||||
int yylex_init (yyscan_t* scanner);
|
||||
|
||||
int yylex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner);
|
||||
|
@ -606,6 +617,10 @@ YYSTYPE * yyget_lval (yyscan_t yyscanner );
|
|||
|
||||
void yyset_lval (YYSTYPE * yylval_param ,yyscan_t yyscanner );
|
||||
|
||||
YYLTYPE *yyget_lloc (yyscan_t yyscanner );
|
||||
|
||||
void yyset_lloc (YYLTYPE * yylloc_param ,yyscan_t yyscanner );
|
||||
|
||||
/* Macros after this point can all be overridden by user definitions in
|
||||
* section 1.
|
||||
*/
|
||||
|
@ -719,10 +734,10 @@ static int input (yyscan_t yyscanner );
|
|||
#define YY_DECL_IS_OURS 1
|
||||
|
||||
extern int yylex \
|
||||
(YYSTYPE * yylval_param ,yyscan_t yyscanner);
|
||||
(YYSTYPE * yylval_param,YYLTYPE * yylloc_param ,yyscan_t yyscanner);
|
||||
|
||||
#define YY_DECL int yylex \
|
||||
(YYSTYPE * yylval_param , yyscan_t yyscanner)
|
||||
(YYSTYPE * yylval_param, YYLTYPE * yylloc_param , yyscan_t yyscanner)
|
||||
#endif /* !YY_DECL */
|
||||
|
||||
/* Code executed at the beginning of each rule, after yytext and yyleng
|
||||
|
@ -749,13 +764,15 @@ YY_DECL
|
|||
register int yy_act;
|
||||
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
|
||||
|
||||
#line 11 "query.lex"
|
||||
#line 21 "query.lex"
|
||||
|
||||
|
||||
#line 756 "lex.yy.c"
|
||||
#line 771 "lex.yy.c"
|
||||
|
||||
yylval = yylval_param;
|
||||
|
||||
yylloc = yylloc_param;
|
||||
|
||||
if ( !yyg->yy_init )
|
||||
{
|
||||
yyg->yy_init = 1;
|
||||
|
@ -839,107 +856,107 @@ do_action: /* This label is used only to access EOF actions. */
|
|||
|
||||
case 1:
|
||||
YY_RULE_SETUP
|
||||
#line 13 "query.lex"
|
||||
#line 23 "query.lex"
|
||||
{ return *yytext; }
|
||||
YY_BREAK
|
||||
case 2:
|
||||
YY_RULE_SETUP
|
||||
#line 14 "query.lex"
|
||||
#line 24 "query.lex"
|
||||
{ return *yytext; }
|
||||
YY_BREAK
|
||||
case 3:
|
||||
YY_RULE_SETUP
|
||||
#line 15 "query.lex"
|
||||
#line 25 "query.lex"
|
||||
{ return FROM; }
|
||||
YY_BREAK
|
||||
case 4:
|
||||
YY_RULE_SETUP
|
||||
#line 16 "query.lex"
|
||||
#line 26 "query.lex"
|
||||
{ return WHERE; }
|
||||
YY_BREAK
|
||||
case 5:
|
||||
YY_RULE_SETUP
|
||||
#line 17 "query.lex"
|
||||
#line 27 "query.lex"
|
||||
{ return SELECT; }
|
||||
YY_BREAK
|
||||
case 6:
|
||||
YY_RULE_SETUP
|
||||
#line 18 "query.lex"
|
||||
#line 28 "query.lex"
|
||||
{ yylval->character = *yytext; return *yytext; }
|
||||
YY_BREAK
|
||||
case 7:
|
||||
YY_RULE_SETUP
|
||||
#line 19 "query.lex"
|
||||
#line 29 "query.lex"
|
||||
{ yylval->character = *yytext; return *yytext; }
|
||||
YY_BREAK
|
||||
case 8:
|
||||
YY_RULE_SETUP
|
||||
#line 20 "query.lex"
|
||||
#line 30 "query.lex"
|
||||
{ yylval->character = *yytext; return *yytext; }
|
||||
YY_BREAK
|
||||
case 9:
|
||||
YY_RULE_SETUP
|
||||
#line 21 "query.lex"
|
||||
#line 31 "query.lex"
|
||||
{ yylval->character = *yytext; return *yytext; }
|
||||
YY_BREAK
|
||||
case 10:
|
||||
YY_RULE_SETUP
|
||||
#line 22 "query.lex"
|
||||
#line 32 "query.lex"
|
||||
{ yylval->character = *yytext; return *yytext; }
|
||||
YY_BREAK
|
||||
case 11:
|
||||
YY_RULE_SETUP
|
||||
#line 23 "query.lex"
|
||||
#line 33 "query.lex"
|
||||
{ yylval->character = *yytext; return *yytext; }
|
||||
YY_BREAK
|
||||
case 12:
|
||||
YY_RULE_SETUP
|
||||
#line 24 "query.lex"
|
||||
#line 34 "query.lex"
|
||||
{ yylval->string = strdup(yytext); return AND; }
|
||||
YY_BREAK
|
||||
case 13:
|
||||
YY_RULE_SETUP
|
||||
#line 25 "query.lex"
|
||||
#line 35 "query.lex"
|
||||
{ yylval->string = strdup(yytext); return OR; }
|
||||
YY_BREAK
|
||||
case 14:
|
||||
YY_RULE_SETUP
|
||||
#line 26 "query.lex"
|
||||
#line 36 "query.lex"
|
||||
{ yylval->string = strdup(yytext); return OPERATION_EQUAL; }
|
||||
YY_BREAK
|
||||
case 15:
|
||||
YY_RULE_SETUP
|
||||
#line 27 "query.lex"
|
||||
#line 37 "query.lex"
|
||||
{ yylval->string = strdup(yytext); return OPERATION_NE; }
|
||||
YY_BREAK
|
||||
case 16:
|
||||
YY_RULE_SETUP
|
||||
#line 28 "query.lex"
|
||||
#line 38 "query.lex"
|
||||
{ yylval->string = strdup(yytext); return OPERATION_LT; }
|
||||
YY_BREAK
|
||||
case 17:
|
||||
YY_RULE_SETUP
|
||||
#line 29 "query.lex"
|
||||
#line 39 "query.lex"
|
||||
{ yylval->string = strdup(yytext); return OPERATION_GT; }
|
||||
YY_BREAK
|
||||
case 18:
|
||||
YY_RULE_SETUP
|
||||
#line 30 "query.lex"
|
||||
#line 40 "query.lex"
|
||||
{ yylval->string = strdup(yytext); return OPERATION_LE; }
|
||||
YY_BREAK
|
||||
case 19:
|
||||
YY_RULE_SETUP
|
||||
#line 31 "query.lex"
|
||||
#line 41 "query.lex"
|
||||
{ yylval->string = strdup(yytext); return OPERATION_GE; }
|
||||
YY_BREAK
|
||||
case 20:
|
||||
YY_RULE_SETUP
|
||||
#line 32 "query.lex"
|
||||
#line 42 "query.lex"
|
||||
{ yylval->string = strdup(yytext); return NAME; }
|
||||
YY_BREAK
|
||||
case 21:
|
||||
YY_RULE_SETUP
|
||||
#line 33 "query.lex"
|
||||
#line 43 "query.lex"
|
||||
{
|
||||
yytext[yyleng-1] = '\0';
|
||||
yylval->string = strdup(yytext+1);
|
||||
|
@ -949,7 +966,7 @@ YY_RULE_SETUP
|
|||
case 22:
|
||||
/* rule 22 can match eol */
|
||||
YY_RULE_SETUP
|
||||
#line 38 "query.lex"
|
||||
#line 48 "query.lex"
|
||||
{
|
||||
yylval->string = strdup(yytext);
|
||||
return STRING_VALUE;
|
||||
|
@ -957,10 +974,10 @@ YY_RULE_SETUP
|
|||
YY_BREAK
|
||||
case 23:
|
||||
YY_RULE_SETUP
|
||||
#line 42 "query.lex"
|
||||
#line 53 "query.lex"
|
||||
ECHO;
|
||||
YY_BREAK
|
||||
#line 964 "lex.yy.c"
|
||||
#line 981 "lex.yy.c"
|
||||
case YY_STATE_EOF(INITIAL):
|
||||
yyterminate();
|
||||
|
||||
|
@ -1952,6 +1969,18 @@ void yyset_lval (YYSTYPE * yylval_param , yyscan_t yyscanner)
|
|||
yylval = yylval_param;
|
||||
}
|
||||
|
||||
YYLTYPE *yyget_lloc (yyscan_t yyscanner)
|
||||
{
|
||||
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
|
||||
return yylloc;
|
||||
}
|
||||
|
||||
void yyset_lloc (YYLTYPE * yylloc_param , yyscan_t yyscanner)
|
||||
{
|
||||
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
|
||||
yylloc = yylloc_param;
|
||||
}
|
||||
|
||||
/* User-visible API */
|
||||
|
||||
/* yylex_init is special because it creates the scanner itself, so it is
|
||||
|
@ -2127,4 +2156,4 @@ void yyfree (void * ptr , yyscan_t yyscanner)
|
|||
|
||||
#define YYTABLES_NAME "yytables"
|
||||
|
||||
#line 42 "query.lex"
|
||||
#line 53 "query.lex"
|
||||
|
|
|
@ -5,7 +5,7 @@ package query
|
|||
import "C"
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
|
@ -135,7 +135,8 @@ func ParseQuery(query string) (*Query, error) {
|
|||
q := C.parse_query(queryString)
|
||||
var err error
|
||||
if q.error != nil {
|
||||
err = errors.New(C.GoString(q.error))
|
||||
str := C.GoString(q.error.err)
|
||||
err = fmt.Errorf("Error at %d:%d. %s", q.error.line, q.error.column, str)
|
||||
}
|
||||
return &Query{q, nil, nil}, err
|
||||
}
|
||||
|
|
|
@ -3,10 +3,20 @@
|
|||
#include <string.h>
|
||||
#include "query_types.h"
|
||||
#include "y.tab.h"
|
||||
|
||||
#define YY_USER_ACTION \
|
||||
do { \
|
||||
yylloc->last_line = yylineno; \
|
||||
yylloc_param->last_column = yycolumn+yyleng-1; \
|
||||
yycolumn += yyleng; \
|
||||
} while(0);
|
||||
%}
|
||||
|
||||
static int yycolumn = 1;
|
||||
|
||||
%option reentrant
|
||||
%option bison-bridge
|
||||
%option bison-locations
|
||||
%option noyywrap
|
||||
%%
|
||||
|
||||
|
@ -39,3 +49,4 @@ select { return SELECT; }
|
|||
yylval->string = strdup(yytext);
|
||||
return STRING_VALUE;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
|
||||
// declare that we want a reentrant parser
|
||||
%define api.pure
|
||||
%error-verbose
|
||||
%locations
|
||||
%parse-param {query *q}
|
||||
%parse-param {void *scanner}
|
||||
%lex-param {void *scanner}
|
||||
|
@ -313,6 +315,9 @@ parse_query(char *const query_s)
|
|||
return q;
|
||||
}
|
||||
|
||||
int yyerror(query *q, void *s, char *err) {
|
||||
q->error = strdup(err);
|
||||
int yyerror(YYLTYPE *locp, query *q, void *s, char *err) {
|
||||
q->error = malloc(sizeof(error));
|
||||
q->error->err = strdup(err);
|
||||
q->error->line = locp->last_line;
|
||||
q->error->column = locp->last_column;
|
||||
}
|
||||
|
|
|
@ -32,11 +32,17 @@ typedef struct {
|
|||
bool_expression *right;
|
||||
} condition;
|
||||
|
||||
typedef struct {
|
||||
int line;
|
||||
int column;
|
||||
char *err;
|
||||
} error;
|
||||
|
||||
typedef struct {
|
||||
array *c;
|
||||
from *f;
|
||||
condition *where_condition;
|
||||
char *error;
|
||||
error *error;
|
||||
} query;
|
||||
|
||||
query parse_query(char *const query_s);
|
||||
|
|
|
@ -59,7 +59,7 @@
|
|||
#define YYPULL 1
|
||||
|
||||
/* Using locations. */
|
||||
#define YYLSP_NEEDED 0
|
||||
#define YYLSP_NEEDED 1
|
||||
|
||||
|
||||
|
||||
|
@ -89,7 +89,7 @@
|
|||
# undef YYERROR_VERBOSE
|
||||
# define YYERROR_VERBOSE 1
|
||||
#else
|
||||
# define YYERROR_VERBOSE 0
|
||||
# define YYERROR_VERBOSE 1
|
||||
#endif
|
||||
|
||||
/* Enabling the token table. */
|
||||
|
@ -166,12 +166,25 @@ typedef union YYSTYPE
|
|||
# define YYSTYPE_IS_DECLARED 1
|
||||
#endif
|
||||
|
||||
#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
|
||||
typedef struct YYLTYPE
|
||||
{
|
||||
int first_line;
|
||||
int first_column;
|
||||
int last_line;
|
||||
int last_column;
|
||||
} YYLTYPE;
|
||||
# define yyltype YYLTYPE /* obsolescent; will be withdrawn */
|
||||
# define YYLTYPE_IS_DECLARED 1
|
||||
# define YYLTYPE_IS_TRIVIAL 1
|
||||
#endif
|
||||
|
||||
|
||||
/* Copy the second part of user declarations. */
|
||||
|
||||
|
||||
/* Line 343 of yacc.c */
|
||||
#line 175 "y.tab.c"
|
||||
#line 188 "y.tab.c"
|
||||
|
||||
#ifdef short
|
||||
# undef short
|
||||
|
@ -329,13 +342,15 @@ void free (void *); /* INFRINGES ON USER NAME SPACE */
|
|||
|
||||
#if (! defined yyoverflow \
|
||||
&& (! defined __cplusplus \
|
||||
|| (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
|
||||
|| (defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
|
||||
&& defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
|
||||
|
||||
/* A type that is properly aligned for any stack member. */
|
||||
union yyalloc
|
||||
{
|
||||
yytype_int16 yyss_alloc;
|
||||
YYSTYPE yyvs_alloc;
|
||||
YYLTYPE yyls_alloc;
|
||||
};
|
||||
|
||||
/* The size of the maximum gap between one aligned stack and the next. */
|
||||
|
@ -344,8 +359,8 @@ union yyalloc
|
|||
/* The size of an array large to enough to hold all stacks, each with
|
||||
N elements. */
|
||||
# define YYSTACK_BYTES(N) \
|
||||
((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
|
||||
+ YYSTACK_GAP_MAXIMUM)
|
||||
((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
|
||||
+ 2 * YYSTACK_GAP_MAXIMUM)
|
||||
|
||||
# define YYCOPY_NEEDED 1
|
||||
|
||||
|
@ -470,10 +485,10 @@ static const yytype_int8 yyrhs[] =
|
|||
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
|
||||
static const yytype_uint8 yyrline[] =
|
||||
{
|
||||
0, 57, 57, 64, 72, 83, 92, 98, 104, 112,
|
||||
122, 131, 139, 146, 153, 156, 164, 173, 175, 177,
|
||||
179, 182, 190, 199, 207, 215, 224, 226, 228, 230,
|
||||
232, 234, 236
|
||||
0, 59, 59, 66, 74, 85, 94, 100, 106, 114,
|
||||
124, 133, 141, 148, 155, 158, 166, 175, 177, 179,
|
||||
181, 184, 192, 201, 209, 217, 226, 228, 230, 232,
|
||||
234, 236, 238
|
||||
};
|
||||
#endif
|
||||
|
||||
|
@ -634,7 +649,7 @@ do \
|
|||
} \
|
||||
else \
|
||||
{ \
|
||||
yyerror (q, scanner, YY_("syntax error: cannot back up")); \
|
||||
yyerror (&yylloc, q, scanner, YY_("syntax error: cannot back up")); \
|
||||
YYERROR; \
|
||||
} \
|
||||
while (YYID (0))
|
||||
|
@ -670,19 +685,28 @@ while (YYID (0))
|
|||
#endif
|
||||
|
||||
|
||||
/* This macro is provided for backward compatibility. */
|
||||
/* YY_LOCATION_PRINT -- Print the location on the stream.
|
||||
This macro was not mandated originally: define only if we know
|
||||
we won't break user code: when these are the locations we know. */
|
||||
|
||||
#ifndef YY_LOCATION_PRINT
|
||||
# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
|
||||
# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
|
||||
# define YY_LOCATION_PRINT(File, Loc) \
|
||||
fprintf (File, "%d.%d-%d.%d", \
|
||||
(Loc).first_line, (Loc).first_column, \
|
||||
(Loc).last_line, (Loc).last_column)
|
||||
# else
|
||||
# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* YYLEX -- calling `yylex' with the right arguments. */
|
||||
|
||||
#ifdef YYLEX_PARAM
|
||||
# define YYLEX yylex (&yylval, YYLEX_PARAM)
|
||||
# define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM)
|
||||
#else
|
||||
# define YYLEX yylex (&yylval, scanner)
|
||||
# define YYLEX yylex (&yylval, &yylloc, scanner)
|
||||
#endif
|
||||
|
||||
/* Enable debugging if requested. */
|
||||
|
@ -705,7 +729,7 @@ do { \
|
|||
{ \
|
||||
YYFPRINTF (stderr, "%s ", Title); \
|
||||
yy_symbol_print (stderr, \
|
||||
Type, Value, q, scanner); \
|
||||
Type, Value, Location, q, scanner); \
|
||||
YYFPRINTF (stderr, "\n"); \
|
||||
} \
|
||||
} while (YYID (0))
|
||||
|
@ -719,19 +743,21 @@ do { \
|
|||
#if (defined __STDC__ || defined __C99__FUNC__ \
|
||||
|| defined __cplusplus || defined _MSC_VER)
|
||||
static void
|
||||
yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, query *q, void *scanner)
|
||||
yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, query *q, void *scanner)
|
||||
#else
|
||||
static void
|
||||
yy_symbol_value_print (yyoutput, yytype, yyvaluep, q, scanner)
|
||||
yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, q, scanner)
|
||||
FILE *yyoutput;
|
||||
int yytype;
|
||||
YYSTYPE const * const yyvaluep;
|
||||
YYLTYPE const * const yylocationp;
|
||||
query *q;
|
||||
void *scanner;
|
||||
#endif
|
||||
{
|
||||
if (!yyvaluep)
|
||||
return;
|
||||
YYUSE (yylocationp);
|
||||
YYUSE (q);
|
||||
YYUSE (scanner);
|
||||
# ifdef YYPRINT
|
||||
|
@ -755,13 +781,14 @@ yy_symbol_value_print (yyoutput, yytype, yyvaluep, q, scanner)
|
|||
#if (defined __STDC__ || defined __C99__FUNC__ \
|
||||
|| defined __cplusplus || defined _MSC_VER)
|
||||
static void
|
||||
yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, query *q, void *scanner)
|
||||
yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, query *q, void *scanner)
|
||||
#else
|
||||
static void
|
||||
yy_symbol_print (yyoutput, yytype, yyvaluep, q, scanner)
|
||||
yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp, q, scanner)
|
||||
FILE *yyoutput;
|
||||
int yytype;
|
||||
YYSTYPE const * const yyvaluep;
|
||||
YYLTYPE const * const yylocationp;
|
||||
query *q;
|
||||
void *scanner;
|
||||
#endif
|
||||
|
@ -771,7 +798,9 @@ yy_symbol_print (yyoutput, yytype, yyvaluep, q, scanner)
|
|||
else
|
||||
YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
|
||||
|
||||
yy_symbol_value_print (yyoutput, yytype, yyvaluep, q, scanner);
|
||||
YY_LOCATION_PRINT (yyoutput, *yylocationp);
|
||||
YYFPRINTF (yyoutput, ": ");
|
||||
yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, q, scanner);
|
||||
YYFPRINTF (yyoutput, ")");
|
||||
}
|
||||
|
||||
|
@ -814,11 +843,12 @@ do { \
|
|||
#if (defined __STDC__ || defined __C99__FUNC__ \
|
||||
|| defined __cplusplus || defined _MSC_VER)
|
||||
static void
|
||||
yy_reduce_print (YYSTYPE *yyvsp, int yyrule, query *q, void *scanner)
|
||||
yy_reduce_print (YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule, query *q, void *scanner)
|
||||
#else
|
||||
static void
|
||||
yy_reduce_print (yyvsp, yyrule, q, scanner)
|
||||
yy_reduce_print (yyvsp, yylsp, yyrule, q, scanner)
|
||||
YYSTYPE *yyvsp;
|
||||
YYLTYPE *yylsp;
|
||||
int yyrule;
|
||||
query *q;
|
||||
void *scanner;
|
||||
|
@ -835,7 +865,7 @@ yy_reduce_print (yyvsp, yyrule, q, scanner)
|
|||
YYFPRINTF (stderr, " $%d = ", yyi + 1);
|
||||
yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
|
||||
&(yyvsp[(yyi + 1) - (yynrhs)])
|
||||
, q, scanner);
|
||||
, &(yylsp[(yyi + 1) - (yynrhs)]) , q, scanner);
|
||||
YYFPRINTF (stderr, "\n");
|
||||
}
|
||||
}
|
||||
|
@ -843,7 +873,7 @@ yy_reduce_print (yyvsp, yyrule, q, scanner)
|
|||
# define YY_REDUCE_PRINT(Rule) \
|
||||
do { \
|
||||
if (yydebug) \
|
||||
yy_reduce_print (yyvsp, Rule, q, scanner); \
|
||||
yy_reduce_print (yyvsp, yylsp, Rule, q, scanner); \
|
||||
} while (YYID (0))
|
||||
|
||||
/* Nonzero means print parse trace. It is left uninitialized so that
|
||||
|
@ -1120,18 +1150,20 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
|
|||
#if (defined __STDC__ || defined __C99__FUNC__ \
|
||||
|| defined __cplusplus || defined _MSC_VER)
|
||||
static void
|
||||
yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, query *q, void *scanner)
|
||||
yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp, query *q, void *scanner)
|
||||
#else
|
||||
static void
|
||||
yydestruct (yymsg, yytype, yyvaluep, q, scanner)
|
||||
yydestruct (yymsg, yytype, yyvaluep, yylocationp, q, scanner)
|
||||
const char *yymsg;
|
||||
int yytype;
|
||||
YYSTYPE *yyvaluep;
|
||||
YYLTYPE *yylocationp;
|
||||
query *q;
|
||||
void *scanner;
|
||||
#endif
|
||||
{
|
||||
YYUSE (yyvaluep);
|
||||
YYUSE (yylocationp);
|
||||
YYUSE (q);
|
||||
YYUSE (scanner);
|
||||
|
||||
|
@ -1197,6 +1229,9 @@ int yychar;
|
|||
/* The semantic value of the lookahead symbol. */
|
||||
YYSTYPE yylval;
|
||||
|
||||
/* Location data for the lookahead symbol. */
|
||||
YYLTYPE yylloc;
|
||||
|
||||
/* Number of syntax errors so far. */
|
||||
int yynerrs;
|
||||
|
||||
|
@ -1207,6 +1242,7 @@ YYSTYPE yylval;
|
|||
/* The stacks and their tools:
|
||||
`yyss': related to states.
|
||||
`yyvs': related to semantic values.
|
||||
`yyls': related to locations.
|
||||
|
||||
Refer to the stacks thru separate pointers, to allow yyoverflow
|
||||
to reallocate them elsewhere. */
|
||||
|
@ -1221,6 +1257,14 @@ YYSTYPE yylval;
|
|||
YYSTYPE *yyvs;
|
||||
YYSTYPE *yyvsp;
|
||||
|
||||
/* The location stack. */
|
||||
YYLTYPE yylsa[YYINITDEPTH];
|
||||
YYLTYPE *yyls;
|
||||
YYLTYPE *yylsp;
|
||||
|
||||
/* The locations where the error started and ended. */
|
||||
YYLTYPE yyerror_range[3];
|
||||
|
||||
YYSIZE_T yystacksize;
|
||||
|
||||
int yyn;
|
||||
|
@ -1230,6 +1274,7 @@ YYSTYPE yylval;
|
|||
/* The variables used to return semantic value and location from the
|
||||
action routines. */
|
||||
YYSTYPE yyval;
|
||||
YYLTYPE yyloc;
|
||||
|
||||
#if YYERROR_VERBOSE
|
||||
/* Buffer for error messages, and its allocated size. */
|
||||
|
@ -1238,7 +1283,7 @@ YYSTYPE yylval;
|
|||
YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
|
||||
#endif
|
||||
|
||||
#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
|
||||
#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N), yylsp -= (N))
|
||||
|
||||
/* The number of symbols on the RHS of the reduced rule.
|
||||
Keep to zero when no symbol should be popped. */
|
||||
|
@ -1247,6 +1292,7 @@ YYSTYPE yylval;
|
|||
yytoken = 0;
|
||||
yyss = yyssa;
|
||||
yyvs = yyvsa;
|
||||
yyls = yylsa;
|
||||
yystacksize = YYINITDEPTH;
|
||||
|
||||
YYDPRINTF ((stderr, "Starting parse\n"));
|
||||
|
@ -1262,6 +1308,13 @@ YYSTYPE yylval;
|
|||
The wasted elements are never initialized. */
|
||||
yyssp = yyss;
|
||||
yyvsp = yyvs;
|
||||
yylsp = yyls;
|
||||
|
||||
#if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
|
||||
/* Initialize the default location before parsing starts. */
|
||||
yylloc.first_line = yylloc.last_line = 1;
|
||||
yylloc.first_column = yylloc.last_column = 1;
|
||||
#endif
|
||||
|
||||
goto yysetstate;
|
||||
|
||||
|
@ -1288,6 +1341,7 @@ YYSTYPE yylval;
|
|||
memory. */
|
||||
YYSTYPE *yyvs1 = yyvs;
|
||||
yytype_int16 *yyss1 = yyss;
|
||||
YYLTYPE *yyls1 = yyls;
|
||||
|
||||
/* Each stack pointer address is followed by the size of the
|
||||
data in use in that stack, in bytes. This used to be a
|
||||
|
@ -1296,8 +1350,10 @@ YYSTYPE yylval;
|
|||
yyoverflow (YY_("memory exhausted"),
|
||||
&yyss1, yysize * sizeof (*yyssp),
|
||||
&yyvs1, yysize * sizeof (*yyvsp),
|
||||
&yyls1, yysize * sizeof (*yylsp),
|
||||
&yystacksize);
|
||||
|
||||
yyls = yyls1;
|
||||
yyss = yyss1;
|
||||
yyvs = yyvs1;
|
||||
}
|
||||
|
@ -1320,6 +1376,7 @@ YYSTYPE yylval;
|
|||
goto yyexhaustedlab;
|
||||
YYSTACK_RELOCATE (yyss_alloc, yyss);
|
||||
YYSTACK_RELOCATE (yyvs_alloc, yyvs);
|
||||
YYSTACK_RELOCATE (yyls_alloc, yyls);
|
||||
# undef YYSTACK_RELOCATE
|
||||
if (yyss1 != yyssa)
|
||||
YYSTACK_FREE (yyss1);
|
||||
|
@ -1329,6 +1386,7 @@ YYSTYPE yylval;
|
|||
|
||||
yyssp = yyss + yysize - 1;
|
||||
yyvsp = yyvs + yysize - 1;
|
||||
yylsp = yyls + yysize - 1;
|
||||
|
||||
YYDPRINTF ((stderr, "Stack size increased to %lu\n",
|
||||
(unsigned long int) yystacksize));
|
||||
|
@ -1404,7 +1462,7 @@ yybackup:
|
|||
|
||||
yystate = yyn;
|
||||
*++yyvsp = yylval;
|
||||
|
||||
*++yylsp = yylloc;
|
||||
goto yynewstate;
|
||||
|
||||
|
||||
|
@ -1435,14 +1493,15 @@ yyreduce:
|
|||
GCC warning that YYVAL may be used uninitialized. */
|
||||
yyval = yyvsp[1-yylen];
|
||||
|
||||
|
||||
/* Default location. */
|
||||
YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
|
||||
YY_REDUCE_PRINT (yyn);
|
||||
switch (yyn)
|
||||
{
|
||||
case 2:
|
||||
|
||||
/* Line 1806 of yacc.c */
|
||||
#line 58 "query.yacc"
|
||||
#line 60 "query.yacc"
|
||||
{
|
||||
q->c = (yyvsp[(2) - (5)].arr);
|
||||
q->f = (yyvsp[(3) - (5)].f);
|
||||
|
@ -1453,7 +1512,7 @@ yyreduce:
|
|||
case 3:
|
||||
|
||||
/* Line 1806 of yacc.c */
|
||||
#line 65 "query.yacc"
|
||||
#line 67 "query.yacc"
|
||||
{
|
||||
q->c = (yyvsp[(2) - (4)].arr);
|
||||
q->f = (yyvsp[(3) - (4)].f);
|
||||
|
@ -1464,7 +1523,7 @@ yyreduce:
|
|||
case 4:
|
||||
|
||||
/* Line 1806 of yacc.c */
|
||||
#line 73 "query.yacc"
|
||||
#line 75 "query.yacc"
|
||||
{
|
||||
(yyval.arr) = malloc(sizeof(array));
|
||||
(yyval.arr)->elems = NULL;
|
||||
|
@ -1479,7 +1538,7 @@ yyreduce:
|
|||
case 5:
|
||||
|
||||
/* Line 1806 of yacc.c */
|
||||
#line 84 "query.yacc"
|
||||
#line 86 "query.yacc"
|
||||
{
|
||||
size_t new_size = (yyvsp[(1) - (3)].arr)->size+1;
|
||||
(yyvsp[(1) - (3)].arr)->elems = realloc((yyvsp[(1) - (3)].arr)->elems, new_size);
|
||||
|
@ -1492,7 +1551,7 @@ yyreduce:
|
|||
case 6:
|
||||
|
||||
/* Line 1806 of yacc.c */
|
||||
#line 93 "query.yacc"
|
||||
#line 95 "query.yacc"
|
||||
{
|
||||
(yyval.f) = malloc(sizeof(from));
|
||||
(yyval.f)->table = (yyvsp[(2) - (2)].string);
|
||||
|
@ -1502,7 +1561,7 @@ yyreduce:
|
|||
case 7:
|
||||
|
||||
/* Line 1806 of yacc.c */
|
||||
#line 99 "query.yacc"
|
||||
#line 101 "query.yacc"
|
||||
{
|
||||
(yyval.condition) = (yyvsp[(2) - (2)].condition);
|
||||
}
|
||||
|
@ -1511,7 +1570,7 @@ yyreduce:
|
|||
case 8:
|
||||
|
||||
/* Line 1806 of yacc.c */
|
||||
#line 105 "query.yacc"
|
||||
#line 107 "query.yacc"
|
||||
{
|
||||
(yyval.arr) = malloc(sizeof(array));
|
||||
(yyval.arr)->elems = realloc((yyval.arr)->elems, sizeof(char*) * 1);
|
||||
|
@ -1523,7 +1582,7 @@ yyreduce:
|
|||
case 9:
|
||||
|
||||
/* Line 1806 of yacc.c */
|
||||
#line 113 "query.yacc"
|
||||
#line 115 "query.yacc"
|
||||
{
|
||||
size_t new_size = (yyvsp[(1) - (3)].arr)->size + 1;
|
||||
(yyvsp[(1) - (3)].arr)->elems = realloc((yyvsp[(1) - (3)].arr)->elems, sizeof(char*) * new_size);
|
||||
|
@ -1536,7 +1595,7 @@ yyreduce:
|
|||
case 10:
|
||||
|
||||
/* Line 1806 of yacc.c */
|
||||
#line 123 "query.yacc"
|
||||
#line 125 "query.yacc"
|
||||
{
|
||||
(yyval.v) = malloc(sizeof(value));
|
||||
(yyval.v)->name = (yyvsp[(1) - (3)].string);
|
||||
|
@ -1549,7 +1608,7 @@ yyreduce:
|
|||
case 11:
|
||||
|
||||
/* Line 1806 of yacc.c */
|
||||
#line 132 "query.yacc"
|
||||
#line 134 "query.yacc"
|
||||
{
|
||||
(yyval.v) = malloc(sizeof(value));
|
||||
(yyval.v)->name = (yyvsp[(1) - (4)].string);
|
||||
|
@ -1560,7 +1619,7 @@ yyreduce:
|
|||
case 12:
|
||||
|
||||
/* Line 1806 of yacc.c */
|
||||
#line 140 "query.yacc"
|
||||
#line 142 "query.yacc"
|
||||
{
|
||||
(yyval.v) = malloc(sizeof(value));
|
||||
(yyval.v)->name = (yyvsp[(1) - (1)].string);
|
||||
|
@ -1571,7 +1630,7 @@ yyreduce:
|
|||
case 13:
|
||||
|
||||
/* Line 1806 of yacc.c */
|
||||
#line 147 "query.yacc"
|
||||
#line 149 "query.yacc"
|
||||
{
|
||||
(yyval.v) = malloc(sizeof(value));
|
||||
(yyval.v)->name = (yyvsp[(1) - (1)].string);
|
||||
|
@ -1582,7 +1641,7 @@ yyreduce:
|
|||
case 15:
|
||||
|
||||
/* Line 1806 of yacc.c */
|
||||
#line 157 "query.yacc"
|
||||
#line 159 "query.yacc"
|
||||
{
|
||||
(yyval.expression) = malloc(sizeof(expression));
|
||||
(yyval.expression)->left = (yyvsp[(1) - (1)].v);
|
||||
|
@ -1594,7 +1653,7 @@ yyreduce:
|
|||
case 16:
|
||||
|
||||
/* Line 1806 of yacc.c */
|
||||
#line 165 "query.yacc"
|
||||
#line 167 "query.yacc"
|
||||
{
|
||||
(yyval.expression) = malloc(sizeof(expression));
|
||||
(yyval.expression)->left = (yyvsp[(1) - (3)].v);
|
||||
|
@ -1606,7 +1665,7 @@ yyreduce:
|
|||
case 21:
|
||||
|
||||
/* Line 1806 of yacc.c */
|
||||
#line 183 "query.yacc"
|
||||
#line 185 "query.yacc"
|
||||
{
|
||||
(yyval.bool_expression) = malloc(sizeof(bool_expression));
|
||||
(yyval.bool_expression)->left = (yyvsp[(1) - (1)].expression);
|
||||
|
@ -1618,7 +1677,7 @@ yyreduce:
|
|||
case 22:
|
||||
|
||||
/* Line 1806 of yacc.c */
|
||||
#line 191 "query.yacc"
|
||||
#line 193 "query.yacc"
|
||||
{
|
||||
(yyval.bool_expression) = malloc(sizeof(bool_expression));
|
||||
(yyval.bool_expression)->left = (yyvsp[(1) - (3)].expression);
|
||||
|
@ -1630,7 +1689,7 @@ yyreduce:
|
|||
case 23:
|
||||
|
||||
/* Line 1806 of yacc.c */
|
||||
#line 200 "query.yacc"
|
||||
#line 202 "query.yacc"
|
||||
{
|
||||
(yyval.condition) = malloc(sizeof(condition));
|
||||
(yyval.condition)->left = (yyvsp[(1) - (3)].bool_expression);
|
||||
|
@ -1642,7 +1701,7 @@ yyreduce:
|
|||
case 24:
|
||||
|
||||
/* Line 1806 of yacc.c */
|
||||
#line 208 "query.yacc"
|
||||
#line 210 "query.yacc"
|
||||
{
|
||||
(yyval.condition) = malloc(sizeof(condition));
|
||||
(yyval.condition)->left = (yyvsp[(1) - (3)].bool_expression);
|
||||
|
@ -1654,7 +1713,7 @@ yyreduce:
|
|||
case 25:
|
||||
|
||||
/* Line 1806 of yacc.c */
|
||||
#line 216 "query.yacc"
|
||||
#line 218 "query.yacc"
|
||||
{
|
||||
(yyval.condition) = malloc(sizeof(condition));
|
||||
(yyval.condition)->left = (yyvsp[(1) - (1)].bool_expression);
|
||||
|
@ -1666,7 +1725,7 @@ yyreduce:
|
|||
|
||||
|
||||
/* Line 1806 of yacc.c */
|
||||
#line 1670 "y.tab.c"
|
||||
#line 1729 "y.tab.c"
|
||||
default: break;
|
||||
}
|
||||
/* User semantic actions sometimes alter yychar, and that requires
|
||||
|
@ -1687,6 +1746,7 @@ yyreduce:
|
|||
YY_STACK_PRINT (yyss, yyssp);
|
||||
|
||||
*++yyvsp = yyval;
|
||||
*++yylsp = yyloc;
|
||||
|
||||
/* Now `shift' the result of the reduction. Determine what state
|
||||
that goes to, based on the state we popped back to and the rule
|
||||
|
@ -1716,7 +1776,7 @@ yyerrlab:
|
|||
{
|
||||
++yynerrs;
|
||||
#if ! YYERROR_VERBOSE
|
||||
yyerror (q, scanner, YY_("syntax error"));
|
||||
yyerror (&yylloc, q, scanner, YY_("syntax error"));
|
||||
#else
|
||||
# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
|
||||
yyssp, yytoken)
|
||||
|
@ -1743,7 +1803,7 @@ yyerrlab:
|
|||
yymsgp = yymsg;
|
||||
}
|
||||
}
|
||||
yyerror (q, scanner, yymsgp);
|
||||
yyerror (&yylloc, q, scanner, yymsgp);
|
||||
if (yysyntax_error_status == 2)
|
||||
goto yyexhaustedlab;
|
||||
}
|
||||
|
@ -1751,7 +1811,7 @@ yyerrlab:
|
|||
#endif
|
||||
}
|
||||
|
||||
|
||||
yyerror_range[1] = yylloc;
|
||||
|
||||
if (yyerrstatus == 3)
|
||||
{
|
||||
|
@ -1767,7 +1827,7 @@ yyerrlab:
|
|||
else
|
||||
{
|
||||
yydestruct ("Error: discarding",
|
||||
yytoken, &yylval, q, scanner);
|
||||
yytoken, &yylval, &yylloc, q, scanner);
|
||||
yychar = YYEMPTY;
|
||||
}
|
||||
}
|
||||
|
@ -1788,6 +1848,7 @@ yyerrorlab:
|
|||
if (/*CONSTCOND*/ 0)
|
||||
goto yyerrorlab;
|
||||
|
||||
yyerror_range[1] = yylsp[1-yylen];
|
||||
/* Do not reclaim the symbols of the rule which action triggered
|
||||
this YYERROR. */
|
||||
YYPOPSTACK (yylen);
|
||||
|
@ -1821,9 +1882,9 @@ yyerrlab1:
|
|||
if (yyssp == yyss)
|
||||
YYABORT;
|
||||
|
||||
|
||||
yyerror_range[1] = *yylsp;
|
||||
yydestruct ("Error: popping",
|
||||
yystos[yystate], yyvsp, q, scanner);
|
||||
yystos[yystate], yyvsp, yylsp, q, scanner);
|
||||
YYPOPSTACK (1);
|
||||
yystate = *yyssp;
|
||||
YY_STACK_PRINT (yyss, yyssp);
|
||||
|
@ -1831,6 +1892,11 @@ yyerrlab1:
|
|||
|
||||
*++yyvsp = yylval;
|
||||
|
||||
yyerror_range[2] = yylloc;
|
||||
/* Using YYLLOC is tempting, but would change the location of
|
||||
the lookahead. YYLOC is available though. */
|
||||
YYLLOC_DEFAULT (yyloc, yyerror_range, 2);
|
||||
*++yylsp = yyloc;
|
||||
|
||||
/* Shift the error token. */
|
||||
YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
|
||||
|
@ -1858,7 +1924,7 @@ yyabortlab:
|
|||
| yyexhaustedlab -- memory exhaustion comes here. |
|
||||
`-------------------------------------------------*/
|
||||
yyexhaustedlab:
|
||||
yyerror (q, scanner, YY_("memory exhausted"));
|
||||
yyerror (&yylloc, q, scanner, YY_("memory exhausted"));
|
||||
yyresult = 2;
|
||||
/* Fall through. */
|
||||
#endif
|
||||
|
@ -1870,7 +1936,7 @@ yyreturn:
|
|||
user semantic actions for why this is necessary. */
|
||||
yytoken = YYTRANSLATE (yychar);
|
||||
yydestruct ("Cleanup: discarding lookahead",
|
||||
yytoken, &yylval, q, scanner);
|
||||
yytoken, &yylval, &yylloc, q, scanner);
|
||||
}
|
||||
/* Do not reclaim the symbols of the rule which action triggered
|
||||
this YYABORT or YYACCEPT. */
|
||||
|
@ -1879,7 +1945,7 @@ yyreturn:
|
|||
while (yyssp != yyss)
|
||||
{
|
||||
yydestruct ("Cleanup: popping",
|
||||
yystos[*yyssp], yyvsp, q, scanner);
|
||||
yystos[*yyssp], yyvsp, yylsp, q, scanner);
|
||||
YYPOPSTACK (1);
|
||||
}
|
||||
#ifndef yyoverflow
|
||||
|
@ -1897,7 +1963,7 @@ yyreturn:
|
|||
|
||||
|
||||
/* Line 2067 of yacc.c */
|
||||
#line 238 "query.yacc"
|
||||
#line 240 "query.yacc"
|
||||
|
||||
void *yy_scan_string(char *, void *);
|
||||
void yy_delete_buffer(void *, void *);
|
||||
|
@ -1976,7 +2042,10 @@ parse_query(char *const query_s)
|
|||
return q;
|
||||
}
|
||||
|
||||
int yyerror(query *q, void *s, char *err) {
|
||||
q->error = strdup(err);
|
||||
int yyerror(YYLTYPE *locp, query *q, void *s, char *err) {
|
||||
q->error = malloc(sizeof(error));
|
||||
q->error->err = strdup(err);
|
||||
q->error->line = locp->last_line;
|
||||
q->error->column = locp->last_column;
|
||||
}
|
||||
|
||||
|
|
|
@ -101,4 +101,18 @@ typedef union YYSTYPE
|
|||
|
||||
|
||||
|
||||
#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
|
||||
typedef struct YYLTYPE
|
||||
{
|
||||
int first_line;
|
||||
int first_column;
|
||||
int last_line;
|
||||
int last_column;
|
||||
} YYLTYPE;
|
||||
# define yyltype YYLTYPE /* obsolescent; will be withdrawn */
|
||||
# define YYLTYPE_IS_DECLARED 1
|
||||
# define YYLTYPE_IS_TRIVIAL 1
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue