diff --git a/grammars/verilogPreprocLexer.g4 b/grammars/verilogPreprocLexer.g4 index d8a025be..8fb4adec 100644 --- a/grammars/verilogPreprocLexer.g4 +++ b/grammars/verilogPreprocLexer.g4 @@ -197,11 +197,11 @@ mode DEFINE_MODE; } }; ID: F_ID; - DN_CODE: ( ( '`' '"' ) | ~('\\'| '\n' | '"') | ( '\\'+ ~[\n]) )+? { + DN_CODE: ( ( '`' '"' ) | ~('\\' | '\r' | '\n' | '"') | ( '\\'+ ~[\r\n]) )+? { // inside of define body popMode(); pushMode(DEFINE_BODY_MODE); - } -> type(CODE); // .* except newline or esacped newline + } -> type(CODE); // .* except newline or escaped newline diff --git a/tests/test_verilog_preproc_macro_db_api.py b/tests/test_verilog_preproc_macro_db_api.py index 860385e0..18900505 100644 --- a/tests/test_verilog_preproc_macro_db_api.py +++ b/tests/test_verilog_preproc_macro_db_api.py @@ -57,6 +57,13 @@ def test_can_recover_defines_from_verilog(self): db = c.preproc_macro_db self.assertIn("TEST_SYMBOL", db) + def test_dos_crlf(self): + c = HdlConvertor() + c.verilog_pp_str("`define P0 1\r\n`define P1 2\r\n`define TEST_SYMBOL `P0\\\r\n `P1\r\n", Language.SYSTEM_VERILOG) + db = c.preproc_macro_db + self.assertIn("TEST_SYMBOL", db) + self.assertEqual(db["TEST_SYMBOL"].get_body(), "1\r\n 2") + if __name__ == "__main__": testLoader = unittest.TestLoader()