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.

52 lines
1.3KB

  1. class Function:
  2. def __init__(self):
  3. self.isBody = False
  4. self.isComplete = False
  5. self.isSignature = False
  6. self.name = None
  7. self.parameters = []
  8. self.returnValue = None
  9. self.statements = []
  10. def parseLine(self, ln):
  11. parts = ln.split(" ")
  12. count = len(parts)
  13. lastPart = parts[count - 1]
  14. # Beginning of signature.
  15. if (
  16. self.returnValue is None and
  17. self.name is None
  18. and lastPart.endswith("(")
  19. ):
  20. self.isSignature = True
  21. # End of parameters.
  22. if (
  23. self.isSignature and
  24. ln.endswith(") {")
  25. ):
  26. self.isSignature = False
  27. isBody = True
  28. # # Parameter.
  29. # if (
  30. # isSignature and
  31. # not ln.endswith(") {")
  32. # ):
  33. # print(f"TODO argument: '{ln}'")
  34. # Return type and name.
  35. if (
  36. self.isSignature and
  37. lastPart.endswith("(")
  38. ):
  39. self.name = lastPart[:-1]
  40. self.returnType = ln[:-len(lastPart) - 1] # -1 for space before function name
  41. def __repr__(self):
  42. return self.__str__()
  43. def __str__(self):
  44. return f"Function(n/rt: '{self.name}'/'{self.returnType}')"