forked from phoedos/pmd
Improvements for Dart interpolated strings
The Dart tokenizer was incomplete, resulting in some strings that use string interpolation not being parsed correctly. This has been worked around by making sure that the contents of string interpolation are all included in the same string token.
This commit is contained in:
@ -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
|
||||
|
@ -54,7 +54,10 @@ public class DartTokenizerTest extends CpdTextComparisonTest {
|
||||
doTest("imports");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testStringInterpolation() {
|
||||
doTest("string_interpolation");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegex() {
|
||||
|
@ -1,3 +1,3 @@
|
||||
var newline = '\n';
|
||||
var dollar = '$';
|
||||
var dollar = '$newLine';
|
||||
var escaped_dollar = "\$";
|
@ -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
|
||||
|
2
pmd-dart/src/test/resources/net/sourceforge/pmd/cpd/testdata/string_interpolation.dart
vendored
Normal file
2
pmd-dart/src/test/resources/net/sourceforge/pmd/cpd/testdata/string_interpolation.dart
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
var stringInStringUnicode = "${"∆"}";
|
||||
var stringInStringNewline = "${"\n")}";
|
12
pmd-dart/src/test/resources/net/sourceforge/pmd/cpd/testdata/string_interpolation.txt
vendored
Normal file
12
pmd-dart/src/test/resources/net/sourceforge/pmd/cpd/testdata/string_interpolation.txt
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
[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 38
|
||||
EOF
|
Reference in New Issue
Block a user