Skip to content

Commit

Permalink
verilog preproc: support dos newline encoding in multilne define #180
Browse files Browse the repository at this point in the history
  • Loading branch information
Nic30 committed May 27, 2023
1 parent e0e2736 commit 56b2da6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions grammars/verilogPreprocLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -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



Expand Down
7 changes: 7 additions & 0 deletions tests/test_verilog_preproc_macro_db_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 56b2da6

Please sign in to comment.