parser: verilog.lex: remove \r from TK_EOL_COMMENT for DOS newlines DOS newlines (\r\n) leak the \r character into TK_EOL_COMMENT token. If the formatter changes the newline mode from UNIX into DOS, the original and the formatted version will be lexically different, triggering an error inside the VerifyFormatting
diff --git a/verible/verilog/parser/verilog.lex b/verible/verilog/parser/verilog.lex index f90216c..759fcc2 100644 --- a/verible/verilog/parser/verilog.lex +++ b/verible/verilog/parser/verilog.lex
@@ -294,7 +294,13 @@ yymore(); } {LineTerminator} { - yyless(yyleng-1); /* return \n to input stream */ + // This is needed in order to avoid lexical differences when the line + // endings are changed through verible-verilog-format. See [1] + // [1] https://github.com/chipsalliance/verible/pull/2371 + if(yytext[yyleng-2] == '\r') + yyless(yyleng-2); /* return \r\n to input stream */ + else + yyless(yyleng-1); /* return \n to input stream */ UpdateLocation(); yy_pop_state(); return TK_EOL_COMMENT;