@@ -139,10 +139,9 @@ if std_compat and os.path.isfile(std_compat):
139139print (" \n :: Phase 2: Scanning module declarations" )
140140
141141# Regex patterns for module declarations in the module declaration region
142- # (before the first non-preprocessor, non-module statement)
143- re_export = re.compile(r ' ^ \s * export\s + module\s + ( [\w . ]+ ) \s * ;' )
144- re_import = re.compile(r ' ^ \s * (?: export\s + ) ? import\s + ( [\w . ]+ ) \s * ;' )
145- re_module = re.compile(r ' ^ \s * module\s + ( [\w . ]+ ) \s * ;' ) # module implementation unit
142+ re_export = re.compile(r ' ^ \s * export\s + module\s + ( [\w .: ]+ ) \s * ;' )
143+ re_import = re.compile(r ' ^ \s * (?: export\s + ) ? import\s + ( [\w .: ]+ ) \s * ;' )
144+ re_module = re.compile(r ' ^ \s * module\s + ( [\w .: ]+ ) \s * ;' ) # module implementation unit
146145
147146# Include both project sources and dependency sources
148147sources = sorted (projroot.glob(" src/**/*.cppm" )) + sorted (projroot.glob(" src/**/*.cpp" ))
@@ -160,25 +159,38 @@ src_requires = {}
160159for src in sources:
161160 provides = []
162161 requires = []
162+ current_module = None # track which module this file belongs to (for partition resolution)
163163 try :
164164 with open (src, ' r' ) as f:
165165 for line in f:
166166 line = line.strip()
167- # Stop scanning at first function/class/namespace body
168- # (module declarations must come before implementation)
169167 if line.startswith(' //' ) or line.startswith(' #' ) or not line:
170168 continue
171169 m = re_export.match(line)
172170 if m:
173- provides.append(m.group(1 ))
171+ mod_name = m.group(1 )
172+ provides.append(mod_name)
173+ # Track the base module name for partition resolution
174+ if ' :' in mod_name:
175+ current_module = mod_name.split(' :' )[0 ]
176+ else :
177+ current_module = mod_name
174178 continue
175179 m = re_module.match(line)
176180 if m and not provides: # module implementation unit
177- requires.append(m.group(1 ))
181+ mod_name = m.group(1 )
182+ if ' :' in mod_name:
183+ current_module = mod_name.split(' :' )[0 ]
184+ else :
185+ current_module = mod_name
186+ requires.append(mod_name)
178187 continue
179188 m = re_import.match(line)
180189 if m:
181190 mod_name = m.group(1 )
191+ # Handle partition imports: `import :options;` → `<current_module>:options`
192+ if mod_name.startswith(' :' ) and current_module:
193+ mod_name = current_module + mod_name
182194 if mod_name not in (" std" , " std.compat" ):
183195 requires.append(mod_name)
184196 continue
0 commit comments