Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 316862 - feature initialization definable in grammar rule
Summary: feature initialization definable in grammar rule
Status: CLOSED DUPLICATE of bug 326298
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-15 04:24 EDT by Robert Wloch CLA
Modified: 2010-09-27 09:07 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Robert Wloch CLA 2010-06-15 04:24:55 EDT
In order to be more flexible with grammars for existing domain models, I'd like to be able to define inital values for features in the grammar. Please, consider this example:

[CODE]
Interface returns myModel::Class:
    'interface' name=ID interface?=INITIALIZE(true)
    ('extends' implementedTypes+=Type
    	(',' implementedTypes+=Type)*
    )?;

Class returns myModel::Class:
    'class' name=ID interface?=INITIALIZE(false)
    ('extends' superTypes+=Type
    	(',' superTypes+=Type)*
    )?
    ('implements' implementedTypes+=Type
    	(',' implementedTypes+=Type)*
    )?;
[/CODE]

It shows how one could implizitely initialize a boolean feature "interface". But a similar approach should also work for strings, numbers, or cross references.
I mentioned that request already in the newsgroup: http://www.eclipse.org/forums/index.php?t=msg&th=170024&start=0&

Cheers
Rob
Comment 1 Bojidar CLA 2010-07-21 04:10:02 EDT
I too would like to have this feature!  It would allow much easier generator rules and some things which right now are not (easily) possible.

Here is my example:

Person: 
        name=ID canTalk?=INITIALIZE(true);

Parrot: 
        name=ID canTalk?='canTalk'; 

Mouse: 
        name=ID canTalk?=INITIALIZE(false); 

Participant: 
        Person | Parrot | Mouse; 

I am using the syntax proposed by Robert, but surely shorter syntax could be invented.  The advantage of this initialization is that now all three participants have a boolean feature canTalk and this is uplifted in Participant, so now I can write a define like this:

«DEFINE main FOR Participant» 
     «IF canTalk»Participant «name» can talk. «ENDIF» 
«ENDDEFINE» 

Of course, I could solve the problem with the current features of XText by using extensions, but by far not as elegantly as the example above.

And using the proposed grammar above, I can also write model checks (*.chk) for a Participant, and for checks it seems impossible to use extensions (at least I was not able to get them to work), so the proposed grammar extension seems to be the only solution.
Comment 2 Sven Efftinge CLA 2010-09-27 09:07:37 EDT

*** This bug has been marked as a duplicate of bug 326298 ***