Commit 113fa5a6 authored by Kenton Varda's avatar Kenton Varda

Support multi-part string literals in capnp.

I was shocked to find that there was no good way to represent a multi-line literal currently. This implements C-style literals, where multiple consecutive string literals are concatenated.
parent 99ef7e39
......@@ -432,12 +432,14 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, ErrorReporter& errorReporterP
initLocation(location, builder);
return result;
}),
p::transform(stringLiteral,
[this](Located<Text::Reader>&& value) -> Orphan<Expression> {
p::transform(p::oneOrMore(stringLiteral),
[this](kj::Array<Located<Text::Reader>>&& value) -> Orphan<Expression> {
auto result = orphanage.newOrphan<Expression>();
auto builder = result.get();
builder.setString(value.value);
value.copyLocationTo(builder);
builder.setString(kj::strArray(
KJ_MAP(part, value) { return part.value; }, ""));
builder.setStartByte(value.front().startByte);
builder.setEndByte(value.back().endByte);
return result;
}),
p::transform(binaryLiteral,
......
......@@ -127,7 +127,8 @@ struct TestDefaults {
textList = ["quux", "corge", "grault"],
dataList = ["garply", "waldo", "fred"],
structList = [
(textField = "x structlist 1"),
(textField = "x " "structlist"
" 1"),
(textField = "x structlist 2"),
(textField = "x structlist 3")],
enumList = [qux, bar, grault]
......@@ -704,7 +705,8 @@ struct TestConstants {
textList = ["quux", "corge", "grault"],
dataList = ["garply", "waldo", "fred"],
structList = [
(textField = "x structlist 1"),
(textField = "x " "structlist"
" 1"),
(textField = "x structlist 2"),
(textField = "x structlist 3")],
enumList = [qux, bar, grault]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment