Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Refer the value of one feature inside the rule
Refer the value of one feature inside the rule [message #986207] Mon, 19 November 2012 13:20 Go to next message
Tommaso De Sica is currently offline Tommaso De SicaFriend
Messages: 131
Registered: March 2012
Location: Italy
Senior Member

Goodmorning everyone!

Is it possible to refer the value of one feature inside the same rule?

I want to realize something like this:
FUNCTION example
example:=1+1;
END_FUNCTION


So I use a code like this:
Function:
'FUNCTION' name=ID
??? ':=' Expression
'END_FUNCTION';


What can I put instead of ??? to force the name of function? (Or I have to realize it with the validator?)

Very thank you.

[Updated on: Mon, 19 November 2012 16:04]

Report message to a moderator

Re: Refer the value of one feature inside the rule [message #986291 is a reply to message #986207] Mon, 19 November 2012 18:28 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

am not sure what your problem is. did you have a look at default cross references?

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Refer the value of one feature inside the rule [message #986353 is a reply to message #986291] Tue, 20 November 2012 08:25 Go to previous messageGo to next message
Tommaso De Sica is currently offline Tommaso De SicaFriend
Messages: 131
Registered: March 2012
Location: Italy
Senior Member

I can use cross reference:
Function:
'FUNCTION' name=ID
output=[Function] ':=' expression=Expression
'END_FUNCTION';


but also something like this is accepted:

FUNCTION example
example:=1+1;
END_FUNCTION

FUNCTION otherExample
example:=1+1;
END_FUNCTION
Re: Refer the value of one feature inside the rule [message #986611 is a reply to message #986353] Wed, 21 November 2012 08:06 Go to previous messageGo to next message
Tommaso De Sica is currently offline Tommaso De SicaFriend
Messages: 131
Registered: March 2012
Location: Italy
Senior Member

up
Re: Refer the value of one feature inside the rule [message #987050 is a reply to message #986611] Fri, 23 November 2012 08:09 Go to previous messageGo to next message
Tommaso De Sica is currently offline Tommaso De SicaFriend
Messages: 131
Registered: March 2012
Location: Italy
Senior Member

ri-up
Re: Refer the value of one feature inside the rule [message #987109 is a reply to message #987050] Fri, 23 November 2012 14:46 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
On 2012-23-11 9:09, Tommaso De Sica wrote:
> ri-up
Love to help, but it is not much use doing something like up, ri-up when
we don't understand what you are asking. If you need help please
elaborate on what it is you need help with in more concrete terms. Which
one of the Xtext features is it that you don't understand, or what is it
your are trying to acheive?

Can't just look at a code snippet in your DSl language and guess what it
is you need help with.


- henrik
Re: Refer the value of one feature inside the rule [message #987126 is a reply to message #987109] Fri, 23 November 2012 16:23 Go to previous messageGo to next message
Tommaso De Sica is currently offline Tommaso De SicaFriend
Messages: 131
Registered: March 2012
Location: Italy
Senior Member

Well, my problem is this:
I want to write a Rule for Functions. A Function, in my DSL, appears like these:
FUNCTION functionName
   {some instruction}
functionName:=expressionForOutput
END_FUNCTION

FUNCTION secondFunctionName
   {some instruction}
secondFunctionName:=expressionForOutput
END_FUNCTION


As you can see, the last instruction must be an assignment where the left member is the name of the function.

If I use something like this:
Function:
   'FUNCTION' name=ID
   instructions+=Instruction*
   output=[Function]':='expression=Expression';' 
   'END_FUNCTION';


the cross reference
[Function]
accepts all Function's names, but I want only the function name of Function where output is in.

Very thanks.
Re: Refer the value of one feature inside the rule [message #987165 is a reply to message #987126] Fri, 23 November 2012 22:34 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
Can output refer to anything else than the same function? If not why do
you need to have an actual reference to itself in the first place?
I.e. you could just use an ID and validate that same ID is being used.
You want to also add this ID when doing code completion.

If you keep it as a reference, you need to look at scoping to understand
how to limit what is visible; here, if the only thing that is selectable
is the function itself, then that is what you need to add in your scope.

Does that help?
- henrik

On 2012-23-11 17:23, Tommaso De Sica wrote:
> Well, my problem is this:
> I want to write a Rule for Functions. A Function, in my DSL, appears
> like these:
>
> FUNCTION functionName
> {some instruction}
> functionName:=expressionForOutput
> END_FUNCTION
>
> FUNCTION secondFunctionName
> {some instruction}
> secondFunctionName:=expressionForOutput
> END_FUNCTION
>
>
> As you can see, the last instruction must be an assignment where the
> left member is the name of the function.
>
> If I use something like this:
>
> Function:
> 'FUNCTION' name=ID
> instructions+=Instruction*
> output=[Function]':='expression=Expression';' 'END_FUNCTION';
>
> the cross reference [Function] accepts all Function's names, but I want
> only the function name of Function where output is in.
>
> Very thanks.
Re: Refer the value of one feature inside the rule [message #987213 is a reply to message #987126] Sat, 24 November 2012 14:29 Go to previous message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 11/23/2012 05:23 PM, Tommaso De Sica wrote:
> Well, my problem is this:
> I want to write a Rule for Functions. A Function, in my DSL, appears
> like these:
>
> FUNCTION functionName
> {some instruction}
> functionName:=expressionForOutput
> END_FUNCTION
>
> FUNCTION secondFunctionName
> {some instruction}
> secondFunctionName:=expressionForOutput
> END_FUNCTION
>
>
> As you can see, the last instruction must be an assignment where the
> left member is the name of the function.
>
> If I use something like this:
>
> Function:
> 'FUNCTION' name=ID
> instructions+=Instruction*
> output=[Function]':='expression=Expression';' 'END_FUNCTION';
>
> the cross reference [Function] accepts all Function's names, but I want
> only the function name of Function where output is in.
>
> Very thanks.

You have to implement a custom Scoping for that!

cheers
Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net


Previous Topic:Question about @Pure annotation
Next Topic:Same optional Modifiers at multiple alternatives
Goto Forum:
  


Current Time: Thu Apr 18 00:23:25 GMT 2024

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

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

Back to the top