I am currently trying to implement a protobuf parser but it's a bit unclear to me how I should interpret some parts of the specification.
Lets start with RPC option. Options for normal fields and enum fields are pretty clear.
Here's the specification for normal fields:
field = [ "repeated" ] type fieldName "=" fieldNumber [ "[" fieldOptions "]" ] ";"
fieldOptions = fieldOption { "," fieldOption }
fieldOption = optionName "=" constant
Here's the specification for enum fields:
enum = "enum" enumName enumBody
enumBody = "{" { option | enumField | emptyStatement | reserved } "}"
enumField = ident "=" [ "-" ] intLit [ "[" enumValueOption { "," enumValueOption } "]" ]";"
enumValueOption = optionName "=" constant
Both fields boils down to optionName which is specified as:
optionName = ( ident | "(" ["."] fullIdent ")" )
Here's the specification for RPC:
service = "service" serviceName "{" { option | rpc | emptyStatement } "}"
rpc = "rpc" rpcName "(" [ "stream" ] messageType ")" "returns" "(" [ "stream" ]
messageType ")" (( "{" {option | emptyStatement } "}" ) | ";")
RPC refers to plain option. Does this mean that the following is valid and intended syntax?
rpc Foo (Req) returns (Res);
rpc Foo (Req) returns (Res) {option opt1 = "opt1"; option opt2 = true; };
rpc Foo (Req) returns (Res) {option opt1 = "opt1"; ;;; option opt2 = true; ;;;};
I added number 3, because it seems like repetition is allowed together with emptyStatement. As a side note, I could not find any examples with RPC options as inspiration or to clear things up.
Further, I also find the specification for optionName a bit unclear.
Here's the specification for option and optionName:
option = "option" optionName "=" constant ";"
optionName = ( ident | "(" ["."] fullIdent ")" )
option (bar).baz = "value";
For me it's pretty clear that the following optionNames are allowed:
foo
(foo)
(foo.bar)
(.foo)
(.foo.bar)
I don't really get which part of the specification that states that "baz", in the example above, is allowed outside of the parenthesis.
Thanks in advance,
/Mattias