Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0fbfba1

Browse files
author
Thomas G. Lockhart
committed
Use exclusive state to help fix unary minus parsing.
Remove "backdoor" for DEFAULT and CHECK.
1 parentc1d3c04 commit0fbfba1

File tree

1 file changed

+62
-69
lines changed

1 file changed

+62
-69
lines changed

‎src/backend/parser/scan.l

Lines changed: 62 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
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
*/
@@ -36,10 +36,6 @@
3636
externchar *parseString;
3737
externchar *parseCh;
3838

39-
intCurScanPosition(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);
6157
extern YYSTYPE yylval;
6258

6359
int llen;
60+
char *ScanString;
6461
char 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
%xxc
82-
/* define an exclusive condition for quoted strings - tgl 1997-07-30 */
8386
%xxq
87+
%xxm
8488

8589
/* We used to allow double-quoted strings, but SQL doesn't so we won't either */
8690
quote'
@@ -97,6 +101,7 @@ xcinside[^*]*
97101
xcstar[^/]
98102

99103
digit[0-9]
104+
number[-+.0-9Ee]
100105
letter[_A-Za-z]
101106
letter_or_digit [_A-Za-z0-9]
102107

@@ -107,32 +112,30 @@ identifier{letter}{letter_or_digit}*
107112
typecast"::"
108113

109114
self[,()\[\].;$\:\+\-\*\/\<\>\=\|]
110-
selfm{self}[\-][\.0-9]
111-
112115
op_and_self[\~\!\@\#\%\^\&\|\`\?\$\:\+\-\*\/\<\>\=]
113-
114116
operator{op_and_self}+
115-
operatorm{op_and_self}+[\-][\.0-9]
117+
118+
xminteger{integer}/-
119+
xmreal{real}/{space}*-{digit}
120+
xmstop-
116121

117122
integer-?{digit}+
118123
real-?{digit}+\.{digit}+([Ee][-+]?{digit}+)?
119124

120125
param\${integer}
121126

122-
comment"--".*\n
123-
comment2"//".*\n
127+
comment("--"|"//").*\n
124128

125129
space[\t\n\f]
126130
other.
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.
167170
llen += 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]{
174187
return (yytext[0]);
175188
}
176189
{self}{return (yytext[0]); }
177-
178-
{operatorm}{
179-
yyless(yyleng-2);
190+
{operator}/-[\.0-9]{
180191
yylval.str =pstrdup((char*)yytext);
181-
return (Op);
192+
return (Op);
182193
}
183194
{operator}{
184195
if (strcmp((char*)yytext,"!=") ==0)
@@ -191,14 +202,34 @@ other.
191202
yylval.ival =atoi((char*)&yytext[1]);
192203
return (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,"\tBad float8 input format\n");
220+
CheckFloat8Val(yylval.dval);
221+
return (FCONST);
222+
}
194223
{integer}{
224+
ScanString =pstrdup((char*)yytext);
195225
yylval.ival =atoi((char*)yytext);
196226
return (ICONST);
197227
}
198228
{real}{
199229
char* endptr;
200230

201231
errno =0;
232+
ScanString =pstrdup((char*)yytext);
202233
yylval.dval =strtod(((char *)yytext),&endptr);
203234
if (*endptr !='\0' || errno == ERANGE)
204235
elog(WARN,"\tBad float8 input format\n");
@@ -215,16 +246,6 @@ other.
215246

216247
keyword =ScanKeywordLookup((char*)yytext);
217248
if (keyword !=NULL) {
218-
if ( keyword->value == DEFAULT )
219-
{
220-
DefaultStartPosition =CurScanPosition () + yyleng +1;
221-
printf("default offset is %d\n", DefaultStartPosition);
222-
}
223-
elseif ( keyword->value == CHECK )
224-
{
225-
CheckStartPosition =CurScanPosition () + yyleng +1;
226-
printf("check offset is %d\n", CheckStartPosition);
227-
}
228249
return (keyword->value);
229250
}
230251
else
@@ -241,7 +262,7 @@ other.
241262

242263
voidyyerror(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

247268
intyywrap()
@@ -267,8 +288,6 @@ init_io()
267288
BEGIN INITIAL;
268289
}
269290

270-
271-
272291
#if !defined(FLEX_SCANNER)
273292
/* get lex input from a string instead of from stdin */
274293
int
@@ -294,16 +313,9 @@ unput(char c)
294313
elseif (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-
staticbool end_of_buf =false;
307319
/* input routine for flex to read input from a string instead of a file */
308320
int
309321
myinput(char* buf,int max)
@@ -321,29 +333,10 @@ myinput(char* buf, int max)
321333
memcpy(buf, parseString, copylen);
322334
buf[copylen] ='\0';
323335
parseCh = parseString;
324-
end_of_buf =false;
325336
return copylen;
326337
}
327338
else
328-
{
329-
end_of_buf =true;
330339
return0;/* 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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp