matchcompiler.py: skip comments in _replaceTokenMatch() (#3825)

This commit is contained in:
Oliver Stöneberg 2022-02-11 21:20:55 +01:00 committed by GitHub
parent 6e57cc4323
commit c690bfb03a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View File

@ -384,6 +384,10 @@ class MatchCompiler:
is_simplematch = func == 'simpleMatch' is_simplematch = func == 'simpleMatch'
pattern_start = 0 pattern_start = 0
while True: while True:
# skip comments
if line.strip().startswith('//'):
break
pos1 = line.find('Token::' + func + '(', pattern_start) pos1 = line.find('Token::' + func + '(', pattern_start)
if pos1 == -1: if pos1 == -1:
break break

View File

@ -191,5 +191,10 @@ class MatchCompilerTest(unittest.TestCase):
'if (match16(parent->tokAt(-3)) && tok->strAt(1) == MatchCompiler::makeConstString(")"))', 'if (match16(parent->tokAt(-3)) && tok->strAt(1) == MatchCompiler::makeConstString(")"))',
output) 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__': if __name__ == '__main__':
unittest.main() unittest.main()