diff --git a/ivlpp/lexor.lex b/ivlpp/lexor.lex index bc352e8f4..6b6f96a22 100644 --- a/ivlpp/lexor.lex +++ b/ivlpp/lexor.lex @@ -189,12 +189,12 @@ W [ \t\b\f]+ are included within the comments. */ "/*" { comment_enter = YY_START; BEGIN(CCOMMENT); ECHO; } -[^\r\n] { ECHO; } -\n\r { istack->lineno += 1; fputc('\n', yyout); } -\r\n { istack->lineno += 1; fputc('\n', yyout); } -\n { istack->lineno += 1; fputc('\n', yyout); } -\r { istack->lineno += 1; fputc('\n', yyout); } -"*/" { BEGIN(comment_enter); ECHO; } +[^\r\n] { ECHO; } +\n\r | +\r\n | +\n | +\r { istack->lineno += 1; fputc('\n', yyout); } +"*/" { BEGIN(comment_enter); ECHO; } /* Detect and pass multiline pragma comments. As with C-style comments, pragma comments are passed through, and preprocessor @@ -203,12 +203,12 @@ W [ \t\b\f]+ "(*"{W}?")" { ECHO; } "(*" { pragma_enter = YY_START; BEGIN(PCOMENT); ECHO; } -[^\r\n] { ECHO; } -\n\r { istack->lineno += 1; fputc('\n', yyout); } -\r\n { istack->lineno += 1; fputc('\n', yyout); } -\n { istack->lineno += 1; fputc('\n', yyout); } -\r { istack->lineno += 1; fputc('\n', yyout); } -"*)" { BEGIN(pragma_enter); ECHO; } +[^\r\n] { ECHO; } +\n\r | +\r\n | +\n | +\r { istack->lineno += 1; fputc('\n', yyout); } +"*)" { BEGIN(pragma_enter); ECHO; } `[a-zA-Z][a-zA-Z0-9_$]* { if (macro_needs_args()) yy_push_state(MA_START); else do_expand(0); } @@ -218,9 +218,9 @@ W [ \t\b\f]+ string. */ \" { string_enter = YY_START; BEGIN(CSTRING); ECHO; } \\\" { ECHO; } -\r\n { fputc('\n', yyout); } -\n\r { fputc('\n', yyout); } -\n { fputc('\n', yyout); } +\r\n | +\n\r | +\n | \r { fputc('\n', yyout); } \" { BEGIN(string_enter); ECHO; } . { ECHO; } @@ -250,14 +250,18 @@ W [ \t\b\f]+ /* These finish the include directive (EOF or EOL) so I revert the lexor state and execute the inclusion. */ -\r\n { istack->lineno += 1; yy_pop_state(); do_include(); } -\n\r { istack->lineno += 1; yy_pop_state(); do_include(); } -\n { istack->lineno += 1; yy_pop_state(); do_include(); } -\r { istack->lineno += 1; yy_pop_state(); do_include(); } + /* There is a bug in flex <= 2.5.34 that prevents the continued action '|' + * from working properly when the final action is associated with <>. + * Therefore, the action is repeated. */ + +\r\n | +\n\r | +\n | +\r { istack->lineno += 1; yy_pop_state(); do_include(); } <> { istack->lineno += 1; yy_pop_state(); do_include(); } /* Anything that is not matched by the above is an error of some - sort. Print and error message and absorb the rest of the line. */ + sort. Print an error message and absorb the rest of the line. */ . { emit_pathline(istack); fprintf(stderr, "error: malformed `include directive." @@ -280,11 +284,8 @@ W [ \t\b\f]+ ")"{W}? { BEGIN(DEF_TXT); } "//"[^\r\n]* { ECHO; } - -"/*" { comment_enter = YY_START; BEGIN(CCOMMENT); ECHO; } - -{W} { } - +"/*" { comment_enter = YY_START; BEGIN(CCOMMENT); ECHO; } +{W} { } (\n|"\r\n"|"\n\r"|\r){W}? { istack->lineno += 1; fputc('\n', yyout); @@ -359,10 +360,7 @@ W [ \t\b\f]+ } } -`ifdef{W} { - ifdef_enter(); - yy_push_state(IFDEF_SUPR); - } +`ifdef{W} | `ifndef{W} { ifdef_enter(); yy_push_state(IFDEF_SUPR); @@ -393,17 +391,17 @@ W [ \t\b\f]+ "/*" { comment_enter = YY_START; BEGIN(IFCCOMMENT); } [^\r\n] { } -\n\r { istack->lineno += 1; } -\r\n { istack->lineno += 1; } -\n { istack->lineno += 1; } +\n\r | +\r\n | +\n | \r { istack->lineno += 1; } "*/" { BEGIN(comment_enter); } -[^\r\n] { } -\n\r { istack->lineno += 1; fputc('\n', yyout); } -\r\n { istack->lineno += 1; fputc('\n', yyout); } -\n { istack->lineno += 1; fputc('\n', yyout); } -\r { istack->lineno += 1; fputc('\n', yyout); } +[^\r\n] { } +\n\r | +\r\n | +\n | +\r { istack->lineno += 1; fputc('\n', yyout); } `endif { ifdef_leave(); yy_pop_state(); } @@ -459,8 +457,7 @@ W [ \t\b\f]+ . { emit_pathline(istack); - fprintf(stderr, "error: missing argument list for `%s.\n", - macro_name()); + fprintf(stderr, "error: missing argument list for `%s.\n", macro_name()); error_count += 1; yy_pop_state(); yyless(0); @@ -510,10 +507,10 @@ W [ \t\b\f]+ output. Very easy. */ [^\r\n] { ECHO; } -\n\r { istack->lineno += 1; fputc('\n', yyout); } -\r\n { istack->lineno += 1; fputc('\n', yyout); } -\n { istack->lineno += 1; fputc('\n', yyout); } -\r { istack->lineno += 1; fputc('\n', yyout); } +\n\r | +\r\n | +\n | +\r { istack->lineno += 1; fputc('\n', yyout); } /* Absorb the rest of the line when a broken directive is detected. */ [^\r\n]* { yy_pop_state(); }