diff --git a/l2/3.lex b/l2/3.lex index 192279d..b6ed871 100644 --- a/l2/3.lex +++ b/l2/3.lex @@ -2,6 +2,7 @@ #include bool leave_docs = false; + bool in_docs = false; %} %x SINGLE_LINE @@ -19,32 +20,54 @@ . { ECHO; } "///"|"//!" { + in_docs = true; if (leave_docs) { ECHO; - } else { - BEGIN(SINGLE_LINE); } + BEGIN(SINGLE_LINE); } "/**/" { putchar(' '); } "/**"|"/*!" { + in_docs = true; if (leave_docs) { ECHO; - } else { - BEGIN(MULTI_LINE); } + BEGIN(MULTI_LINE); } "//" { BEGIN(SINGLE_LINE); } . { ECHO; } "\\\n" { } -\n { BEGIN(INITIAL); } -. { } +\n { + if (leave_docs && in_docs) { + ECHO; + in_docs = false; + } + BEGIN(INITIAL); +} +. { + if (leave_docs && in_docs) { + ECHO; + } +} "/*" { BEGIN(MULTI_LINE); } -"*/" { putchar(' '); BEGIN(INITIAL); } -. { } +"*/" { + if (leave_docs && in_docs) { + ECHO; + in_docs = false; + } else { + putchar(' '); + } + BEGIN(INITIAL); +} +. { + if (leave_docs && in_docs) { + ECHO; + } +} %% // single line comment