mirror of
https://github.com/postgres/postgres.git
synced 2025-07-31 22:04:40 +03:00
Use exclusive state to help fix unary minus parsing.
Remove "backdoor" for DEFAULT and CHECK.
This commit is contained in:
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.20 1997/09/12 09:01:46 vadim Exp $
|
* $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.21 1997/09/13 03:12:55 thomas Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -36,10 +36,6 @@
|
|||||||
extern char *parseString;
|
extern char *parseString;
|
||||||
extern char *parseCh;
|
extern char *parseCh;
|
||||||
|
|
||||||
int CurScanPosition(void);
|
|
||||||
int DefaultStartPosition;
|
|
||||||
int CheckStartPosition;
|
|
||||||
|
|
||||||
/* some versions of lex define this as a macro */
|
/* some versions of lex define this as a macro */
|
||||||
#if defined(yywrap)
|
#if defined(yywrap)
|
||||||
#undef yywrap
|
#undef yywrap
|
||||||
@ -61,6 +57,7 @@ void unput(char);
|
|||||||
extern YYSTYPE yylval;
|
extern YYSTYPE yylval;
|
||||||
|
|
||||||
int llen;
|
int llen;
|
||||||
|
char *ScanString;
|
||||||
char literal[MAX_PARSE_BUFFER];
|
char literal[MAX_PARSE_BUFFER];
|
||||||
|
|
||||||
%}
|
%}
|
||||||
@ -68,19 +65,26 @@ char literal[MAX_PARSE_BUFFER];
|
|||||||
* The longest pattern which matches an input string is always chosen.
|
* The longest pattern which matches an input string is always chosen.
|
||||||
* For equal-length patterns, the first occurring in the rules list is chosen.
|
* For equal-length patterns, the first occurring in the rules list is chosen.
|
||||||
* INITIAL is the starting condition, to which all non-conditional rules apply.
|
* INITIAL is the starting condition, to which all non-conditional rules apply.
|
||||||
* <xc> is an exclusive condition to allow embedded C-style comments.
|
|
||||||
* When in an exclusive condition, only those rules defined for that condition apply.
|
* When in an exclusive condition, only those rules defined for that condition apply.
|
||||||
* So, when in condition <xc>, only strings which would terminate the "extended comment"
|
*
|
||||||
* trigger any action other than "ignore".
|
* Exclusive states change parsing rules while the state is active.
|
||||||
|
* There are exclusive states for quoted strings, extended comments,
|
||||||
|
* and to eliminate parsing troubles for numeric strings.
|
||||||
|
* Exclusive states:
|
||||||
|
* <xc> extended C-style comments - tgl 1997-07-12
|
||||||
|
* <xq> quoted strings - tgl 1997-07-30
|
||||||
|
* <xm> numeric strings with embedded minus sign - tgl 1997-09-05
|
||||||
|
*
|
||||||
* The "extended comment" syntax closely resembles allowable operator syntax.
|
* The "extended comment" syntax closely resembles allowable operator syntax.
|
||||||
* Therefore, be sure to match _any_ candidate comment, including those with appended
|
* So, when in condition <xc>, only strings which would terminate the
|
||||||
|
* "extended comment" trigger any action other than "ignore".
|
||||||
|
* Be sure to match _any_ candidate comment, including those with appended
|
||||||
* operator-like symbols. - thomas 1997-07-14
|
* operator-like symbols. - thomas 1997-07-14
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* define an exclusive condition to allow extended C-style comments - tgl 1997-07-12 */
|
|
||||||
%x xc
|
%x xc
|
||||||
/* define an exclusive condition for quoted strings - tgl 1997-07-30 */
|
|
||||||
%x xq
|
%x xq
|
||||||
|
%x xm
|
||||||
|
|
||||||
/* We used to allow double-quoted strings, but SQL doesn't so we won't either */
|
/* We used to allow double-quoted strings, but SQL doesn't so we won't either */
|
||||||
quote '
|
quote '
|
||||||
@ -97,6 +101,7 @@ xcinside [^*]*
|
|||||||
xcstar [^/]
|
xcstar [^/]
|
||||||
|
|
||||||
digit [0-9]
|
digit [0-9]
|
||||||
|
number [-+.0-9Ee]
|
||||||
letter [_A-Za-z]
|
letter [_A-Za-z]
|
||||||
letter_or_digit [_A-Za-z0-9]
|
letter_or_digit [_A-Za-z0-9]
|
||||||
|
|
||||||
@ -107,32 +112,30 @@ identifier {letter}{letter_or_digit}*
|
|||||||
typecast "::"
|
typecast "::"
|
||||||
|
|
||||||
self [,()\[\].;$\:\+\-\*\/\<\>\=\|]
|
self [,()\[\].;$\:\+\-\*\/\<\>\=\|]
|
||||||
selfm {self}[\-][\.0-9]
|
|
||||||
|
|
||||||
op_and_self [\~\!\@\#\%\^\&\|\`\?\$\:\+\-\*\/\<\>\=]
|
op_and_self [\~\!\@\#\%\^\&\|\`\?\$\:\+\-\*\/\<\>\=]
|
||||||
|
|
||||||
operator {op_and_self}+
|
operator {op_and_self}+
|
||||||
operatorm {op_and_self}+[\-][\.0-9]
|
|
||||||
|
xminteger {integer}/-
|
||||||
|
xmreal {real}/{space}*-{digit}
|
||||||
|
xmstop -
|
||||||
|
|
||||||
integer -?{digit}+
|
integer -?{digit}+
|
||||||
real -?{digit}+\.{digit}+([Ee][-+]?{digit}+)?
|
real -?{digit}+\.{digit}+([Ee][-+]?{digit}+)?
|
||||||
|
|
||||||
param \${integer}
|
param \${integer}
|
||||||
|
|
||||||
comment "--".*\n
|
comment ("--"|"//").*\n
|
||||||
comment2 "//".*\n
|
|
||||||
|
|
||||||
space [ \t\n\f]
|
space [ \t\n\f]
|
||||||
other .
|
other .
|
||||||
|
|
||||||
%%
|
/* DO NOT PUT ANY COMMENTS IN THE FOLLOWING SECTION.
|
||||||
{sysfunc} {
|
* AT&T lex does not properly handle C-style comments in this second lex block.
|
||||||
yylval.str = pstrdup(SystemFunctionHandler((char *)yytext));
|
* So, put comments here. tgl - 1997-09-08
|
||||||
return (SCONST);
|
*/
|
||||||
}
|
|
||||||
|
|
||||||
{comment} { /* ignore */ }
|
%%
|
||||||
{comment2} { /* ignore */ }
|
{comment} { /* ignore */ }
|
||||||
|
|
||||||
{xcline} { /* ignore */ }
|
{xcline} { /* ignore */ }
|
||||||
|
|
||||||
@ -167,18 +170,26 @@ other .
|
|||||||
llen += yyleng-1;
|
llen += yyleng-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<xm>{space}* { /* ignore */ }
|
||||||
|
<xm>{xmstop} {
|
||||||
|
BEGIN(INITIAL);
|
||||||
|
return (yytext[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
{sysfunc} {
|
||||||
|
yylval.str = pstrdup(SystemFunctionHandler((char *)yytext));
|
||||||
|
return (SCONST);
|
||||||
|
}
|
||||||
|
|
||||||
{typecast} { return TYPECAST; }
|
{typecast} { return TYPECAST; }
|
||||||
|
|
||||||
{selfm} {
|
{self}/-[\.0-9] {
|
||||||
yyless(yyleng-2);
|
|
||||||
return (yytext[0]);
|
return (yytext[0]);
|
||||||
}
|
}
|
||||||
{self} { return (yytext[0]); }
|
{self} { return (yytext[0]); }
|
||||||
|
{operator}/-[\.0-9] {
|
||||||
{operatorm} {
|
|
||||||
yyless(yyleng-2);
|
|
||||||
yylval.str = pstrdup((char*)yytext);
|
yylval.str = pstrdup((char*)yytext);
|
||||||
return (Op);
|
return (Op);
|
||||||
}
|
}
|
||||||
{operator} {
|
{operator} {
|
||||||
if (strcmp((char*)yytext,"!=") == 0)
|
if (strcmp((char*)yytext,"!=") == 0)
|
||||||
@ -191,7 +202,26 @@ other .
|
|||||||
yylval.ival = atoi((char*)&yytext[1]);
|
yylval.ival = atoi((char*)&yytext[1]);
|
||||||
return (PARAM);
|
return (PARAM);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{integer}/{space}*-{number} {
|
||||||
|
BEGIN(xm);
|
||||||
|
ScanString = pstrdup((char*)yytext);
|
||||||
|
yylval.ival = atoi((char*)yytext);
|
||||||
|
return (ICONST);
|
||||||
|
}
|
||||||
|
{real}/{space}*-{number} {
|
||||||
|
char* endptr;
|
||||||
|
BEGIN(xm);
|
||||||
|
errno = 0;
|
||||||
|
ScanString = pstrdup((char*)yytext);
|
||||||
|
yylval.dval = strtod(((char *)yytext),&endptr);
|
||||||
|
if (*endptr != '\0' || errno == ERANGE)
|
||||||
|
elog(WARN,"\tBad float8 input format\n");
|
||||||
|
CheckFloat8Val(yylval.dval);
|
||||||
|
return (FCONST);
|
||||||
|
}
|
||||||
{integer} {
|
{integer} {
|
||||||
|
ScanString = pstrdup((char*)yytext);
|
||||||
yylval.ival = atoi((char*)yytext);
|
yylval.ival = atoi((char*)yytext);
|
||||||
return (ICONST);
|
return (ICONST);
|
||||||
}
|
}
|
||||||
@ -199,6 +229,7 @@ other .
|
|||||||
char* endptr;
|
char* endptr;
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
|
ScanString = pstrdup((char*)yytext);
|
||||||
yylval.dval = strtod(((char *)yytext),&endptr);
|
yylval.dval = strtod(((char *)yytext),&endptr);
|
||||||
if (*endptr != '\0' || errno == ERANGE)
|
if (*endptr != '\0' || errno == ERANGE)
|
||||||
elog(WARN,"\tBad float8 input format\n");
|
elog(WARN,"\tBad float8 input format\n");
|
||||||
@ -215,16 +246,6 @@ other .
|
|||||||
|
|
||||||
keyword = ScanKeywordLookup((char*)yytext);
|
keyword = ScanKeywordLookup((char*)yytext);
|
||||||
if (keyword != NULL) {
|
if (keyword != NULL) {
|
||||||
if ( keyword->value == DEFAULT )
|
|
||||||
{
|
|
||||||
DefaultStartPosition = CurScanPosition () + yyleng + 1;
|
|
||||||
printf( "default offset is %d\n", DefaultStartPosition);
|
|
||||||
}
|
|
||||||
else if ( keyword->value == CHECK )
|
|
||||||
{
|
|
||||||
CheckStartPosition = CurScanPosition () + yyleng + 1;
|
|
||||||
printf( "check offset is %d\n", CheckStartPosition);
|
|
||||||
}
|
|
||||||
return (keyword->value);
|
return (keyword->value);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -241,7 +262,7 @@ other .
|
|||||||
|
|
||||||
void yyerror(char message[])
|
void yyerror(char message[])
|
||||||
{
|
{
|
||||||
elog(WARN, "parser: %s at or near \"%s\"\n", message, yytext);
|
elog(WARN, "parser: %s at or near \"%s\"", message, yytext);
|
||||||
}
|
}
|
||||||
|
|
||||||
int yywrap()
|
int yywrap()
|
||||||
@ -267,8 +288,6 @@ init_io()
|
|||||||
BEGIN INITIAL;
|
BEGIN INITIAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if !defined(FLEX_SCANNER)
|
#if !defined(FLEX_SCANNER)
|
||||||
/* get lex input from a string instead of from stdin */
|
/* get lex input from a string instead of from stdin */
|
||||||
int
|
int
|
||||||
@ -294,16 +313,9 @@ unput(char c)
|
|||||||
else if (c != 0)
|
else if (c != 0)
|
||||||
*--parseCh = c;
|
*--parseCh = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
|
||||||
CurScanPosition(void)
|
|
||||||
{
|
|
||||||
return (parseCh - parseString - yyleng);
|
|
||||||
}
|
|
||||||
#endif /* !defined(FLEX_SCANNER) */
|
#endif /* !defined(FLEX_SCANNER) */
|
||||||
|
|
||||||
#ifdef FLEX_SCANNER
|
#ifdef FLEX_SCANNER
|
||||||
static bool end_of_buf = false;
|
|
||||||
/* input routine for flex to read input from a string instead of a file */
|
/* input routine for flex to read input from a string instead of a file */
|
||||||
int
|
int
|
||||||
myinput(char* buf, int max)
|
myinput(char* buf, int max)
|
||||||
@ -321,29 +333,10 @@ myinput(char* buf, int max)
|
|||||||
memcpy(buf, parseString, copylen);
|
memcpy(buf, parseString, copylen);
|
||||||
buf[copylen] = '\0';
|
buf[copylen] = '\0';
|
||||||
parseCh = parseString;
|
parseCh = parseString;
|
||||||
end_of_buf = false;
|
|
||||||
return copylen;
|
return copylen;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
end_of_buf = true;
|
|
||||||
return 0; /* end of string */
|
return 0; /* end of string */
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
|
||||||
CurScanPosition(void)
|
|
||||||
{
|
|
||||||
int spos;
|
|
||||||
|
|
||||||
if ( end_of_buf )
|
|
||||||
spos = strlen (parseString) - strlen (yytext);
|
|
||||||
else
|
|
||||||
spos = yy_c_buf_p - yy_current_buffer->yy_ch_buf - yyleng;
|
|
||||||
|
|
||||||
printf( "current position is %d\n", spos);
|
|
||||||
return (spos);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* FLEX_SCANNER */
|
#endif /* FLEX_SCANNER */
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user