From 56b2da68d494f8cec3e22d74e219415c151259f9 Mon Sep 17 00:00:00 2001 From: Nic30 Date: Sat, 27 May 2023 15:26:02 +0200 Subject: [PATCH] verilog preproc: support dos newline encoding in multilne define #180 --- grammars/verilogPreprocLexer.g4 | 4 ++-- tests/test_verilog_preproc_macro_db_api.py | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) 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()