syntax coloring [message #776527] |
Sun, 08 January 2012 17:24 |
Mokhtar Alshubei 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:
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 |
Henrik Lindberg 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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03067 seconds