|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- from Type import *
-
- class Function:
- def __init__(self):
- self.isBody = False
- self.isComplete = False
- self.isSignature = False
- self.name = None
- self.parameters = []
- self.returnType = None
- self.statements = []
-
- def parseLine(self, ln):
- parts = ln.split(" ")
- count = len(parts)
- lastPart = parts[count - 1]
-
- # Beginning of signature.
- if (
- self.returnType is None and
- self.name is None
- and lastPart.endswith("(")
- ):
- self.isSignature = True
-
- # End of parameters.
- if (
- self.isSignature and
- ln.endswith(") {")
- ):
- self.isSignature = False
- isBody = True
-
- # # Parameter.
- # if (
- # isSignature and
- # not ln.endswith(") {")
- # ):
- # print(f"TODO argument: '{ln}'")
-
- # Return type and name.
- if (
- self.isSignature and
- lastPart.endswith("(")
- ):
- self.name = lastPart[:-1]
- rawReturnType = ln[:-len(lastPart) - 1] # -1 for space before function name
- self.returnType = Type(rawReturnType)
-
- def __repr__(self):
- return self.__str__()
- def __str__(self):
- return f"Function(n/rt: '{self.name}'/'{self.returnType}')"
|