Commit 8ac5e88f authored by Michael Meskes's avatar Michael Meskes

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.
parent 64d15e42
...@@ -102,7 +102,8 @@ static struct _if_value ...@@ -102,7 +102,8 @@ static struct _if_value
* and to eliminate parsing troubles for numeric strings. * and to eliminate parsing troubles for numeric strings.
* Exclusive states: * Exclusive states:
* <xb> bit string literal * <xb> bit string literal
* <xc> extended C-style comments - thomas 1997-07-12 * <xcc> extended C-style comments in C
* <xcsql> extended C-style comments in SQL
* <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
...@@ -115,7 +116,8 @@ static struct _if_value ...@@ -115,7 +116,8 @@ static struct _if_value
*/ */
%x xb %x xb
%x xc %x xcc
%x xcsql
%x xd %x xd
%x xdc %x xdc
%x xh %x xh
...@@ -369,23 +371,32 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})(.*\\{space})*. ...@@ -369,23 +371,32 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})(.*\\{space})*.
<SQL>{whitespace} { /* ignore */ } <SQL>{whitespace} { /* ignore */ }
<C,SQL>{xcstart} { <C>{xcstart} {
token_start = yytext; token_start = yytext;
state_before = YYSTATE; state_before = YYSTATE;
xcdepth = 0; xcdepth = 0;
BEGIN(xc); BEGIN(xcc);
/* Put back any characters past slash-star; see above */ /* Put back any characters past slash-star; see above */
yyless(2); yyless(2);
fputs("/*", yyout); fputs("/*", yyout);
} }
<xc>{xcstart} { <SQL>{xcstart} {
token_start = yytext;
state_before = YYSTATE;
xcdepth = 0;
BEGIN(xcsql);
/* Put back any characters past slash-star; see above */
yyless(2);
fputs("/*", yyout);
}
<xcc>{xcstart} { ECHO; }
<xcsql>{xcstart} {
xcdepth++; xcdepth++;
/* Put back any characters past slash-star; see above */ /* Put back any characters past slash-star; see above */
yyless(2); yyless(2);
fputs("/*", yyout); fputs("/*", yyout);
} }
<xcsql>{xcstop} {
<xc>{xcstop} {
ECHO; ECHO;
if (xcdepth <= 0) if (xcdepth <= 0)
{ {
...@@ -395,12 +406,16 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})(.*\\{space})*. ...@@ -395,12 +406,16 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})(.*\\{space})*.
else else
xcdepth--; xcdepth--;
} }
<xcc>{xcstop} {
ECHO;
BEGIN(state_before);
token_start = NULL;
}
<xcc,xcsql>{xcinside} { ECHO; }
<xcc,xcsql>{op_chars} { ECHO; }
<xcc,xcsql>\*+ { ECHO; }
<xc>{xcinside} { ECHO; } <xcc,xcsql><<EOF>> { mmfatal(PARSE_ERROR, "unterminated /* comment"); }
<xc>{op_chars} { ECHO; }
<xc>\*+ { ECHO; }
<xc><<EOF>> { mmfatal(PARSE_ERROR, "unterminated /* comment"); }
<SQL>{xbstart} { <SQL>{xbstart} {
token_start = yytext; token_start = yytext;
......
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