Пример #1
0
    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)
Пример #2
0
 def serialize(self) -> str:
     return serialize(self)
Пример #3
0
 def serialize(self):
     return serialize(self)