fixed complex strings
This commit is contained in:
@@ -170,30 +170,48 @@ def _split_expression_parts(expr: str) -> list[str]:
|
|||||||
return parts
|
return parts
|
||||||
|
|
||||||
|
|
||||||
def _resolve_property(name: str, props: dict[str, str], designator: str = "") -> str:
|
def _resolve_property(
|
||||||
|
name: str,
|
||||||
|
props: dict[str, str],
|
||||||
|
designator: str = "",
|
||||||
|
resolving: frozenset[str] | None = None,
|
||||||
|
) -> str:
|
||||||
|
if resolving is None:
|
||||||
|
resolving = frozenset()
|
||||||
|
if name in resolving:
|
||||||
|
return ""
|
||||||
if name == "Designator":
|
if name == "Designator":
|
||||||
raw = designator or props.get("Designator", "")
|
raw = designator or props.get("Designator", "")
|
||||||
else:
|
else:
|
||||||
raw = props.get(name, "")
|
raw = props.get(name, "")
|
||||||
if not raw:
|
if not raw:
|
||||||
return ""
|
return ""
|
||||||
if raw.startswith("=") or (raw.startswith('"') and raw.endswith('"') and len(raw) > 1):
|
if raw.startswith("="):
|
||||||
return resolve_expression(raw, props, designator)
|
return resolve_expression(raw, props, designator, resolving | {name})
|
||||||
return raw
|
return raw
|
||||||
|
|
||||||
|
|
||||||
def resolve_expression(value: str, props: dict[str, str], designator: str = "") -> str:
|
def resolve_expression(
|
||||||
|
value: str,
|
||||||
|
props: dict[str, str],
|
||||||
|
designator: str = "",
|
||||||
|
resolving: frozenset[str] | None = None,
|
||||||
|
) -> str:
|
||||||
"""
|
"""
|
||||||
Altium complex string: ='literal'+"Property"+Name
|
Altium complex string: ='literal'+"Property"+Name
|
||||||
- single quotes = literal text
|
- single quotes = literal text
|
||||||
- double quotes = component property reference
|
- double quotes = component property reference
|
||||||
- bare identifiers = property reference
|
- bare identifiers = property reference
|
||||||
"""
|
"""
|
||||||
|
if resolving is None:
|
||||||
|
resolving = frozenset()
|
||||||
|
if len(resolving) > 64:
|
||||||
|
return ""
|
||||||
if not value:
|
if not value:
|
||||||
return ""
|
return ""
|
||||||
value = value.strip()
|
value = value.strip()
|
||||||
if value.startswith('"') and value.endswith('"') and not value.startswith('="'):
|
if value.startswith('"') and value.endswith('"') and not value.startswith('="'):
|
||||||
return _resolve_property(value[1:-1], props, designator)
|
return _resolve_property(value[1:-1], props, designator, resolving)
|
||||||
if not value.startswith("="):
|
if not value.startswith("="):
|
||||||
return value
|
return value
|
||||||
|
|
||||||
@@ -204,9 +222,9 @@ def resolve_expression(value: str, props: dict[str, str], designator: str = "")
|
|||||||
if part.startswith("'") and part.endswith("'") and len(part) >= 2:
|
if part.startswith("'") and part.endswith("'") and len(part) >= 2:
|
||||||
result.append(part[1:-1])
|
result.append(part[1:-1])
|
||||||
elif part.startswith('"') and part.endswith('"') and len(part) >= 2:
|
elif part.startswith('"') and part.endswith('"') and len(part) >= 2:
|
||||||
result.append(_resolve_property(part[1:-1], props, designator))
|
result.append(_resolve_property(part[1:-1], props, designator, resolving))
|
||||||
elif part == "Designator":
|
elif part == "Designator":
|
||||||
result.append(designator or props.get("Designator", ""))
|
result.append(designator or props.get("Designator", ""))
|
||||||
else:
|
else:
|
||||||
result.append(_resolve_property(part, props, designator))
|
result.append(_resolve_property(part, props, designator, resolving))
|
||||||
return "".join(result)
|
return "".join(result)
|
||||||
|
|||||||
Reference in New Issue
Block a user