|
Re: Complex Cross Reference [message #818633 is a reply to message #818593] |
Sun, 11 March 2012 23:38 |
Henrik Lindberg 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 #819254 is a reply to message #819124] |
Mon, 12 March 2012 17:15 |
Henrik Lindberg 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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04028 seconds