Xtext 2.0 Syntax Coloring [message #708869] |
Wed, 03 August 2011 04:43  |
Eclipse User |
|
|
|
Hello
I faced with a problem while I was trying to add syntax coloring feature for a type.
I have created a OurDefaultHighlightingConfiguration class (in com.example.mydsl.ui same packet with DslUIModel)which implements ISemanticHighlightingCalculator and overridden
following method
However, when I want to call NodeUtil, there is not such a NodeUtil class?
If you can help, I will appreciate
BR
Caner
@Override
public void provideHighlightingFor(XtextResource resource,
IHighlightedPositionAcceptor acceptor) {
/*
if(resource==null)
return;
Iterable<AbstractNode> allNode= NodeUtil.getAllContents(resource.getParseResult().getRootNode());
*/
}
[Updated on: Wed, 03 August 2011 16:26] by Moderator
|
|
|
|
|
|
|
|
Re: NodeUtil class not exists [message #708982 is a reply to message #708953] |
Wed, 03 August 2011 07:16   |
Eclipse User |
|
|
|
Hi again
now I have the code as below, is there anything missing? I didnt understand why it not working
I have implemented these two classes
public class MyHighlightingConfiguration implements IHighlightingConfiguration {
public final static String my_REF = "first reference";
public void configure(IHighlightingConfigurationAcceptor acceptor) {
acceptor.acceptDefaultHighlighting(my_REF,
"first_reference", myReferenceTextStyle());
}
public TextStyle myReferenceTextStyle() {
TextStyle textStyle = new TextStyle();
textStyle.setStyle(SWT.ITALIC);
textStyle.setColor(new RGB(127,0,85));
return textStyle;
}
}
public class OurDefaultHighlightingConfiguration implements ISemanticHighlightingCalculator {
public void provideHighlightingFor(XtextResource resource,
IHighlightedPositionAcceptor acceptor) {
if (resource == null || resource.getParseResult() == null)
return;
INode root = resource.getParseResult().getRootNode();
//Writer is the target type for coloring
for (INode node : root.getAsTreeIterable()) {
if (node.getGrammarElement() instanceof Writer) {
acceptor.addPosition(node.getOffset(), node.getLength(),
MyHighlightingConfiguration.my_REF);
}
}
}
}
And I bind them in the DSLUIMODEL
public class DSLUiModule extends AbstractDSLModule {
......
public Class<? extends OurDefaultHighlightingConfiguration> bindISemanticHighlightingCalculator(){
return OurDefaultHighlightingConfiguration.class;
}
public Class<? extends IHighlightingConfiguration> bindIHighlightingConfiguration () {
return MyHighlightingConfiguration.class;
}
}
BR caner
[Updated on: Wed, 03 August 2011 07:16] by Moderator
|
|
|
|
|
|
|
|
|
|
|
|
Re: NodeUtil class not exists [message #713482 is a reply to message #709342] |
Mon, 08 August 2011 10:23   |
Eclipse User |
|
|
|
Hi Christian
Regarding syntax coloring;
If a type has a keyword/symbol , I am not able to implement syntax coloring for that type, for example i have a type which has "keyword" as a keyword
and try to create syntax coloring feature just like below, but it doesnt work. Do you have any advice for me please?
BR
caner
Grammar
LibModel:
(types+=Type)*;
Type:
typeWithKey|NonEmpityLine;
typeWithKey: 'keyword' type=Words ;
Words hidden (): ID ;
public class OurDefaultHighlightingConfiguration implements
ISemanticHighlightingCalculator {
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.getGrammarElement() instanceof
RuleCall&& (RuleCall)node.getGrammarElement()).getRule().equals(grammarAccess.gettypeWithKeyRule())) {
acceptor.addPosition(node.getOffset(), node.getLength(),
MyHighlightingConfiguration.typeWithKey_Ref);
}
public class MyHighlightingConfiguration implements IHighlightingConfiguration {
public static String typeWithKey_Ref = "keyword";
--etc---
public void configure(IHighlightingConfigurationAcceptor acceptor) {
acceptor.acceptDefaultHighlighting(typeWithKey_Ref ,
"With Key", mytypeWithKeyTextStyle());
private TextStyle mytypeWithKeyTextStyle[code][/code]() {
TextStyle textStyle = new TextStyle();
textStyle.setStyle(SWT.ITALIC);
textStyle.setStyle(SWT.BOLD);
textStyle.setColor(new RGB(42, 0, 255));
return textStyle;
}
and of course these classes have been binned in UIModule.java
[Updated on: Mon, 08 August 2011 10:25] by Moderator
|
|
|
|
|
|
|
|
|
|
|
Re: NodeUtil class not exists [message #713670 is a reply to message #713650] |
Mon, 08 August 2011 14:48  |
Eclipse User |
|
|
|
Do you actually open the editor for your language or is it a plain text
editor, e.g. does content assist work?
Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
On 08.08.11 20:18, Caner wrote:
> Hi
> I dont know what is wrong but it seems each method is alive
>
> and entire line (ley word and ID are still black)
>
> caner
|
|
|
Powered by
FUDForum. Page generated in 0.06263 seconds