views:

59

answers:

1

Hello everybody! The question of today is the following: I'm developing a code generator for my department at university. It's very simple: they want to use a custom "scripting" language really human readable, parse that and then translate these instructions in Java. I used SableCC to do the trick, it was really smooth. The problem now is that I have to create a plugin editor for Eclipse, mainly for a syntax highligthing purpose and possibly to catch validation errors.

I've found many tutorials about "how to create a custom editor in Eclipse" but what I can't figure out is: I've already created my parser and my scanner rigth? It's nonsense to do that again for the editor. Is there a way to integrate my scanner inside the plugin? What class should I extend or implement? Can you suggest any tutorial?

+1  A: 

I'd suggest to look into Xtext - you would basically have to port your grammar to the Xtext format, but from there, Xtext generates a full Eclipse editor with syntax coloring, error marking, outline view, content assist, etc. Also, as you mention code generation, it will allow you to generate code from the parsed input easily using Xpand, a statically typed template language. They have very nice tutorials and screencasts on their site.

Fabian Steeg
uhm...first of all I din't know Xtext, I've read the docs and it's freakin' cool but, I've already have the code generator so...I don't get, reading from the docs, if is it possibile to integrate my code generator with Xtext or it only accepts Xpand.
dierre
@dierre No I don't think it is, I was trying to say that you would basically have to restart from the grammar, but that you get so much automatically with Xtext that it might very well be worth it.
Fabian Steeg
Well, or I can just execute the code from the editor trough the External Tool utility once I've edited it, I think...
dierre
@dierre The problem with that would be that you'd be maintaining two grammars and generated parsers, but yes you could probably do something like that. If you are at that point check out Xpand though, you can basically write the code you want generated and insert the values that change, having code completion based on your grammar elements in the Xpand editor, it's really very convenient.
Fabian Steeg
@Fabian: what do you think about starting a plug-in project "with editor"?
dierre
@dierre You mean the wizard template? That will create an XML editor, not something for a custom language. To create an Xtext editor, you would use the Xtext-specific wizard, see http://www.eclipse.org/Xtext/documentation/latest/xtext.html#getting-started
Fabian Steeg