# Path: sdopt/nodes/types.py
# class ntype:
#     DIV = 'div'
#     EXP = 'exp'
#     LOG = 'log'
#     MUL = 'mul'
#     NEG = 'neg'
#     NUM = 'num'
#     POW = 'pow'
#     SQR = 'sqr'
#     SUM = 'sum'
#     VAR = 'var'
# 
# def is_var_node(node_dict):
#     return node_dict[NodeAttr.type] == ntype.VAR
# 
# Path: sdopt/nodes/attributes.py
# class NodeAttr:
#     bounds    =  1
#     con_num   =  2
#     d_term    =  3
#     display   =  4
#     input_ord =  5
#     n_term    =  6
#     name      =  7
#     node_id   =  8
#     number    =  9
#     operation = 10
#     type      = 11
#     var_num   = 12
# 
# class Bounds(namedtuple('Bounds', 'l u')):
#         __slots__ = ()
#         def __str__(self):
#             return '[%g,%g]' % (self.l, self.u)


from ..nodes.types import ntype, is_var_node
from ..nodes.attributes import NodeAttr, Bounds

def parse(problem, elems):
    node_id = elems.pop()
    node_dict = create_node(node_id, elems)
    if is_var_node(node_dict):
        problem.var_node_ids.add(node_id)
    problem.dag.add_node(node_id, node_dict)

def create_node(node_id, line_as_list):
    attr = { NodeAttr.node_id : node_id}
    for elems in line_as_list:
        kind = elems[0]
        func = lookup_table.get(kind, unimplemented)
        func(node_id, elems, attr)
    attr[NodeAttr.display] = '?'
    attr[NodeAttr.node_id] = node_id
    return attr

def bounds(unused1, elems, attr):
    # b [0,I]
    lb, ub = elems[1][1:-1].replace('I','inf').split(',')

# Path: sdopt/nodes/types.py
# class ntype:
#     DIV = 'div'
#     EXP = 'exp'
#     LOG = 'log'
#     MUL = 'mul'
#     NEG = 'neg'
#     NUM = 'num'
#     POW = 'pow'
#     SQR = 'sqr'
#     SUM = 'sum'
#     VAR = 'var'
# 
# def is_var_node(node_dict):
#     return node_dict[NodeAttr.type] == ntype.VAR
# 
# Path: sdopt/nodes/attributes.py
# class NodeAttr:
#     bounds    =  1
#     con_num   =  2
#     d_term    =  3
#     display   =  4
#     input_ord =  5
#     n_term    =  6
#     name      =  7
#     node_id   =  8
#     number    =  9
#     operation = 10
#     type      = 11
#     var_num   = 12
# 
# class Bounds(namedtuple('Bounds', 'l u')):
#         __slots__ = ()
#         def __str__(self):
#             return '[%g,%g]' % (self.l, self.u)


# Path: sdopt/parsers/node_line.py
from ..nodes.types import ntype, is_var_node
from ..nodes.attributes import NodeAttr, Bounds


def parse(problem, elems):
    node_id = elems.pop()
    node_dict = create_node(node_id, elems)
    if is_var_node(node_dict):
        problem.var_node_ids.add(node_id)
    problem.dag.add_node(node_id, node_dict)

def create_node(node_id, line_as_list):
    attr = { NodeAttr.node_id : node_id}
    for elems in line_as_list:
        kind = elems[0]
        func = lookup_table.get(kind, unimplemented)
        func(node_id, elems, attr)
    attr[NodeAttr.display] = '?'
    attr[NodeAttr.node_id] = node_id
    return attr

def bounds(unused1, elems, attr):
    # b [0,I]
    lb, ub = elems[1][1:-1].replace('I','inf').split(',')

    attr[NodeAttr.bounds] = Bounds(float(lb), float(ub))