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] # Complete. if ( self.isBody and ln.startswith("#}") ): self.isComplete = True # Statements. if ( self.isBody and not ln.startswith("#}") ): self.statements.append(ln) # Parameters. if ( self.isSignature and not ln.endswith(":") ): p = ln # Remove comma if present. if p.endswith(","): p = p[:-1] self.parameters.append(p) # Beginning of signature. if ( self.returnType is None and self.name is None and lastPart.endswith("(") ): self.isSignature = True # Return type. if ( self.isSignature and ln.startswith(") -> ") and ln.endswith(":") ): self.returnType = ln[len(") -> "):-len(":")] # End of parameters/signature. if ( self.isSignature and ln.startswith(") -> ") and ln.endswith(":") ): self.isSignature = False self.isBody = True # Name. if ( self.isSignature and lastPart.endswith("(") ): self.name = lastPart[:-1] def __repr__(self): return self.__str__() def __str__(self): return f"Function(name/returnT/parameters/statements: '{self.name}'/'{self.returnType}'/'{self.parameters}'/'{self.statements}')"