Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » reference whitespace issue
reference whitespace issue [message #1310499] Wed, 23 April 2014 08:15 Go to next message
Grzegorz Daniec is currently offline Grzegorz DaniecFriend
Messages: 2
Registered: April 2014
Junior Member
Hi everyone.
I am working on grammar for test language and need some advice with one of the instructions.
In my language it is possible to define constants in the following way:
define <name> <INT or define name reference with $ sign at the beginning>

Lets look at the example:
define first 3
define second $first

The problem is connected with '$' sign.
I defined grammar rule this way:

Define:
'define' name=ID (INT | '$' value=[Define])
;

But it allows me to insert white spaces between '$' and name. How can I eliminate this possibility?

Thanks in advance for your help and great work you put in Xtext plugin,
Grzesiek
Re: reference whitespace issue [message #1311087 is a reply to message #1310499] Wed, 23 April 2014 15:39 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
On 2014-23-04 15:23, Grzegorz Daniec wrote:
> Hi everyone.
> I am working on grammar for test language and need some advice with one
> of the instructions.
> In my language it is possible to define constants in the following way:
> define <name> <INT or define name reference with $ sign at the beginning>
>
> Lets look at the example:
> define first 3
> define second $first
>
> The problem is connected with '$' sign. I defined grammar rule this way:
>
> Define:
> 'define' name=ID (INT | '$' value=[Define])
> ;
>
> But it allows me to insert white spaces between '$' and name. How can I
> eliminate this possibility?

You can control the visibility of the tokens that are placed in the
hidden channel. You do this by specifying what should be hidden. By
default rules inherit this trait.

You find information about this in the documentation.

If you want nothing to be hidden you write the rule:

Define hidden():
...

The tokens hidden by default are WS, SL_COMMENT and ML_COMMENT.

But you must then be explicit where hidden tokens may appear in the grammar.

If you need to have only portions of a grammar rule be subject to seeing
hidden tokens, you need to break it out into a separate rule.

Hope that helps

- henrik
Re: reference whitespace issue [message #1312294 is a reply to message #1311087] Thu, 24 April 2014 07:45 Go to previous message
Grzegorz Daniec is currently offline Grzegorz DaniecFriend
Messages: 2
Registered: April 2014
Junior Member
Thanks Henrik.

That is exactly what I was looking for.
Changing define rule in the following way did the job:

Define hidden(SL_COMMENT):
'define' WS name=ID WS (INT | '$' value=[Define])
;

- Grzesiek
Previous Topic:Rule written for DSL in xtext, It is not working as expected
Next Topic:Annyoing XText model (hyper)linking
Goto Forum:
  


Current Time: Thu Apr 25 20:14:48 GMT 2024

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

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

Back to the top