Wednesday, April 14, 2010

Google's Protocol Buffers implemented in Xtext

Eat your own dog food is an excellent advice. So do I and therefore I use Xtext to implement languages from time to time. Usually these are languages we either implement for one of our open source projects (examples or the recently added MWE2 language I developed together with Sebastian) or for customer projects.

A couple of weeks ago I implemented the DSL of Google's Protocol Buffers using Xtext. I don't want to add it as an example to Xtext, because it doesn't add any specific value over the existing examples nor do I have the time to start a new project or maintain it in any way. However, I thought there might be some people who want to have a look as an example or want to take it over and extend/maintain it further.

I didn't know Protocol Buffers so I had to learn the language using the documentation and the unit tests they have. The concepts of the language (scoping, imports) are very close to Xtext's defaults so that it took me only 3 hours to implement it. Most of the time was spent to get the lexing part right, which was not so close to the defaults :-).

If you want to have a look, here are the two Eclipse projects. Feel free to do whatever you want with that code. I of course would love to see someone creating a new open source project for it or adding it to an existing. In any case I'll be glad to help you getting started with the code.

The code should work with every post-M6-milestone as well as the final Xtext 1.0.0 release which will be published in June.

I also recorded a short screen cast demoing the result: