from parlai.agents.programr.parser.template.nodes.base import TemplateNode
# from parlai.agents.programr.utils.logging.ylogger import YLogger
import parlai.utils.logging as logging

class TemplateFormalNode(TemplateNode):

    def __init__(self):
        TemplateNode.__init__(self)

    def resolve_to_string(self, brain):
        resolved = self.resolve_children_to_string(brain)
        return resolved.title()

    def resolve(self, brain):
        try:
            return self.resolve_to_string(brain)
        except Exception as excep:
            # YLogger.exception(brain, "Failed to resolve", excep)
            logging.error( f"Failed to resolve {excep}")
            return ""

    def to_string(self):
        return "FORMAL"

    def to_xml(self, client_context):
        xml = "<formal>"
        xml += self.children_to_xml(client_context)
        xml += "</formal>"
        return xml

    #######################################################################################################
    # <formal>ABC</formal>

    def add_default_star(self):
        return True

    def parse_expression(self, graph, expression):
        self._parse_node(graph, expression)
