Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Xtext Semantic Coloring(Xtext Semantic Coloring)
Xtext Semantic Coloring [message #1715614] Tue, 24 November 2015 16:44 Go to next message
Jia Poh Kow is currently offline Jia Poh KowFriend
Messages: 25
Registered: November 2015
Junior Member
Hi! I am working on a syntax coloring for the ARM machine code
Here is part of my xtext syntax

MUL_3R_OP:
op?=('mul' | 'MUL')(suffix?=CONDITION_SUFFIX)?(s?=('s' | 'S'))?
;

terminal CONDITION_SUFFIX:
'eq' | 'ne'
;

output can be a number of combination as follows:
muleqs
muleq
muls

However, the syntax coloring gone when it comes to different combinations.
The syntax will only be colored when the output is
mul or MUL

I tried configuring the ISemanticHighlightingCalculator by having following this but it did not works.

package org.xtext.fyp.ui;

import org.eclipse.xtext.nodemodel.INode;
import org.eclipse.xtext.nodemodel.impl.CompositeNodeWithSemanticElement;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightedPositionAcceptor;
import org.eclipse.xtext.ui.editor.syntaxcoloring.ISemanticHighlightingCalculator;
import org.xtext.fyp.fyp.MUL_3R_OP;

public class fypHighlightingCalculator implements ISemanticHighlightingCalculator{

@Override
public void provideHighlightingFor(XtextResource resource, IHighlightedPositionAcceptor acceptor) {
if (resource == null || resource.getParseResult() == null)
return;

INode root = resource.getParseResult().getRootNode();
for (INode node : root.getAsTreeIterable()) {
if(node instanceof CompositeNodeWithSemanticElement){
CompositeNodeWithSemanticElement compositeNode = (CompositeNodeWithSemanticElement) node;

if (node.getSemanticElement() instanceof MUL_3R_OP){
acceptor.addPosition(node.getOffset(), node.getLength(), fypHighlightingConfiguration.OPERATION_ID);
}
}
}
}
}

Any one can help on this??
Really appreciate your help.Thank you.
Re: Xtext Semantic Coloring [message #1715654 is a reply to message #1715614] Wed, 25 November 2015 06:03 Go to previous messageGo to next message
Ed Merks is currently online Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
I see you've posted this on the Xtext forum as well. Please always use
that for Xtext questions.

On 24/11/2015 5:51 PM, Jia Poh Kow wrote:
> Hi! I am working on a syntax coloring for the ARM machine code
> Here is part of my xtext syntax
>
> MUL_3R_OP:
> op?=('mul' | 'MUL')(suffix?=CONDITION_SUFFIX)?(s?=('s' | 'S'))?
> ;
>
> terminal CONDITION_SUFFIX:
> 'eq' | 'ne' ;
>
> output can be a number of combination as follows:
> muleqs
> muleq
> muls
>
> However, the syntax coloring gone when it comes to different
> combinations.
> The syntax will only be colored when the output is mul or MUL
>
> I tried configuring the ISemanticHighlightingCalculator by having
> following this but it did not works.
>
> package org.xtext.fyp.ui;
>
> import org.eclipse.xtext.nodemodel.INode;
> import org.eclipse.xtext.nodemodel.impl.CompositeNodeWithSemanticElement;
> import org.eclipse.xtext.resource.XtextResource;
> import
> org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightedPositionAcceptor;
> import
> org.eclipse.xtext.ui.editor.syntaxcoloring.ISemanticHighlightingCalculator;
> import org.xtext.fyp.fyp.MUL_3R_OP;
>
> public class fypHighlightingCalculator implements
> ISemanticHighlightingCalculator{
>
> @Override
> public void provideHighlightingFor(XtextResource resource,
> IHighlightedPositionAcceptor acceptor) {
> if (resource == null || resource.getParseResult() == null)
> return;
> INode root = resource.getParseResult().getRootNode();
> for (INode node : root.getAsTreeIterable()) {
> if(node instanceof CompositeNodeWithSemanticElement){
> CompositeNodeWithSemanticElement compositeNode =
> (CompositeNodeWithSemanticElement) node;
>
> if (node.getSemanticElement() instanceof MUL_3R_OP){
> acceptor.addPosition(node.getOffset(),
> node.getLength(), fypHighlightingConfiguration.OPERATION_ID);
> }
> }
> }
> }
> }
>
> Any one can help on this??
> Really appreciate your help.Thank you.
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Xtext Semantic Coloring [message #1715657 is a reply to message #1715654] Wed, 25 November 2015 06:19 Go to previous messageGo to next message
Jia Poh Kow is currently offline Jia Poh KowFriend
Messages: 25
Registered: November 2015
Junior Member
Hi!

I was my first post >< So sorry for did not notice that...
Do you mean I need to post another post in the xtext forum??

Thank you and sorry for any inconvenience caused.
Re: Xtext Semantic Coloring [message #1715669 is a reply to message #1715657] Wed, 25 November 2015 07:49 Go to previous message
Ed Merks is currently online Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
No, just use it in the future. I see you already posted there, so just
follow that thread.

On 25/11/2015 7:19 AM, Jia Poh Kow wrote:
> Hi!
>
> I was my first post >< So sorry for did not notice that...
> Do you mean I need to post another post in the xtext forum??
>
> Thank you and sorry for any inconvenience caused.
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Cannot get Eclipse for C/C++ to debug
Next Topic:My Eclipse Marketplace Repository doesn't contains favourite plugins
Goto Forum:
  


Current Time: Thu Apr 25 15:05:55 GMT 2024

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

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

Back to the top