Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Highlighting with Xtext
Highlighting with Xtext [message #755981] Thu, 10 November 2011 06:41 Go to next message
Eclipse UserFriend
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 07:01 Go to previous message
Eclipse UserFriend
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
Previous Topic:How to write correct parser rules using JavaVMTypes
Next Topic:Problems with multidimensional arrays
Goto Forum:
  


Current Time: Wed Jul 23 08:30:58 EDT 2025

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

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

Back to the top