This is a project to provide an Eclipse plugin for CoffeeScript, using Xtext. Development uses Xtext 2.1. It just started, so you may be interested in the roadmap, including where we are at the moment.
There are quite a few editors with CoffeeScript support, but most of them have just a little more than syntax highlighting. Only three of them do actual parsing:
- CoffeeBrew for IntelliJ IDEA which has added some official support of coffeescript based on CoffeeBrew.
- Netbeans plugin which seems quite mature
- Aptana Studio3 plugin
Besides, there is CoffeeScript's own compilation method as a good source of ideas. Let's see what we can learn from them or how they could be used.
CoffeeBrew is based on IntelliJ's own packages, using a Java-based lexer, and processes a flex file. It's not clear yet if whether and how it can handle significant whispaces of coffeescript, but at first it looks a promising starting point. The only downside is, it's development halted in favor of the official coffeescript support. I couldn't find how parsing is done here.
Regarding the Netbeans plugin, it seems to have implemented both lexing, and parsing in pure Java code, making use of Netbeans' own parsing framework. It would be quite difficult to use it, either directly (importing it), or indirectly understanding the algorithm.
The Aptana Studio3 plugin is based on the Beaver parser generator with a Java scanner class which is either generated, or crafted by hand. It is accompanied by a rewriter class which takes care of indentation and other niceties. Since they extend the Beaver API, they may be not directly usable, but more on that later.
First step: a custom lexer
The main issue with coffeescript is that it uses significant whitespaces. It's not obvious how to handle it with Xtext, but there are a few attempts at resolving it. See Pythonisque indent/dedent block structure for a Xtext DSL; a Stackoverflow question about Xtext with significant/semantic whitespace and the todotext implementation referred to in an answer.
Conclusion and status: the Aptana scanner got integrated into Xtext successfully.
Second step: implement an LL grammar for the parser
Other implementations use LALR parsers, but Xtext is based on Antlr which is an LL parser. Transforming a LALR grammar to an LL one is not a mechanic task, even a simple expression language feels challenging at first, see Parsing Expressions with Xtext. There are some basic rules to follow Converting a Grammar from LALR to LL.
On the other hand, some good test cases are needed, too. CoffeeScript tests are geared toward execution and not only parsing, and they quite coarse grained for our purposes now. The parser tests of Aptana may be a good starting point with some drawbacks:
- The Aptana parser produces a different AST than the one generated by Xtext
- The test cases suffer from Java's lack of multiline strings.