Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Grammar element with cross-reference
Grammar element with cross-reference [message #1409736] Mon, 18 August 2014 21:55 Go to next message
Bryan Banz is currently offline Bryan BanzFriend
Messages: 10
Registered: August 2009
Junior Member
I'm struggling to figure out how (if possible) to define my grammar such that I can specify either an entity or a cross-reference to an entity of the same type, e.g.:


Entity:
'entity' name = ID id = STRING
form = (FormRef | [FormRef])
;

Form:
'form' name = ID
....
;

When I generate the XText artifacts I get the following warning:

Decision can match input such as "'form' RULE_ID RULE_STRING" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input

And then when running my model, I can only parse input for an explicit definition of form and not the cross-reference.

Is there any way to accomplish this?


Can anyone offer me some assistance or direction?

Thanks!
Re: Grammar element with cross-reference [message #1409821 is a reply to message #1409736] Tue, 19 August 2014 04:12 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,


Ecore does not support such a pattern.

you have to decide for containment or non containment.

second the grammar has to be non ambigous.

so the cross ref and the containment ref may not be represented by the same thing.

the grammar your posted is missing the most important stuff so it is impossible to give a working example grammar


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Grammar element with cross-reference [message #1409989 is a reply to message #1409821] Tue, 19 August 2014 13:54 Go to previous messageGo to next message
Bryan Banz is currently offline Bryan BanzFriend
Messages: 10
Registered: August 2009
Junior Member
Hi Christian, thanks for the response.

Oops, I realized that in creating my example grammar I wasn't consistent. In my example, Form and FormRef were supposed to be the same rule...


So my understanding is that my rule (Entity) must have two assignable attributes, one for supporting a cross ref and one for defining the object in place. Like so:

Model:
(entities += Entity)*
(forms += Form)*
;

Entity:
'entity' name = ID id = STRING
(formref = [Form])?
(form = Form)?
;

Form:
'form' name = ID
....
;


This grammar will create an EObject for Entity with a 'formref' and 'form' attribute, both typed as a 'FormRef'. I was hoping that I could unify these into one attribute, but perhaps not. It would be nice, so that in all the supporting code I don't have to have checks such as

if(entity.form != null)
doSomethingWith(entity.form)
else
doSomethingWith(entity.formRef)


Does this make my goals more clear?

Thanks!
Re: Grammar element with cross-reference [message #1410001 is a reply to message #1409989] Tue, 19 August 2014 14:31 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
you can only do this if you do

oneAttribute=Parent;

Parent : Child | Childref;

Child : "child" name=ID

Childref: ref=[Child]


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:xtextbin
Next Topic:Parsing single line commands
Goto Forum:
  


Current Time: Fri Apr 19 02:09:27 GMT 2024

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

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

Back to the top