From c690bfb03a9a82577dea176b0b031376c3c91c3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Fri, 11 Feb 2022 21:20:55 +0100 Subject: [PATCH] matchcompiler.py: skip comments in _replaceTokenMatch() (#3825) --- tools/matchcompiler.py | 4 ++++ tools/test_matchcompiler.py | 5 +++++ 2 files changed, 9 insertions(+) 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()