From cc38babfb0debbf479c9fc02047a170c6aeb2b81 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Wed, 10 May 2023 22:25:31 -0700 Subject: [PATCH] Fix bug in block comment parsing. `--]]` is just a convention, apparently. `]]` is what actually ends the block. --- dcs/lua/parse.py | 4 ++-- dcs/lua/test_parse.py | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/dcs/lua/parse.py b/dcs/lua/parse.py index 29d12f2e..0c5d463d 100644 --- a/dcs/lua/parse.py +++ b/dcs/lua/parse.py @@ -347,10 +347,10 @@ def eat_line(self) -> None: self.pos += 1 def eat_block_comment(self) -> None: - while not self.eob() and self.next_n_chars(4) != "--]]": + while not self.eob() and self.next_n_chars(2) != "]]": self.pos += 1 if not self.eob(): - self.pos += 4 + self.pos += 2 def eat_ws(self): """ diff --git a/dcs/lua/test_parse.py b/dcs/lua/test_parse.py index e5680a37..191dd180 100644 --- a/dcs/lua/test_parse.py +++ b/dcs/lua/test_parse.py @@ -304,6 +304,16 @@ def test_block_comment(self) -> None: loads("--[[ Old Bort Calls For 1.5.3 and Older ]]--") + r = loads( + textwrap.dedent( + """\ + --[[ Comment ]] + foo = "bar" + """ + ) + ) + self.assertEqual(r["foo"], "bar") + if __name__ == '__main__': unittest.main()