Skip to content

Commit

Permalink
Make separator character configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
formatc1702 committed Nov 17, 2020
1 parent 45a45dc commit 0d1e3d7
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/wireviz/wireviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,13 @@ def parse(yaml_input: str, file_out: (str, Path) = None, return_types: (None, st

# go through connection sets, generate and connect components ==============

def resolve_designator(inp):
if '.' in inp: # generate a new instance of an item
template, designator = inp.split('.') # TODO: handle more than one `.`
template_separator_char = '.' # TODO: make user-configurable (in case user wants to use `.` as part of their template/component names)

def resolve_designator(inp, separator):
if separator in inp: # generate a new instance of an item
if inp.count(separator) > 1:
raise Exception(f'{inp} - Found more than one separator ({separator})')
template, designator = inp.split(separator)
if designator == '':
autogenerated_designators[template] = autogenerated_designators.get(template, 0) + 1
designator = f'__{template}_{autogenerated_designators[template]}'
Expand Down Expand Up @@ -148,11 +152,11 @@ def alternate_type(): # flip between connector and cable/arrow
for index, entry in enumerate(connection_set):
if isinstance(entry, list):
for subindex, item in enumerate(entry):
template, designator = resolve_designator(item)
template, designator = resolve_designator(item, template_separator_char)
connection_set[index][subindex] = designator
elif isinstance(entry, dict):
key = list(entry.keys())[0]
template, designator = resolve_designator(key)
template, designator = resolve_designator(key, template_separator_char)
value = entry[key]
connection_set[index] = {designator: value}
else:
Expand Down

0 comments on commit 0d1e3d7

Please sign in to comment.