protobuf-nim icon indicating copy to clipboard operation
protobuf-nim copied to clipboard

Create DSL for specification declaration

Open PMunch opened this issue 6 years ago • 2 comments

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.

PMunch avatar Mar 29 '18 23:03 PMunch

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 :-)

oskaritimperi avatar Apr 03 '18 14:04 oskaritimperi

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.

PMunch avatar Apr 03 '18 14:04 PMunch