Implement SQL92 binary and hexadecimal string decoding (b'10' and x'1F').

Check decoding of integer in x - y syntax (already done for most ints).
This commit is contained in:
Thomas G. Lockhart 1997-11-17 16:31:39 +00:00
parent 2fa330284c
commit 3d4d1e14f8
1 changed files with 64 additions and 2 deletions

View File

@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.28 1997/11/14 15:43:27 thomas Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.29 1997/11/17 16:31:39 thomas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -71,6 +71,8 @@ char literal[MAX_PARSE_BUFFER];
* There are exclusive states for quoted strings, extended comments, * There are exclusive states for quoted strings, extended comments,
* and to eliminate parsing troubles for numeric strings. * and to eliminate parsing troubles for numeric strings.
* Exclusive states: * Exclusive states:
* <xb> binary numeric string - thomas 1997-11-16
* <xh> hexadecimal numeric string - thomas 1997-11-16
* <xc> extended C-style comments - tgl 1997-07-12 * <xc> extended C-style comments - tgl 1997-07-12
* <xq> quoted strings - tgl 1997-07-30 * <xq> quoted strings - tgl 1997-07-30
* <xm> numeric strings with embedded minus sign - tgl 1997-09-05 * <xm> numeric strings with embedded minus sign - tgl 1997-09-05
@ -83,8 +85,10 @@ char literal[MAX_PARSE_BUFFER];
* operator-like symbols. - thomas 1997-07-14 * operator-like symbols. - thomas 1997-07-14
*/ */
%x xb
%x xc %x xc
%x xd %x xd
%x xh
%x xq %x xq
%x xm %x xm
@ -97,6 +101,16 @@ xqembedded "\\'"
xqliteral [\\](.|\n) xqliteral [\\](.|\n)
xqcat {quote}{space}*\n{space}*{quote} xqcat {quote}{space}*\n{space}*{quote}
xbstart [bB]{quote}
xbstop {quote}
xbinside [^']*
xbcat {quote}{space}*\n{space}*{quote}
xhstart [xX]{quote}
xhstop {quote}
xhinside [^']*
xhcat {quote}{space}*\n{space}*{quote}
dquote \" dquote \"
xdstart {dquote} xdstart {dquote}
xdstop {dquote} xdstop {dquote}
@ -162,6 +176,48 @@ other .
<xc>{xcinside} { /* ignore */ } <xc>{xcinside} { /* ignore */ }
{xbstart} {
BEGIN(xb);
llen = 0;
*literal = '\0';
}
<xb>{xbstop} {
char* endptr;
BEGIN(INITIAL);
errno = 0;
yylval.ival = strtol((char *)literal,&endptr,2);
if (*endptr != '\0' || errno == ERANGE)
elog(WARN,"Bad binary integer input '%s'",literal);
return (ICONST);
}
<xh>{xhinside} |
<xb>{xbinside} {
if ((llen+yyleng) > (MAX_PARSE_BUFFER - 1))
elog(WARN,"quoted string parse buffer of %d chars exceeded",MAX_PARSE_BUFFER);
memcpy(literal+llen, yytext, yyleng+1);
llen += yyleng;
}
<xh>{xhcat} |
<xb>{xbcat} {
}
{xhstart} {
BEGIN(xh);
llen = 0;
*literal = '\0';
}
<xh>{xhstop} {
char* endptr;
BEGIN(INITIAL);
errno = 0;
yylval.ival = strtol((char *)literal,&endptr,16);
if (*endptr != '\0' || errno == ERANGE)
elog(WARN,"Bad hexadecimal integer input '%s'",literal);
return (ICONST);
}
{xqstart} { {xqstart} {
BEGIN(xq); BEGIN(xq);
llen = 0; llen = 0;
@ -250,12 +306,18 @@ other .
} }
{integer}/{space}*-{number} { {integer}/{space}*-{number} {
char* endptr;
BEGIN(xm); BEGIN(xm);
yylval.ival = atoi((char*)yytext); errno = 0;
yylval.ival = strtol((char *)yytext,&endptr,10);
if (*endptr != '\0' || errno == ERANGE)
elog(WARN,"Bad integer input '%s'",yytext);
return (ICONST); return (ICONST);
} }
{real}/{space}*-{number} { {real}/{space}*-{number} {
char* endptr; char* endptr;
BEGIN(xm); BEGIN(xm);
errno = 0; errno = 0;
yylval.dval = strtod(((char *)yytext),&endptr); yylval.dval = strtod(((char *)yytext),&endptr);