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 offline Christian DietrichFriend
Messages: 14661
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
	}
}


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: Fri Mar 29 13:16:07 GMT 2024

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

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

Back to the top