# HG changeset patch # User Dan Smith dsmith@danplanet.com # Date 1380994422 25200 # Node ID ed55293fb6ae9134a646ad708df9ca75fa138469 # Parent 917830c94a36e21a0b30cad52a62f5df3430ea94 Add C++ style comment support to bitwise
diff -r 917830c94a36 -r ed55293fb6ae chirp/bitwise_grammar.py --- a/chirp/bitwise_grammar.py Thu Oct 03 21:33:09 2013 -0500 +++ b/chirp/bitwise_grammar.py Sat Oct 05 10:33:42 2013 -0700 @@ -80,6 +80,10 @@
def parse(data): lines = data.split("\n") + for index, line in enumerate(lines): + if '//' in line: + lines[index] = line[:line.index('//')] + class FakeFileInput: """Simulate line-by-line file reading from @data""" line = -1 diff -r 917830c94a36 -r ed55293fb6ae tests/unit/test_bitwise.py --- a/tests/unit/test_bitwise.py Thu Oct 03 21:33:09 2013 -0500 +++ b/tests/unit/test_bitwise.py Sat Oct 05 10:33:42 2013 -0700 @@ -227,3 +227,12 @@ class TestBitwiseErrors(BaseTest): def test_missing_semicolon(self): self.assertRaises(SyntaxError, bitwise.parse, "u8 foo", "") + +class TestBitwiseComments(BaseTest): + def test_comment_inline_cppstyle(self): + obj = bitwise.parse('u8 foo; // test', '\x10') + self.assertEqual(16, obj.foo) + + def test_comment_cppstyle(self): + obj = bitwise.parse('// Test this\nu8 foo;', '\x10') + self.assertEqual(16, obj.foo)