stringLiteral method
Implementation
Parser<ExpressionNode> stringLiteral() =>
ref0(singleStringLiteral).plus().map((strings) {
if (strings.length == 1) return strings.first;
final hasInterpolations = strings.any(
(s) => s is JoinedStrNode || s is FormattedValueNode,
);
if (hasInterpolations) {
final parts = <ExpressionNode>[];
for (final s in strings) {
if (s is JoinedStrNode) {
parts.addAll(s.values);
} else {
parts.add(s);
}
}
return JoinedStrNode(parts);
} else {
final buffer = StringBuffer();
for (final s in strings) {
if (s is ConstantNode) {
buffer.write(s.value);
}
}
return ConstantNode(buffer.toString());
}
});