Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Exclude keywords in certain context
Exclude keywords in certain context [message #922627] Tue, 25 September 2012 07:21 Go to next message
Tu Do is currently offline Tu DoFriend
Messages: 21
Registered: August 2012
Junior Member
In some certain rules, I want to treat some keywords as normal ID. How do I do that? For example:

ENUM:
    'enum' ID '{' ( literal = ID ('=' INT)? ','? )+  '}' ';'

FREE:
    'FREE' ID ';'


Example code of the above grammar should be like this:
enum State {
      BUSY = 1,
      FREE
}

I declared 'FREE' as a keyword. Xtext will highlight 'FREE' in enum as an error and require me to write according to FREE rule. How can I exclude FREE rule in ENUM rule?
Re: Exclude keywords in certain context [message #923412 is a reply to message #922627] Tue, 25 September 2012 22:27 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2500
Registered: July 2009
Senior Member
SomeRule : ID | FREE | ...;

- henrik

On 2012-25-09 24:21, Tu Do wrote:
> In some certain rules, I want to treat some keywords as normal ID. How
> do I do that? For example:
>
> ENUM:
> 'enum' ID '{' ( literal = ID ('=' INT)? ','? )+ '}' ';'
>
> FREE:
> 'FREE' ID ';'
>
> Example code of the above grammar should be like this:
>
> enum State {
> BUSY = 1,
> FREE
> }
> I declared 'FREE' as a keyword. Xtext will highlight 'FREE' in enum as
> an error and require me to write according to FREE rule. How can I
> exclude FREE rule in ENUM rule?
Re: Exclude keywords in certain context [message #923716 is a reply to message #923412] Wed, 26 September 2012 06:12 Go to previous messageGo to next message
Tu Do is currently offline Tu DoFriend
Messages: 21
Registered: August 2012
Junior Member
Henrik Lindberg wrote on Tue, 25 September 2012 18:27
SomeRule : ID | FREE | ...;

- henrik

On 2012-25-09 24:21, Tu Do wrote:
> In some certain rules, I want to treat some keywords as normal ID. How
> do I do that? For example:
>
> ENUM:
> 'enum' ID '{' ( literal = ID ('=' INT)? ','? )+ '}' ';'
>
> FREE:
> 'FREE' ID ';'
>
> Example code of the above grammar should be like this:
>
> enum State {
> BUSY = 1,
> FREE
> }
> I declared 'FREE' as a keyword. Xtext will highlight 'FREE' in enum as
> an error and require me to write according to FREE rule. How can I
> exclude FREE rule in ENUM rule?

I thought of that before, but I think it will highlight the keywords, and I don't want it to be highlighted.
Re: Exclude keywords in certain context [message #923731 is a reply to message #923716] Wed, 26 September 2012 06:30 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6492
Registered: July 2009
Senior Member
Hi,

you can adapt highlighting

~Christian
Re: Exclude keywords in certain context [message #923761 is a reply to message #923731] Wed, 26 September 2012 07:13 Go to previous messageGo to next message
Tu Do is currently offline Tu DoFriend
Messages: 21
Registered: August 2012
Junior Member
Christian Dietrich wrote on Wed, 26 September 2012 02:30
Hi,

you can adapt highlighting

~Christian

As far as I know, I can only highlight static keyword. The highlighted keyword will be applied everywhere it is seen in my language. So, if every constant in my enum type is highlighted with Black, except a constant which is highlighted as red. If I highlighted the keyword to be the same as the constants, it will lose the keyword markup.

Certainly, I don't want to markup constant elements of enum the same as my keywords. Or is there a way to highlight according to the current rule?

[Updated on: Wed, 26 September 2012 07:16]

Report message to a moderator

Re: Exclude keywords in certain context [message #923848 is a reply to message #923761] Wed, 26 September 2012 08:41 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6492
Registered: July 2009
Senior Member
You can fix this using semantic highlighting. We do this in our
project - I cannot give you the code for copyright issues

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Re: Exclude keywords in certain context [message #923849 is a reply to message #923761] Wed, 26 September 2012 08:42 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6492
Registered: July 2009
Senior Member
You can fix this using semantic highlighting. We do this in our
project - I cannot give you the code for copyright issues

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Re: Exclude keywords in certain context [message #924142 is a reply to message #923848] Wed, 26 September 2012 14:46 Go to previous message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2500
Registered: July 2009
Senior Member
On 2012-26-09 1:41, Christian Dietrich wrote:
> You can fix this using semantic highlighting. We do this in our project
> - I cannot give you the code for copyright issues
>
For an example look at
org.cloudsmith.geppetto.pp.dsl.ui.coloring.PPSemanticHighlightingCalculator
in project cloudsmith / geppetto @ github - it uses several different
ways of highlighting.

- henrik
Previous Topic:Dynamically extend parts of the grammar
Next Topic:Split grammar (multiple grammars) in 1 project?
Goto Forum:
  


Current Time: Tue Nov 25 00:52:15 GMT 2014

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

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