Menu

#120 C++ Multi line string literal fix

closed
None
5
2012-10-07
2006-01-06
Tom Judge
No

The C++ parser was not correctly identifying multi line
string literals. This patch fixes this.

Discussion

  • Tom Judge

    Tom Judge - 2006-01-06

    C++ Parser MultiLine String Literal Fix

     
  • Tom Copeland

    Tom Copeland - 2006-01-06

    Logged In: YES
    user_id=5159

    Hi Tom -

    About this one - can you reproduce the problem that this is
    fixing? For example, CPD can parse this code fine:

    =============
    int main(int argc, char* argv) {
    char
    x = "foo\
    bar";
    return 0;
    }
    =============

    Is this patch addressing something other than stuff like in
    the above code?

    Thanks,

    tom

     
  • James Bursa

    James Bursa - 2006-01-09

    Logged In: YES
    user_id=453739

    I can reproduce this problem with the example you gave
    using CVS HEAD. If I save your code as test/test.c:

    $ java net.sourceforge.pmd.cpd.CPD --minimum-tokens 100 --
    language cpp --files test
    net.sourceforge.pmd.cpd.cppast.TokenMgrError: Lexical error
    at line 2, column 18. Encountered: "\n" (10), after : "\"
    foo\"
    at net.sourceforge.pmd.cpd.cppast.
    CPPParserTokenManager.getNextToken(CPPParserTokenManager.
    java:1619)
    at net.sourceforge.pmd.cpd.CPPTokenizer.tokenize
    (CPPTokenizer.java:31)
    at net.sourceforge.pmd.cpd.CPD.add(CPD.java:91)
    at net.sourceforge.pmd.cpd.CPD.add(CPD.java:63)
    at net.sourceforge.pmd.cpd.CPD.addDirectory(CPD.
    java:72)
    at net.sourceforge.pmd.cpd.CPD.addRecursively(CPD.
    java:58)
    at net.sourceforge.pmd.cpd.CPD.main(CPD.java:184)
    Skipping /usr/home/james/test/test.c due to parse error

    With our patch (I work with Tom Judge) it parses
    successfully.

     
  • Tom Copeland

    Tom Copeland - 2006-01-09

    Logged In: YES
    user_id=5159

    Gah! I was specifiying "--language c" vs "--language cpp"
    on the command line, which meant that it was using the
    AnyLanguage parser rather than the C/C++ parser. Hm. OK, I
    just changed it so it maps both "--language c" and
    "--language cpp" to the C/C++ parser. Excellent.

    And now I've applied the patch and it works fine, thanks
    much! You can download a new pmd-3.4.jar file here:

    http://infoether.com/~tom/pmd-3.4.jar

    that contains this fix.

    Note that we've recently added a dependency on jakarta-oro
    to support regular expressions in XPath expressions; you can
    get that here:

    http://infoether.com/~tom/jakarta-oro-2.0.8.jar

    Thanks for the nice patch,

    Yours,

    Tom
    Support PMD, get the book: http://pmdapplied.com/

     

Log in to post a comment.

MongoDB Logo MongoDB