Skip to content

Commit

Permalink
fix nensenses related yyllex, using older form of bison option
Browse files Browse the repository at this point in the history
  • Loading branch information
okbob committed Jan 23, 2018
1 parent e71c7d7 commit 612fca5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
9 changes: 6 additions & 3 deletions sqlparse.y
@@ -1,4 +1,9 @@
%define api.prefix {orafce_sql_yy}
/*
* %define api.prefix {orafce_sql_yy} is not compileable on old bison 2.4
* so I am using obsolete but still working option.
*/

%name-prefix "orafce_sql_yy"

%{

Expand Down Expand Up @@ -46,8 +51,6 @@ static int scanbuflen;

void orafce_sql_yyerror(List **result, const char *message);


#define ORAFCE_SQL_YYLTYPE int
#define YYMALLOC malloc /* XXX: should use palloc? */
#define YYFREE free /* XXX: should use pfree? */

Expand Down
8 changes: 3 additions & 5 deletions sqlscan.l
Expand Up @@ -48,7 +48,7 @@ static bool extended_string = false;

static YY_BUFFER_STATE scanbufhandle;

#define SET_YYLLOC() (orafce_sql_yylval.val.lloc = orafce_sql_yylloc = yytext - scanbuf)
#define SET_YYLLOC() (orafce_sql_yylval.val.lloc = yytext - scanbuf)

/* Handles to the buffer that the lexer uses internally */
static char *scanbuf;
Expand Down Expand Up @@ -884,7 +884,7 @@ lexer_errposition(void)
int pos;

/* Convert byte offset to character number */
pos = _pg_mbstrlen_with_len(scanbuf, yylloc) + 1;
pos = _pg_mbstrlen_with_len(scanbuf, orafce_sql_yylval.val.lloc) + 1;
/* And pass it to the ereport mechanism */
return errposition(pos);
}
Expand All @@ -902,21 +902,19 @@ lexer_errposition(void)
void
orafce_sql_yyerror(List **result, const char *message)
{
const char *loc = scanbuf + yylloc;
const char *loc = scanbuf + orafce_sql_yylval.val.lloc;

if (*loc == YY_END_OF_BUFFER_CHAR)
{
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
/* translator: %s is typically "syntax error" */
errmsg("%s at end of input", _(message)),
lexer_errposition()));
}
else
{
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
/* translator: first %s is typically "syntax error" */
errmsg("%s at or near \"%s\"", _(message), loc),
lexer_errposition()));
}
Expand Down

0 comments on commit 612fca5

Please sign in to comment.