Support message with no fields
Opened this issue · 3 comments
pma commented
The grammar won't accept a message with no fields. Example (see Derived2):
message Base {
enum MsgType {
Derived1 = 1;
Derived2 = 2;
}
message Derived1 {
required uint32 extra1 = 1;
}
message Derived2 {
}
required MsgType type = 1;
optional Derived1 derived1 = 2;
optional Derived2 derived2 = 3;
}
Tried with other libs including gpb (erlang), protoc (python), protobuf-j2me (java) and they manage to parse it.
jeremyong commented
Mind posting the error?
pma commented
iex(1)> tokens = Exprotoc.Parser.tokenize("base.proto", ["priv"])
iex(2)> Exprotoc.Parser.parse(tokens)
** (MatchError) no match of right hand side value: {:error, {12, :proto_grammar, ['syntax error before: ', '\'}\'']}}
lib/exprotoc/parser.ex:36: Exprotoc.Parser.parse/1
The yecc generated parser is returning an error on line 12 of the base.proto, which is the unexpected '}'.
The yrl file defines a message as:
p_message -> message message_name '{' fields '}' : {message, '$2', '$4'}.
and fields can't be empty.
jeremyong commented
Gotcha this should be pretty easy to fix. I'll try to get to it later today.