def parse(input): results = [] snap = input.snapshot() pos = input.currentPos() while True: result = parser(input) if result.result: results.append(result.node) snap = input.snapshot() else: input.reset(snap) return ParseResult.OK( createNode(results, pos ) if len(results) > 0 else NoneNode())
def evaluator(cls, node, environment): iterator = expressionEvaluator(doAssert=True)(node.left, environment).value parameters = [identifier.value for identifier in node.parameters ] if type(node.parameters) != NoneNode() else [] try: environment.appendScope() output = { Type.INTEGER: cls.numberEvaluator, Type.BOOL: cls.boolEvaluator, Type.LIST: cls.listEvaluator, Type.MAP: cls.mapEvaluator }[iterator.type](node, environment, iterator, parameters, node.filter) environment.popScope() except KeyError: raise RuntimeException( f"The {iterator.type.name.lower()} type cannot stand as an iterator for loop statement", node.left.pos) return Type.list(output)
def __init__(self, pos): super().__init__(pos) self.children = [NoneNode(), NoneNode(), NoneNode()]
def createNode(cls, ifNode, condition, elseNode=NoneNode()): node = cls(ifNode.pos) node.ifNode = ifNode node.condition = condition node.elseNode = elseNode return node
def withValues(cls, pos, type, specifiers=NoneNode()): node = cls(pos) node.type = type node.specifiers = specifiers return node
def epsilon(): return lambda *args: ParseResult.OK(NoneNode())
def parse(input): result = parser(input) if result.result: return result return ParseResult.OK(NoneNode())