diff --git a/tools/matchcompiler.py b/tools/matchcompiler.py index eb62f88e6..c794f7c35 100755 --- a/tools/matchcompiler.py +++ b/tools/matchcompiler.py @@ -384,6 +384,10 @@ class MatchCompiler: is_simplematch = func == 'simpleMatch' pattern_start = 0 while True: + # skip comments + if line.strip().startswith('//'): + break + pos1 = line.find('Token::' + func + '(', pattern_start) if pos1 == -1: break diff --git a/tools/test_matchcompiler.py b/tools/test_matchcompiler.py index 0cf3181b8..82327fb86 100755 --- a/tools/test_matchcompiler.py +++ b/tools/test_matchcompiler.py @@ -191,5 +191,10 @@ class MatchCompilerTest(unittest.TestCase): 'if (match16(parent->tokAt(-3)) && tok->strAt(1) == MatchCompiler::makeConstString(")"))', output) + def test_parseMatchSkipComments(self): + input = '// TODO: suggest Token::exactMatch() for Token::simpleMatch() when pattern contains no whitespaces' + output = self.mc._replaceTokenMatch(input, 0, "foo.cpp") + self.assertEqual(output, '// TODO: suggest Token::exactMatch() for Token::simpleMatch() when pattern contains no whitespaces') + if __name__ == '__main__': unittest.main()