mransan/ocaml-protoc

Online grammar debug/documentation/development

mingodad opened this issue · 4 comments

I've just added this project grammar to https://mingodad.github.io/parsertl-playground/playground/ (select Protobuf3 parser under examples then click Parse to see the parser tree).

I hope it can help develop/debug/extend/test/document the grammar used in this project.

I did some changes there:

  • Converted right recursion to left recursion.
  • Eliminate some redundant? rules to simplify the parser tree (proto_content : * proto removed and added proto_content_oom )

Any feedback is welcome !

c-cube commented

Oh that's cool, I looked the other day and it wasn't working but now it is! Very neat :)

I just found an example that this grammar doesn't seem to accept in https://github.com/electric-sql/electric/blob/main/protocol/satellite.proto :

enum SatAuthHeader {
    reserved 1;
    // Required by the Protobuf spec.
    UNSPECIFIED = 0;
}

There is no rule to accept reserved 1;.

Changing the grammar like this seems to fix the problem:

enum_body_content :
	option
	| enum_value
	| reserved   //<<<   adding this rule
	;

See documentation here https://protobuf.dev/programming-guides/proto3/#reserved