Skip to main content



      Home
Home » Modeling » TMF (Xtext) » reference whitespace issue
reference whitespace issue [message #1310499] Wed, 23 April 2014 04:15 Go to next message
Eclipse UserFriend
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 11:39 Go to previous messageGo to next message
Eclipse UserFriend
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 03:45 Go to previous message
Eclipse UserFriend
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: Wed Jul 23 03:49:23 EDT 2025

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

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

Back to the top