Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Complex Cross Reference
Complex Cross Reference [message #818593] Sun, 11 March 2012 22:10 Go to next message
Denis Brighi is currently offline Denis BrighiFriend
Messages: 5
Registered: March 2012
Junior Member
Hi all,
i'm pretty new of this forum... and i've discovered the power of xtext2... currently i'm using it for my degree thesis..
I have a problem with cross reference, that maybe this community, much more expert than me, can resolve...

MainRule:
'goals {' ((goalsList+=Goal) (',' goalsList+=Goal)*)? '}' //Pre-defined Goal
(planList+=[Plan])+


Plan:
'plan' name=ID '{'
(('event' eventName=[Event]) | ('goal' goalName=[Goal])) //Pre-defined goal or new one
'context' context=BoolExpr
'body {'
planBody+=Action*
'}'
'}'
;
//One of the Action is this...
ModifyGoal returns SingleAction:
planAction=('add' | 'delete') goalName=[Goal]; //Both pre-defined or new

The fact is that i don't want lose the cross reference function in goals definition. The list of goals doesn't have to be fully explained in the "goals" rule. Anyway in Plan-Goal i would like to reference that goals and other new. Finally i would like to reference both - preDefined and post defined goal - from ModifyGoal rule...

is it possible to have that dynamic behaviour?

thank you so much!
Denis
Re: Complex Cross Reference [message #818633 is a reply to message #818593] Sun, 11 March 2012 23:38 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
x = [GOAL]
means that x is a reference to a GOAL, that is found by searching for an
instance of GOAL with an exported name matching a parsed ID - i.e.

x = [GOAL | ID ]

By default, anything is referenceable that has a name = ID attribute.
(Other things can be made referenceable even if they do not have a name
attribute).

It does not matter where this GOAL comes from when you are specifying
the grammar - it can be in the same file, some other file, in a jar, in
a different project etc. etc. all depending on how you configure your
language.

I do not understand what you mean by "pre-defined" goal vs.
"post-defined" - can you elaborate?

Hope the answer above still helps you.

Regards
- henrik

On 2012-11-03 23:10, Denis Brighi wrote:
> Hi all,
> i'm pretty new of this forum... and i've discovered the power of
> xtext2... currently i'm using it for my degree thesis.. I have a problem
> with cross reference, that maybe this community, much more expert than
> me, can resolve...
>
> MainRule:
> 'goals {' ((goalsList+=Goal) (',' goalsList+=Goal)*)? '}' //Pre-defined
> Goal
> (planList+=[Plan])+
>
>
> Plan:
> 'plan' name=ID '{'
> (('event' eventName=[Event]) | ('goal' goalName=[Goal])) //Pre-defined
> goal or new one
> 'context' context=BoolExpr
> 'body {'
> planBody+=Action*
> '}'
> '}'
> ;
> //One of the Action is this...
> ModifyGoal returns SingleAction:
> planAction=('add' | 'delete') goalName=[Goal]; //Both pre-defined or new
>
> The fact is that i don't want lose the cross reference function in goals
> definition. The list of goals doesn't have to be fully explained in the
> "goals" rule. Anyway in Plan-Goal i would like to reference that goals
> and other new. Finally i would like to reference both - preDefined and
> post defined goal - from ModifyGoal rule...
>
> is it possible to have that dynamic behaviour?
>
> thank you so much!
> Denis
>
Re: Complex Cross Reference [message #818906 is a reply to message #818633] Mon, 12 March 2012 09:07 Go to previous messageGo to next message
Denis Brighi is currently offline Denis BrighiFriend
Messages: 5
Registered: March 2012
Junior Member
Thank you for the fast response Very Happy
I try to explain myself better...

"Pre-defined" goal, are static-like task in my language, listed a priori.
But i would like to define other Goal, not listed before, and use them to cross refernce
the action ModifyGoal

Is it more clear now?

Ok... i did the try (as you can see below, in the complete code)

 x = [GOAL | ID ] 


but when i run the editor and i try to write in a plan like this one:
goals {
      goal1, goal2
}

plan piano1 {
	goal goal1 //OK
	context true
	body {
		...
	}
}

plan piano1 {
	goal nonInListGoal //Error
	context true
	body {
		...
	}
}

it continues to give me error: "Couldn't resolve reference to Goal 'nonInListGoal'."

i attach the complete part of grammar to this point
MainRule:
         'goals {' ((goalsList+=Goal) (',' goalsList+=Goal)*)? '}' //Pre-defined Goal
         (planList+=[Plan])+;

...

Plan:
	'plan' name=ID '{'
		(('event' eventName=[Event]) | ('goal' goalName=[Goal|ID]))
		'context' context=BoolExpr
		'body {'
			planBody+=Action*
		'}'
	'}'
;
...
//Action:
//       ... | ModifyGoal;

ModifyGoal returns SingleAction:
	planAction=('add' | 'delete') goalName=[Goal];

Goal:
	name=ID;

[Updated on: Mon, 12 March 2012 09:09]

Report message to a moderator

Re: Complex Cross Reference [message #819112 is a reply to message #818906] Mon, 12 March 2012 14:03 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
Where is the "nonInList" goal defined?

Btw [Goal] and [Goal|ID] means exactly the same thing.

- henrik

On 2012-12-03 10:07, Denis Brighi wrote:
> Thank you for the fast response :d
> I try to explain myself better...
> "Pre-defined" goal, are static-like task in my language, listed a priori.
> But i would like to define other Goal, not listed before, and use them
> to cross refernce
> the action ModifyGoal
>
> Is it more clear now?
>
> Ok... i did try the
>
> x = [GOAL | ID ]
> but when i run the editor and i try to write in a plan like this one:
>
> goals {
> goal1, goal2
> }
>
> plan piano1 {
> goal goal1 //OK
> context true
> body {
> ...
> }
> }
>
> plan piano1 {
> goal nonInListGoal //Error
> context true
> body {
> ...
> }
> }
>
> it continues to give me error: "Couldn't resolve reference to Goal
> 'nonInListGoal'."
>
> i attach the complete part of grammar to this point
>
> MainRule:
> 'goals {' ((goalsList+=Goal) (',' goalsList+=Goal)*)? '}' //Pre-defined
> Goal
> (planList+=[Plan])+;
>
> Plan:
> 'plan' name=ID '{'
> (('event' eventName=[Event]) | ('goal' goalName=[Goal|ID]))
> 'context' context=BoolExpr
> 'body {'
> planBody+=Action*
> '}'
> '}'
> ;
>
> //Action:
> // ... | ModifyGoal;
>
> ModifyGoal returns SingleAction:
> planAction=('add' | 'delete') goalName=[Goal];
>
> Goal:
> name=ID;
>
Re: Complex Cross Reference [message #819124 is a reply to message #819112] Mon, 12 March 2012 14:28 Go to previous messageGo to next message
Denis Brighi is currently offline Denis BrighiFriend
Messages: 5
Registered: March 2012
Junior Member
Quote:
Where is the "nonInList" goal defined?


Anywhere... it's a name for a new plan, defined there inside that plan...

In plan rule, i would reference - (a previously defined goal OR a new goal)
Re: Complex Cross Reference [message #819254 is a reply to message #819124] Mon, 12 March 2012 17:15 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
On 2012-12-03 15:28, Denis Brighi wrote:
> Quote:
>> Where is the "nonInList" goal defined?
>
>
> Anywhere... it's a name for a new plan, defined there inside that plan...
>
> In plan rule, i would reference - (a previously defined goal OR a new goal)

From a language perspective, it makes it hard to differentiate between
a reference to something that exists and it was not spelled correctly,
and something new.

If you use a keyword to denote the intent to create a new goal it is
both much easier to handle (works out of the box), and IMO would be help
users with potential errors.

i.e. something like:

('goal' goalRef = [Goal]) | ('new' 'goal' newGoal = Goal)

If you really want "if it does not exist, then create it" you need to
customize how the linking is done - either by customizing scoping or by
doing your own (additional) linking. There are some blog posts available
on the topic of linking to an EObject, and solving what it can reference
using scoping (don't have the URL handly - IIRC Meinte Boersma's blog).
If you want custom linking, I posted on that subject before.

PS: I would use the 'new' 'goal', saves you a lot of work.


- henrik
Re: Complex Cross Reference [message #819380 is a reply to message #819254] Mon, 12 March 2012 21:17 Go to previous messageGo to next message
Denis Brighi is currently offline Denis BrighiFriend
Messages: 5
Registered: March 2012
Junior Member
i think so... thank you very much!
Re: Complex Cross Reference [message #820784 is a reply to message #819254] Wed, 14 March 2012 15:04 Go to previous message
Denis Brighi is currently offline Denis BrighiFriend
Messages: 5
Registered: March 2012
Junior Member

I concluded with a complete listing of goal with a keyword,
like

goals {
goal1, goal2 disabled, goal3
}

So the effect is the same...

thank you very much for the help!

Previous Topic:Validation just for the changed elements?
Next Topic:Reference to implicit variable
Goto Forum:
  


Current Time: Thu Apr 18 22:52:38 GMT 2024

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

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

Back to the top