Merge branch 'pr-1822'

This commit is contained in:
Andreas Dangel 2019-05-12 16:19:29 +02:00
commit 465b303f3c
3 changed files with 22 additions and 4 deletions

View File

@ -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 %}

View File

@ -140,6 +140,7 @@ PARSER_END(MatlabParser)
<DEFAULT> TOKEN :
{
< STRING: "'" ( <ESC_SEQ> | "'" "'" | ~["\\","'","\n"] )* "'" >
| < DSTRING: "\"" ( "\\" | "\"" "\"" | ~["\\","\"","\n"] )* "\"" >
| < #ESC_SEQ:
"\\" ( "b" | "t" | "n" | "f" | "r" | "\"" | "'" | "\\" )
| <UNICODE_ESC>

View File

@ -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());
}
}