Skip to content

Commit da758c2

Browse files
author
Michael Meskes
committed
Fixed lexer to correctly parse C quotes.
1 parent 59fc64a commit da758c2

File tree

2 files changed

+23
-35
lines changed

2 files changed

+23
-35
lines changed

src/interfaces/ecpg/ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2279,6 +2279,10 @@ Fri, 28 Dec 2007 12:15:38 +0100
22792279
<itagaki.takahiro@oss.ntt.co.jp> to fix bug in connect statement if
22802280
user name is a variable.
22812281
- Also fixed test case that didn't detect this.
2282+
2283+
Fri, 11 Jan 2008 16:16:24 +0100
2284+
2285+
- Fixed lexer to correctly parse C quotes.
22822286
- Set pgtypes library version to 3.0.
22832287
- Set compat library version to 3.0.
22842288
- Set ecpg library version to 6.0.

src/interfaces/ecpg/preproc/pgc.l

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
*
1414
* IDENTIFICATION
15-
* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.157 2008/01/01 19:45:59 momjian Exp $
15+
* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.158 2008/01/11 15:19:16 meskes Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -29,7 +29,6 @@ extern YYSTYPE yylval;
2929
static int xcdepth = 0; /* depth of nesting in slash-star comments */
3030
static char *dolqstart; /* current $foo$ quote start string */
3131
static bool escape_string_warning;
32-
static bool warn_on_first_escape;
3332
static YY_BUFFER_STATE scanbufhandle;
3433
static char *scanbuf;
3534

@@ -47,7 +46,6 @@ static int literalalloc; /* current allocated buffer size */
4746
static void addlit(char *ytext, int yleng);
4847
static void addlitchar (unsigned char);
4948
static void parse_include (void);
50-
static void check_escape_warning(void);
5149
static bool ecpg_isspace(char ch);
5250
static bool isdefine(void);
5351
static bool isinformixdefine(void);
@@ -101,6 +99,7 @@ static struct _if_value
10199
* <xd> delimited identifiers (double-quoted identifiers) - thomas 1997-10-27
102100
* <xh> hexadecimal numeric string - thomas 1997-11-16
103101
* <xq> standard quoted strings - thomas 1997-07-30
102+
* <xqc> standard quoted strings in C - michael
104103
* <xe> extended quoted strings (support backslash escape sequences)
105104
* <xn> national character quoted strings
106105
* <xdolq> $foo$ quoted strings
@@ -114,6 +113,7 @@ static struct _if_value
114113
%x xe
115114
%x xn
116115
%x xq
116+
%x xqc
117117
%x xdolq
118118
%x xcond
119119
%x xskip
@@ -145,6 +145,7 @@ xch 0[xX][0-9A-Fa-f]*
145145
*/
146146
xqstart {quote}
147147
xqdouble {quote}{quote}
148+
xqcquote [\\]{quote}
148149
xqinside [^']+
149150

150151
/* $foo$ style quotes ("dollar quoting")
@@ -409,35 +410,31 @@ cppline {space}*#(.*\\{space})*.*{newline}
409410
/* National character.
410411
* Transfer it as-is to the backend.
411412
*/
412-
warn_on_first_escape = true;
413-
token_start = yytext;
413+
token_start = yytext;
414414
state_before = YYSTATE;
415415
BEGIN(xn);
416416
startlit();
417417
}
418418
<C>{xqstart} {
419-
warn_on_first_escape = false;
420419
token_start = yytext;
421420
state_before = YYSTATE;
422-
BEGIN(xq);
421+
BEGIN(xqc);
423422
startlit();
424423
}
425424
<SQL>{xqstart} {
426-
warn_on_first_escape = true;
427425
token_start = yytext;
428426
state_before = YYSTATE;
429427
BEGIN(xq);
430428
startlit();
431429
}
432430
<SQL>{xestart} {
433-
warn_on_first_escape = false;
434431
token_start = yytext;
435432
state_before = YYSTATE;
436433
BEGIN(xe);
437434
startlit();
438435
}
439-
<xq>{quotestop} |
440-
<xq>{quotefail} {
436+
<xq,xqc>{quotestop} |
437+
<xq,xqc>{quotefail} {
441438
yyless(1);
442439
BEGIN(state_before);
443440
yylval.str = mm_strdup(literalbuf);
@@ -457,27 +454,22 @@ cppline {space}*#(.*\\{space})*.*{newline}
457454
yylval.str = mm_strdup(literalbuf);
458455
return NCONST;
459456
}
460-
<xq,xe,xn>{xqdouble} { addlitchar('\''); }
461-
<xq,xn>{xqinside} { addlit(yytext, yyleng); }
462-
<xe>{xeinside} { addlit(yytext, yyleng); }
463-
<xe>{xeescape} {
464-
check_escape_warning();
465-
addlit(yytext, yyleng);
457+
<xq,xe,xn>{xqdouble} { addlitchar('\''); }
458+
<xqc>{xqcquote} {
459+
addlitchar('\\');
460+
addlitchar('\'');
466461
}
467-
<xe>{xeoctesc} {
468-
check_escape_warning();
469-
addlit(yytext, yyleng);
470-
}
471-
<xe>{xehexesc} {
472-
check_escape_warning();
473-
addlit(yytext, yyleng);
474-
}
475-
<xq,xe,xn>{quotecontinue} { /* ignore */ }
462+
<xq,xqc,xn>{xqinside} { addlit(yytext, yyleng); }
463+
<xe>{xeinside} { addlit(yytext, yyleng); }
464+
<xe>{xeescape} { addlit(yytext, yyleng); }
465+
<xe>{xeoctesc} { addlit(yytext, yyleng); }
466+
<xe>{xehexesc} { addlit(yytext, yyleng); }
467+
<xq,xqc,xe,xn>{quotecontinue} { /* ignore */ }
476468
<xe>. {
477469
/* This is only needed for \ just before EOF */
478470
addlitchar(yytext[0]);
479471
}
480-
<xq,xe,xn><<EOF>> { mmerror(PARSE_ERROR, ET_FATAL, "Unterminated quoted string"); }
472+
<xq,xqc,xe,xn><<EOF>> { mmerror(PARSE_ERROR, ET_FATAL, "Unterminated quoted string"); }
481473
<SQL>{dolqfailed} {
482474
/* throw back all but the initial "$" */
483475
yyless(1);
@@ -1284,14 +1276,6 @@ parse_include(void)
12841276
BEGIN(C);
12851277
}
12861278

1287-
static void
1288-
check_escape_warning(void)
1289-
{
1290-
if (warn_on_first_escape && escape_string_warning)
1291-
mmerror (PARSE_ERROR, ET_WARNING, "nonstandard use of escape in a string literal");
1292-
warn_on_first_escape = false; /* warn only once per string */
1293-
}
1294-
12951279
/*
12961280
* ecpg_isspace() --- return TRUE if flex scanner considers char whitespace
12971281
*/

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy