Research portable Memory game | Исследовать портируемую игру Память
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Function.py 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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.returnType = None
  9. self.statements = []
  10. def parseLine(self, ln):
  11. parts = ln.split(" ")
  12. count = len(parts)
  13. lastPart = parts[count - 1]
  14. # Complete.
  15. if (
  16. self.isBody and
  17. ln.startswith("#}")
  18. ):
  19. self.isComplete = True
  20. # Statements.
  21. if (
  22. self.isBody and
  23. not ln.startswith("#}")
  24. ):
  25. self.statements.append(ln)
  26. # Parameters.
  27. if (
  28. self.isSignature and
  29. not ln.endswith(":")
  30. ):
  31. p = ln
  32. # Remove comma if present.
  33. if p.endswith(","):
  34. p = p[:-1]
  35. self.parameters.append(p)
  36. # Beginning of signature.
  37. if (
  38. self.returnType is None and
  39. self.name is None
  40. and lastPart.endswith("(")
  41. ):
  42. self.isSignature = True
  43. # Return type.
  44. if (
  45. self.isSignature and
  46. ln.startswith(") -> ") and
  47. ln.endswith(":")
  48. ):
  49. self.returnType = ln[len(") -> "):-len(":")]
  50. # End of parameters/signature.
  51. if (
  52. self.isSignature and
  53. ln.startswith(") -> ") and
  54. ln.endswith(":")
  55. ):
  56. self.isSignature = False
  57. self.isBody = True
  58. # Name.
  59. if (
  60. self.isSignature and
  61. lastPart.endswith("(")
  62. ):
  63. self.name = lastPart[:-1]
  64. def __repr__(self):
  65. return self.__str__()
  66. def __str__(self):
  67. return f"Function(name/returnT/parameters/statements: '{self.name}'/'{self.returnType}'/'{self.parameters}'/'{self.statements}')"