Skip to content

Commit

Permalink
cope with macros in function calls - converter
Browse files Browse the repository at this point in the history
  • Loading branch information
gilesknap committed Sep 23, 2023
1 parent f7c8d86 commit e59ee7d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"type": "python",
"python": "/dls_sw/prod/tools/RHEL7-x86_64/defaults/bin/dls-python",
"request": "launch",
"program": "builder2ibek.support.py",
"program": "dls_builder_conversion/builder2ibek.support.py",
"console": "integratedTerminal",
"args": [
"/dls_sw/prod/R3.14.12.7/support/ADCore/3-9dls2",
Expand Down
15 changes: 9 additions & 6 deletions dls_builder_conversion/builder2ibek.support.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
is_float_re = re.compile(r"[-+]?\d*\.\d+([eE][-+]?\d+)?$")
# this monster regex finds strings between '' or "" (just wow!)
extract_printed_strings_re = re.compile(r"([\"'])((?:\\\1|(?:(?!\1))[\S\s])*)(?:\1)")
macros_re = re.compile(r"%\((.*?)\).|\n")
macro_to_jinja_re = r"{{\1}}"


class Builder2Support:
Expand Down Expand Up @@ -262,7 +264,8 @@ def _make_init_script(self, builder_object, func_name, typ, script):
for print_string in print_strings:
matches = extract_printed_strings_re.findall(print_string)
if matches:
script_item["value"].append(matches[0][1])
line = macros_re.sub(macro_to_jinja_re, matches[0][1])
script_item["value"].append(line)

if len(script_item["value"]) > 0:
script.append(script_item)
Expand Down Expand Up @@ -322,14 +325,14 @@ def write_yaml_tree(self, filename):
def tidy_up(yaml):
# add blank lines between major fields
for field in [
"- type:",
"- file:",
"- name:",
"databases:",
"pre_init:",
" databases:",
" pre_init:",
"module",
"defs",
" args",
]:
yaml = re.sub(r"(\s*%s)" % field, "\n\\g<1>", yaml)
yaml = re.sub(r"(\n%s)" % field, "\n\\g<1>", yaml)

return yaml

Expand Down

0 comments on commit e59ee7d

Please sign in to comment.