From ee38dfaea72d1f7747ed043fef38ee5a961e3c9f Mon Sep 17 00:00:00 2001 From: Martin Taibr Date: Fri, 27 Oct 2017 13:37:59 +0200 Subject: [PATCH] match blocks and do nothing with them --- qcsrc/tools/unc-chained-if-fix.py | 54 ++++++++++++++++--------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/qcsrc/tools/unc-chained-if-fix.py b/qcsrc/tools/unc-chained-if-fix.py index 23a7a87b1..9dc6e8fb6 100755 --- a/qcsrc/tools/unc-chained-if-fix.py +++ b/qcsrc/tools/unc-chained-if-fix.py @@ -18,6 +18,10 @@ if(?[\t ]*) # the first if [^()\n]*\( (?&expr1) # this is to match nested parentheses correctly \)[^()\n]* + | + (?: # i am not sure why this branch is necessary + [^()\n]*\([^()\n]*\)[^()\n]* + )+ )+ ) \) @@ -38,7 +42,7 @@ if(?[\t ]*) # the first if (?&expr2) \)[^()\n]* | - (?: # i am not sure why this branch is necessary + (?: [^()\n]*\([^()\n]*\)[^()\n]* )+ )+ @@ -54,34 +58,32 @@ if(?[\t ]*) # the first if [\t ]* ) (? - [^{\n].* - \n + [^{}\n].*\n | - (? - \{ - ) + \{ + (? # the more options here and inside, the fewer results because some overlap + [^{}]* + | + [^{}]* + \{ + (?&block)* + \} + [^{}]* + | + (?: + [^{}]* + \{ + [^{}]* + \} + [^{}]* + )+ + )+ + \} ) """, regex.VERBOSE) -#(? -# [\t ]* -# [^{}\n]+ -# \n -#| -# [\t ]* -# { -#) - -# allows empty match -#(? -# [^{}\n]* -#| -# [^{}\n]*{ -# (?&block)+ # not sure if + is necessary -# }[^{}\n]* -#) - -# [\t ]*(?:[^{\n]+) +# TODO remove and rerun to see overlapping +# TODO try removing \n from nested exprs def count_indents(whitespace: str): print("counting: >{}<".format(whitespace)) @@ -146,7 +148,7 @@ for file_name in all_files: print("first comm:", first_comment) print("other conds:", other_conds) print("other comms:", other_comments) - print("then:", then) + print("then:", then) # TODO check for comments if then.startswith("if"): print("WARNING - then if", count_indents(indent), count_indents(then_indent)) #print("captures expr1:", match.captures('expr1')) -- 2.39.2