def serialize(self): if not self.token or "id" not in self.token: raise ParseException( "Could not serialize tree, missing 'id' field.") def flatten_tree(root_token, token_list=[]): token_list.append(root_token.token) for child_token in root_token.children: flatten_tree(child_token, token_list) return token_list tokens = flatten_tree(self) tokens = sorted(tokens, key=lambda t: t['id']) tokenlist = TokenList(tokens, self.metadata) return serialize(tokenlist)
def serialize(self) -> str: return serialize(self)
def serialize(self): return serialize(self)