diff --git a/site_ansto/instrument/util/gen_sct.py b/site_ansto/instrument/util/gen_sct.py index f1d1f810..21ac0e7e 100755 --- a/site_ansto/instrument/util/gen_sct.py +++ b/site_ansto/instrument/util/gen_sct.py @@ -65,7 +65,7 @@ SourceLineList = [] def PrintParseError(message): global PrintedFileName global lexer - global SourceData + global SourceLineList, SourceData curr_line = lexer.lineno curr_file = SourceLineList[curr_line - 1][0] if curr_file != PrintedFileName: @@ -936,10 +936,10 @@ def dump_driver_groups(groups, indent): if Comment in groups[item]: print indent + ' # %s = \'%s\'' % (Comment, groups[item][Comment]) for subitem in sorted([x for x in groups[item] if not x in Deferred]): - print indent + ' ', subitem, '=', groups[item][subitem] + print indent + ' ', subitem, '= \'%s\'' % groups[item][subitem] if 'GroupProperty' in groups[item]: for subitem in groups[item]['GroupProperty']: - print indent + ' GroupProperty', subitem, '=', groups[item]['GroupProperty'][subitem] + print indent + ' GroupProperty', subitem, '= \'%s\'' % groups[item]['GroupProperty'][subitem] dump_driver_vars(groups[item]['Vars'], indent) dump_driver_groups(groups[item]['Groups'], indent + ' ') print indent + '}' @@ -1819,9 +1819,36 @@ def load_file(source_file, depth_list): fd = open(SourceFile, 'r') LocalData = [] line_no = 0 + execing = False + exec_input = [] + exec_line = 0 for line in fd: line_no += 1 line = line.rstrip('\n') + if execing: + match = re.match(r'\s*%end', line, flags=re.IGNORECASE) + if match: + #print "exec_input:" + #for temp_line in exec_input: + # print " " + temp_line + kw = {} + kw['exec_output'] = [] + exec('\n'.join(exec_input)) in kw + #print "exec_output:" + for line in kw['exec_output']: + # print " " + line + LocalData.append(line) + SourceLineList.append((curr_file, exec_line)) + exec_input = [] + execing = False + else: + exec_input.append(line) + continue + match = re.match(r'\s*%exec', line, flags=re.IGNORECASE) + if match: + execing = True + exec_line = line_no + continue match = re.match(r'\s*%include\s+', line, flags=re.IGNORECASE) if match: new_source = re.sub(r'\s*%include\s+(.*)', r'\1', line, flags=re.IGNORECASE)