Skip to content

Commit 8a9ddbe

Browse files
authored
Merge pull request #6 from gormster/fix-allow-many-macro-args
Support more than two macro arguments
2 parents 5aa76fa + dae008c commit 8a9ddbe

1 file changed

Lines changed: 12 additions & 34 deletions

File tree

picaxepreprocess.py

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -324,22 +324,13 @@ def progparse(curfilename, called_from_line=None, called_from_file=None):
324324
# line=line+" 'DEFINE: "+value+" SUBSTITUTED FOR "+key+"\n"
325325
for key, macrovars in macros.items():
326326
if key in line:
327-
params={}
328-
argnum=0
329327
macrocontents=line.split(key)[1]
330328
macrocontents=macrocontents.strip().strip("(").strip(")")
331-
while(1):
332-
argnum+=1
333-
334-
if "," in macrocontents:
335-
params[argnum]=macrocontents.split(",")[0].rstrip() #
336-
337-
macrocontents=macrocontents.split(",")[1].strip() # Remove the first parameter nd try again
338-
else:
339-
preprocessor_info("finished parsing macro contents")
340-
params[argnum]=macrocontents.split(",")[0].rstrip()
341-
preprocessor_info(params)
342-
break
329+
330+
params = {i + 1: m.rstrip() for i, m in enumerate(macrocontents.split(','))}
331+
preprocessor_info("finished parsing macro params")
332+
preprocessor_info(params)
333+
343334
line = replace(key, macrovars[0], line)
344335

345336
# # Make sure each line is commented out in a multiline macro if the surrounding code should be commented out
@@ -383,7 +374,7 @@ def progparse(curfilename, called_from_line=None, called_from_file=None):
383374
preprocessor_info("Old define found, leaving intact")
384375
# Make it replace any call to itdelf with itself so that it is in the dictionary for ifdef
385376
definitions[workingline.split()[0]] = workingline.split()[0]
386-
377+
387378
with open (outputfilename, 'a') as output_file:
388379
output_file.write("; " + line.rstrip()+"\n") # Comment out to make sure
389380
# this script does all processing and there isn't the risk of the
@@ -406,25 +397,12 @@ def progparse(curfilename, called_from_line=None, called_from_file=None):
406397
preprocessor_info(macroname)
407398
with open (outputfilename, 'a') as output_file:
408399
output_file.write("'PARSED MACRO "+macroname)
409-
macrocontents=workingline.split("(")[1].rstrip()
410-
macros[macroname]={}
411-
argnum=0
412-
while(1):
413-
argnum+=1
414-
if macrocontents.strip()==")":
415-
preprocessor_info("no parameters to macro")
416-
macros[macroname][0]="'Start of macro: "+macroname+"\n"
417-
preprocessor_info(macros)
418-
break
419-
else:
420-
macrocontents=macrocontents.rstrip(")").strip("(")
421-
macros[macroname][argnum]=macrocontents.split(",")[0].rstrip() #create spot in dictionary for macro variables, but don't populate yet
422-
if "," in macrocontents:
423-
macrocontents=macrocontents.split(",")[1].strip().rstrip()
424-
else:
425-
preprocessor_info("finished parsing macro contents")
426-
macros[macroname][0]="'--START OF MACRO: "+macroname+"\n"
427-
break
400+
macrocontents=workingline.split("(", maxsplit=1)[1].split(")", maxsplit=1)[0].rstrip()
401+
macros[macroname] = {i + 1: m.strip() for i, m in enumerate(macrocontents.split(','))}
402+
macros[macroname][0]="'--START OF MACRO: "+macroname+"\n"
403+
preprocessor_info("finished parsing macro contents")
404+
preprocessor_info(macros[macroname])
405+
428406
elif savingmacro==True:
429407
if workingline.lower().startswith("#endmacro"):
430408
savingmacro=False

0 commit comments

Comments
 (0)