a simple editor with xtext

XText is a pretty cool plugin/SDK for Eclipse that makes it relatively easy to make a full-featured editor for your favorite language. I recently (wasted a few days) played around with it and created a simple editor for my current language of choice, IcedCoffeescript. (If you’re really curious/bored, the source is on github.)

Almost all of the information you find on Xtext requires defining a complete grammar for your language, which is a bit too much hassle if you’re just starting out and all you really want is some pretty syntax. Fortunately, it’s pretty straightforward to get a syntax only parser if you want one – simply define a grammar with all of your terminals:

terminal KW_X: "x";
terminal KW_Y: "y";
terminal KW_Z: "z";
terminal ANY: .;

and a single top-level rule:

Script: ANY+;

You then can supply a highlighting configuration to specify how various terms should be highlighted, and a TokenMapper that maps from actual tokens to term classes. (Yes, I know the terminology gets a bit confusing/baroque). Here’s some links to the various parts I used in my project: