tags:

views:

81

answers:

2

Hi,

I'm trying to find a solution to highlight part of a text file in Java. Basically, what I'm doing is lexing and parsing a text file respecting a certain grammar, storing some information related to the various elements of this file and then logging the information to a database.

I would like to have something more visual like a representation of the text file with some parts highlighted (and an index of the various colors used) - or even better with some context-sensitive information attached to a particular token.

Is there an easy way to do so? Basically what I would like to have, in terms of features, is a really primitive Eclipse plugin for a particular language and stand-alone. Maybe there's a framework to build DSL editors, something like that.

Hope it is clear... Thanks

+4  A: 

I think Xtext is just what you are looking for, it generates an Eclipse editor and more from a grammar.

Fabian Steeg
yes, i remember that. The thing is that i already have a parser, and gathered all the required information, i don't know how to attach the information gathered to the Xtext editor, though.
LB
That's probably not so easy. But if you already have a formal grammar definition, I think it's really worth giving it a try, you'll get a lot of the stuff you seem to want out of the box (like syntax coloring and context sensitive information).
Fabian Steeg
the problem is that i would have to re-implement my collection of information. Is there any real-world grammar examples ? and if i don't want to edit the file but just highlights some parts ?
LB
The grammar is described with an example in the user guide (http://www.eclipse.org/Xtext/documentation/latest/xtext.html#grammarLanguage). I don't know about an easy approach to just visualize certain parts, although you could hook into the outline view (but that would show more the structure of your file, not the full text) or make the editor read-only (but that would kind of defeat its purpose).
Fabian Steeg
Also, it's really easy to generate some other representation or visualization code for your file with Xpand (http://www.peterfriese.de/getting-started-with-xtext-part-2/), once its parsed with the generated Xtext parser.
Fabian Steeg
+1  A: 

Although not for Eclipse, there's MPS by JetBrains (the makers of the now open source IntelliJ IDEA) which may be worth taking a look at:

http://www.jetbrains.com/mps/

Webinator
also recommend MPS by JetBrains
Cong De Peng