Skip to content

Commit 0190db8

Browse files
committed
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
1 parent 244712c commit 0190db8

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

verible/verilog/parser/verilog.lex

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,13 @@ PragmaEndProtected {Pragma}{Space}+protect{Space}+end_protected
294294
yymore();
295295
}
296296
{LineTerminator} {
297-
yyless(yyleng-1); /* return \n to input stream */
297+
// This is needed in order to avoid lexical differences when the line
298+
// endings are changed through verible-verilog-format. See [1]
299+
// [1] https://github.com/chipsalliance/verible/pull/2371
300+
if(yytext[yyleng-2] == '\r')
301+
yyless(yyleng-2); /* return \r\n to input stream */
302+
else
303+
yyless(yyleng-1); /* return \n to input stream */
298304
UpdateLocation();
299305
yy_pop_state();
300306
return TK_EOL_COMMENT;

0 commit comments

Comments
 (0)