Is this reference authoritative or correct?
Is this reference either generated from source code or used as the authoritative grammar for implementations? If it is merely notional, where can the authoritative protocol buffers grammar be found?
Debugging a .proto file parser leads to questions. The example file includes a message with an optional field:
message Foo {
message GroupMessage {
optional bool a = 1;
}
GroupMessage groupmessage = [features.message_encoding = DELIMITED];
}
A cursory reading of the grammar does not indicate that a normal field (i.e. not oneof or mapField) can have an "optional" label, and the "optional" literal is not included in the spec at all, though it appears seven times in examples.
message = "message" messageName messageBody
messageBody = "{" { field | enum | message | extend | extensions | group |
option | oneof | mapField | reserved | emptyStatement } "}"
label = [ "repeated" ]
type = "double" | "float" | "int32" | "int64" | "uint32" | "uint64"
| "sint32" | "sint64" | "fixed32" | "fixed64" | "sfixed32" | "sfixed64"
| "bool" | "string" | "bytes" | messageType | enumType
fieldNumber = intLit;
field = [label] type fieldName "=" fieldNumber [ "[" fieldOptions "]" ] ";"
fieldOptions = fieldOption { "," fieldOption }
fieldOption = optionName "=" constant
This seems like a pretty basic problem that has existed through several schema versions. What EBNF production allows a message to have optional fields?
It is neither generated from source nor the authoritative grammar for implementations. It's a best-effort representation of the grammar that we use.
Thanks for pointing out that some of our examples in the grammar topic for Editions 2023 include optional. The topic was a copy/paste/modify of the proto3 topic, and we missed some updates in the process.
Grammar changes from proto2/3 to Editions are also covered in summary in this section.
I've removed instances of optional from the language spec for edition 2023.