Skip to content

Comments

compiler: Add participle-based protobuf parser#20

Open
camh- wants to merge 1 commit intomasterfrom
parser
Open

compiler: Add participle-based protobuf parser#20
camh- wants to merge 1 commit intomasterfrom
parser

Conversation

@camh-
Copy link
Member

@camh- camh- commented Aug 18, 2022

Add a protobuf parser using participle, based on the example in Alec
Thomas's protobuf compiler. I have reworked the parser to be more how I
think it should look and to bring it closer to the BNF(ish) in the
protobuf spec. I have also removed comments from the grammar (they are
ignored like whitespace) since I don't believe the best way to handle
comments will be in the grammar (I am thinking of attaching comments to
tokens in the lexer; we'll see).

At the moment, the protog command just prints out the Go struct for
the parsed form of the protobuf. This will grow into something more
useful as the compiler evolves to be a proper compiler.

We bump the required Go version to 1.18 as there is a small use of
generics in the test code, but I also want to use generics wherever it
makes sense.

Link: https://github.com/alecthomas/participle
Link: https://github.com/alecthomas/protobuf
Link: https://developers.google.com/protocol-buffers/docs/reference/proto2-spec
Link: https://developers.google.com/protocol-buffers/docs/reference/proto3-spec

@camh- camh- force-pushed the parser branch 2 times, most recently from d1f0734 to ec88818 Compare August 18, 2022 07:23
Base automatically changed from tidy-up to master August 18, 2022 07:30
Add a protobuf parser using participle, based on the example in Alec
Thomas's protobuf compiler. I have reworked the parser to be more how I
think it should look and to bring it closer to the BNF(ish) in the
protobuf spec. I have also removed comments from the grammar (they are
ignored like whitespace) since I don't believe the best way to handle
comments will be in the grammar (I am thinking of attaching comments to
tokens in the lexer; we'll see).

At the moment, the `protog` command just prints out the Go struct for
the parsed form of the protobuf. This will grow into something more
useful as the compiler evolves to be a proper compiler.

We bump the required Go version to 1.18 as there is a small use of
generics in the test code, but I also want to use generics wherever it
makes sense.

Link: https://github.com/alecthomas/participle
Link: https://github.com/alecthomas/protobuf
Link: https://developers.google.com/protocol-buffers/docs/reference/proto2-spec
Link: https://developers.google.com/protocol-buffers/docs/reference/proto3-spec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant