ctaggart / froto

Froto: F# Protocol Buffers
MIT License
146 stars 27 forks source link

Parse error when optional/required/repeated is missing #115

Closed RicoSuter closed 4 years ago

RicoSuter commented 4 years ago

The following grpc proto file fails to be parsed:

message EchoRequest {
  string message = 1;
}

message EchoResponse {
  string message = 1;
}

service EchoService {
  rpc Echo(EchoRequest) returns (EchoResponse);
}

(from: https://grpc.io/docs/tutorials/basic/web/)

System.FormatException: Error in Ln: 2 Col: 3
  string message = 1;
  ^
Expecting: newline, tab, ' ', '/*', '//', ';', 'enum', 'extend', 'extensions',
'map', 'message', 'oneof', 'option', 'optional', 'repeated', 'required',
'reserved' or '}'

   at Froto.Parser.Parse.resultOrFail[a,b](ParserResult`2 parserResult)

Seems that the froto parser requires optional/required/repeated because this works:

message EchoRequest {
  required string message = 1;
}

message EchoResponse {
  required string message = 1;
}

service EchoService {
  rpc Echo(EchoRequest) returns (EchoResponse);
}
jhugard commented 4 years ago

Have you tried specifying proto3 syntax at the top of the file?

syntax = "proto3";

https://developers.google.com/protocol-buffers/docs/proto3

The first line of the file specifies that you're using proto3 syntax: if you don't do this the protocol buffer compiler will assume you are using proto2. This must be the first non-empty, non-comment line of the file.

RicoSuter commented 4 years ago

Yes this was it - thank you very much. Do you know what the default is for gRPC? proto3 or proto2? It seems that gRPC assumes proto3 (they dont specify it) and here the default is proto2.

jhugard commented 4 years ago

Not sure what gRPC defaults to, but based on the above the protoc compiler should be defaulting to proto2.