Hello,
i would like to adjust the coloring of my syntax.
I understood that there are 2 different possibilities
1. Lexical Highlighting
2. Semantic Highlighting
In my case syntactical Highlighting would be sufficient.
I found a lot of tutorials online which suggested to implement a 2 java classes:
MyDslHighlightingConfiguration.java :
package org.xtext.example.mydsl.ui.syntaxColoring;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightingConfiguration;
import org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightingConfigurationAcceptor;
import org.eclipse.xtext.ui.editor.utils.TextStyle;
public class MyDslHighlightingConfiguration implements IHighlightingConfiguration{
public static final String DEFAULT_ID = "default";
public static final String NUMBER_ID = "number";
@Override
public void configure(IHighlightingConfigurationAcceptor acceptor) {
acceptor.acceptDefaultHighlighting(DEFAULT_ID, "Default", defaultTextStyle());
acceptor.acceptDefaultHighlighting(NUMBER_ID, "Number", numberTextStyle());
}
protected TextStyle defaultTextStyle() {
TextStyle textStyle = new TextStyle();
textStyle.setColor(new RGB(0, 0, 0));
return textStyle;
}
protected TextStyle numberTextStyle() {
TextStyle textStyle = defaultTextStyle().copy();
textStyle.setColor(new RGB(127, 127, 127));
return textStyle;
}
}
MyDslAntlrTokenToAttributeIdMapper.java
package org.xtext.example.mydsl.ui.syntaxColoring;
import org.eclipse.xtext.ide.editor.syntaxcoloring.AbstractAntlrTokenToAttributeIdMapper;
public class MyDslAntlrTokenToAttributeIdMapper extends AbstractAntlrTokenToAttributeIdMapper
{
@Override
protected String calculateId(String tokenName, int tokenType) {
if (tokenName.equals("NumberLiteral")) {
return MyDslHighlightingConfiguration.NUMBER_ID;
}
return MyDslHighlightingConfiguration.DEFAULT_ID;
}
}
And lastly the functios shall be registered with the UI module by editing the file
MyDslUiModule.java which is a generated file in my project and therefore gets overwritten. i have seen that there is a MyDslUiModule.xtend but i dont know how to write the methods.
Should i create the classes above in xtend language instedad of java?
Anyhow... as you can see I am a bit confused on how the standard procedure would look like and would be very happy for clarification.
Thank you!
Lukas Schaus