3

I am building a tool for a custom language. It will have many components including a source code editor. What are the coponents I will need to build this editor. I would like syntax highlighting, outline and formating to start with.

I have already developed a parser using ANTLR.

Tasawer Khan
  • 5,994
  • 7
  • 46
  • 69

3 Answers3

6

If you really want to/need to create your DSL and the editor for it "by hand", then I suggest using the JFace Text framework to create the editor.

However, although you said that you already have a parser, I strongly suggest you take a look at Xtext and see if it suits your needs. It gives you a way to define your DSL and automatically generates an editor with syntax highlighting, code completion, and so on. And AFAIK, it uses ANTLR underneath to generate a parser. With Xtext, you can also create a compiler (or interpreter) for your language.

Sandman
  • 9,610
  • 8
  • 36
  • 41
  • Thank you sandman. I had a look on XText yesterday and left because I will have to wrote language grammar again in a different format. Will I be able to extend that XText provided IDE just like any other RCP app? – Tasawer Khan May 04 '11 at 16:13
  • @Tasawer Khan Xtext will not generate a whole RCP app, but a set of plugins. You can then, of course, export them to an RCP app. And, as far as I know, yes, you should be able to extend it with plugins just like any other RCP app. @Favonius: Thanks :) – Sandman May 04 '11 at 18:03
3

I think Xtext is exactly what you are looking for. With Xtext you define a DSL and then you can launch a custom Eclipse which provides code completion, syntax highlighting etc for the DSL you defined.

Kai
  • 38,985
  • 14
  • 88
  • 103
-1

Look at the JEditorPane and its associated Document. This can be used to highlight. Also look at http://download.oracle.com/javase/tutorial/uiswing/components/editorpane.html for further information on how to customise the document, specifically, the StyledDocument.

spot35
  • 888
  • 4
  • 9
  • 1
    Why are you suggesting a Swing-based solution? Usually, if one is doing an Eclipse RCP app, his toolkit of choice would be SWT. Furthermore, OP specifically tagged his question with the "SWT" tag, which would imply he's looking for a standard Eclipse RCP/SWT way to do this. And finally, although you can use Swing in an Eclipse RCP app, there are certain things you need to be aware of (for example, thread safety), so Swing should really not be the first suggestion that comes to mind when the question is about developing an Eclipse RCP application. – Sandman May 04 '11 at 14:15