From 8814747508e57a72e584fd25cab13cea199fe3f0 Mon Sep 17 00:00:00 2001 From: MilhouseVH Date: Mon, 14 Oct 2019 20:11:20 +0100 Subject: [PATCH] tools/fixlexcode.py: support embedded backtick comments as used by ffmpegx --- tools/fixlecode.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/tools/fixlecode.py b/tools/fixlecode.py index d999da832a..03d270acf5 100755 --- a/tools/fixlecode.py +++ b/tools/fixlecode.py @@ -129,17 +129,35 @@ def fix_backticks(line, changed): changes = 0 newline = '' intick = False + iscomment = False + c = 0 - for c in line: - if c == '`': - if not intick: + # Don't fix backticks in comments as more likely to be markdown + if line.startswith('#'): + return line + + while c < len(line): + char = line[c:c+1] + charn = line[c+1:c+2] + + # Don't convert "embedded" comments such as `# blah blah` + if not intick and char == '`' and charn == '#': + iscomment = True + + if char == '`' and (intick or charn != '#'): + if iscomment: + newline += char + iscomment = False + elif not intick: newline += '$(' changes += 1 else: newline += ')' intick = not intick else: - newline += c + newline += char + + c += 1 changed['backticks'] += changes changed['isdirty'] = (changed['isdirty'] or changes != 0)