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: 19
Registered: October 2016
Junior Member
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
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: 10888
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() {
MyImpl
}


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Previous Topic:Using ResourceFactory without depending in UI project
Next Topic:Generate syntax graph during automatic build
Goto Forum:
  


Current Time: Mon Jul 24 03:06:02 GMT 2017

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

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