'This parser is written in a dynamic way, meaning that this parser
allows using different grammars (even non-Python). However, error
recovery is purely written for Python.'

def error_recovery(self, grammar, stack, arcs, typ, value, start_pos, prefix, add_token_callback):

    if (not self._error_recovery):
        return super(Parser, self).error_recovery(grammar, stack, arcs, typ, value, start_pos, prefix, add_token_callback)
    def current_suite(stack):
        for (index, (dfa, state, (type_, nodes))) in reversed(list(enumerate(stack))):
            symbol = grammar.number2symbol[type_]
            if (symbol == 'file_input'):
                break
            elif ((symbol == 'suite') and (len(nodes) > 1)):
                break
            elif ((symbol == 'simple_stmt') and (len(nodes) > 1)):
                break
        return (index, symbol, nodes)
    (index, symbol, nodes) = current_suite(stack)
    if (symbol == 'simple_stmt'):
        index -= 2
        (_, _, (type_, suite_nodes)) = stack[index]
        symbol = grammar.number2symbol[type_]
        suite_nodes.append(tree.PythonNode(symbol, list(nodes)))
        nodes[:] = []
        nodes = suite_nodes
        stack[index]
    if self._stack_removal(grammar, stack, arcs, (index + 1), value, start_pos):
        add_token_callback(typ, value, start_pos, prefix)
    elif (typ == INDENT):
        self._omit_dedent_list.append(self._indent_counter)
    else:
        error_leaf = tree.PythonErrorLeaf(tok_name[typ].lower(), value, start_pos, prefix)
        stack[(-1)][2][1].append(error_leaf)
