Beispiel #1
0
def confprol_range(start_expr,end_expr):
    start = start_expr.value
    end = end_expr.value

    if not type(start)==int:
        raise ConfprolValueError(f"The start value in range() must be an integer.")

    if not type(end)==int:
        raise ConfprolValueError(f"The end value in range() must be an integer.")

    range_ = range(start,end)
    list_ = map(lambda x: BasicExpression(ConfprolObject(x),x,ValueType.NUMBER),range_)
    return ListExpression(ConfprolObject(list_),f"range({start},{end})")
Beispiel #2
0
def has_attribute(args):
    expr = args[0]
    attr = args[1].value

    if type(attr)!= str:
        raise ConfprolValueError("The second argument of the function 'has_attribute' must be a string")

    return BasicExpression(ConfprolObject(expr.has_attribute(attr)),f"has_attribute({expr}{attr})",ValueType.BOOLEAN)
Beispiel #3
0
def evaluate_quantic_y(expression):
    raise ConfprolValueError(f"Cannot evaluate a non quantic value.")
Beispiel #4
0
def to_float(expression):
    raise ConfprolValueError(f"Cannot transform an object of type {expression.type} to float.")
Beispiel #5
0
def to_float(expression):
    try:
        float_value = float(expression.value)
        return BasicExpression(ConfprolObject(float_value), f"int({expression.value})", ValueType.NUMBER)
    except ValueError:
        raise ConfprolValueError(f"The string/variable '{expression.name}' can't be transformed to float.")
Beispiel #6
0
def to_integer(expression):
    raise ConfprolValueError(f"Cannot transform an object of type {expression.type} to integer.")
Beispiel #7
0
def to_integer(expression):
    try:
        int_value = int(float(expression.value))  # First to float to allow strings like "3.2"
        return BasicExpression(ConfprolObject(int_value), f"int({expression.value})", ValueType.NUMBER)
    except ValueError:
        raise ConfprolValueError(f"The string/variable '{expression.name}' can't be transformed to integer.")
Beispiel #8
0
def confprol_range(start,end):
    raise ConfprolValueError(f"The start and end in range() must be integers.")