Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext custom syntax highlighting(Xtext custom syntax highlighting)
Xtext custom syntax highlighting [message #1730142] Thu, 21 April 2016 17:27 Go to next message
RamaRao Nandamuri is currently offline RamaRao NandamuriFriend
Messages: 120
Registered: April 2016
Senior Member
Hi,
I have a terminal rule

terminal HASH_COMMENT: '#' !('\n' | '\r')*;

when I am using something like this:

# I am testing hash comment color

The color of the line is in black. I want to show to green like a comment color but I don't want to override SL_COMMENT.
Can anyone tell me?
Re: Xtext custom syntax highlighting [message #1730144 is a reply to message #1730142] Thu, 21 April 2016 17:52 Go to previous message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 13219
Registered: July 2009
Senior Member
same answer as the other threads you asked this question. opening a new thread each time makes no sense

package org.xtext.example.mydsl11.ide;

import org.eclipse.xtext.ide.editor.syntaxcoloring.DefaultAntlrTokenToAttributeIdMapper;
import org.eclipse.xtext.ide.editor.syntaxcoloring.HighlightingStyles;

public class MyDslAntlrTokenToAttributeIdMapper extends DefaultAntlrTokenToAttributeIdMapper {
	
	@Override
	protected String calculateId(String tokenName, int tokenType) {
		if ("RULE_HASH_COMMENT".equals(tokenName)) {
			return HighlightingStyles.COMMENT_ID;
		}
		return super.calculateId(tokenName, tokenType);
	}

}


package org.xtext.example.mydsl11.ui

import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor
import org.eclipse.xtext.ide.editor.syntaxcoloring.AbstractAntlrTokenToAttributeIdMapper
import org.xtext.example.mydsl11.ide.MyDslAntlrTokenToAttributeIdMapper

@FinalFieldsConstructor
class MyDslUiModule extends AbstractMyDslUiModule {
	
	def Class<? extends AbstractAntlrTokenToAttributeIdMapper> bindAbstractAntlrTokenToAttributeIdMapper() {
		MyDslAntlrTokenToAttributeIdMapper
	}
}


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:"Find references" shows classes names
Next Topic:Xtext & ANTLR IP questions
Goto Forum:
  


Current Time: Thu Nov 21 18:30:46 GMT 2019

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

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

Back to the top