| Summary: | feature initialization definable in grammar rule | ||
|---|---|---|---|
| Product: | [Modeling] TMF | Reporter: | Robert Wloch <robert> |
| Component: | Xtext | Assignee: | Project Inbox <tmf.xtext-inbox> |
| Status: | CLOSED DUPLICATE | QA Contact: | |
| Severity: | enhancement | ||
| Priority: | P3 | CC: | bojidar.dimitrov, robert, sebastian.zarnekow, sven.efftinge |
| Version: | unspecified | ||
| Target Milestone: | --- | ||
| Hardware: | All | ||
| OS: | All | ||
| Whiteboard: | |||
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.
*** This bug has been marked as a duplicate of bug 326298 *** |
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