diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 507dfcc91b..bf0bb98f04 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -16,15 +16,21 @@ This is a {{ site.pmd.release_type }} release. #### Enhanced Matlab support -Thanks to the contribution from [Maikel Steneker](https://github.com/maikelsteneker) CPD for Matlab can -now parse matlab programs which use the question mark operator to specify access to +Thanks to the contributions from [Maikel Steneker](https://github.com/maikelsteneker) CPD for Matlab can +now parse Matlab programs which use the question mark operator to specify access to class members: ``` -lassdef Class1 +classdef Class1 properties (SetAccess = ?Class2) ``` +CPD also understands now double quoted strings, which are supported since version R2017a of Matlab: + +``` +str = "This is a string" +``` + ### Fixed Issues * dart @@ -48,6 +54,7 @@ properties (SetAccess = ?Class2) * [#1807](https://github.com/pmd/pmd/pull/1807): \[ci] Fix missing local branch issues when executing pmd-regression-tester - [BBG](https://github.com/djydewang) * [#1813](https://github.com/pmd/pmd/pull/1813): \[matlab] \[cpd] Matlab comments - [Maikel Steneker](https://github.com/maikelsteneker) * [#1821](https://github.com/pmd/pmd/pull/1821): \[matlab] \[cpd] Matlab question mark token - [Maikel Steneker](https://github.com/maikelsteneker) +* [#1822](https://github.com/pmd/pmd/pull/1822): \[matlab] \[cpd] Double quoted string - [Maikel Steneker](https://github.com/maikelsteneker) {% endtocmaker %} diff --git a/pmd-matlab/etc/grammar/matlab.jj b/pmd-matlab/etc/grammar/matlab.jj index f74d0d5bcb..31aca621e7 100644 --- a/pmd-matlab/etc/grammar/matlab.jj +++ b/pmd-matlab/etc/grammar/matlab.jj @@ -140,6 +140,7 @@ PARSER_END(MatlabParser) TOKEN : { < STRING: "'" ( | "'" "'" | ~["\\","'","\n"] )* "'" > +| < DSTRING: "\"" ( "\\" | "\"" "\"" | ~["\\","\"","\n"] )* "\"" > | < #ESC_SEQ: "\\" ( "b" | "t" | "n" | "f" | "r" | "\"" | "'" | "\\" ) | diff --git a/pmd-matlab/src/test/java/net/sourceforge/pmd/cpd/MatlabTokenizerTest.java b/pmd-matlab/src/test/java/net/sourceforge/pmd/cpd/MatlabTokenizerTest.java index 426ef34774..cc45bfb48f 100644 --- a/pmd-matlab/src/test/java/net/sourceforge/pmd/cpd/MatlabTokenizerTest.java +++ b/pmd-matlab/src/test/java/net/sourceforge/pmd/cpd/MatlabTokenizerTest.java @@ -51,7 +51,6 @@ public class MatlabTokenizerTest extends AbstractTokenizerTest { )); Tokens tokens = new Tokens(); tokenizer.tokenize(sourceCode, tokens); - TokenEntry.getEOF(); assertEquals(2, tokens.size()); // 2 tokens: "end" + EOF } @@ -85,6 +84,7 @@ public class MatlabTokenizerTest extends AbstractTokenizerTest { assertEquals(13, tokens.size()); } + @Test public void testQuestionMark() throws IOException { SourceCode sourceCode = new SourceCode(new SourceCode.StringCodeLoader("classdef Class1" + PMD.EOL + "properties (SetAccess = ?Class2)")); @@ -92,4 +92,14 @@ public class MatlabTokenizerTest extends AbstractTokenizerTest { tokenizer.tokenize(sourceCode, tokens); assertEquals(10, tokens.size()); } + + @Test + public void testDoubleQuotedStrings() throws IOException { + SourceCode sourceCode = new SourceCode(new SourceCode.StringCodeLoader( + "error(\"This is a double-quoted string\");")); + Tokens tokens = new Tokens(); + tokenizer.tokenize(sourceCode, tokens); + assertEquals("\"This is a double-quoted string\"", tokens.getTokens().get(2).toString()); + assertEquals(6, tokens.size()); + } }