From: Michael Meskes Date: Sun, 24 Nov 2013 11:26:00 +0000 (+0100) Subject: Distinguish between C and SQL mode for C-style comments. X-Git-Tag: REL9_4_BETA1~903 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8ac5e88f9fc54c480ed1419c0ce94f54653fe8c3;p=postgresql Distinguish between C and SQL mode for C-style comments. SQL standard asks for allowing nested comments, while C does not. Therefore the two comments, while mostly similar, have to be parsed seperately. --- diff --git a/src/interfaces/ecpg/preproc/pgc.l b/src/interfaces/ecpg/preproc/pgc.l index 24936ea935..6deef59d53 100644 --- a/src/interfaces/ecpg/preproc/pgc.l +++ b/src/interfaces/ecpg/preproc/pgc.l @@ -102,7 +102,8 @@ static struct _if_value * and to eliminate parsing troubles for numeric strings. * Exclusive states: * bit string literal - * extended C-style comments - thomas 1997-07-12 + * extended C-style comments in C + * extended C-style comments in SQL * delimited identifiers (double-quoted identifiers) - thomas 1997-10-27 * hexadecimal numeric string - thomas 1997-11-16 * standard quoted strings - thomas 1997-07-30 @@ -115,7 +116,8 @@ static struct _if_value */ %x xb -%x xc +%x xcc +%x xcsql %x xd %x xdc %x xh @@ -369,23 +371,32 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})(.*\\{space})*. {whitespace} { /* ignore */ } -{xcstart} { +{xcstart} { token_start = yytext; state_before = YYSTATE; xcdepth = 0; - BEGIN(xc); + BEGIN(xcc); /* Put back any characters past slash-star; see above */ yyless(2); fputs("/*", yyout); } -{xcstart} { +{xcstart} { + token_start = yytext; + state_before = YYSTATE; + xcdepth = 0; + BEGIN(xcsql); + /* Put back any characters past slash-star; see above */ + yyless(2); + fputs("/*", yyout); + } +{xcstart} { ECHO; } +{xcstart} { xcdepth++; /* Put back any characters past slash-star; see above */ yyless(2); fputs("/*", yyout); } - -{xcstop} { +{xcstop} { ECHO; if (xcdepth <= 0) { @@ -395,12 +406,16 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})(.*\\{space})*. else xcdepth--; } +{xcstop} { + ECHO; + BEGIN(state_before); + token_start = NULL; + } +{xcinside} { ECHO; } +{op_chars} { ECHO; } +\*+ { ECHO; } -{xcinside} { ECHO; } -{op_chars} { ECHO; } -\*+ { ECHO; } - -<> { mmfatal(PARSE_ERROR, "unterminated /* comment"); } +<> { mmfatal(PARSE_ERROR, "unterminated /* comment"); } {xbstart} { token_start = yytext;