Beispiel #1
0
    def _stack_removal(self, grammar, stack, arcs, start_index, value, start_pos):
        failed_stack = []
        found = False
        all_nodes = []
        for dfa, state, (typ, nodes) in stack[start_index:]:
            if nodes:
                found = True
            if found:
                symbol = grammar.number2symbol[typ]
                failed_stack.append((symbol, nodes))
                all_nodes += nodes
        if failed_stack:
            stack[start_index - 1][2][1].append(pt.ErrorNode(all_nodes))

        stack[start_index:] = []
        return failed_stack
Beispiel #2
0
    def _stack_removal(self, grammar, stack, arcs, start_index, value,
                       start_pos):
        failed_stack = []
        found = False
        all_nodes = []
        for dfa, state, (typ, nodes) in stack[start_index:]:
            if nodes:
                found = True
            if found:
                symbol = grammar.number2symbol[typ]
                failed_stack.append((symbol, nodes))
                all_nodes += nodes
            if nodes and nodes[0] in ('def', 'class', 'lambda'):
                self._scope_names_stack.pop()
        if failed_stack:
            stack[start_index - 1][2][1].append(pt.ErrorNode(all_nodes))

        self._last_failed_start_pos = start_pos

        stack[start_index:] = []
        return failed_stack
Beispiel #3
0
    def _stack_removal(self, grammar, stack, arcs, start_index, value,
                       start_pos):
        def clear_names(children):
            for c in children:
                try:
                    clear_names(c.children)
                except AttributeError:
                    if isinstance(c, pt.Name):
                        try:
                            self._scope_names_stack[-1][c.value].remove(c)
                            self._used_names[c.value].remove(c)
                        except ValueError:
                            pass  # This may happen with CompFor.

        for dfa, state, node in stack[start_index:]:
            clear_names(children=node[1])

        failed_stack = []
        found = False
        all_nodes = []
        for dfa, state, (typ, nodes) in stack[start_index:]:
            if nodes:
                found = True
            if found:
                symbol = grammar.number2symbol[typ]
                failed_stack.append((symbol, nodes))
                all_nodes += nodes
            if nodes and nodes[0] in ('def', 'class', 'lambda'):
                self._scope_names_stack.pop()
        if failed_stack:
            stack[start_index - 1][2][1].append(pt.ErrorNode(all_nodes))

        self._last_failed_start_pos = start_pos

        stack[start_index:] = []
        return failed_stack