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

[matlab] [cpd] Parse error with backslashes in string literals #2258

Open
chrite opened this issue Jan 28, 2020 · 0 comments
Open

[matlab] [cpd] Parse error with backslashes in string literals #2258

chrite opened this issue Jan 28, 2020 · 0 comments
Labels
a:bug PMD crashes or fails to analyse a file.

Comments

@chrite
Copy link

chrite commented Jan 28, 2020

Description:
I tried using cpd on Windows 10 in a medium large code base, but got a (wrong?) Lexical error immediately. I think MATLAB's weird sometimes-escape-character \ isn't handled properly:

net.sourceforge.pmd.lang.ast.TokenMgrError: Lexical error in file Untitled.m at line 3, column 56.  Encountered: "$" (36), after : ""
        at net.sourceforge.pmd.lang.matlab.ast.MatlabParserTokenManager.getNextToken(MatlabParserTokenManager.java:1996)
        at net.sourceforge.pmd.lang.matlab.MatlabTokenManager.getNextToken(MatlabTokenManager.java:31)
        at net.sourceforge.pmd.cpd.token.internal.BaseTokenFilter.getNextToken(BaseTokenFilter.java:30)
        at net.sourceforge.pmd.cpd.internal.JavaCCTokenizer.tokenize(JavaCCTokenizer.java:40)
        at net.sourceforge.pmd.cpd.CPD.addAndThrowLexicalError(CPD.java:144)
        at net.sourceforge.pmd.cpd.CPD.add(CPD.java:139)
        at net.sourceforge.pmd.cpd.CPD.add(CPD.java:108)
        at net.sourceforge.pmd.cpd.CPD.add(CPD.java:70)
        at net.sourceforge.pmd.cpd.CPD.addDirectory(CPD.java:80)
        at net.sourceforge.pmd.cpd.CPD.addRecursively(CPD.java:65)
        at net.sourceforge.pmd.cpd.CPDCommandLineInterface.addSourcesFilesToCPD(CPDCommandLineInterface.java:134)
        at net.sourceforge.pmd.cpd.CPDCommandLineInterface.addSourceFilesToCPD(CPDCommandLineInterface.java:114)
        at net.sourceforge.pmd.cpd.CPDCommandLineInterface.main(CPDCommandLineInterface.java:87)
        at net.sourceforge.pmd.cpd.CPD.main(CPD.java:179)

--ignore-literals doesn't help as a work-around either...

Code Sample demonstrating the issue:

names = {'hallo_welt', 'hello_world'};
texEscape = strrep(names, '_', '\_');

or

nameUnit = 'hello [world]';
name = strtrim(regexprep(nameUnit, '\s\[.*\]$', ''));
@oowekyala oowekyala added the a:bug PMD crashes or fails to analyse a file. label Jan 28, 2020
@jsotuyod jsotuyod added needs:pmd7-revalidation The issue hasn't yet been retested vs PMD 7 and may be stale and removed needs:pmd7-revalidation The issue hasn't yet been retested vs PMD 7 and may be stale labels Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:bug PMD crashes or fails to analyse a file.
Projects
None yet
Development

No branches or pull requests

3 participants