88 *
99 *
1010 * IDENTIFICATION
11- * $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.20 1997/09/12 09:01:46 vadim Exp $
11+ * $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.21 1997/09/13 03:12:55 thomas Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414*/
3636extern char *parseString;
3737extern char *parseCh;
3838
39- int CurScanPosition (void );
40- int DefaultStartPosition;
41- int CheckStartPosition;
42-
4339/* some versions of lex define this as a macro*/
4440#if defined(yywrap)
4541#undef yywrap
@@ -61,26 +57,34 @@ void unput(char);
6157extern YYSTYPE yylval;
6258
6359int llen;
60+ char *ScanString;
6461char literal[MAX_PARSE_BUFFER];
6562
6663%}
6764/* OK, here is a short description of lex/flex rules behavior.
6865 * The longest pattern which matches an input string is always chosen.
6966 * For equal-length patterns, the first occurring in the rules list is chosen.
7067 * INITIAL is the starting condition, to which all non-conditional rules apply.
71- * <xc> is an exclusive condition to allow embedded C-style comments.
7268 * When in an exclusive condition, only those rules defined for that condition apply.
73- * So, when in condition <xc>, only strings which would terminate the "extended comment"
74- *trigger any action other than "ignore".
69+ *
70+ * Exclusive states change parsing rules while the state is active.
71+ * There are exclusive states for quoted strings, extended comments,
72+ * and to eliminate parsing troubles for numeric strings.
73+ * Exclusive states:
74+ * <xc> extended C-style comments - tgl 1997-07-12
75+ * <xq> quoted strings - tgl 1997-07-30
76+ * <xm> numeric strings with embedded minus sign - tgl 1997-09-05
77+ *
7578 * The "extended comment" syntax closely resembles allowable operator syntax.
76- * Therefore, be sure to match _any_ candidate comment, including those with appended
79+ * So, when in condition <xc>, only strings which would terminate the
80+ * "extended comment" trigger any action other than "ignore".
81+ * Be sure to match _any_ candidate comment, including those with appended
7782 *operator-like symbols. - thomas 1997-07-14
7883 */
7984
80- /* define an exclusive condition to allow extended C-style comments - tgl 1997-07-12 */
8185%x xc
82- /* define an exclusive condition for quoted strings - tgl 1997-07-30 */
8386%x xq
87+ %x xm
8488
8589/* We used to allow double-quoted strings, but SQL doesn't so we won't either */
8690quote '
@@ -97,6 +101,7 @@ xcinside[^*]*
97101xcstar [^ / ]
98102
99103digit [0 -9 ]
104+ number [-+.0 -9Ee ]
100105letter [_A -Za -z ]
101106letter_or_digit [_A -Za -z0 -9 ]
102107
@@ -107,32 +112,30 @@ identifier{letter}{letter_or_digit}*
107112typecast " ::"
108113
109114self [,() \[\] .;$ \:\+\-\*\/\<\>\=\| ]
110- selfm {self }[\- ][\. 0 -9 ]
111-
112115op_and_self [\~\!\@\#\%\^\&\|\`\?\$\:\+\-\*\/\<\>\= ]
113-
114116operator {op_and_self }+
115- operatorm {op_and_self }+ [\- ][\. 0 -9 ]
117+
118+ xminteger {integer }/ -
119+ xmreal {real }/ {space }* -{digit }
120+ xmstop -
116121
117122integer -? {digit }+
118123real -? {digit }+ \. {digit }+ ([Ee ][-+ ]? {digit }+ )?
119124
120125param \$ {integer }
121126
122- comment " --" . * \n
123- comment2 " //" . * \n
127+ comment (" --" | " //" ). * \n
124128
125129space [\t\n\f ]
126130other .
127131
128- %%
129- {sysfunc }{
130- yylval.str =pstrdup (SystemFunctionHandler ((char *)yytext));
131- return (SCONST);
132- }
132+ /* DO NOT PUT ANY COMMENTS IN THE FOLLOWING SECTION.
133+ * AT&T lex does not properly handle C-style comments in this second lex block.
134+ * So, put comments here. tgl - 1997-09-08
135+ */
133136
134- { comment }{ /* ignore */ }
135- {comment2 }{/* ignore */ }
137+ %%
138+ {comment }{/* ignore */ }
136139
137140{xcline }{/* ignore */ }
138141
@@ -167,18 +170,26 @@ other.
167170llen += yyleng-1 ;
168171}
169172
173+ <xm >{space }* {/* ignore */ }
174+ <xm >{xmstop }{
175+ BEGIN (INITIAL);
176+ return (yytext[0 ]);
177+ }
178+
179+ {sysfunc }{
180+ yylval.str =pstrdup (SystemFunctionHandler ((char *)yytext));
181+ return (SCONST);
182+ }
183+
170184{typecast }{return TYPECAST; }
171185
172- {selfm }{
173- yyless (yyleng-2 );
186+ {self }/ -[\. 0 -9 ]{
174187return (yytext[0 ]);
175188}
176189{self }{return (yytext[0 ]); }
177-
178- {operatorm }{
179- yyless (yyleng-2 );
190+ {operator }/ -[\. 0 -9 ]{
180191yylval.str =pstrdup ((char *)yytext);
181- return (Op);
192+ return (Op);
182193}
183194{operator }{
184195if (strcmp ((char *)yytext," !=" ) ==0 )
@@ -191,14 +202,34 @@ other.
191202yylval.ival =atoi ((char *)&yytext[1 ]);
192203return (PARAM);
193204}
205+
206+ {integer }/ {space }* -{number }{
207+ BEGIN (xm);
208+ ScanString =pstrdup ((char *)yytext);
209+ yylval.ival =atoi ((char *)yytext);
210+ return (ICONST);
211+ }
212+ {real }/ {space }* -{number } {
213+ char * endptr;
214+ BEGIN (xm);
215+ errno =0 ;
216+ ScanString =pstrdup ((char *)yytext);
217+ yylval.dval =strtod (((char *)yytext),&endptr);
218+ if (*endptr !=' \0 ' || errno == ERANGE)
219+ elog (WARN," \t Bad float8 input format\n " );
220+ CheckFloat8Val (yylval.dval );
221+ return (FCONST);
222+ }
194223{integer }{
224+ ScanString =pstrdup ((char *)yytext);
195225yylval.ival =atoi ((char *)yytext);
196226return (ICONST);
197227}
198228{real }{
199229char * endptr;
200230
201231errno =0 ;
232+ ScanString =pstrdup ((char *)yytext);
202233yylval.dval =strtod (((char *)yytext),&endptr);
203234if (*endptr !=' \0 ' || errno == ERANGE)
204235elog (WARN," \t Bad float8 input format\n " );
@@ -215,16 +246,6 @@ other.
215246
216247keyword =ScanKeywordLookup ((char *)yytext);
217248if (keyword !=NULL ) {
218- if ( keyword->value == DEFAULT )
219- {
220- DefaultStartPosition =CurScanPosition () + yyleng +1 ;
221- printf (" default offset is %d\n " , DefaultStartPosition);
222- }
223- else if ( keyword->value == CHECK )
224- {
225- CheckStartPosition =CurScanPosition () + yyleng +1 ;
226- printf (" check offset is %d\n " , CheckStartPosition);
227- }
228249return (keyword->value );
229250}
230251else
@@ -241,7 +262,7 @@ other.
241262
242263void yyerror (char message[])
243264{
244- elog (WARN," parser: %s at or near\" %s\"\n " , message, yytext);
265+ elog (WARN," parser: %s at or near\" %s\" " , message, yytext);
245266}
246267
247268int yywrap ()
@@ -267,8 +288,6 @@ init_io()
267288BEGIN INITIAL;
268289}
269290
270-
271-
272291#if !defined(FLEX_SCANNER)
273292/* get lex input from a string instead of from stdin */
274293int
@@ -294,16 +313,9 @@ unput(char c)
294313else if (c !=0 )
295314*--parseCh = c;
296315}
297-
298- int
299- CurScanPosition (void )
300- {
301- return (parseCh - parseString - yyleng);
302- }
303316#endif /* !defined(FLEX_SCANNER) */
304317
305318#ifdef FLEX_SCANNER
306- static bool end_of_buf =false ;
307319/* input routine for flex to read input from a string instead of a file */
308320int
309321myinput (char * buf,int max)
@@ -321,29 +333,10 @@ myinput(char* buf, int max)
321333memcpy (buf, parseString, copylen);
322334buf[copylen] =' \0 ' ;
323335parseCh = parseString;
324- end_of_buf =false ;
325336return copylen;
326337}
327338else
328- {
329- end_of_buf =true ;
330339return 0 ;/* end of string */
331- }
332340}
333-
334- int
335- CurScanPosition (void )
336- {
337- int spos;
338-
339- if ( end_of_buf )
340- spos =strlen (parseString) -strlen (yytext);
341- else
342- spos = yy_c_buf_p - yy_current_buffer->yy_ch_buf - yyleng;
343-
344- printf (" current position is %d\n " , spos);
345- return (spos);
346- }
347-
348341#endif /* FLEX_SCANNER */
349342