Ejemplo n.º 1
0
def _function1(env, vararg):
    map = {}
    for entry in vararg:
        key, value = entry.value
        map[key] = value

    return Type.map(map)
Ejemplo n.º 2
0
def _function2(env, list):
    map = {}
    for entry in list.value:
        key, value = entry.value
        map[key] = value

    return Type.map(map)
Ejemplo n.º 3
0
    def mapEvaluator(cls, left, operator, right):
        if operator.value == "+":
            return Type.map({**left.value, **right.value})

        if operator.value == "-":
            raise RuntimeException(
                f"Operator {operator.value} is not supported by map types",
                operator.pos)

        raise RuntimeError("This line should never be reached")
Ejemplo n.º 4
0
    def evaluator(cls, node, environment):
        map = {}
        keyEvaluator = Evaluator.oneOf(
            Evaluator.forNodes(lambda node, environment: EvaluationResult.OK(Type.string(node.value)), Identifier),
            expressionEvaluator(doAssert=True)
        )
        for entry in node.children:
            key = keyEvaluator(entry.key, environment).value
            if key in map:
                raise RuntimeException(f"Duplicated key '{key.stringify()}' found in map", entry.pos)
            map[key] = expressionEvaluator(doAssert=True)(entry.value, environment).value

        return Type.map(map)