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 ...@@ -432,12 +432,14 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, ErrorReporter& errorReporterP
initLocation(location, builder); initLocation(location, builder);
return result; return result;
}), }),
p::transform(stringLiteral, p::transform(p::oneOrMore(stringLiteral),
[this](Located<Text::Reader>&& value) -> Orphan<Expression> { [this](kj::Array<Located<Text::Reader>>&& value) -> Orphan<Expression> {
auto result = orphanage.newOrphan<Expression>(); auto result = orphanage.newOrphan<Expression>();
auto builder = result.get(); auto builder = result.get();
builder.setString(value.value); builder.setString(kj::strArray(
value.copyLocationTo(builder); KJ_MAP(part, value) { return part.value; }, ""));
builder.setStartByte(value.front().startByte);
builder.setEndByte(value.back().endByte);
return result; return result;
}), }),
p::transform(binaryLiteral, p::transform(binaryLiteral,
......
...@@ -127,7 +127,8 @@ struct TestDefaults { ...@@ -127,7 +127,8 @@ struct TestDefaults {
textList = ["quux", "corge", "grault"], textList = ["quux", "corge", "grault"],
dataList = ["garply", "waldo", "fred"], dataList = ["garply", "waldo", "fred"],
structList = [ structList = [
(textField = "x structlist 1"), (textField = "x " "structlist"
" 1"),
(textField = "x structlist 2"), (textField = "x structlist 2"),
(textField = "x structlist 3")], (textField = "x structlist 3")],
enumList = [qux, bar, grault] enumList = [qux, bar, grault]
...@@ -704,7 +705,8 @@ struct TestConstants { ...@@ -704,7 +705,8 @@ struct TestConstants {
textList = ["quux", "corge", "grault"], textList = ["quux", "corge", "grault"],
dataList = ["garply", "waldo", "fred"], dataList = ["garply", "waldo", "fred"],
structList = [ structList = [
(textField = "x structlist 1"), (textField = "x " "structlist"
" 1"),
(textField = "x structlist 2"), (textField = "x structlist 2"),
(textField = "x structlist 3")], (textField = "x structlist 3")],
enumList = [qux, bar, grault] 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