Research portable Memory game | Исследовать портируемую игру Память
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.5KB

  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)