Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext(Need back space to be colour)
Xtext [message #1715618] Tue, 24 November 2015 17:11 Go to next message
Jia Poh Kow is currently offline Jia Poh KowFriend
Messages: 25
Registered: November 2015
Junior Member
Hi.
my xtext rule is like follows:

PREPROCESSOR:
code?= ( '#if' | '#else' | '#elif' | '#error' | '#pragma'
| '#define' | '#undef' | '#include' | '#ifdef' | '#ifndef'
| '#endif' | '#line' | '#loop')
;
the output like:
#define
#pragma

work well. But when it come to output like :
#else
#elif
#endif
It did not color once finish typing. I observed that whenever the first two character of the syntax are the same, it stops coloring.
But when I pressed backspace and press enter in front of the #, it will be colored again.

Any idea on what is happening?

So, I come out with an alternative way to solve this.

PREPROCESSOR:
hash?=('#') code?= ( 'if' | 'else' | 'elif' | 'error' | 'pragma'
| 'define' | 'undef' | 'include' | 'ifdef' | 'ifndef'
| 'endif' | 'line' | 'loop')
;

In this case, even the first two character like else and elif is the same, they still work well.
However, for this case, the # is not colored and remain as a string and is not colored with the keyword together.

Any idea to help on this?
Thank you very much.
Re: Xtext [message #1715623 is a reply to message #1715618] Tue, 24 November 2015 17:45 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi i cannot reproduce that. Can you please share everything needed to reproduce

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext [message #1715656 is a reply to message #1715623] Wed, 25 November 2015 06:13 Go to previous messageGo to next message
Jia Poh Kow is currently offline Jia Poh KowFriend
Messages: 25
Registered: November 2015
Junior Member
Hi!
Below is the xtext code for the first version.
Expected outcome : syntax is colour starting from # till the end

Steps to reproduce:
(1) type #pragma
result : you can see the output #pragma is color

(2) type #else
result : output #else is not color like #pragma

(3) press backspace
result : output #else is color like #pragma

Below is the complete code needed to reproduce:

Model:
elements+=ARMInstr*
;
ARMInstr:
PREPROCESSOR

;

PREPROCESSOR:
code?= ( '#if' | '#else' | '#elif' | '#error' | '#pragma'
| '#define' | '#undef' | '#include' | '#ifdef' | '#ifndef'
| '#endif' | '#line' | '#loop')
;

Second version of code
Expected Outcome: Syntax color starting from # till the end
Result: # is not color, keyword is color

Complete xtext code :

Model:
elements+=ARMInstr*
;
ARMInstr:
PREPROCESSOR
;

PREPROCESSOR:
hash?=('#') code?= ( 'if' | 'else' | 'elif' | 'error' | 'pragma'
| 'define' | 'undef' | 'include' | 'ifdef' | 'ifndef'
| 'endif' | 'line' | 'loop')
;
Re: Xtext [message #1715663 is a reply to message #1715656] Wed, 25 November 2015 07:23 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
in this combination it can be reproduced. can you file a ticket?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext [message #1715698 is a reply to message #1715663] Wed, 25 November 2015 10:29 Go to previous messageGo to next message
Jia Poh Kow is currently offline Jia Poh KowFriend
Messages: 25
Registered: November 2015
Junior Member
Chirstian,

Ticket filed. I have another condition here.

Here is part of my xtext syntax

Model:
elements+=ARMInstr*
;
ARMInstr:
MUL_3R_OP
;
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 either
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);
}
}
}
}
}

Is this of the same problem?? Or do you have any idea to get through it??
Thank you Christian=)
Re: Xtext [message #1715702 is a reply to message #1715698] Wed, 25 November 2015 10:48 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
this Looks basically of. i dont know if this is the same Problem.

what you can do is to ask the resources parseresult fot the roottastnode, traverse that one and use nodemodelutils to find the node.
but if there is a general Problem that wont help


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:XText 2.9 and single quotes
Next Topic:Generate production artifacts with 2.9
Goto Forum:
  


Current Time: Thu Mar 28 13:06:33 GMT 2024

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

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

Back to the top