mransan / ocaml-protoc

A Protobuf Compiler for OCaml
https://mransan.github.io/ocaml-protoc/
MIT License
178 stars 33 forks source link

Online grammar debug/documentation/development #217

Open mingodad opened 10 months ago

mingodad commented 10 months ago

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:

Any feedback is welcome !

c-cube commented 10 months ago

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

mingodad commented 10 months ago

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;.

mingodad commented 10 months ago

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

mingodad commented 10 months ago

The above can be tested on https://mingodad.github.io/parsertl-playground/playground/ :+1: