From: Michael Meskes Date: Mon, 25 Nov 2013 14:29:51 +0000 (+0100) Subject: More improvement to comment parsing in ecpg. X-Git-Tag: REL9_4_BETA1~898 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=05b476c2983a8d38bf6a0254553b4a0776896aa7;p=postgresql More improvement to comment parsing in ecpg. ECPG is not supposed to allow and output nested comments in C. These comments are only allowed in the SQL parts and must not be written into the C file. Also the different handling of different comments is documented. --- diff --git a/doc/src/sgml/ecpg.sgml b/doc/src/sgml/ecpg.sgml index c629726aff..120d760ba2 100644 --- a/doc/src/sgml/ecpg.sgml +++ b/doc/src/sgml/ecpg.sgml @@ -64,8 +64,10 @@ EXEC SQL ...; These statements syntactically take the place of a C statement. Depending on the particular statement, they can appear at the global level or within a function. Embedded - SQL statements follow the case-sensitivity rules - of normal SQL code, and not those of C. + SQL statements follow the case-sensitivity rules of + normal SQL code, and not those of C. Also they allow nested + C-style comments that are part of the SQL standard. The C part of the + program, however, follows the C standard of not accepting nested comments. diff --git a/src/interfaces/ecpg/preproc/pgc.l b/src/interfaces/ecpg/preproc/pgc.l index 6deef59d53..f04e34a53d 100644 --- a/src/interfaces/ecpg/preproc/pgc.l +++ b/src/interfaces/ecpg/preproc/pgc.l @@ -394,17 +394,20 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})(.*\\{space})*. xcdepth++; /* Put back any characters past slash-star; see above */ yyless(2); - fputs("/*", yyout); + fputs("/_*", yyout); } {xcstop} { - ECHO; if (xcdepth <= 0) { + ECHO; BEGIN(state_before); token_start = NULL; } else + { xcdepth--; + fputs("*_/", yyout); + } } {xcstop} { ECHO; @@ -861,6 +864,7 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})(.*\\{space})*. } } } +{xcstop} { mmerror(PARSE_ERROR, ET_ERROR, "nested /* ... */ comments"); } ":" { return(':'); } ";" { return(';'); } "," { return(','); }