Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Customizing Syntax Highlighting
Customizing Syntax Highlighting [message #1006210] Wed, 30 January 2013 13:24 Go to next message
Phil H is currently offline Phil H
Messages: 267
Registered: November 2012
Senior Member
Hi,

I've tried out to customize my Syntax Highlighting and have got two questions.

1. I've have implemented the necessary classes for customizing the Syntax Highlighting for one element of my grammar (which works so far). But then, the standrad Syntax Highlighting i.e. key word highlightig doesn't work anymore. Is this normal behaviuour?

2. In my grammar, one element consist of a Boolean flag. Depending on true or false, I want to change the Syntax Highlighting for this element. But I don't know how to access the Boolean attribute out of the ISemanticHighlightingCalculator. I used INodes so far:

public void provideHighlightingFor(XtextResource resource,
			IHighlightedPositionAcceptor acceptor) {

		if (resource == null || resource.getParseResult() == null)
			return;

		INode root = resource.getParseResult().getRootNode();
		BidiTreeIterator<INode> iterator = root.getAsTreeIterable().iterator();
		while (iterator.hasNext()) {
			INode node = iterator.next();
			if (node.getSemanticElement() instanceof ParameterDesc) {
				// What I want to have:
                                // if (pdesc.isUnselected() == true) { do something }
			}
		}
}
Re: Customizing Syntax Highlighting [message #1006319 is a reply to message #1006210] Wed, 30 January 2013 19:48 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6307
Registered: July 2009
Senior Member
Hi,

(1) it (syntacic highlighting) may not work for the particular place you provide semantic highlighting for (offset,length) but for other places

(2) i do not unserstand your question - simply downcast from EObject to ParameterDesc
Re: Customizing Syntax Highlighting [message #1006347 is a reply to message #1006319] Wed, 30 January 2013 22:54 Go to previous messageGo to next message
Phil H is currently offline Phil H
Messages: 267
Registered: November 2012
Senior Member
Ok the second question is solved..

But again to the first question. I implemented the belowed code into MySemanticHighlightingCalculator and the color for the one element changes as expected. But the default Syntax Highlighting, like the purple color for keywords didn't work anymore. That's what I don't understand. Is the reason maybe that I iterating through the whole tree?

public void provideHighlightingFor(XtextResource resource,
			IHighlightedPositionAcceptor acceptor) {

		if (resource == null || resource.getParseResult() == null)
			return;

		INode root = resource.getParseResult().getRootNode();
		BidiTreeIterator<INode> iterator = root.getAsTreeIterable().iterator();
		while (iterator.hasNext()) {
			INode node = iterator.next();
			if (node.getSemanticElement() instanceof ParameterDesc) {
				ParameterDesc paramdesc = (ParameterDesc) node
						.getSemanticElement();
				if (paramdesc.isUnselected() == true) {
					setStyles(
							acceptor,
							iterator,
							MySemanticHighlightingConfiguration.PARAMETER_DESCRIPTION);
				}
			}
		}
	}
Re: Customizing Syntax Highlighting [message #1006351 is a reply to message #1006347] Wed, 30 January 2013 23:25 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6307
Registered: July 2009
Senior Member
Strange your code is looking

INode root = resource.getParseResult().getRootNode();
BidiTreeIterator<INode> iterator = root.getAsTreeIterable().iterator();
while (iterator.hasNext()) {
INode node = iterator.next();
if(...)
acceptor.addPosition(node.getOffset(), node.getLength(), MYHighlightingConfiguration.MY_ID);

}
}

[Updated on: Wed, 30 January 2013 23:25]

Report message to a moderator

Re: Customizing Syntax Highlighting [message #1006352 is a reply to message #1006351] Wed, 30 January 2013 23:27 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6307
Registered: July 2009
Senior Member
P.S: the default highlighting will not be applyed between offset and offset+length cause you define explicitely the style for that region
Re: Customizing Syntax Highlighting [message #1006444 is a reply to message #1006352] Thu, 31 January 2013 11:22 Go to previous messageGo to next message
Phil H is currently offline Phil H
Messages: 267
Registered: November 2012
Senior Member
Hmm, no the default highlighting doesn't work for the whole document :/
But when I remove this from MyDSLUiModule, the default highlighting work again:

public Class<? extends IHighlightingConfiguration> bindIHighlightingConfiguration() {
		return MySemanticHighlightingConfiguration.class;
	}

Re: Customizing Syntax Highlighting [message #1006793 is a reply to message #1006444] Fri, 01 February 2013 23:01 Go to previous messageGo to next message
Phil H is currently offline Phil H
Messages: 267
Registered: November 2012
Senior Member
any suggestions on this?
Re: Customizing Syntax Highlighting [message #1007141 is a reply to message #1006793] Mon, 04 February 2013 15:35 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik Lindberg
Messages: 2500
Registered: July 2009
Senior Member
On 2013-02-02 24:01, Phil H wrote:
> any suggestions on this?
Not really, but I did write a highlighter that does semantic as well as
textual highlighting in cloudsmith / geppetto @ github. It may be worth
taking a look at.

Regards
- henrik
Re: Customizing Syntax Highlighting [message #1007465 is a reply to message #1007141] Wed, 06 February 2013 01:23 Go to previous message
Phil H is currently offline Phil H
Messages: 267
Registered: November 2012
Senior Member
extending DefaultHighlightingConfiguration and invoking super.configure() was the right way Wink

[Updated on: Wed, 06 February 2013 01:23]

Report message to a moderator

Previous Topic:How to obtain starting offset in textual representation of a model element?
Next Topic:Creating RCP, no executable
Goto Forum:
  


Current Time: Sat Sep 20 22:14:30 GMT 2014

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

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