diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index d3244c0305..ca28bc57ba 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -45,6 +45,8 @@ This is useful to find duplicated sections in XML files. * core * [#2444](https://github.com/pmd/pmd/pull/2444): \[core] Support reproducible builds * [#2484](https://github.com/pmd/pmd/issues/2484): \[core] Update maven-enforcer-plugin to require Java 118 +* c# + * [#2495](https://github.com/pmd/pmd/pull/2495): \[c#] Support for interpolated verbatim strings * java * [#2472](https://github.com/pmd/pmd/issues/2472): \[java] JavaCharStream throws an Error on invalid escape * java-bestpractices @@ -89,6 +91,7 @@ definitive API. * [#2479](https://github.com/pmd/pmd/pull/2479): \[java] False positive with Hamcrest's assertThat - [andreoss](https://github.com/andreoss) * [#2481](https://github.com/pmd/pmd/pull/2481): \[java] Fix JUnitSpellingRule false positive - [Artem Krosheninnikov](https://github.com/KroArtem) * [#2493](https://github.com/pmd/pmd/pull/2493): \[java] Deprecate redundant String Comparison rules - [John-Teng](https://github.com/John-Teng) +* [#2495](https://github.com/pmd/pmd/pull/2495): \[c#] Support for interpolated verbatim strings - [Maikel Steneker](https://github.com/maikelsteneker) {% endtocmaker %} diff --git a/pmd-cs/src/main/antlr4/net/sourceforge/pmd/lang/cs/antlr4/CSharpLexer.g4 b/pmd-cs/src/main/antlr4/net/sourceforge/pmd/lang/cs/antlr4/CSharpLexer.g4 index 37428cbc72..f381392fa9 100644 --- a/pmd-cs/src/main/antlr4/net/sourceforge/pmd/lang/cs/antlr4/CSharpLexer.g4 +++ b/pmd-cs/src/main/antlr4/net/sourceforge/pmd/lang/cs/antlr4/CSharpLexer.g4 @@ -148,7 +148,7 @@ REGULAR_STRING: '"' (~["\\\r\n\u0085\u2028\u2029] | Common VERBATIUM_STRING: '@"' (~'"' | '""')* '"'; INTERPOLATED_REGULAR_STRING_START: '$"' { interpolatedStringLevel++; interpolatedVerbatiums.push(false); verbatium = false; } -> pushMode(INTERPOLATION_STRING); -INTERPOLATED_VERBATIUM_STRING_START: '$@"' +INTERPOLATED_VERBATIUM_STRING_START: ('$@"' | '@$"') { interpolatedStringLevel++; interpolatedVerbatiums.push(true); verbatium = true; } -> pushMode(INTERPOLATION_STRING); //B.1.9 Operators And Punctuators diff --git a/pmd-cs/src/test/java/net/sourceforge/pmd/cpd/CsTokenizerTest.java b/pmd-cs/src/test/java/net/sourceforge/pmd/cpd/CsTokenizerTest.java index 3736bea90d..2f638af1af 100644 --- a/pmd-cs/src/test/java/net/sourceforge/pmd/cpd/CsTokenizerTest.java +++ b/pmd-cs/src/test/java/net/sourceforge/pmd/cpd/CsTokenizerTest.java @@ -162,6 +162,17 @@ public class CsTokenizerTest { assertEquals("using", tokens.getTokens().get(0).toString()); } + @Test + public void testInterpolatedVerbatimStrings() { + tokenizer.setIgnoreUsings(true); + tokenizer.tokenize(toSourceCode( + "var test = $@\"test\";\n" + + "var test2 = @$\"test\";"), + tokens + ); + assertEquals(15, tokens.size()); + } + private SourceCode toSourceCode(String source) { return new SourceCode(new SourceCode.StringCodeLoader(source)); }