Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

partial support for map based selector conversion #386

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 15 additions & 19 deletions boa/cli/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,27 +68,22 @@ def main(docname):
result_yaml = CommentedMap()
result_yaml["context"] = context

def has_selector(s):
return s.strip().endswith("]")
selector_re = re.compile("( *)(-?)([^#]*)# \\[(.*)\\]\\W*")

quoted_lines = []
selector_lines = []
prev_selector_line = ""
for line in rest_lines:
if has_selector(line):
selector_start = line.rfind("[")
selector_end = line.rfind("]")
selector_content = line[selector_start + 1 : selector_end]

if line.strip().startswith("-"):
line = (
line[: line.find("-") + 1]
+ f" sel({selector_content}): "
+ line[
line.find("-") + 1 : min(line.rfind("#"), line.rfind("["))
].strip()
+ "\n"
)
quoted_lines.append(line)
rest_lines = quoted_lines
m = selector_re.match(line)
if m and m.group(2):
line = m.group(1) + "- sel(" + m.group(4) + "):" + m.group(3) + "\n"
elif m:
selector_line = m.group(1) + "sel(" + m.group(4) + "):\n"
if selector_line != prev_selector_line:
selector_lines.append(selector_line)
line = m.group(1) + " " + m.group(3) + "\n"
prev_selector_line = selector_line
selector_lines.append(line)
rest_lines = selector_lines

def check_if_quoted(s):
s = s.strip()
Expand Down Expand Up @@ -128,6 +123,7 @@ def check_if_quoted(s):
wo_skip_lines.append(line)

rest_lines = wo_skip_lines

result_yaml.update(yaml.load("".join(rest_lines)))

if len(skips) != 0:
Expand Down
Loading