Lexical syntax highlighting [message #479001] |
Fri, 07 August 2009 22:21 |
Eclipse User |
|
|
|
Originally posted by: c.krause.cwi.nl
Hi,
sorry I know this is covered in the docu, but I do not fully understand
how I can hook up my own custom lexical highlighter. Is there any
example that shows how exactly I should hook up the
ILexicalHighlightingConfiguration and the AbstractTokenScanner +
AbstractAntlrTokenToAttributeIdMapper?
The token scanner I should hook up via bindITokenScanner() in my
XXXUIModule, right? And then I override getTokenIdMapper() in there?
How about the ILexicalHighlightingConfiguration?
Cheers,
Christian
|
|
|
|
Re: Lexical syntax highlighting [message #479067 is a reply to message #479020] |
Sat, 08 August 2009 18:55 |
Eclipse User |
|
|
|
Originally posted by: christian.krause.cwi.nl
Thanks a lot. That worked like a charm.
Christian
Am 08.08.2009 10:21, schrieb KD:
> Christian Krause wrote:
>
>> sorry I know this is covered in the docu, but I do not fully
>> understand how I can hook up my own custom lexical highlighter. Is
>> there any example that shows how exactly I should hook up the
>> ILexicalHighlightingConfiguration and the AbstractTokenScanner +
>> AbstractAntlrTokenToAttributeIdMapper?
>
> The documentation is not really helpful for beginners. But once you get
> the hang of guice injection and how it is used within XText, everything
> should look simple.
>
>> The token scanner I should hook up via bindITokenScanner() in my
>> XXXUIModule, right? And then I override getTokenIdMapper() in there?
>
> If you bind a ITokenScanner you need to implement all the stuff. In
> XText, you just need to bind a AbstractAntlrTokenToAttributeIdMapper.
>
> In detail:
>
> 1. Create a LexicalHighlightingConfiguration class that extends either
> DefaultLexicalHighlightingConfiguration or implements
> ILexicalHighlightingConfiguration. You need to override
> configure(IHighlightingConfigurationAcceptor acceptor) method and call
> acceptor.acceptDefaultHighlighting to register textstyles.
> 2. Create a AntlrTokenToAttributeIdMapper class that extends either
> DefaultAntlrTokenToAttributeIdMapper or
> AbstractAntlrTokenToAttributeIdMapper. You need to override the
> calculateId(String tokenName, int tokenType) method and return the ID
> defined in the LexicalHighlightingConfiguration for the tokens.
> 3. Update your <grammar>UIModule.java and add these two functions:
> public Class<? extends ILexicalHighlightingConfiguration>
> bindILexicalHighlightingConfiguration() {
> return LexicalHighlightingConfiguration.class;
> }
>
> public Class<? extends AbstractAntlrTokenToAttributeIdMapper>
> bindAbstractAntlrTokenToAttributeIdMapper() {
> return AntlrTokenToAttributeIdMapper.class ;
> }
>
> XText uses reflection to find all bind* methods and injects the
> appropriate objects.
>
> Done.
>
> HTH.
>
> -- KD
>
>
|
|
|
|
|
Re: Lexical syntax highlighting [message #552736 is a reply to message #552731] |
Fri, 13 August 2010 10:31 |
Jos Warmer Messages: 66 Registered: July 2009 |
Member |
|
|
Alex, this is what I am trying to do. IOn the Lexical highlighting I define a new style:
public class MyHighLightingConfiguration extends DefaultHighlightingConfiguration{
public static final String LAYOUT_ID = "layout";
public void configure(IHighlightingConfigurationAcceptor acceptor) {
super.configure(acceptor);
acceptor.acceptDefaultHighlighting(LAYOUT_ID, "Layout", layoutTextStyle());
}
public TextStyle layoutTextStyle() {
TextStyle textStyle = new TextStyle();
textStyle.setColor(new RGB(0, 0, 255));
textStyle.setStyle(SWT.ITALIC);
return textStyle;
}
}
And in the token id scanner I try to use it:
public class MyAntlrTokenToAttributeIdMapper extends DefaultAntlrTokenToAttributeIdMapper {
@Override
protected String calculateId(String tokenName, int tokenType) {
if( "container".equals(tokenName)) {
return MyHighLightingConfiguration.LAYOUT_ID;
}
return super.calculateId(tokenName, tokenType);
}
}
And in the module I bind them:
public Class<? extends IHighlightingConfiguration> bindILexicalHighlightingConfiguration() {
return MyHighLightingConfiguration.class;
}
public Class<? extends AbstractAntlrTokenToAttributeIdMapper> bindAbstractAntlrTokenToAttributeIdMapper() {
return MyAntlrTokenToAttributeIdMapper.class ;
}
Nothing happens, I still get the default keyword color for the "container" keyword.
If I take out the call to 'super' in MyHighlightingConfiguration all keyword syntax coloring dissappears, so the binding works ok.
-- Jos
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04969 seconds