def resolve(val):
    """ Convert a pyparsing value to the python type """
    name = val.getName()
    if name == "number":
        try:
            return int(val.number)
        except ValueError:
            return Decimal(val.number)
    elif name == "str":
        return unwrap(val.str)
    elif name == "null":
        return None
    elif name == "binary":
        return Binary(val.binary[2:-1])
    elif name == "set":
        if val.set == "()":
            return set()
        return set([resolve(v) for v in val.set])
    elif name == "bool":
        return val.bool == "TRUE"
    elif name == "list":
        return [resolve(v) for v in val.list]
    elif name == "dict":
        dict_val = {}
        for k, v in val.dict:
            dict_val[resolve(k)] = resolve(v)
        return dict_val
    elif name == "ts_function":
        return dt_to_ts(eval_function(val.ts_function))
    elif name == "ts_expression":
        return dt_to_ts(eval_expression(val))
    else:
        raise SyntaxError("Unable to resolve value '%s'" % val)
Convert a pyparsing value to the python type