I am using Eclipse for a Java project with some tests written in Groovy / Spock which uses the given:
when:
then:
syntax. I would like these keywords to highlighted with some colour. Note: the spock plugin is supposed to this but doesn't work. So wanted to just do this myself.
given:
, when:
, etc. are statement labels. There is currently no support for highlighting statement labels in Groovy-Eclipse. They are actually a bit tricky to pin down since they are not saved in the AST with source position information. org.codehaus.groovy.ast.stmt.Statement.getStatementLabels()
returns List<String>
. So it is possible to tell which statements have labels, but then the source range of the statement would need to be scanned to find the range of the label.
It seems like there is not any support for the label in Groovy. I have done some search but as @emilles said, there is nothing on the web.
If you have the grammar file or can get it somewhere (I did not find it after some search), transform it into a HRC File then follow the step under. See there (http://colorer.sourceforge.net/hrc-ref/index.html)
Now, you could just create the coloring for your language. There are many plugin out there for doing this like EclipseColorer. I have already use that one, so I gonna give you the step :
1 - Install the software (Help -> Install New Software)
2 - Search http://colorer.sf.net/eclipsecolorer/
3 - Once the plugin is installed and Eclipse is restart
4 - Copy the HRC file in the eclipse's folder
5 - Add the prototype file
The basic one :
<?xml version="1.0" encoding='Windows-1251'?>
<!DOCTYPE hrc PUBLIC
"-//Cail Lomecb//DTD Colorer HRC take5//EN"
"http://colorer.sf.net/2003/hrc.dtd"
>
<hrc version="take5" xmlns="http://colorer.sf.net/2003/hrc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://colorer.sf.net/2003/hrc http://colorer.sf.net/2003/hrc.xsd"
><annotation><documentation>
'auto' is a place for include
to colorer your own HRCs
</documentation></annotation>
<prototype name="d" group="main" description="D">
<location link="types/d.hrc"/>
<filename>/.(d)$/i</filename>
</prototype>
</hrc>
6 - In Eclipse Window -> Preferences -> General -> Editors -> File Associations
7 - Add the filetype for your syntax
8 - Restart Eclipse and your good
If you dont have this kind of file is gonna be long and difficult, it's a domain specific language and you have to start from the beginning. So the only real method to do this, it's by creating a new coloring syntax for your need but it's very tricky to achieve.
You have some information there about it : http://www.mo-seph.com/projects/syntaxhighlighting
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With