Fixed lexer to correctly parse C quotes.
authorMichael Meskes
Fri, 11 Jan 2008 15:19:16 +0000 (15:19 +0000)
committerMichael Meskes
Fri, 11 Jan 2008 15:19:16 +0000 (15:19 +0000)
src/interfaces/ecpg/ChangeLog
src/interfaces/ecpg/preproc/pgc.l

index 815ba9d2a179eb374bf765169204c80e370aa5ee..8876c56643083f9ca5346745a4bfd5e88744914d 100644 (file)
@@ -2279,6 +2279,10 @@ Fri, 28 Dec 2007 12:15:38 +0100
       to fix bug in connect statement if
      user name is a variable. 
    - 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 compat library version to 3.0.
    - Set ecpg library version to 6.0.
index 7de33a5fc95fbadf4cbd737dcf280447a2dc5f69..1bdfc7e0fa9716c11526181356e8c0ab318a7e68 100644 (file)
@@ -12,7 +12,7 @@
  *
  *
  * 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;
 static int     xcdepth = 0;    /* depth of nesting in slash-star comments */
 static char       *dolqstart;      /* current $foo$ quote start string */
 static bool        escape_string_warning;
-static bool    warn_on_first_escape;
 static YY_BUFFER_STATE scanbufhandle;
 static char *scanbuf;
 
@@ -47,7 +46,6 @@ static int        literalalloc;           /* current allocated buffer size */
 static void addlit(char *ytext, int yleng);
 static void addlitchar (unsigned char);
 static void parse_include (void);
-static void check_escape_warning(void);
 static bool ecpg_isspace(char ch);
 static bool isdefine(void);
 static bool isinformixdefine(void);
@@ -101,6 +99,7 @@ static struct _if_value
  *  delimited identifiers (double-quoted identifiers) - thomas 1997-10-27
  *  hexadecimal numeric string - thomas 1997-11-16
  *  standard quoted strings - thomas 1997-07-30
+ *  standard quoted strings in C - michael
  *  extended quoted strings (support backslash escape sequences)
  *  national character quoted strings
  *   $foo$ quoted strings
@@ -114,6 +113,7 @@ static struct _if_value
 %x xe
 %x xn
 %x xq
+%x xqc
 %x xdolq
 %x xcond
 %x xskip
@@ -145,6 +145,7 @@ xch             0[xX][0-9A-Fa-f]*
  */
 xqstart            {quote}
 xqdouble       {quote}{quote}
+xqcquote       [\\]{quote}
 xqinside       [^']+
 
 /* $foo$ style quotes ("dollar quoting")
@@ -409,35 +410,31 @@ cppline           {space}*#(.*\\{space})*.*{newline}
                /* National character.
                 * Transfer it as-is to the backend.
                 */
-               warn_on_first_escape = true;
-               token_start = yytext;
+               token_start = yytext;
                state_before = YYSTATE;
                BEGIN(xn);
                startlit();
            }
 {xqstart}   {
-               warn_on_first_escape = false;
                token_start = yytext;
                state_before = YYSTATE;
-               BEGIN(xq);
+               BEGIN(xqc);
                startlit();
            }
 {xqstart} {
-               warn_on_first_escape = true;
                token_start = yytext;
                state_before = YYSTATE;
                BEGIN(xq);
                startlit();
            }
 {xestart} {
-               warn_on_first_escape = false;
                token_start = yytext;
                state_before = YYSTATE;
                BEGIN(xe);
                startlit();
            }
-{quotestop} |
-{quotefail} {
+,xqc>{quotestop} |
+,xqc>{quotefail} {
                yyless(1);
                BEGIN(state_before);
                yylval.str = mm_strdup(literalbuf);
@@ -457,27 +454,22 @@ cppline           {space}*#(.*\\{space})*.*{newline}
                yylval.str = mm_strdup(literalbuf);
                return NCONST;
            }
-{xqdouble}       { addlitchar('\''); }
-{xqinside}      { addlit(yytext, yyleng); }
-{xeinside}     { addlit(yytext, yyleng); }
-{xeescape}     { 
-               check_escape_warning();
-               addlit(yytext, yyleng);
+{xqdouble}   { addlitchar('\''); }
+{xqcquote}        {
+               addlitchar('\\');
+               addlitchar('\'');
            }
-{xeoctesc}     { 
-               check_escape_warning();
-               addlit(yytext, yyleng);
-           }
-{xehexesc}     { 
-               check_escape_warning();
-               addlit(yytext, yyleng);
-           }
-{quotecontinue}  { /* ignore */ }
+{xqinside}  { addlit(yytext, yyleng); }
+{xeinside}     { addlit(yytext, yyleng); }
+{xeescape}     { addlit(yytext, yyleng); }
+{xeoctesc}     { addlit(yytext, yyleng); }
+{xehexesc}     { addlit(yytext, yyleng); }
+{quotecontinue}  { /* ignore */ }
 .                   {
               /* This is only needed for \ just before EOF */
               addlitchar(yytext[0]);
            }
-e,xn><>      { mmerror(PARSE_ERROR, ET_FATAL, "Unterminated quoted string"); }
+qc,xe,xn><>  { mmerror(PARSE_ERROR, ET_FATAL, "Unterminated quoted string"); }
 {dolqfailed}  {
                /* throw back all but the initial "$" */
                yyless(1);
@@ -1284,14 +1276,6 @@ parse_include(void)
    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
  */