Enable iterating through the map
This commit is contained in:
@@ -11,7 +11,8 @@ class AsteriskEvaluator(Evaluator):
|
|||||||
iterator = expressionEvaluator(doAssert=True)(node.iterator, environment).value #TODO check if it isn't necessary to verify 'result' attr of EvaluatioNResult
|
iterator = expressionEvaluator(doAssert=True)(node.iterator, environment).value #TODO check if it isn't necessary to verify 'result' attr of EvaluatioNResult
|
||||||
return Evaluator.oneOf(
|
return Evaluator.oneOf(
|
||||||
cls._numberIteratorAsteriskEvaluator(iterator),
|
cls._numberIteratorAsteriskEvaluator(iterator),
|
||||||
cls._listIteratorAsteriskEvaluator(iterator)
|
cls._listIteratorAsteriskEvaluator(iterator),
|
||||||
|
cls._mapIteratorAsteriskEvaluator(iterator)
|
||||||
)(node, environment).value #TODO check if it isn't necessary to verify 'result' attr of EvaluatioNResult
|
)(node, environment).value #TODO check if it isn't necessary to verify 'result' attr of EvaluatioNResult
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -78,3 +79,26 @@ class AsteriskEvaluator(Evaluator):
|
|||||||
return EvaluationResult.FAIL()
|
return EvaluationResult.FAIL()
|
||||||
|
|
||||||
return evaluator
|
return evaluator
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _mapIteratorAsteriskEvaluator(cls, evaluatedIterator):
|
||||||
|
def evaluator(node, environment):
|
||||||
|
if evaluatedIterator.type == Type.MAP:
|
||||||
|
results = []
|
||||||
|
automaticVariableKey = cls._automaticNamedVariable(node.iterator, environment, "_")
|
||||||
|
automaticVariableValue = cls._automaticNamedVariable(node.iterator, environment, "__")
|
||||||
|
for k, v in evaluatedIterator.value.items():
|
||||||
|
environment.scopes[-1][automaticVariableKey] = k
|
||||||
|
environment.scopes[-1][automaticVariableValue] = v
|
||||||
|
result = evaluate(node.statement, environment).value # TODO check if it isn't necessary to verify 'result' attr of EvaluatioNResult
|
||||||
|
if result is not None and result.type != Type.VOID:
|
||||||
|
results.append(result)
|
||||||
|
|
||||||
|
del environment.scopes[-1][automaticVariableKey]
|
||||||
|
del environment.scopes[-1][automaticVariableValue]
|
||||||
|
|
||||||
|
return EvaluationResult.OK(Type.list(results).decompose())
|
||||||
|
|
||||||
|
return EvaluationResult.FAIL()
|
||||||
|
|
||||||
|
return evaluator
|
||||||
Reference in New Issue
Block a user