From f77a3c24d47b9bc19687f829f615aac4d7cec9c8 Mon Sep 17 00:00:00 2001 From: Martin Taibr Date: Sun, 29 Oct 2017 00:45:09 +0200 Subject: [PATCH] fix edge case --- qcsrc/tools/unc-chained-if-fix.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/qcsrc/tools/unc-chained-if-fix.py b/qcsrc/tools/unc-chained-if-fix.py index 16cadae1d..c90d024a4 100755 --- a/qcsrc/tools/unc-chained-if-fix.py +++ b/qcsrc/tools/unc-chained-if-fix.py @@ -1,5 +1,16 @@ #!/usr/bin/env python3 +# converts code like +# ``` +# if (some_long_condition) +# if (some_other_long_condition) +# ``` +# into +# ``` +# if (some_long_condition +# && some_other_long_condition) +# ``` + import regex # needs regex instead of re for multiple captures of a group import glob @@ -140,7 +151,7 @@ for file_name in all_files: then = match.group('then') then_end = match.end('then') next_code = old_code[then_end : then_end + 50] # won't error when past end - contains_else = regex.search("[\n\t ]*else", next_code) != None + contains_else = regex.search("^[\n\t ]*else", next_code) != None if then.startswith("if"): print("WARNING - then if", count_indents(indent), count_indents(then_indent)) -- 2.39.2