88 *
99 *
1010 * IDENTIFICATION
11- * $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.28 1997/11/14 15:43:27 thomas Exp $
11+ * $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.29 1997/11/17 16:31:39 thomas Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414*/
@@ -71,6 +71,8 @@ char literal[MAX_PARSE_BUFFER];
7171 * There are exclusive states for quoted strings, extended comments,
7272 * and to eliminate parsing troubles for numeric strings.
7373 * Exclusive states:
74+ * <xb> binary numeric string - thomas 1997-11-16
75+ * <xh> hexadecimal numeric string - thomas 1997-11-16
7476 * <xc> extended C-style comments - tgl 1997-07-12
7577 * <xq> quoted strings - tgl 1997-07-30
7678 * <xm> numeric strings with embedded minus sign - tgl 1997-09-05
@@ -83,8 +85,10 @@ char literal[MAX_PARSE_BUFFER];
8385 *operator-like symbols. - thomas 1997-07-14
8486 */
8587
88+ %x xb
8689%x xc
8790%x xd
91+ %x xh
8892%x xq
8993%x xm
9094
@@ -97,6 +101,16 @@ xqembedded"\\'"
97101xqliteral [\\ ](. | \n )
98102xqcat {quote }{space }* \n {space }* {quote }
99103
104+ xbstart [bB ]{quote }
105+ xbstop {quote }
106+ xbinside [^ ' ]*
107+ xbcat {quote }{space }* \n {space }* {quote }
108+
109+ xhstart [xX ]{quote }
110+ xhstop {quote }
111+ xhinside [^ ' ]*
112+ xhcat {quote }{space }* \n {space }* {quote }
113+
100114dquote \"
101115xdstart {dquote }
102116xdstop {dquote }
@@ -162,6 +176,48 @@ other.
162176
163177<xc >{xcinside }{/* ignore */ }
164178
179+ {xbstart }{
180+ BEGIN (xb);
181+ llen =0 ;
182+ *literal =' \0 ' ;
183+ }
184+ <xb >{xbstop }{
185+ char * endptr;
186+
187+ BEGIN (INITIAL);
188+ errno =0 ;
189+ yylval.ival =strtol ((char *)literal,&endptr,2 );
190+ if (*endptr !=' \0 ' || errno == ERANGE)
191+ elog (WARN," Bad binary integer input '%s'" ,literal);
192+ return (ICONST);
193+ }
194+ <xh >{xhinside }|
195+ <xb >{xbinside }{
196+ if ((llen+yyleng) > (MAX_PARSE_BUFFER -1 ))
197+ elog (WARN," quoted string parse buffer of %d chars exceeded" ,MAX_PARSE_BUFFER);
198+ memcpy (literal+llen, yytext, yyleng+1 );
199+ llen += yyleng;
200+ }
201+ <xh >{xhcat }|
202+ <xb >{xbcat }{
203+ }
204+
205+ {xhstart }{
206+ BEGIN (xh);
207+ llen =0 ;
208+ *literal =' \0 ' ;
209+ }
210+ <xh >{xhstop }{
211+ char * endptr;
212+
213+ BEGIN (INITIAL);
214+ errno =0 ;
215+ yylval.ival =strtol ((char *)literal,&endptr,16 );
216+ if (*endptr !=' \0 ' || errno == ERANGE)
217+ elog (WARN," Bad hexadecimal integer input '%s'" ,literal);
218+ return (ICONST);
219+ }
220+
165221{xqstart }{
166222BEGIN (xq);
167223llen =0 ;
@@ -250,12 +306,18 @@ other.
250306}
251307
252308{integer }/ {space }* -{number }{
309+ char * endptr;
310+
253311BEGIN (xm);
254- yylval.ival =atoi ((char *)yytext);
312+ errno =0 ;
313+ yylval.ival =strtol ((char *)yytext,&endptr,10 );
314+ if (*endptr !=' \0 ' || errno == ERANGE)
315+ elog (WARN," Bad integer input '%s'" ,yytext);
255316return (ICONST);
256317}
257318{real }/ {space }* -{number } {
258319char * endptr;
320+
259321BEGIN (xm);
260322errno =0 ;
261323yylval.dval =strtod (((char *)yytext),&endptr);