Research portable Memory game | Исследовать портируемую игру Память
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

7 个月前
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. def process(FILE_IN):
  2. # Read file.
  3. lines_in = []
  4. with open(FILE_IN) as file:
  5. for line in file:
  6. lines_in.append(line.rstrip())
  7. # Translate.
  8. lines_out = []
  9. isDeclaration = False
  10. isDeclarationLine = False
  11. isBody = False
  12. functionName = None
  13. returnType = None
  14. argumentNames = []
  15. argumentTypes = []
  16. for ln in lines_in:
  17. ln = ln.rstrip()
  18. # Ignore includes.
  19. if "#include" in ln:
  20. continue
  21. parts = ln.split(" ")
  22. count = len(parts)
  23. lastPart = parts[count - 1]
  24. if not isBody and lastPart.endswith("("):
  25. isDeclaration = True
  26. isDeclarationLine = True
  27. isBody = False
  28. # End of function arguments.
  29. if not isDeclarationLine and not isBody and ln.endswith(") {"):
  30. isDeclaration = False
  31. isBody = True
  32. # Function argument.
  33. if (
  34. isDeclaration and
  35. not isDeclarationLine and
  36. not isBody and
  37. not ln.endswith(") {")
  38. ):
  39. print(f"TODO argument: '{ln}'")
  40. # Function return type and function name.
  41. if isDeclaration and lastPart.endswith("("):
  42. functionName = lastPart[:-1]
  43. returnType = ln[:-len(lastPart) - 1] # -1 for space before function name
  44. print(f"Function name: '{functionName}'")
  45. print(f"Return type: '{returnType}'")
  46. isDeclarationLine = False
  47. lines_out.append(ln)
  48. return "\n".join(lines_out)