From 334d9d0e0c334316f81c9a72bccde5bbadcde5f3 Mon Sep 17 00:00:00 2001 From: Douglas Clowes Date: Mon, 29 Sep 2014 11:52:29 +1000 Subject: [PATCH] Check function code for balanced parentheses, brackets, and braces --- site_ansto/instrument/util/gen_sct.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/site_ansto/instrument/util/gen_sct.py b/site_ansto/instrument/util/gen_sct.py index 8871aaab..656c4316 100755 --- a/site_ansto/instrument/util/gen_sct.py +++ b/site_ansto/instrument/util/gen_sct.py @@ -825,6 +825,30 @@ def adjust_group(MyGroup): if Verbose: print 'post adjust_group', MyGroup +def check_func_code(MyDriver): + for name in MyDriver['Funcs']: + #print name + left_paren_count = 0 + right_paren_count = 0 + left_brack_count = 0 + right_brack_count = 0 + left_brace_count = 0 + right_brace_count = 0 + for idx, line in enumerate(MyDriver['Funcs'][name]['text']): + #print "%4d:" % (idx + 1), line + left_paren_count += line.count('(') + right_paren_count += line.count(')') + left_brack_count += line.count('[') + right_brack_count += line.count(']') + left_brace_count += line.count('{') + right_brace_count += line.count('}') + if left_paren_count != right_paren_count: + PrintPostError("Warning: Mismatched Parens in function %s (%d != %d)" % (name, left_paren_count, right_paren_count)) + if left_brack_count != right_brack_count: + PrintPostError("Warning: Mismatched Brackets in function %s (%d != %d)" % (name, left_brack_count, right_brack_count)) + if left_brace_count != right_brace_count: + PrintPostError("Warning: Mismatched Braces in function %s (%d != %d)" % (name, left_brace_count, right_brace_count)) + def build_driver(MyDriver, TheTree): if Verbose: print "TheTree:", TheTree @@ -1752,6 +1776,7 @@ def process_drivers(TheDrivers): MyDriver['Permlink'] = {} MyDriver['Deferred'] = [] build_driver(MyDriver, TheDrivers[driver]) + check_func_code(MyDriver) if Verbose: print "MyDriver:", MyDriver['name'], '=', MyDriver if DriverDump or Verbose: