protobuf-nim
protobuf-nim copied to clipboard
Create DSL for specification declaration
This currently parses the official protobuf specification. However if you only plan to use it for Nim -> Nim communication there is no need to specify your protobuf format in it's own file only to parse it every time you want to compile. It would be nice to have a Nim DSL for creating these specifications, the data structure is already there, so it's mostly deciding on a grammar and implementing a simple AST to internal representation macro.
With Nim a lot of stuff is possible. At some point I was thinking something along the lines of:
protobuf:
message Test1:
repeated sint64 value1 = 1
string value2 = 2
enumeration Enum1:
Value1 = 0
Value2 = 1
The example passes some data to protobuf
macro, which could then transform this to whatever is needed. Amazing what magic you can do with this :-)
Yeah I know, I've written plenty of macros like this by now if you look at my repositories 😃. Your example is pretty much exactly what I was thinking about, since my solution revolves around an internal node representation of the protobuf syntax it should be a fairly simple task to write a macro that just converts to a call to generator procedure and a node initialisation.