Commit da758c26 authored by Michael Meskes's avatar Michael Meskes

Fixed lexer to correctly parse C quotes.

parent 59fc64ac
...@@ -2279,6 +2279,10 @@ Fri, 28 Dec 2007 12:15:38 +0100 ...@@ -2279,6 +2279,10 @@ Fri, 28 Dec 2007 12:15:38 +0100
<itagaki.takahiro@oss.ntt.co.jp> to fix bug in connect statement if <itagaki.takahiro@oss.ntt.co.jp> to fix bug in connect statement if
user name is a variable. user name is a variable.
- Also fixed test case that didn't detect this. - Also fixed test case that didn't detect this.
Fri, 11 Jan 2008 16:16:24 +0100
- Fixed lexer to correctly parse C quotes.
- Set pgtypes library version to 3.0. - Set pgtypes library version to 3.0.
- Set compat library version to 3.0. - Set compat library version to 3.0.
- Set ecpg library version to 6.0. - Set ecpg library version to 6.0.
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.157 2008/01/01 19:45:59 momjian Exp $ * $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.158 2008/01/11 15:19:16 meskes Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -29,7 +29,6 @@ extern YYSTYPE yylval; ...@@ -29,7 +29,6 @@ extern YYSTYPE yylval;
static int xcdepth = 0; /* depth of nesting in slash-star comments */ static int xcdepth = 0; /* depth of nesting in slash-star comments */
static char *dolqstart; /* current $foo$ quote start string */ static char *dolqstart; /* current $foo$ quote start string */
static bool escape_string_warning; static bool escape_string_warning;
static bool warn_on_first_escape;
static YY_BUFFER_STATE scanbufhandle; static YY_BUFFER_STATE scanbufhandle;
static char *scanbuf; static char *scanbuf;
...@@ -47,7 +46,6 @@ static int literalalloc; /* current allocated buffer size */ ...@@ -47,7 +46,6 @@ static int literalalloc; /* current allocated buffer size */
static void addlit(char *ytext, int yleng); static void addlit(char *ytext, int yleng);
static void addlitchar (unsigned char); static void addlitchar (unsigned char);
static void parse_include (void); static void parse_include (void);
static void check_escape_warning(void);
static bool ecpg_isspace(char ch); static bool ecpg_isspace(char ch);
static bool isdefine(void); static bool isdefine(void);
static bool isinformixdefine(void); static bool isinformixdefine(void);
...@@ -101,6 +99,7 @@ static struct _if_value ...@@ -101,6 +99,7 @@ static struct _if_value
* <xd> delimited identifiers (double-quoted identifiers) - thomas 1997-10-27 * <xd> delimited identifiers (double-quoted identifiers) - thomas 1997-10-27
* <xh> hexadecimal numeric string - thomas 1997-11-16 * <xh> hexadecimal numeric string - thomas 1997-11-16
* <xq> standard quoted strings - thomas 1997-07-30 * <xq> standard quoted strings - thomas 1997-07-30
* <xqc> standard quoted strings in C - michael
* <xe> extended quoted strings (support backslash escape sequences) * <xe> extended quoted strings (support backslash escape sequences)
* <xn> national character quoted strings * <xn> national character quoted strings
* <xdolq> $foo$ quoted strings * <xdolq> $foo$ quoted strings
...@@ -114,6 +113,7 @@ static struct _if_value ...@@ -114,6 +113,7 @@ static struct _if_value
%x xe %x xe
%x xn %x xn
%x xq %x xq
%x xqc
%x xdolq %x xdolq
%x xcond %x xcond
%x xskip %x xskip
...@@ -145,6 +145,7 @@ xch 0[xX][0-9A-Fa-f]* ...@@ -145,6 +145,7 @@ xch 0[xX][0-9A-Fa-f]*
*/ */
xqstart {quote} xqstart {quote}
xqdouble {quote}{quote} xqdouble {quote}{quote}
xqcquote [\\]{quote}
xqinside [^']+ xqinside [^']+
/* $foo$ style quotes ("dollar quoting") /* $foo$ style quotes ("dollar quoting")
...@@ -409,35 +410,31 @@ cppline {space}*#(.*\\{space})*.*{newline} ...@@ -409,35 +410,31 @@ cppline {space}*#(.*\\{space})*.*{newline}
/* National character. /* National character.
* Transfer it as-is to the backend. * Transfer it as-is to the backend.
*/ */
warn_on_first_escape = true; token_start = yytext;
token_start = yytext;
state_before = YYSTATE; state_before = YYSTATE;
BEGIN(xn); BEGIN(xn);
startlit(); startlit();
} }
<C>{xqstart} { <C>{xqstart} {
warn_on_first_escape = false;
token_start = yytext; token_start = yytext;
state_before = YYSTATE; state_before = YYSTATE;
BEGIN(xq); BEGIN(xqc);
startlit(); startlit();
} }
<SQL>{xqstart} { <SQL>{xqstart} {
warn_on_first_escape = true;
token_start = yytext; token_start = yytext;
state_before = YYSTATE; state_before = YYSTATE;
BEGIN(xq); BEGIN(xq);
startlit(); startlit();
} }
<SQL>{xestart} { <SQL>{xestart} {
warn_on_first_escape = false;
token_start = yytext; token_start = yytext;
state_before = YYSTATE; state_before = YYSTATE;
BEGIN(xe); BEGIN(xe);
startlit(); startlit();
} }
<xq>{quotestop} | <xq,xqc>{quotestop} |
<xq>{quotefail} { <xq,xqc>{quotefail} {
yyless(1); yyless(1);
BEGIN(state_before); BEGIN(state_before);
yylval.str = mm_strdup(literalbuf); yylval.str = mm_strdup(literalbuf);
...@@ -457,27 +454,22 @@ cppline {space}*#(.*\\{space})*.*{newline} ...@@ -457,27 +454,22 @@ cppline {space}*#(.*\\{space})*.*{newline}
yylval.str = mm_strdup(literalbuf); yylval.str = mm_strdup(literalbuf);
return NCONST; return NCONST;
} }
<xq,xe,xn>{xqdouble} { addlitchar('\''); } <xq,xe,xn>{xqdouble} { addlitchar('\''); }
<xq,xn>{xqinside} { addlit(yytext, yyleng); } <xqc>{xqcquote} {
<xe>{xeinside} { addlit(yytext, yyleng); } addlitchar('\\');
<xe>{xeescape} { addlitchar('\'');
check_escape_warning();
addlit(yytext, yyleng);
} }
<xe>{xeoctesc} { <xq,xqc,xn>{xqinside} { addlit(yytext, yyleng); }
check_escape_warning(); <xe>{xeinside} { addlit(yytext, yyleng); }
addlit(yytext, yyleng); <xe>{xeescape} { addlit(yytext, yyleng); }
} <xe>{xeoctesc} { addlit(yytext, yyleng); }
<xe>{xehexesc} { <xe>{xehexesc} { addlit(yytext, yyleng); }
check_escape_warning(); <xq,xqc,xe,xn>{quotecontinue} { /* ignore */ }
addlit(yytext, yyleng);
}
<xq,xe,xn>{quotecontinue} { /* ignore */ }
<xe>. { <xe>. {
/* This is only needed for \ just before EOF */ /* This is only needed for \ just before EOF */
addlitchar(yytext[0]); addlitchar(yytext[0]);
} }
<xq,xe,xn><<EOF>> { mmerror(PARSE_ERROR, ET_FATAL, "Unterminated quoted string"); } <xq,xqc,xe,xn><<EOF>> { mmerror(PARSE_ERROR, ET_FATAL, "Unterminated quoted string"); }
<SQL>{dolqfailed} { <SQL>{dolqfailed} {
/* throw back all but the initial "$" */ /* throw back all but the initial "$" */
yyless(1); yyless(1);
...@@ -1284,14 +1276,6 @@ parse_include(void) ...@@ -1284,14 +1276,6 @@ parse_include(void)
BEGIN(C); BEGIN(C);
} }
static void
check_escape_warning(void)
{
if (warn_on_first_escape && escape_string_warning)
mmerror (PARSE_ERROR, ET_WARNING, "nonstandard use of escape in a string literal");
warn_on_first_escape = false; /* warn only once per string */
}
/* /*
* ecpg_isspace() --- return TRUE if flex scanner considers char whitespace * ecpg_isspace() --- return TRUE if flex scanner considers char whitespace
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment