Merge branch 'cpd_dart_string_interpolation' into master

Refs #2749
This commit is contained in:
Clément Fournier
2020-08-30 16:49:31 +02:00
7 changed files with 54 additions and 16 deletions

View File

@ -191,6 +191,7 @@ are deprecated as internal API.
* [#2733](https://github.com/pmd/pmd/pull/2733): Cleanup: Collection::addAll issues - [XenoAmess](https://github.com/XenoAmess)
* [#2734](https://github.com/pmd/pmd/pull/2734): Cleanup: use try with resources - [XenoAmess](https://github.com/XenoAmess)
* [#2744](https://github.com/pmd/pmd/pull/2744): Cleanup: fix typos - [XenoAmess](https://github.com/XenoAmess)
* [#2749](https://github.com/pmd/pmd/pull/2749): \[dart] \[cpd] Improvements for Dart interpolated strings - [Maikel Steneker](https://github.com/maikelsteneker)
{% endtocmaker %}

View File

@ -351,16 +351,16 @@ SingleLineString
fragment
StringContentDQ
: ~('\\' | '"' /*| '$'*/ | '\n' | '\r')
: ~('\\' | '"' | '$' | '\n' | '\r')
| '\\' ~('\n' | '\r')
//| stringInterpolation
| StringInterpolation
;
fragment
StringContentSQ
: ~('\\' | '\'' /*| '$'*/ | '\n' | '\r')
: ~('\\' | '\'' | '$' | '\n' | '\r')
| '\\' ~('\n' | '\r')
//| stringInterpolation
| StringInterpolation
;
MultiLineString
@ -372,15 +372,16 @@ MultiLineString
fragment
StringContentTDQ
: ~('\\' | '"' /*| '$'*/)
: ~('\\' | '"' | '$')
| '"' ~'"' | '""' ~'"'
//| stringInterpolation
| StringInterpolation
;
fragment StringContentTSQ
: ~('\\' | '\'' /*| '$'*/)
fragment
StringContentTSQ
: ~('\\' | '\'' | '$')
| '\'' ~'\'' | '\'\'' ~'\''
//| stringInterpolation
| StringInterpolation
;
NEWLINE
@ -390,10 +391,17 @@ NEWLINE
;
// 16.5.1 String Interpolation
stringInterpolation
// : '$' IDENTIFIER_NO_DOLLAR
: '$' identifier// FIXME
| '${' expression '}'
fragment
StringInterpolation
: '$' IDENTIFIER_NO_DOLLAR
| '${' StringInterpolationContent* '}'
;
fragment
StringInterpolationContent
: ~('$' | '{' | '}')
| '$' IDENTIFIER_NO_DOLLAR
| '${' StringInterpolationContent* '}'
;
// 16.6 Symbols

View File

@ -54,7 +54,10 @@ public class DartTokenizerTest extends CpdTextComparisonTest {
doTest("imports");
}
@Test
public void testStringInterpolation() {
doTest("string_interpolation");
}
@Test
public void testRegex() {

View File

@ -1,3 +1,3 @@
var newline = '\n';
var dollar = '$';
var dollar = '$newLine';
var escaped_dollar = "\$";

View File

@ -8,7 +8,7 @@ L2
[var] 1 3
[dollar] 5 10
[=] 12 12
['$'] 14 16
['$newLine'] 14 23
L3
[var] 1 3
[escaped_dollar] 5 18

View File

@ -0,0 +1,4 @@
var stringInStringUnicode = "${""}";
var stringInStringNewline = "${"\n"}";
var nestedInterpolation = "${"${"\n"}"}";
var interpolationWithMethodCall = "${foo("")}";

View File

@ -0,0 +1,22 @@
[Image] or [Truncated image[ Bcol Ecol
L1
[var] 1 3
[stringInStringUnicode] 5 25
[=] 27 27
["${"∆"}"] 29 36
L2
[var] 1 3
[stringInStringNewline] 5 25
[=] 27 27
["${"\\n"}"] 29 37
L3
[var] 1 3
[nestedInterpolation] 5 23
[=] 25 25
["${"${"\\n"}"}"] 27 40
L4
[var] 1 3
[interpolationWithMethodCall] 5 31
[=] 33 33
["${foo("")}"] 35 46
EOF