interpolatedString method
String interpolation: simple $foo or ${expression}.
Implementation
Parser<ExpressionNode> interpolatedString() =>
ref1(
token,
[
string('"""')
.seq(ref0(stringInterpolationContentMultiDouble).plus())
.seq(string('"""')),
string("'''")
.seq(ref0(stringInterpolationContentMultiSingle).plus())
.seq(string("'''")),
char('"')
.seq(ref0(stringInterpolationContentDouble).plus())
.seq(char('"')),
char("'")
.seq(ref0(stringInterpolationContentSingle).plus())
.seq(char("'")),
].toChoiceParser(),
).map((token) {
final parts = (token.value as List)[1] as List;
final nodes = <DartNode>[];
for (final p in parts) {
if (p is DartNode) {
nodes.add(p);
} else if (p is String && p.isNotEmpty) {
nodes.add(StringLiteralNode(p));
}
}
if (nodes.length == 1 && nodes.first is ExpressionNode) {
return nodes.first as ExpressionNode;
}
return InterpolatedStringNode(nodes);
});