neo-nie / pynsource

Automatically exported from code.google.com/p/pynsource
0 stars 0 forks source link

Parser crashes on power operator #31

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. parse any source with the ** operator
2. e.g.

class Incoming1:
    def HandlePowerOperator(self):
        x = 10**2
        print x

What is the expected output? What do you see instead?

crashes the parser.

Original issue reported on code.google.com by abu...@gmail.com on 6 Sep 2012 at 6:35

GoogleCodeExporter commented 8 years ago
As reported by Charlie:

I assumed that Pow was for exponentiation(i.e.  ‘**’).

So I downloaded the source code and added the “Pow” operator to 
“core_parser_ast.py” as follows:

BINOP_SYMBOLS = {
    Add:        '+',
    Sub:        '-',
    Mult:       '*',
    Div:        '/',
    FloorDiv:   '//',
    Mod:        '%',
    LShift:     '<<',
    RShift:     '>>',
    BitOr:      '|',
    BitAnd:     '&',
    Pow:        '**',
    BitXor:     '^'
}
The code seemed to work just fine after that (running from source and not the 
Windows exe).

I’m sorry I cannot send you the python source that caused the problem, it is 
my employer’s code.

As an aside… after sending you the first email, I got another error in 
core_parser_ast.py. An assert statement caused the code to crash at line 364 
(with my new added Pow).

I commented out the “assert” and had the code just print a warning (see 
below).  It seemed to solve my second problem as well.

                #assert node.name in self.quick_parse.quick_found_module_defs
                # cet change
                if  node.name not in self.quick_parse.quick_found_module_defs:
                    print 'ERROR... node.name=',node.name,'is not in quick_found_module_defs'

Charlie

Original comment by abu...@gmail.com on 6 Sep 2012 at 6:37

GoogleCodeExporter commented 8 years ago
Also reported by Marco

I recently installed your windows executable in a Windows XP machine, I tried 
to graph simple python code and I got problems with the exponentiation 
operator. Is that expected?

Thanks in advance.

--Marco

Original comment by abu...@gmail.com on 6 Sep 2012 at 6:38

GoogleCodeExporter commented 8 years ago
This issue was updated by revision r573.

Added unit test to catch power operator parsing problem.

Original comment by abu...@gmail.com on 6 Sep 2012 at 6:39

GoogleCodeExporter commented 8 years ago
This issue was closed by revision r574.

Original comment by abu...@gmail.com on 6 Sep 2012 at 6:46