Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Syntax coloring / highlighting xtext 2.9(What is the standar way of syntax coloring in xtext 2.9)
Syntax coloring / highlighting xtext 2.9 [message #1746700] Thu, 03 November 2016 12:02 Go to next message
Lukas Schaus is currently offline Lukas SchausFriend
Messages: 37
Registered: October 2016

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: :
package org.xtext.example.mydsl.ui.syntaxColoring;

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";
	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;

package org.xtext.example.mydsl.ui.syntaxColoring;

import org.eclipse.xtext.ide.editor.syntaxcoloring.AbstractAntlrTokenToAttributeIdMapper;

public class MyDslAntlrTokenToAttributeIdMapper extends AbstractAntlrTokenToAttributeIdMapper

	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 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
Re: Syntax coloring / highlighting xtext 2.9 [message #1746701 is a reply to message #1746700] Thu, 03 November 2016 12:17 Go to previous message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 14497
Registered: July 2009
Senior Member
yes they need to be in xtend. the docs contain a section on how the naming conventions are

ususally it is

def Class<? extends XtextExtensionPoint> bindXtextExtensionPoint() {

Need professional support for Xtext, Xpand, EMF?
Go to:
Twitter : @chrdietrich
Blog :
Previous Topic:Debugging non-deterministic serialization failure
Next Topic:Generate syntax graph during automatic build
Goto Forum:

Current Time: Wed Jun 07 17:06:07 GMT 2023

Powered by FUDForum. Page generated in 0.01763 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top