Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double negative/minus operator causes IndexError #255

Open
ghost opened this issue Jul 16, 2020 · 1 comment
Open

Double negative/minus operator causes IndexError #255

ghost opened this issue Jul 16, 2020 · 1 comment

Comments

@ghost
Copy link

ghost commented Jul 16, 2020

Formulae such as --("A"="B") cause IndexError in koala/ast/__init__.py:build_ast due to "double operator"
Workaround until fix: replace -- with 1* in workbook

Example minimum reproduction: double_minus.xlsx

    def build_ast(expression, debug = False):
        """build an AST from an Excel formula expression in reverse polish notation"""
        #use a directed graph to store the tree
        G = DiGraph()
        stack = []
    
    
        for n in expression:
            # Since the graph does not maintain the order of adding nodes/edges
            # add an extra attribute 'pos' so we can always sort to the correct order
            if isinstance(n,OperatorNode):
                if n.ttype == "operator-infix":
                    arg2 = stack.pop()
                    arg1 = stack.pop()
                    # Hack to write the name of sheet in 2argument address
                    if(n.tvalue == ':'):
                        if '!' in arg1.tvalue and arg2.ttype == 'operand' and '!' not in arg2.tvalue:
                            arg2.tvalue = arg1.tvalue.split('!')[0] + '!' + arg2.tvalue
    
                    G.add_node(arg1,pos = 1)
                    G.add_node(arg2,pos = 2)
                    G.add_edge(arg1, n)
                    G.add_edge(arg2, n)
                else:
>                   arg1 = stack.pop()
E                   IndexError: pop from empty list

.venv/lib/python3.7/site-packages/koala/ast/__init__.py:295: IndexError
@victorjmarin
Copy link

The same issue is discussed here dgorissen/pycel#105.

Setting unary negation to be 'right' associative instead of 'left' should fix the problem. https://github.com/vallettea/koala/blob/master/koala/tokenizer.py#L710

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant