MCPcopy Create free account
hub / github.com/AcademySoftwareFoundation/MaterialX / parseSpecTypes

Function parseSpecTypes

python/Scripts/comparenodedefs.py:62–96  ·  view source on GitHub ↗

Parse a specification type string into (types, typeRef). Supported patterns: - Simple types: "float", "color3" - Comma-separated: "float, color3" - Union with "or": "BSDF or VDF", "BSDF, EDF, or VDF" - Type references: "Same as bg", "Same as in1 or float"

(typeStr)

Source from the content-addressed store, hash-verified

60 return variables
61
62def parseSpecTypes(typeStr):
63 '''
64 Parse a specification type string into (types, typeRef).
65
66 Supported patterns:
67 - Simple types: "float", "color3"
68 - Comma-separated: "float, color3"
69 - Union with "or": "BSDF or VDF", "BSDF, EDF, or VDF"
70 - Type references: "Same as bg", "Same as in1 or float"
71 '''
72 if typeStr is None or not typeStr.strip():
73 return set(), None
74
75 typeStr = typeStr.strip()
76
77 # Handle "Same as X" and "Same as X or Y" references
78 sameAsMatch = re.match(r'^Same as\s+`?(\w+)`?(?:\s+or\s+(.+))?$', typeStr, re.IGNORECASE)
79 if sameAsMatch:
80 refPort = sameAsMatch.group(1)
81 extraTypes = sameAsMatch.group(2)
82 extraSet = set()
83 if extraTypes:
84 extraSet, _ = parseSpecTypes(extraTypes)
85 return extraSet, refPort
86
87 # Normalize "or" to comma: "X or Y" -> "X, Y", "X, Y, or Z" -> "X, Y, Z"
88 normalized = re.sub(r',?\s+or\s+', ', ', typeStr)
89
90 result = set()
91 for t in normalized.split(','):
92 t = t.strip()
93 if t:
94 result.add(t)
95
96 return result, None
97
98def expandTypeSet(types, typeGroups, typeGroupVariables):
99 '''Expand type groups to concrete types. Returns list of (concreteType, groupName) tuples.'''

Callers 1

parseSpecDocumentFunction · 0.85

Calls 3

setClass · 0.50
matchMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected