From 6cc5dd93fe9bfbd8b6f0e98f64c28635ccb9a1a1 Mon Sep 17 00:00:00 2001 From: steve Date: Tue, 15 Jul 2003 02:41:07 +0000 Subject: [PATCH] Handle line termination a la mac/windows/unix. --- ivlpp/lexor.lex | 50 +++++++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/ivlpp/lexor.lex b/ivlpp/lexor.lex index 11b38c293..975ab736f 100644 --- a/ivlpp/lexor.lex +++ b/ivlpp/lexor.lex @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) && !defined(macintosh) -#ident "$Id: lexor.lex,v 1.39 2003/05/08 16:20:17 steve Exp $" +#ident "$Id: lexor.lex,v 1.40 2003/07/15 02:41:07 steve Exp $" #endif # include "config.h" @@ -104,15 +104,18 @@ W [ \t\b\f]+ %% -"//".* { ECHO; } +"//"[^\r\n]* { ECHO; } /* detect multiline, c-style comments, passing them directly to the output. This is necessary to allow for ignoring directives that are included within the comments. */ "/*" { comment_enter = YY_START; BEGIN(CCOMMENT); ECHO; } -. { ECHO; } -\n { istack->lineno += 1; 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; } /* Detect and pass multiline pragma comments. As with C-style @@ -121,8 +124,11 @@ W [ \t\b\f]+ expanded, however. */ "(*" { comment_enter = YY_START; BEGIN(PCOMENT); ECHO; } -. { ECHO; } -\n { istack->lineno += 1; 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; } `[a-zA-Z][a-zA-Z0-9_$]* { def_match(); } @@ -131,7 +137,10 @@ W [ \t\b\f]+ string. */ \" { comment_enter = YY_START; BEGIN(CSTRING); ECHO; } \\\" { ECHO; } -\n { ECHO; } +\r\n { fputc('\n', yyout); } +\n\r { fputc('\n', yyout); } +\n { fputc('\n', yyout); } +\r { fputc('\n', yyout); } \" { BEGIN(comment_enter); ECHO; } . { ECHO; } `[a-zA-Z][a-zA-Z0-9_$]* { def_match(); } @@ -156,9 +165,10 @@ W [ \t\b\f]+ /* These finish the include directive (EOF or EOL) so I revert the lexor state and execute the inclusion. */ -\n { istack->lineno += 1; yy_pop_state(); do_include(); } \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(); } <> { istack->lineno += 1; yy_pop_state(); do_include(); } /* Anything that is not matched by the above is an error of some @@ -177,11 +187,9 @@ W [ \t\b\f]+ `define{W}[a-zA-Z_][a-zA-Z0-9_$]*{W}? { yy_push_state(PPDEFINE); def_start(); } -.* { - do_define(); - } +.*[^\r\n] { do_define(); } -(\n|"\r\n"|"\n\r") { +(\n|"\r\n"|"\n\r"|\r) { if (def_is_done()) { def_finish(); istack->lineno += 1; @@ -244,9 +252,12 @@ W [ \t\b\f]+ `else { BEGIN(IFDEF_TRUE); } `else { } -"//".* { } -. { } -\n { istack->lineno += 1; fputc('\n', yyout); } +"//"[^\r\n]* { } +[^\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); } `endif { yy_pop_state(); @@ -258,11 +269,14 @@ W [ \t\b\f]+ /* Any text that is not a directive just gets passed through to the output. Very easy. */ -. { ECHO; } -\n { istack->lineno += 1; 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); } /* Absorb the rest of the line when a broken directive is detected. */ -.* { yy_pop_state(); } +[^\r\n]* { yy_pop_state(); } %% /* Defined macros are kept in this table for convenient lookup. As