Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is this reference authoritative or correct? #187

Open
davaya opened this issue Sep 24, 2024 · 2 comments
Open

Is this reference authoritative or correct? #187

davaya opened this issue Sep 24, 2024 · 2 comments

Comments

@davaya
Copy link

davaya commented Sep 24, 2024

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?

@Logofile
Copy link
Member

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.

@Logofile
Copy link
Member

Grammar changes from proto2/3 to Editions are also covered in summary in this section.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants