Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » syntax coloring(change color for an element in certain positions)
syntax coloring [message #776527] Sun, 08 January 2012 17:24 Go to next message
Mokhtar Alshubei is currently offline Mokhtar AlshubeiFriend
Messages: 121
Registered: November 2011
Location: Germany
Senior Member
Hello,

i have been lost myself to find a simple example about how to customize the syntax color of a DSL element. The question is is it possible to introduce different color for the same rule element like red if it is on top and black if it is nested????
I have a rule like this:
Model:
elements+= Rule*
;
Rule:
functor= ID '(' arg=Term ')' '.'
;
Term:
STRING|ID|INT|Function
;
Function:
t+=Term(','t+=Term)*
;

now if i have these two legal inputs:
p("s1").
f(p(4)).

can i change the color of the functor p in p("s1") to red and black in f(p(4))???
Regards,
Mokhtar

[Updated on: Sun, 08 January 2012 17:25]

Report message to a moderator

Re: syntax coloring [message #776537 is a reply to message #776527] Sun, 08 January 2012 17:58 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
On 2012-08-01 18:24, Xtexter wrote:
> Hello,
>
> i have been lost to find a simple example about how to customize the
> syntax color of a DSL element. The question is is it possible to
> introduce different color for the same rule element like red if it is on
> top and black if it is nested????
> I have a rule like this:
>
> Model:
> elements+= Rule
> ;
> Rule:
> functor= ID '(' arg=Term ')' '.'
> ;
> Term:
> STRING|ID|INT|Function
> ;
> Function:
> t+=Term(','t+=Term)*
> ;
>
> now if i have these two legal inputs:
>
> p("s1").
> f(p(4)).
>
> can i change the color of the functor p in p("s1") to red and black in
> f(p(4))???

Yes.
You implement ISemanticHighlightingCalculator, bind it in your runtime,
and add the highlights you want.

You can take a look at one of my implementations
(org.cloudsmith.geppetto.pp.dsl.ui.coloring.PPSemanticHighlightingCalculator)
found in project cloudsmith/geppetto @ github. There I make use of
several kinds of highlighting, based on the model (typical semantic
highlighting), based on the text (I highlight non breaking spaces, and
other special WS characters), and based on parsed nodes (i.e. highlight
based on how the semantic object was parsed (which rule etc.)).

Hope that provides some ideas.
Your case should be quite straight forward to implement. You probably
just have to go up the eContainer chain for you semantic object (the
functor) to learn how/if it is contained.

Regards
- henrik
Re: syntax coloring [message #776544 is a reply to message #776537] Sun, 08 January 2012 18:28 Go to previous messageGo to next message
Mokhtar Alshubei is currently offline Mokhtar AlshubeiFriend
Messages: 121
Registered: November 2011
Location: Germany
Senior Member
Thank you! but as i am a beginner i dont know even what does the mwe2 fragment look like if i have to provide any. if i am not wrong, i need just coloring for the keyword "functor = 'p' " or generally "= ID"?. can you please shoot me a simple example and i will go ahead?
very simple like for Greeting example.. i didnt know how to get your big project running on my eclipse Sad

thanks a lot
Re: syntax coloring [message #776557 is a reply to message #776544] Sun, 08 January 2012 19:18 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14669
Registered: July 2009
Senior Member
Hi,

search the forum/web/docs for ISemanticHighlightingCalculator and IHighlightingConfiguration
and you will find many examples even simple ones.

i dont think you still that noodby that you are absolutely unable to give it a try yourself.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Sun, 08 January 2012 19:39]

Report message to a moderator

Previous Topic:label provider
Next Topic:[xtend] Floating Point number and expressions with them
Goto Forum:
  


Current Time: Sat Apr 27 00:36:16 GMT 2024

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

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

Back to the top