我正在将Eclipse用于Java项目,其中一些测试用Groovy / Spock编写,它使用given:
when:
then:
语法。我想用一些颜色突出显示这些关键字。注意:spock插件应该是这样但不起作用。所以我想自己做这件事。
答案 0 :(得分:1)
given:
,when:
等是声明标签。目前不支持在Groovy-Eclipse中突出显示语句标签。它们确实有点棘手,因为它们没有保存在具有源位置信息的AST中。 org.codehaus.groovy.ast.stmt.Statement.getStatementLabels()
返回List<String>
。因此,可以判断哪些语句具有标签,但是需要扫描语句的源范围以查找标签的范围。
答案 1 :(得分:1)
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