Commit 83f9754e authored by Kenton Varda's avatar Kenton Varda

Require a colon before 'group' or 'union' except for unnamed unions as well as…

Require a colon before 'group' or 'union' except for unnamed unions as well as the legacy case of a named union with an ordinal (where the colon is optional).
parent 89ee9afe
...@@ -37,14 +37,14 @@ enum Operation { ...@@ -37,14 +37,14 @@ enum Operation {
struct Expression { struct Expression {
op@0: Operation; op@0: Operation;
left @1 union { left :union {
value@2: Int32; value@1: Int32;
expression@3: Expression; expression@2: Expression;
} }
right @4 union { right :union {
value@5: Int32; value@3: Int32;
expression@6: Expression; expression@4: Expression;
} }
} }
......
...@@ -223,9 +223,9 @@ struct Declaration { ...@@ -223,9 +223,9 @@ struct Declaration {
name @0 :LocatedText; # If null, param failed to parse. name @0 :LocatedText; # If null, param failed to parse.
type @1 :TypeExpression; type @1 :TypeExpression;
annotations @2 :List(AnnotationApplication); annotations @2 :List(AnnotationApplication);
defaultValue @3 union { defaultValue :union {
none @4 :Void; none @3 :Void;
value @5 :ValueExpression; value @4 :ValueExpression;
} }
} }
} }
......
...@@ -1437,7 +1437,7 @@ static const ::capnp::_::AlignedData<74> b_fffe08a9a697d2a5 = { ...@@ -1437,7 +1437,7 @@ static const ::capnp::_::AlignedData<74> b_fffe08a9a697d2a5 = {
96, 0, 0, 0, 2, 0, 1, 0, 96, 0, 0, 0, 2, 0, 1, 0,
116, 0, 0, 0, 2, 0, 1, 0, 116, 0, 0, 0, 2, 0, 1, 0,
3, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0,
1, 0, 1, 0, 3, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
71, 234, 136, 253, 21, 69, 16, 229, 71, 234, 136, 253, 21, 69, 16, 229,
113, 0, 0, 0, 106, 0, 0, 0, 113, 0, 0, 0, 106, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
...@@ -1505,14 +1505,14 @@ static const ::capnp::_::AlignedData<48> b_e5104515fd88ea47 = { ...@@ -1505,14 +1505,14 @@ static const ::capnp::_::AlignedData<48> b_e5104515fd88ea47 = {
108, 117, 101, 0, 0, 0, 0, 0, 108, 117, 101, 0, 0, 0, 0, 0,
8, 0, 0, 0, 3, 0, 4, 0, 8, 0, 0, 0, 3, 0, 4, 0,
0, 0, 255, 255, 0, 0, 0, 0, 0, 0, 255, 255, 0, 0, 0, 0,
0, 0, 1, 0, 4, 0, 0, 0, 0, 0, 1, 0, 3, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
41, 0, 0, 0, 42, 0, 0, 0, 41, 0, 0, 0, 42, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
36, 0, 0, 0, 2, 0, 1, 0, 36, 0, 0, 0, 2, 0, 1, 0,
44, 0, 0, 0, 2, 0, 1, 0, 44, 0, 0, 0, 2, 0, 1, 0,
1, 0, 254, 255, 3, 0, 0, 0, 1, 0, 254, 255, 3, 0, 0, 0,
0, 0, 1, 0, 5, 0, 0, 0, 0, 0, 1, 0, 4, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
41, 0, 0, 0, 50, 0, 0, 0, 41, 0, 0, 0, 50, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
......
...@@ -205,14 +205,14 @@ TEST(Lexer, Statements) { ...@@ -205,14 +205,14 @@ TEST(Lexer, Statements) {
"tokens = [" "tokens = ["
"(identifier = 'foo', endByte = 3)" "(identifier = 'foo', endByte = 3)"
"], " "], "
"block = (statements = [" "block = ["
"(tokens = [" "(tokens = ["
"(identifier = 'bar', startByte = 5, endByte = 8)" "(identifier = 'bar', startByte = 5, endByte = 8)"
"], startByte = 5, endByte = 9), " "], startByte = 5, endByte = 9), "
"(tokens = [" "(tokens = ["
"(identifier = 'baz', startByte = 10, endByte = 13)" "(identifier = 'baz', startByte = 10, endByte = 13)"
"], startByte = 10, endByte = 14)" "], startByte = 10, endByte = 14)"
"]), " "], "
"endByte = 15" "endByte = 15"
"), " "), "
"(tokens = [" "(tokens = ["
...@@ -300,14 +300,14 @@ TEST(Lexer, DocComments) { ...@@ -300,14 +300,14 @@ TEST(Lexer, DocComments) {
"tokens = [" "tokens = ["
"(identifier = 'foo', endByte = 3)" "(identifier = 'foo', endByte = 3)"
"], " "], "
"block = (statements = [" "block = ["
"(tokens = [" "(tokens = ["
"(identifier = 'bar', startByte = 17, endByte = 20)" "(identifier = 'bar', startByte = 17, endByte = 20)"
"], docComment = 'hi\\n', startByte = 17, endByte = 27), " "], docComment = 'hi\\n', startByte = 17, endByte = 27), "
"(tokens = [" "(tokens = ["
"(identifier = 'baz', startByte = 28, endByte = 31)" "(identifier = 'baz', startByte = 28, endByte = 31)"
"], startByte = 28, endByte = 32)" "], startByte = 28, endByte = 32)"
"]), " "], "
"docComment = 'blah blah\\n', " "docComment = 'blah blah\\n', "
"endByte = 44" "endByte = 44"
"), " "), "
...@@ -323,14 +323,14 @@ TEST(Lexer, DocComments) { ...@@ -323,14 +323,14 @@ TEST(Lexer, DocComments) {
"tokens = [" "tokens = ["
"(identifier = 'foo', endByte = 3)" "(identifier = 'foo', endByte = 3)"
"], " "], "
"block = (statements = [" "block = ["
"(tokens = [" "(tokens = ["
"(identifier = 'bar', startByte = 5, endByte = 8)" "(identifier = 'bar', startByte = 5, endByte = 8)"
"], startByte = 5, endByte = 9), " "], startByte = 5, endByte = 9), "
"(tokens = [" "(tokens = ["
"(identifier = 'baz', startByte = 10, endByte = 13)" "(identifier = 'baz', startByte = 10, endByte = 13)"
"], startByte = 10, endByte = 14)" "], startByte = 10, endByte = 14)"
"]), " "], "
"docComment = 'late comment\\n', " "docComment = 'late comment\\n', "
"endByte = 31" "endByte = 31"
"), " "), "
......
...@@ -224,7 +224,7 @@ Lexer::Lexer(Orphanage orphanageParam, const ErrorReporter& errorReporterParam) ...@@ -224,7 +224,7 @@ Lexer::Lexer(Orphanage orphanageParam, const ErrorReporter& errorReporterParam)
KJ_IF_MAYBE(c, comment) { KJ_IF_MAYBE(c, comment) {
attachDocComment(builder, kj::mv(*c)); attachDocComment(builder, kj::mv(*c));
} }
builder.getBlock().setNone(); builder.setLine();
return result; return result;
}), }),
transform( transform(
...@@ -241,7 +241,7 @@ Lexer::Lexer(Orphanage orphanageParam, const ErrorReporter& errorReporterParam) ...@@ -241,7 +241,7 @@ Lexer::Lexer(Orphanage orphanageParam, const ErrorReporter& errorReporterParam)
} else KJ_IF_MAYBE(c, lateComment) { } else KJ_IF_MAYBE(c, lateComment) {
attachDocComment(builder, kj::mv(*c)); attachDocComment(builder, kj::mv(*c));
} }
auto list = builder.getBlock().initStatements(statements.size()); auto list = builder.initBlock(statements.size());
for (uint i = 0; i < statements.size(); i++) { for (uint i = 0; i < statements.size(); i++) {
list.adoptWithCaveats(i, kj::mv(statements[i])); list.adoptWithCaveats(i, kj::mv(statements[i]));
} }
......
...@@ -44,15 +44,15 @@ struct Token { ...@@ -44,15 +44,15 @@ struct Token {
struct Statement { struct Statement {
tokens @0 :List(Token); tokens @0 :List(Token);
block @1 union { union {
none @2 :Void; line @1 :Void;
statements @3 :List(Statement); block @2 :List(Statement);
} }
docComment @4 :Text; docComment @3 :Text;
startByte @5 :UInt32; startByte @4 :UInt32;
endByte @6 :UInt32; endByte @5 :UInt32;
} }
struct LexedTokens { struct LexedTokens {
......
...@@ -181,17 +181,17 @@ const ::capnp::_::RawSchema s_91cc55cd57de5419 = { ...@@ -181,17 +181,17 @@ const ::capnp::_::RawSchema s_91cc55cd57de5419 = {
0x91cc55cd57de5419, b_91cc55cd57de5419.words, 165, d_91cc55cd57de5419, m_91cc55cd57de5419, 0x91cc55cd57de5419, b_91cc55cd57de5419.words, 165, d_91cc55cd57de5419, m_91cc55cd57de5419,
1, 9, i_91cc55cd57de5419, nullptr, nullptr 1, 9, i_91cc55cd57de5419, nullptr, nullptr
}; };
static const ::capnp::_::AlignedData<87> b_c6725e678d60fa37 = { static const ::capnp::_::AlignedData<110> b_c6725e678d60fa37 = {
{ 0, 0, 0, 0, 5, 0, 5, 0, { 0, 0, 0, 0, 5, 0, 5, 0,
55, 250, 96, 141, 103, 94, 114, 198, 55, 250, 96, 141, 103, 94, 114, 198,
0, 0, 0, 0, 1, 0, 2, 0, 0, 0, 0, 0, 1, 0, 2, 0,
238, 195, 31, 98, 210, 86, 57, 167, 238, 195, 31, 98, 210, 86, 57, 167,
3, 0, 7, 0, 0, 0, 0, 0, 3, 0, 7, 0, 0, 0, 2, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
17, 0, 0, 0, 42, 1, 0, 0, 17, 0, 0, 0, 42, 1, 0, 0,
33, 0, 0, 0, 7, 0, 0, 0, 33, 0, 0, 0, 7, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
29, 0, 0, 0, 31, 1, 0, 0, 29, 0, 0, 0, 87, 1, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
99, 97, 112, 110, 112, 47, 99, 111, 99, 97, 112, 110, 112, 47, 99, 111,
109, 112, 105, 108, 101, 114, 47, 108, 109, 112, 105, 108, 101, 114, 47, 108,
...@@ -199,42 +199,49 @@ static const ::capnp::_::AlignedData<87> b_c6725e678d60fa37 = { ...@@ -199,42 +199,49 @@ static const ::capnp::_::AlignedData<87> b_c6725e678d60fa37 = {
110, 112, 58, 83, 116, 97, 116, 101, 110, 112, 58, 83, 116, 97, 116, 101,
109, 101, 110, 116, 0, 0, 0, 0, 109, 101, 110, 116, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0,
20, 0, 0, 0, 3, 0, 4, 0, 24, 0, 0, 0, 3, 0, 4, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
125, 0, 0, 0, 58, 0, 0, 0, 153, 0, 0, 0, 58, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
120, 0, 0, 0, 2, 0, 1, 0, 148, 0, 0, 0, 2, 0, 1, 0,
140, 0, 0, 0, 2, 0, 1, 0, 168, 0, 0, 0, 2, 0, 1, 0,
1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 255, 255, 0, 0, 0, 0,
1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0,
100, 202, 149, 252, 126, 130, 2, 221,
137, 0, 0, 0, 50, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
165, 0, 0, 0, 42, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
160, 0, 0, 0, 2, 0, 1, 0,
168, 0, 0, 0, 2, 0, 1, 0,
2, 0, 254, 255, 1, 0, 0, 0,
0, 0, 1, 0, 2, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2, 0, 0, 0, 2, 0, 0, 0, 165, 0, 0, 0, 50, 0, 0, 0,
0, 0, 1, 0, 4, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
113, 0, 0, 0, 90, 0, 0, 0, 160, 0, 0, 0, 2, 0, 1, 0,
180, 0, 0, 0, 2, 0, 1, 0,
3, 0, 0, 0, 2, 0, 0, 0,
0, 0, 1, 0, 3, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
112, 0, 0, 0, 2, 0, 1, 0, 177, 0, 0, 0, 90, 0, 0, 0,
120, 0, 0, 0, 2, 0, 1, 0,
3, 0, 0, 0, 1, 0, 0, 0,
0, 0, 1, 0, 5, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
117, 0, 0, 0, 82, 0, 0, 0, 176, 0, 0, 0, 2, 0, 1, 0,
184, 0, 0, 0, 2, 0, 1, 0,
4, 0, 0, 0, 1, 0, 0, 0,
0, 0, 1, 0, 4, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
116, 0, 0, 0, 2, 0, 1, 0, 181, 0, 0, 0, 82, 0, 0, 0,
124, 0, 0, 0, 2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4, 0, 0, 0, 2, 0, 0, 0, 180, 0, 0, 0, 2, 0, 1, 0,
0, 0, 1, 0, 6, 0, 0, 0, 188, 0, 0, 0, 2, 0, 1, 0,
5, 0, 0, 0, 2, 0, 0, 0,
0, 0, 1, 0, 5, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
121, 0, 0, 0, 66, 0, 0, 0, 185, 0, 0, 0, 66, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
116, 0, 0, 0, 2, 0, 1, 0, 180, 0, 0, 0, 2, 0, 1, 0,
124, 0, 0, 0, 2, 0, 1, 0, 188, 0, 0, 0, 2, 0, 1, 0,
116, 111, 107, 101, 110, 115, 0, 0, 116, 111, 107, 101, 110, 115, 0, 0,
14, 0, 0, 0, 0, 0, 0, 0, 14, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
...@@ -245,7 +252,23 @@ static const ::capnp::_::AlignedData<87> b_c6725e678d60fa37 = { ...@@ -245,7 +252,23 @@ static const ::capnp::_::AlignedData<87> b_c6725e678d60fa37 = {
14, 0, 0, 0, 0, 0, 0, 0, 14, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
108, 105, 110, 101, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
98, 108, 111, 99, 107, 0, 0, 0, 98, 108, 111, 99, 107, 0, 0, 0,
14, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 2, 0, 1, 0,
16, 0, 0, 0, 0, 0, 0, 0,
55, 250, 96, 141, 103, 94, 114, 198,
0, 0, 0, 0, 0, 0, 0, 0,
14, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
100, 111, 99, 67, 111, 109, 109, 101, 100, 111, 99, 67, 111, 109, 109, 101,
110, 116, 0, 0, 0, 0, 0, 0, 110, 116, 0, 0, 0, 0, 0, 0,
12, 0, 0, 0, 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0,
...@@ -272,74 +295,13 @@ static const ::capnp::_::AlignedData<87> b_c6725e678d60fa37 = { ...@@ -272,74 +295,13 @@ static const ::capnp::_::AlignedData<87> b_c6725e678d60fa37 = {
}; };
static const ::capnp::_::RawSchema* const d_c6725e678d60fa37[] = { static const ::capnp::_::RawSchema* const d_c6725e678d60fa37[] = {
&s_91cc55cd57de5419, &s_91cc55cd57de5419,
&s_dd02827efc95ca64,
};
static const uint16_t m_c6725e678d60fa37[] = {1, 2, 4, 3, 0};
static const uint16_t i_c6725e678d60fa37[] = {0, 1, 2, 3, 4};
const ::capnp::_::RawSchema s_c6725e678d60fa37 = {
0xc6725e678d60fa37, b_c6725e678d60fa37.words, 87, d_c6725e678d60fa37, m_c6725e678d60fa37,
2, 5, i_c6725e678d60fa37, nullptr, nullptr
};
static const ::capnp::_::AlignedData<50> b_dd02827efc95ca64 = {
{ 0, 0, 0, 0, 5, 0, 5, 0,
100, 202, 149, 252, 126, 130, 2, 221,
37, 0, 0, 0, 1, 0, 2, 0,
55, 250, 96, 141, 103, 94, 114, 198,
3, 0, 7, 0, 1, 0, 2, 0,
0, 0, 0, 0, 0, 0, 0, 0,
17, 0, 0, 0, 90, 1, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
29, 0, 0, 0, 119, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
99, 97, 112, 110, 112, 47, 99, 111,
109, 112, 105, 108, 101, 114, 47, 108,
101, 120, 101, 114, 46, 99, 97, 112,
110, 112, 58, 83, 116, 97, 116, 101,
109, 101, 110, 116, 46, 98, 108, 111,
99, 107, 0, 0, 0, 0, 0, 0,
8, 0, 0, 0, 3, 0, 4, 0,
0, 0, 255, 255, 0, 0, 0, 0,
0, 0, 1, 0, 2, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
41, 0, 0, 0, 42, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
36, 0, 0, 0, 2, 0, 1, 0,
44, 0, 0, 0, 2, 0, 1, 0,
1, 0, 254, 255, 1, 0, 0, 0,
0, 0, 1, 0, 3, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
41, 0, 0, 0, 90, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
40, 0, 0, 0, 2, 0, 1, 0,
60, 0, 0, 0, 2, 0, 1, 0,
110, 111, 110, 101, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
115, 116, 97, 116, 101, 109, 101, 110,
116, 115, 0, 0, 0, 0, 0, 0,
14, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 2, 0, 1, 0,
16, 0, 0, 0, 0, 0, 0, 0,
55, 250, 96, 141, 103, 94, 114, 198,
0, 0, 0, 0, 0, 0, 0, 0,
14, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, }
};
static const ::capnp::_::RawSchema* const d_dd02827efc95ca64[] = {
&s_c6725e678d60fa37, &s_c6725e678d60fa37,
}; };
static const uint16_t m_dd02827efc95ca64[] = {0, 1}; static const uint16_t m_c6725e678d60fa37[] = {2, 3, 5, 1, 4, 0};
static const uint16_t i_dd02827efc95ca64[] = {0, 1}; static const uint16_t i_c6725e678d60fa37[] = {1, 2, 0, 3, 4, 5};
const ::capnp::_::RawSchema s_dd02827efc95ca64 = { const ::capnp::_::RawSchema s_c6725e678d60fa37 = {
0xdd02827efc95ca64, b_dd02827efc95ca64.words, 50, d_dd02827efc95ca64, m_dd02827efc95ca64, 0xc6725e678d60fa37, b_c6725e678d60fa37.words, 110, d_c6725e678d60fa37, m_c6725e678d60fa37,
1, 2, i_dd02827efc95ca64, nullptr, nullptr 2, 6, i_c6725e678d60fa37, nullptr, nullptr
}; };
static const ::capnp::_::AlignedData<35> b_9e69a92512b19d18 = { static const ::capnp::_::AlignedData<35> b_9e69a92512b19d18 = {
{ 0, 0, 0, 0, 5, 0, 5, 0, { 0, 0, 0, 0, 5, 0, 5, 0,
...@@ -441,8 +403,6 @@ CAPNP_DEFINE_STRUCT( ...@@ -441,8 +403,6 @@ CAPNP_DEFINE_STRUCT(
::capnp::compiler::Token); ::capnp::compiler::Token);
CAPNP_DEFINE_STRUCT( CAPNP_DEFINE_STRUCT(
::capnp::compiler::Statement); ::capnp::compiler::Statement);
CAPNP_DEFINE_STRUCT(
::capnp::compiler::Statement::Block);
CAPNP_DEFINE_STRUCT( CAPNP_DEFINE_STRUCT(
::capnp::compiler::LexedTokens); ::capnp::compiler::LexedTokens);
CAPNP_DEFINE_STRUCT( CAPNP_DEFINE_STRUCT(
......
...@@ -28,19 +28,11 @@ struct Token { ...@@ -28,19 +28,11 @@ struct Token {
struct Statement { struct Statement {
Statement() = delete; Statement() = delete;
class Reader;
class Builder;
struct Block;
};
struct Statement::Block {
Block() = delete;
class Reader; class Reader;
class Builder; class Builder;
enum Which: uint16_t { enum Which: uint16_t {
NONE, LINE,
STATEMENTS, BLOCK,
}; };
}; };
...@@ -68,7 +60,6 @@ namespace schemas { ...@@ -68,7 +60,6 @@ namespace schemas {
extern const ::capnp::_::RawSchema s_91cc55cd57de5419; extern const ::capnp::_::RawSchema s_91cc55cd57de5419;
extern const ::capnp::_::RawSchema s_c6725e678d60fa37; extern const ::capnp::_::RawSchema s_c6725e678d60fa37;
extern const ::capnp::_::RawSchema s_dd02827efc95ca64;
extern const ::capnp::_::RawSchema s_9e69a92512b19d18; extern const ::capnp::_::RawSchema s_9e69a92512b19d18;
extern const ::capnp::_::RawSchema s_a11f97b9d6c73dd4; extern const ::capnp::_::RawSchema s_a11f97b9d6c73dd4;
...@@ -81,9 +72,6 @@ CAPNP_DECLARE_STRUCT( ...@@ -81,9 +72,6 @@ CAPNP_DECLARE_STRUCT(
CAPNP_DECLARE_STRUCT( CAPNP_DECLARE_STRUCT(
::capnp::compiler::Statement, c6725e678d60fa37, ::capnp::compiler::Statement, c6725e678d60fa37,
2, 3, INLINE_COMPOSITE); 2, 3, INLINE_COMPOSITE);
CAPNP_DECLARE_STRUCT(
::capnp::compiler::Statement::Block, dd02827efc95ca64,
2, 3, INLINE_COMPOSITE);
CAPNP_DECLARE_STRUCT( CAPNP_DECLARE_STRUCT(
::capnp::compiler::LexedTokens, 9e69a92512b19d18, ::capnp::compiler::LexedTokens, 9e69a92512b19d18,
0, 1, POINTER); 0, 1, POINTER);
...@@ -257,11 +245,17 @@ public: ...@@ -257,11 +245,17 @@ public:
return _reader.totalSize() / ::capnp::WORDS; return _reader.totalSize() / ::capnp::WORDS;
} }
inline Which which() const;
inline bool hasTokens() const; inline bool hasTokens() const;
inline ::capnp::List< ::capnp::compiler::Token>::Reader getTokens() const; inline ::capnp::List< ::capnp::compiler::Token>::Reader getTokens() const;
inline bool isLine() const;
inline bool hasLine() const;
inline ::capnp::Void getLine() const;
inline bool isBlock() const;
inline bool hasBlock() const; inline bool hasBlock() const;
inline Block::Reader getBlock() const; inline ::capnp::List< ::capnp::compiler::Statement>::Reader getBlock() const;
inline bool hasDocComment() const; inline bool hasDocComment() const;
inline ::capnp::Text::Reader getDocComment() const; inline ::capnp::Text::Reader getDocComment() const;
...@@ -300,6 +294,7 @@ public: ...@@ -300,6 +294,7 @@ public:
inline size_t totalSizeInWords() { return asReader().totalSizeInWords(); } inline size_t totalSizeInWords() { return asReader().totalSizeInWords(); }
inline Which which();
inline bool hasTokens(); inline bool hasTokens();
inline ::capnp::List< ::capnp::compiler::Token>::Builder getTokens(); inline ::capnp::List< ::capnp::compiler::Token>::Builder getTokens();
inline void setTokens( ::capnp::List< ::capnp::compiler::Token>::Reader value); inline void setTokens( ::capnp::List< ::capnp::compiler::Token>::Reader value);
...@@ -307,9 +302,18 @@ public: ...@@ -307,9 +302,18 @@ public:
inline void adoptTokens(::capnp::Orphan< ::capnp::List< ::capnp::compiler::Token>>&& value); inline void adoptTokens(::capnp::Orphan< ::capnp::List< ::capnp::compiler::Token>>&& value);
inline ::capnp::Orphan< ::capnp::List< ::capnp::compiler::Token>> disownTokens(); inline ::capnp::Orphan< ::capnp::List< ::capnp::compiler::Token>> disownTokens();
inline bool isLine();
inline bool hasLine();
inline ::capnp::Void getLine();
inline void setLine( ::capnp::Void value = ::capnp::Void::VOID);
inline bool isBlock();
inline bool hasBlock(); inline bool hasBlock();
inline Block::Builder getBlock(); inline ::capnp::List< ::capnp::compiler::Statement>::Builder getBlock();
inline Block::Builder initBlock(); inline void setBlock( ::capnp::List< ::capnp::compiler::Statement>::Reader value);
inline ::capnp::List< ::capnp::compiler::Statement>::Builder initBlock(unsigned int size);
inline void adoptBlock(::capnp::Orphan< ::capnp::List< ::capnp::compiler::Statement>>&& value);
inline ::capnp::Orphan< ::capnp::List< ::capnp::compiler::Statement>> disownBlock();
inline bool hasDocComment(); inline bool hasDocComment();
inline ::capnp::Text::Builder getDocComment(); inline ::capnp::Text::Builder getDocComment();
...@@ -338,80 +342,6 @@ inline ::kj::StringTree KJ_STRINGIFY(Statement::Builder builder) { ...@@ -338,80 +342,6 @@ inline ::kj::StringTree KJ_STRINGIFY(Statement::Builder builder) {
return ::capnp::_::structString<Statement>(builder._builder.asReader()); return ::capnp::_::structString<Statement>(builder._builder.asReader());
} }
class Statement::Block::Reader {
public:
typedef Block Reads;
Reader() = default;
inline explicit Reader(::capnp::_::StructReader base): _reader(base) {}
inline size_t totalSizeInWords() const {
return _reader.totalSize() / ::capnp::WORDS;
}
inline Which which() const;
inline bool isNone() const;
inline bool hasNone() const;
inline ::capnp::Void getNone() const;
inline bool isStatements() const;
inline bool hasStatements() const;
inline ::capnp::List< ::capnp::compiler::Statement>::Reader getStatements() const;
private:
::capnp::_::StructReader _reader;
template <typename T, ::capnp::Kind k>
friend struct ::capnp::ToDynamic_;
template <typename T, ::capnp::Kind k>
friend struct ::capnp::_::PointerHelpers;
template <typename T, ::capnp::Kind k>
friend struct ::capnp::List;
friend class ::capnp::MessageBuilder;
friend class ::capnp::Orphanage;
friend ::kj::StringTree KJ_STRINGIFY(Statement::Block::Reader reader);
};
inline ::kj::StringTree KJ_STRINGIFY(Statement::Block::Reader reader) {
return ::capnp::_::structString<Statement::Block>(reader._reader);
}
class Statement::Block::Builder {
public:
typedef Block Builds;
Builder() = default;
inline explicit Builder(::capnp::_::StructBuilder base): _builder(base) {}
inline operator Reader() const { return Reader(_builder.asReader()); }
inline Reader asReader() const { return *this; }
inline size_t totalSizeInWords() { return asReader().totalSizeInWords(); }
inline Which which();
inline bool isNone();
inline bool hasNone();
inline ::capnp::Void getNone();
inline void setNone( ::capnp::Void value = ::capnp::Void::VOID);
inline bool isStatements();
inline bool hasStatements();
inline ::capnp::List< ::capnp::compiler::Statement>::Builder getStatements();
inline void setStatements( ::capnp::List< ::capnp::compiler::Statement>::Reader value);
inline ::capnp::List< ::capnp::compiler::Statement>::Builder initStatements(unsigned int size);
inline void adoptStatements(::capnp::Orphan< ::capnp::List< ::capnp::compiler::Statement>>&& value);
inline ::capnp::Orphan< ::capnp::List< ::capnp::compiler::Statement>> disownStatements();
private:
::capnp::_::StructBuilder _builder;
template <typename T, ::capnp::Kind k>
friend struct ::capnp::ToDynamic_;
friend class ::capnp::Orphanage;
friend ::kj::StringTree KJ_STRINGIFY(Statement::Block::Builder builder);
};
inline ::kj::StringTree KJ_STRINGIFY(Statement::Block::Builder builder) {
return ::capnp::_::structString<Statement::Block>(builder._builder.asReader());
}
class LexedTokens::Reader { class LexedTokens::Reader {
public: public:
typedef LexedTokens Reads; typedef LexedTokens Reads;
...@@ -927,6 +857,13 @@ inline void Token::Builder::setEndByte( ::uint32_t value) { ...@@ -927,6 +857,13 @@ inline void Token::Builder::setEndByte( ::uint32_t value) {
4 * ::capnp::ELEMENTS, value); 4 * ::capnp::ELEMENTS, value);
} }
inline Statement::Which Statement::Reader::which() const {
return _reader.getDataField<Which>(0 * ::capnp::ELEMENTS);
}
inline Statement::Which Statement::Builder::which() {
return _builder.getDataField<Which>(0 * ::capnp::ELEMENTS);
}
inline bool Statement::Reader::hasTokens() const { inline bool Statement::Reader::hasTokens() const {
return !_reader.isPointerFieldNull(0 * ::capnp::POINTERS); return !_reader.isPointerFieldNull(0 * ::capnp::POINTERS);
} }
...@@ -959,25 +896,93 @@ inline ::capnp::Orphan< ::capnp::List< ::capnp::compiler::Token>> Statement::Bui ...@@ -959,25 +896,93 @@ inline ::capnp::Orphan< ::capnp::List< ::capnp::compiler::Token>> Statement::Bui
_builder, 0 * ::capnp::POINTERS); _builder, 0 * ::capnp::POINTERS);
} }
inline bool Statement::Reader::isLine() const {
return which() == Statement::LINE;
}
inline bool Statement::Builder::isLine() {
return which() == Statement::LINE;
}
inline bool Statement::Reader::hasLine() const {
if (which() != Statement::LINE) return false;
return _reader.hasDataField< ::capnp::Void>(0 * ::capnp::ELEMENTS);
}
inline bool Statement::Builder::hasLine() {
if (which() != Statement::LINE) return false;
return _builder.hasDataField< ::capnp::Void>(0 * ::capnp::ELEMENTS);
}
inline ::capnp::Void Statement::Reader::getLine() const {
KJ_IREQUIRE(which() == Statement::LINE,
"Must check which() before get()ing a union member.");
return _reader.getDataField< ::capnp::Void>(
0 * ::capnp::ELEMENTS);
}
inline ::capnp::Void Statement::Builder::getLine() {
KJ_IREQUIRE(which() == Statement::LINE,
"Must check which() before get()ing a union member.");
return _builder.getDataField< ::capnp::Void>(
0 * ::capnp::ELEMENTS);
}
inline void Statement::Builder::setLine( ::capnp::Void value) {
_builder.setDataField<Statement::Which>(
0 * ::capnp::ELEMENTS, Statement::LINE);
_builder.setDataField< ::capnp::Void>(
0 * ::capnp::ELEMENTS, value);
}
inline bool Statement::Reader::isBlock() const {
return which() == Statement::BLOCK;
}
inline bool Statement::Builder::isBlock() {
return which() == Statement::BLOCK;
}
inline bool Statement::Reader::hasBlock() const { inline bool Statement::Reader::hasBlock() const {
return _reader.getDataField< ::uint16_t>(0 * ::capnp::ELEMENTS) != 0 if (which() != Statement::BLOCK) return false;
|| !_reader.isPointerFieldNull(1 * ::capnp::POINTERS); return !_reader.isPointerFieldNull(1 * ::capnp::POINTERS);
} }
inline bool Statement::Builder::hasBlock() { inline bool Statement::Builder::hasBlock() {
return _builder.getDataField< ::uint16_t>(0 * ::capnp::ELEMENTS) != 0 if (which() != Statement::BLOCK) return false;
|| !_builder.isPointerFieldNull(1 * ::capnp::POINTERS); return !_builder.isPointerFieldNull(1 * ::capnp::POINTERS);
}
inline ::capnp::List< ::capnp::compiler::Statement>::Reader Statement::Reader::getBlock() const {
KJ_IREQUIRE(which() == Statement::BLOCK,
"Must check which() before get()ing a union member.");
return ::capnp::_::PointerHelpers< ::capnp::List< ::capnp::compiler::Statement>>::get(
_reader, 1 * ::capnp::POINTERS);
}
inline ::capnp::List< ::capnp::compiler::Statement>::Builder Statement::Builder::getBlock() {
KJ_IREQUIRE(which() == Statement::BLOCK,
"Must check which() before get()ing a union member.");
return ::capnp::_::PointerHelpers< ::capnp::List< ::capnp::compiler::Statement>>::get(
_builder, 1 * ::capnp::POINTERS);
}
inline void Statement::Builder::setBlock( ::capnp::List< ::capnp::compiler::Statement>::Reader value) {
_builder.setDataField<Statement::Which>(
0 * ::capnp::ELEMENTS, Statement::BLOCK);
::capnp::_::PointerHelpers< ::capnp::List< ::capnp::compiler::Statement>>::set(
_builder, 1 * ::capnp::POINTERS, value);
} }
inline Statement::Block::Reader Statement::Reader::getBlock() const { inline ::capnp::List< ::capnp::compiler::Statement>::Builder Statement::Builder::initBlock(unsigned int size) {
return Statement::Block::Reader(_reader); _builder.setDataField<Statement::Which>(
0 * ::capnp::ELEMENTS, Statement::BLOCK);
return ::capnp::_::PointerHelpers< ::capnp::List< ::capnp::compiler::Statement>>::init(
_builder, 1 * ::capnp::POINTERS, size);
} }
inline Statement::Block::Builder Statement::Builder::getBlock() { inline void Statement::Builder::adoptBlock(
return Statement::Block::Builder(_builder); ::capnp::Orphan< ::capnp::List< ::capnp::compiler::Statement>>&& value) {
_builder.setDataField<Statement::Which>(
0 * ::capnp::ELEMENTS, Statement::BLOCK);
::capnp::_::PointerHelpers< ::capnp::List< ::capnp::compiler::Statement>>::adopt(
_builder, 1 * ::capnp::POINTERS, kj::mv(value));
} }
inline Statement::Block::Builder Statement::Builder::initBlock() { inline ::capnp::Orphan< ::capnp::List< ::capnp::compiler::Statement>> Statement::Builder::disownBlock() {
_builder.setDataField< ::uint16_t>(0 * ::capnp::ELEMENTS, 0); KJ_IREQUIRE(which() == Statement::BLOCK,
_builder.clearPointer(1 * ::capnp::POINTERS); "Must check which() before get()ing a union member.");
return Statement::Block::Builder(_builder); return ::capnp::_::PointerHelpers< ::capnp::List< ::capnp::compiler::Statement>>::disown(
_builder, 1 * ::capnp::POINTERS);
} }
inline bool Statement::Reader::hasDocComment() const { inline bool Statement::Reader::hasDocComment() const {
return !_reader.isPointerFieldNull(2 * ::capnp::POINTERS); return !_reader.isPointerFieldNull(2 * ::capnp::POINTERS);
} }
...@@ -1052,100 +1057,6 @@ inline void Statement::Builder::setEndByte( ::uint32_t value) { ...@@ -1052,100 +1057,6 @@ inline void Statement::Builder::setEndByte( ::uint32_t value) {
2 * ::capnp::ELEMENTS, value); 2 * ::capnp::ELEMENTS, value);
} }
inline Statement::Block::Which Statement::Block::Reader::which() const {
return _reader.getDataField<Which>(0 * ::capnp::ELEMENTS);
}
inline Statement::Block::Which Statement::Block::Builder::which() {
return _builder.getDataField<Which>(0 * ::capnp::ELEMENTS);
}
inline bool Statement::Block::Reader::isNone() const {
return which() == Statement::Block::NONE;
}
inline bool Statement::Block::Builder::isNone() {
return which() == Statement::Block::NONE;
}
inline bool Statement::Block::Reader::hasNone() const {
if (which() != Statement::Block::NONE) return false;
return _reader.hasDataField< ::capnp::Void>(0 * ::capnp::ELEMENTS);
}
inline bool Statement::Block::Builder::hasNone() {
if (which() != Statement::Block::NONE) return false;
return _builder.hasDataField< ::capnp::Void>(0 * ::capnp::ELEMENTS);
}
inline ::capnp::Void Statement::Block::Reader::getNone() const {
KJ_IREQUIRE(which() == Statement::Block::NONE,
"Must check which() before get()ing a union member.");
return _reader.getDataField< ::capnp::Void>(
0 * ::capnp::ELEMENTS);
}
inline ::capnp::Void Statement::Block::Builder::getNone() {
KJ_IREQUIRE(which() == Statement::Block::NONE,
"Must check which() before get()ing a union member.");
return _builder.getDataField< ::capnp::Void>(
0 * ::capnp::ELEMENTS);
}
inline void Statement::Block::Builder::setNone( ::capnp::Void value) {
_builder.setDataField<Statement::Block::Which>(
0 * ::capnp::ELEMENTS, Statement::Block::NONE);
_builder.setDataField< ::capnp::Void>(
0 * ::capnp::ELEMENTS, value);
}
inline bool Statement::Block::Reader::isStatements() const {
return which() == Statement::Block::STATEMENTS;
}
inline bool Statement::Block::Builder::isStatements() {
return which() == Statement::Block::STATEMENTS;
}
inline bool Statement::Block::Reader::hasStatements() const {
if (which() != Statement::Block::STATEMENTS) return false;
return !_reader.isPointerFieldNull(1 * ::capnp::POINTERS);
}
inline bool Statement::Block::Builder::hasStatements() {
if (which() != Statement::Block::STATEMENTS) return false;
return !_builder.isPointerFieldNull(1 * ::capnp::POINTERS);
}
inline ::capnp::List< ::capnp::compiler::Statement>::Reader Statement::Block::Reader::getStatements() const {
KJ_IREQUIRE(which() == Statement::Block::STATEMENTS,
"Must check which() before get()ing a union member.");
return ::capnp::_::PointerHelpers< ::capnp::List< ::capnp::compiler::Statement>>::get(
_reader, 1 * ::capnp::POINTERS);
}
inline ::capnp::List< ::capnp::compiler::Statement>::Builder Statement::Block::Builder::getStatements() {
KJ_IREQUIRE(which() == Statement::Block::STATEMENTS,
"Must check which() before get()ing a union member.");
return ::capnp::_::PointerHelpers< ::capnp::List< ::capnp::compiler::Statement>>::get(
_builder, 1 * ::capnp::POINTERS);
}
inline void Statement::Block::Builder::setStatements( ::capnp::List< ::capnp::compiler::Statement>::Reader value) {
_builder.setDataField<Statement::Block::Which>(
0 * ::capnp::ELEMENTS, Statement::Block::STATEMENTS);
::capnp::_::PointerHelpers< ::capnp::List< ::capnp::compiler::Statement>>::set(
_builder, 1 * ::capnp::POINTERS, value);
}
inline ::capnp::List< ::capnp::compiler::Statement>::Builder Statement::Block::Builder::initStatements(unsigned int size) {
_builder.setDataField<Statement::Block::Which>(
0 * ::capnp::ELEMENTS, Statement::Block::STATEMENTS);
return ::capnp::_::PointerHelpers< ::capnp::List< ::capnp::compiler::Statement>>::init(
_builder, 1 * ::capnp::POINTERS, size);
}
inline void Statement::Block::Builder::adoptStatements(
::capnp::Orphan< ::capnp::List< ::capnp::compiler::Statement>>&& value) {
_builder.setDataField<Statement::Block::Which>(
0 * ::capnp::ELEMENTS, Statement::Block::STATEMENTS);
::capnp::_::PointerHelpers< ::capnp::List< ::capnp::compiler::Statement>>::adopt(
_builder, 1 * ::capnp::POINTERS, kj::mv(value));
}
inline ::capnp::Orphan< ::capnp::List< ::capnp::compiler::Statement>> Statement::Block::Builder::disownStatements() {
KJ_IREQUIRE(which() == Statement::Block::STATEMENTS,
"Must check which() before get()ing a union member.");
return ::capnp::_::PointerHelpers< ::capnp::List< ::capnp::compiler::Statement>>::disown(
_builder, 1 * ::capnp::POINTERS);
}
inline bool LexedTokens::Reader::hasTokens() const { inline bool LexedTokens::Reader::hasTokens() const {
return !_reader.isPointerFieldNull(0 * ::capnp::POINTERS); return !_reader.isPointerFieldNull(0 * ::capnp::POINTERS);
} }
......
...@@ -706,32 +706,55 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep ...@@ -706,32 +706,55 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep
return DeclParserResult(kj::mv(decl)); return DeclParserResult(kj::mv(decl));
})); }));
// Parse an ordinal followed by an optional colon, or no ordinal but require a colon.
auto& ordinalOrColon = arena.copy(p::oneOf(
p::transform(p::sequence(parsers.ordinal, p::optional(op("!")), p::optional(op(":"))),
[this](Orphan<LocatedInteger>&& ordinal,
kj::Maybe<kj::Tuple<>> exclamation,
kj::Maybe<kj::Tuple<>> colon)
-> kj::Maybe<Orphan<LocatedInteger>> {
if (exclamation == nullptr) {
errorReporter.addErrorOn(ordinal.getReader(),
"As of Cap'n Proto v0.3, it is no longer necessary to assign numbers to "
"unions. However, removing the number will break binary compatibility. "
"If this is an old protocol and you need to retain compatibility, please "
"add an exclamation point after the number to indicate that it is really "
"needed, e.g. `foo @1! :union {`. If this is a new protocol or compatibility "
"doesn't matter, just remove the @n entirely. Sorry for the inconvenience, "
"and thanks for being an early adopter! :)");
}
if (colon == nullptr) {
errorReporter.addErrorOn(ordinal.getReader(),
"As of Cap'n Proto v0.3, the 'union' keyword should be prefixed with a colon "
"for named unions, e.g. `foo :union {`.");
}
return kj::mv(ordinal);
}),
p::transform(op(":"),
[]() -> kj::Maybe<Orphan<LocatedInteger>>{ return nullptr; })));
parsers.unionDecl = arena.copy(p::transform( parsers.unionDecl = arena.copy(p::transform(
// Hacky: The first branch of this oneOf() can correctly match named unions as well as // The first branch of this oneOf() matches named unions. The second branch matches unnamed
// anonymous unions that have an ordinal, but fails to match anonymous unions wil no // unions and generates dummy values for the parse results.
// ordinal because the "union" keyword is matched as an identifier and interpreted as
// the name, and then parsing fails after that. So, we have the second branch which
// just matches the "union" keyword alone, and injects dummy null values for the
// name and ordinal.
p::oneOf( p::oneOf(
p::sequence( p::sequence(
p::optional(identifier), p::optional(parsers.ordinal), identifier, ordinalOrColon,
p::optional(op(":")), keyword("union"), p::many(parsers.annotation)), keyword("union"), p::many(parsers.annotation)),
p::sequence( p::transform(keyword("union"),
keyword("union"), []() {
p::optional([](ParserInput&) -> kj::Maybe<Located<Text::Reader>> { return nullptr; }), return kj::tuple(
p::optional([](ParserInput&) -> kj::Maybe<Orphan<LocatedInteger>>{ return nullptr; }), Located<Text::Reader>("", 0, 0),
p::optional([](ParserInput&) -> kj::Maybe<kj::Tuple<>> { return nullptr; }), kj::Maybe<Orphan<LocatedInteger>>(nullptr),
p::many(parsers.annotation))), kj::Array<Orphan<Declaration::AnnotationApplication>>(nullptr));
[this](kj::Maybe<Located<Text::Reader>>&& name, })),
[this](Located<Text::Reader>&& name,
kj::Maybe<Orphan<LocatedInteger>>&& ordinal, kj::Maybe<Orphan<LocatedInteger>>&& ordinal,
kj::Maybe<kj::Tuple<>>&&,
kj::Array<Orphan<Declaration::AnnotationApplication>>&& annotations) kj::Array<Orphan<Declaration::AnnotationApplication>>&& annotations)
-> DeclParserResult { -> DeclParserResult {
auto decl = orphanage.newOrphan<Declaration>(); auto decl = orphanage.newOrphan<Declaration>();
auto builder = decl.get(); auto builder = decl.get();
KJ_IF_MAYBE(n, name) { if (name.value.size() > 0) {
n->copyTo(builder.initName()); name.copyTo(builder.initName());
} }
KJ_IF_MAYBE(ord, ordinal) { KJ_IF_MAYBE(ord, ordinal) {
builder.getId().adoptOrdinal(kj::mv(*ord)); builder.getId().adoptOrdinal(kj::mv(*ord));
...@@ -747,9 +770,8 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep ...@@ -747,9 +770,8 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep
})); }));
parsers.groupDecl = arena.copy(p::transform( parsers.groupDecl = arena.copy(p::transform(
p::sequence(identifier, p::optional(op(":")), keyword("group"), p::many(parsers.annotation)), p::sequence(identifier, op(":"), keyword("group"), p::many(parsers.annotation)),
[this](Located<Text::Reader>&& name, [this](Located<Text::Reader>&& name,
kj::Maybe<kj::Tuple<>>&&,
kj::Array<Orphan<Declaration::AnnotationApplication>>&& annotations) kj::Array<Orphan<Declaration::AnnotationApplication>>&& annotations)
-> DeclParserResult { -> DeclParserResult {
auto decl = orphanage.newOrphan<Declaration>(); auto decl = orphanage.newOrphan<Declaration>();
...@@ -943,17 +965,17 @@ kj::Maybe<Orphan<Declaration>> CapnpParser::parseStatement( ...@@ -943,17 +965,17 @@ kj::Maybe<Orphan<Declaration>> CapnpParser::parseStatement(
builder.setStartByte(statement.getStartByte()); builder.setStartByte(statement.getStartByte());
builder.setEndByte(statement.getEndByte()); builder.setEndByte(statement.getEndByte());
switch (statement.getBlock().which()) { switch (statement.which()) {
case Statement::Block::NONE: case Statement::LINE:
if (output->memberParser != nullptr) { if (output->memberParser != nullptr) {
errorReporter.addError(statement.getStartByte(), statement.getEndByte(), errorReporter.addError(statement.getStartByte(), statement.getEndByte(),
"This statement should end with a semicolon, not a block."); "This statement should end with a semicolon, not a block.");
} }
break; break;
case Statement::Block::STATEMENTS: case Statement::BLOCK:
KJ_IF_MAYBE(memberParser, output->memberParser) { KJ_IF_MAYBE(memberParser, output->memberParser) {
auto memberStatements = statement.getBlock().getStatements(); auto memberStatements = statement.getBlock();
kj::Vector<Orphan<Declaration>> members(memberStatements.size()); kj::Vector<Orphan<Declaration>> members(memberStatements.size());
for (auto memberStatement: memberStatements) { for (auto memberStatement: memberStatements) {
KJ_IF_MAYBE(member, parseStatement(memberStatement, *memberParser)) { KJ_IF_MAYBE(member, parseStatement(memberStatement, *memberParser)) {
......
...@@ -408,6 +408,14 @@ TEST(Stringify, UnnamedUnions) { ...@@ -408,6 +408,14 @@ TEST(Stringify, UnnamedUnions) {
" bar = 123,\n" " bar = 123,\n"
" after = \"foooooooooooooooooooooooooooooooo\" )", " after = \"foooooooooooooooooooooooooooooooo\" )",
prettyPrint(root).flatten()); prettyPrint(root).flatten());
root.setFoo(0);
EXPECT_EQ("(before = \"before\", after = \"foooooooooooooooooooooooooooooooo\")", kj::str(root));
EXPECT_EQ(
"( before = \"before\",\n"
" after = \"foooooooooooooooooooooooooooooooo\" )",
prettyPrint(root).flatten());
} }
TEST(Stringify, StructUnions) { TEST(Stringify, StructUnions) {
......
...@@ -207,6 +207,8 @@ static kj::StringTree print(const DynamicValue::Reader& value, ...@@ -207,6 +207,8 @@ static kj::StringTree print(const DynamicValue::Reader& value,
unionValue = kj::strTree( unionValue = kj::strTree(
fieldProto.getName(), " = ", fieldProto.getName(), " = ",
print(structValue.get(*field), whichFieldType(*field), indent.next(), PREFIXED)); print(structValue.get(*field), whichFieldType(*field), indent.next(), PREFIXED));
} else {
which = nullptr;
} }
} }
......
...@@ -177,7 +177,7 @@ struct TestOutOfOrder { ...@@ -177,7 +177,7 @@ struct TestOutOfOrder {
} }
struct TestUnion { struct TestUnion {
union0 @0 union { union0 @0! :union {
# Pack union 0 under ideal conditions: there is no unused padding space prior to it. # Pack union 0 under ideal conditions: there is no unused padding space prior to it.
u0f0s0 @4: Void; u0f0s0 @4: Void;
u0f0s1 @5: Bool; u0f0s1 @5: Bool;
...@@ -200,7 +200,7 @@ struct TestUnion { ...@@ -200,7 +200,7 @@ struct TestUnion {
# Pack one bit in order to make pathological situation for union1. # Pack one bit in order to make pathological situation for union1.
bit0 @18: Bool; bit0 @18: Bool;
union1 @1 union { union1 @1! :union {
# Pack pathologically bad case. Each field takes up new space. # Pack pathologically bad case. Each field takes up new space.
u1f0s0 @19: Void; u1f0s0 @19: Void;
u1f0s1 @20: Bool; u1f0s1 @20: Bool;
...@@ -237,7 +237,7 @@ struct TestUnion { ...@@ -237,7 +237,7 @@ struct TestUnion {
# Interleave two unions to be really annoying. # Interleave two unions to be really annoying.
# Also declare in reverse order to make sure union discriminant values are sorted by field number # Also declare in reverse order to make sure union discriminant values are sorted by field number
# and not by declaration order. # and not by declaration order.
union2 @2 union { union2 @2! :union {
u2f0s64 @54: Int64; u2f0s64 @54: Int64;
u2f0s32 @52: Int32; u2f0s32 @52: Int32;
u2f0s16 @50: Int16; u2f0s16 @50: Int16;
...@@ -245,7 +245,7 @@ struct TestUnion { ...@@ -245,7 +245,7 @@ struct TestUnion {
u2f0s1 @45: Bool; u2f0s1 @45: Bool;
} }
union3 @3 union { union3 @3! :union {
u3f0s64 @55: Int64; u3f0s64 @55: Int64;
u3f0s32 @53: Int32; u3f0s32 @53: Int32;
u3f0s16 @51: Int16; u3f0s16 @51: Int16;
...@@ -422,13 +422,13 @@ struct TestLateUnion { ...@@ -422,13 +422,13 @@ struct TestLateUnion {
bar @1 :Text; bar @1 :Text;
baz @2 :Int16; baz @2 :Int16;
theUnion @3 union { theUnion @3! :union {
qux @4 :Text; qux @4 :Text;
corge @5 :List(Int32); corge @5 :List(Int32);
grault @6 :Float32; grault @6 :Float32;
} }
anotherUnion @7 union { anotherUnion @7! :union {
qux @8 :Text; qux @8 :Text;
corge @9 :List(Int32); corge @9 :List(Int32);
grault @10 :Float32; grault @10 :Float32;
...@@ -452,7 +452,7 @@ struct TestNewVersion { ...@@ -452,7 +452,7 @@ struct TestNewVersion {
} }
struct TestStructUnion { struct TestStructUnion {
un @0 union { un @0! :union {
allTypes @1 :TestAllTypes; allTypes @1 :TestAllTypes;
object @2 :TestObject; object @2 :TestObject;
} }
......
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