Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#46 Crashes parsing indented #define

closed-fixed
nobody
None
5
2012-09-20
2012-09-19
bgrupczy
No

CODE:
from CppHeaderParser import CppHeader
code = """
struct Struct
{
#define DOUBLE(var) \ ((var) * 2)

UINT32 var;
};
"""
cppheader = CppHeader(code, argType="string")
print "1. Executed successfully"

fd = open(<INSERT FILE NAME FOR CODE ABOVE HERE>)
code = "".join(fd.readlines())
fd.close()
cppheader = CppHeader(code, argType="string")
print "2. Executed successfully"

OUTPUT:
1. Executed successfully
Traceback (most recent call last):
File "C:\eclipse_wa_python\t4\parser.py", line 18, in <module>
cppheader = CppHeader(code, argType="string")
File "C:\Python27\lib\site-packages\CppHeaderParser\CppHeaderParser.py", line 2122, in __init__
% (self.headerFileName, tok.lineno, tok.value, " ".join(self.nameStack)))
CppHeaderParser.CppHeaderParser.CppParseError: Not able to parse on line 5 evaluating ";"
Error around: ( ( var ) * 2 ) UINT32 var

Discussion

  • Sorry, this one works for me. Do you have white space after the \ in the #define? Can you attach a .cpp file in case there is something copied over in a copy/paste

     
  • By .cpp I mean .h. I tried as a string and as a file. Unix format and dos format. There has to be some extra char in there somewhere

     
  • bgrupczy
    bgrupczy
    2012-09-20

    header crashing module

     
    Attachments
  • bgrupczy
    bgrupczy
    2012-09-20

    Does not work for me on Win 7 and AIX 5.3. Python 2.7.3. I thought it had something to do with the join but you know best.

    Versions:
    CppHeaderParser = Head
    ply = 3.4

    CODE:
    from CppHeaderParser import CppHeader
    code = """
    struct Struct
    {
    #define DOUBLE(var) \ ((var) * 2)

    UINT32 var;
    };
    """
    cppheader = CppHeader(code, argType="string")
    print "1. Executed successfully"

    cppheader = CppHeader("test.h")
    print "2. Executed successfully"

    OUTPUT:
    1. Executed successfully
    Traceback (most recent call last):
    File "C:\eclipse_wa_python\t4\parser.py", line 14, in <module>
    cppheader = CppHeader("test.h")
    File "C:\Python27\lib\site-packages\CppHeaderParser\CppHeaderParser.py", line 2122, in __init__
    % (self.headerFileName, tok.lineno, tok.value, " ".join(self.nameStack)))
    CppHeaderParser.CppHeaderParser.CppParseError: Not able to parse test.h on line 5 evaluating ";"
    Error around: ( ( var ) * 2 ) UINT32 var

     
  • bgrupczy
    bgrupczy
    2012-09-20

    Oh. No extra characters. From my testing, it has something to do with the nested parenthesis on the second line of the #define.

     
  • Fixed in commit 95:859cf19a5981

    Issue was the #define had whitespace in front of it

     
    • summary: Crashes parsing from file but not string --> Crashes parsing indented #define
    • status: open --> closed-fixed
     
  • AIX, I am very curious what you are using this library for. I love to hear what people use it for if you could tell me.