Highlighting with Xtext [message #755981] |
Thu, 10 November 2011 11:41 |
haceface Messages: 5 Registered: November 2011 |
Junior Member |
|
|
Hey guys!
I'm currently developing a json editor. I want to highlight only the "Object" and "Array" types in it, i already done some lexical highlighting but i just cant figure out how to do the sematic highlighing. Here is my code.
xtext file
Editor:
element = Object
;
Object:
'{' firstObjectItem+=mainObjectType (',' insideOfObjectItems+=mainObjectType)*
'}'
;
Array:
'[' firstArrayItem += ObjectType (',' insideOfArrayItems+=ObjectType)*
']'
;
mainObjectType:
maintype = STRING ':'(insideOfObject = ObjectType)
;
ObjectType:
type = STRING | NUMBER | Object | Array | Boolean | EmptyObject | EmptyArray | Null
;
and my editor highlight configuration
public class EditorHighLightingConfiguration extends DefaultHighlightingConfiguration{
public static final String LAYOUT_ID = "layout";
public static final String STRING_OVR_ID = "stringovrid";
public static final String OBJECT_ID = "objectid";
public void configure(IHighlightingConfigurationAcceptor acceptor) {
super.configure(acceptor);
acceptor.acceptDefaultHighlighting(LAYOUT_ID, "Layout", layoutTextStyle());
acceptor.acceptDefaultHighlighting(STRING_OVR_ID, "StringOVRID", stringTextStyle());
acceptor.acceptDefaultHighlighting(OBJECT_ID, "ObjectID", objectTextStyle());
}
public TextStyle layoutTextStyle() {
TextStyle textStyle = new TextStyle();
textStyle.setColor(new RGB(255, 0, 0));
textStyle.setStyle(SWT.BOLD);
return textStyle;
}
public TextStyle stringTextStyle() {
TextStyle textStyle = new TextStyle();
textStyle.setColor(new RGB(0, 0, 128));
textStyle.setStyle(SWT.NORMAL);
return textStyle;
}
public TextStyle objectTextStyle() {
TextStyle textStyle = new TextStyle();
textStyle.setColor(new RGB(0, 128, 0));
textStyle.setStyle(SWT.BOLD);
return textStyle;
}
}
I just can't find any good tutorial about how to work with this sematic stuff.
Hope you guys can help.
|
|
|
Re: Highlighting with Xtext [message #755987 is a reply to message #755981] |
Thu, 10 November 2011 12:01 |
Jan Koehnlein Messages: 760 Registered: July 2009 Location: Hamburg |
Senior Member |
|
|
So far you have just registered the text sytles. In addition you have to
implement and bind an ISemanticHighlightingCalculator. This is really
documented in the help pages in detail. If you need an example, have a
look at the domainmodel example shipped with Xtext.
Am 10.11.11 12:41, schrieb haceface:
> Hey guys!
>
> I'm currently developing a json editor. I want to highlight only the
> "Object" and "Array" types in it, i already done some lexical
> highlighting but i just cant figure out how to do the sematic
> highlighing. Here is my code.
>
> xtext file
>
> Editor:
> element = Object
> ;
> Object:
> '{' firstObjectItem+=mainObjectType (','
> insideOfObjectItems+=mainObjectType)* '}'
> ;
>
> Array:
> '[' firstArrayItem += ObjectType (',' insideOfArrayItems+=ObjectType)*
> ']'
> ;
>
> mainObjectType:
> maintype = STRING ':'(insideOfObject = ObjectType)
> ;
>
> ObjectType:
> type = STRING | NUMBER | Object | Array | Boolean | EmptyObject |
> EmptyArray | Null
> ;
>
> and my editor highlight configuration public class
> EditorHighLightingConfiguration extends DefaultHighlightingConfiguration{
>
> public static final String LAYOUT_ID = "layout";
> public static final String STRING_OVR_ID = "stringovrid";
> public static final String OBJECT_ID = "objectid";
>
> public void configure(IHighlightingConfigurationAcceptor acceptor) {
> super.configure(acceptor);
>
> acceptor.acceptDefaultHighlighting(LAYOUT_ID, "Layout", layoutTextStyle());
> acceptor.acceptDefaultHighlighting(STRING_OVR_ID, "StringOVRID",
> stringTextStyle());
> acceptor.acceptDefaultHighlighting(OBJECT_ID, "ObjectID",
> objectTextStyle());
> }
>
> public TextStyle layoutTextStyle() {
> TextStyle textStyle = new TextStyle();
> textStyle.setColor(new RGB(255, 0, 0));
> textStyle.setStyle(SWT.BOLD);
> return textStyle;
> }
>
> public TextStyle stringTextStyle() {
> TextStyle textStyle = new TextStyle();
> textStyle.setColor(new RGB(0, 0, 128));
> textStyle.setStyle(SWT.NORMAL);
> return textStyle;
> }
>
> public TextStyle objectTextStyle() {
> TextStyle textStyle = new TextStyle();
> textStyle.setColor(new RGB(0, 128, 0));
> textStyle.setStyle(SWT.BOLD);
> return textStyle;
> }
> }
>
> I just can't find any good tutorial about how to work with this sematic
> stuff. Hope you guys can help.
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
---
Get professional support from the Xtext committers at www.typefox.io
|
|
|
Powered by
FUDForum. Page generated in 0.03642 seconds