diff --git a/pmd-matlab/etc/grammar/Matlab.jj b/pmd-matlab/etc/grammar/Matlab.jj index d83368fc73b..c9b168dc641 100644 --- a/pmd-matlab/etc/grammar/Matlab.jj +++ b/pmd-matlab/etc/grammar/Matlab.jj @@ -136,21 +136,8 @@ PARSER_END(MatlabParserImpl) TOKEN : { - < STRING: "'" ( | "'" "'" | ~["\\","'","\n"] )* "'" > + < STRING: "'" ( "\\" | "'" "'" | ~["\\","'","\n"] )* "'" > | < DSTRING: "\"" ( "\\" | "\"" "\"" | ~["\\","\"","\n"] )* "\"" > -| < #ESC_SEQ: - "\\" ( "b" | "t" | "n" | "f" | "r" | "\"" | "'" | "\\" ) - | - | - > -| < #UNICODE_ESC: "\\" "u" > -| < #OCTAL_ESC: - "\\" ["0" - "3"] - | "\\" - | "\\" - > -| < #HEX_DIGIT: ["0"-"9", "a"-"f", "A"-"F"] > -| < #OCTAL_DIGIT: ["0"-"7"] > } TOKEN : diff --git a/pmd-matlab/src/test/java/net/sourceforge/pmd/lang/matlab/cpd/MatlabCpdLexerTest.java b/pmd-matlab/src/test/java/net/sourceforge/pmd/lang/matlab/cpd/MatlabCpdLexerTest.java index 39b56ccfd29..c6c96713003 100644 --- a/pmd-matlab/src/test/java/net/sourceforge/pmd/lang/matlab/cpd/MatlabCpdLexerTest.java +++ b/pmd-matlab/src/test/java/net/sourceforge/pmd/lang/matlab/cpd/MatlabCpdLexerTest.java @@ -49,4 +49,9 @@ void testDoubleQuotedStrings() { void testTabWidth() { doTest("tabWidth"); } + + @Test + void testBackslash() { + doTest("stringsWithBackslash"); + } } diff --git a/pmd-matlab/src/test/resources/net/sourceforge/pmd/lang/matlab/cpd/testdata/stringsWithBackslash.m b/pmd-matlab/src/test/resources/net/sourceforge/pmd/lang/matlab/cpd/testdata/stringsWithBackslash.m new file mode 100644 index 00000000000..10dbe95d1c8 --- /dev/null +++ b/pmd-matlab/src/test/resources/net/sourceforge/pmd/lang/matlab/cpd/testdata/stringsWithBackslash.m @@ -0,0 +1,3 @@ +error('$\phi$'); +error('\\192.168.1.1\Disk'); +error('\'); diff --git a/pmd-matlab/src/test/resources/net/sourceforge/pmd/lang/matlab/cpd/testdata/stringsWithBackslash.txt b/pmd-matlab/src/test/resources/net/sourceforge/pmd/lang/matlab/cpd/testdata/stringsWithBackslash.txt new file mode 100644 index 00000000000..3f6fad23002 --- /dev/null +++ b/pmd-matlab/src/test/resources/net/sourceforge/pmd/lang/matlab/cpd/testdata/stringsWithBackslash.txt @@ -0,0 +1,20 @@ + [Image] or [Truncated image[ Bcol Ecol +L1 + [error] 1 6 + [(] 6 7 + ['$\\phi$'] 7 15 + [)] 15 16 + [;] 16 17 +L2 + [error] 1 6 + [(] 6 7 + ['\\\\192.168.1.1\\Disk'] 7 27 + [)] 27 28 + [;] 28 29 +L3 + [error] 1 6 + [(] 6 7 + ['\\'] 7 10 + [)] 10 11 + [;] 11 12 +EOF