Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Question about enum rules
Question about enum rules [message #557611] Wed, 08 September 2010 09:43 Go to next message
Michael Frey is currently offline Michael FreyFriend
Messages: 48
Registered: August 2010
Member
Hi,

the Xtext documentation states that it's possible to define enumeration rules which return enumeration literals. I'm wondering if there is a mechanism to define a enumeration of grammar elements which return a element of a grammer. I've stucked multiple times in a situation where I want to assign an attribute of a rule different values, e.g.

TagOperator:
  'tag''('parameters+=TagOperatorParameters(',' parameters+=TagOperatorParameters)*')';

TagOperatorParameters:
  reference=[StreamElement] 'is' element=([OWL::OWLClass]) | [OWL::OWLObjectProperty]);


If I try that I get multiple warnings that alternatives are disabled. I'm pretty sure that I'm missing something and maybe somebody can provide a pattern for dealing with such rules?

Thanks in advance!
Regards,
Michael
Re: Question about enum rules [message #557614 is a reply to message #557611] Wed, 08 September 2010 10:25 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

without testing it out but why not:

TagOperator:
  'tag''('parameters+=TagOperatorParameters(',' parameters+=TagOperatorParameters)*')';

TagOperatorParameters:
  reference=[StreamElement] 'is' (element=[OWL::OWLClass]) | element=[OWL::OWLObjectProperty]);


of course OWL::OWLClass and OWL::OWLObjectProperty have to have a common superclass.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Wed, 08 September 2010 10:26]

Report message to a moderator

Re: Question about enum rules [message #557624 is a reply to message #557614] Wed, 08 September 2010 11:24 Go to previous messageGo to next message
Michael Frey is currently offline Michael FreyFriend
Messages: 48
Registered: August 2010
Member
Hi,

thanks for your reply. Unfortunateley they don't share a common super type. Any workaround for that case? I've thought I could be smart and change your suggestion a bit, e.g.

TagOperatorParameters:
  reference=[StreamElement] 'is' (cElement=[OWL::OWLClass] | pElement=[OWL::OWLObjectProperty]);


But that causes nearly the same error.

Regards,
Michael
Re: Question about enum rules [message #557650 is a reply to message #557624] Wed, 08 September 2010 12:37 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
Alternatives being disabled is a sign that your grammar is ambiguous, (in this case) meaning that a set of alternatives can consume the same tokens (quite probably both OWL types have a 'name' attribute which fit the ID terminal rule, which is the default parser rule used in cross-references) so the parser will not be able to determine which alternative to choose. (The error's actually an ANTLR error.) This also explains why your 2nd solution doesn't solve it, since parsing is still ambiguous even though the alternatives would end up in different attributes.

The solution usually is to make a common super type for the set of alternatives (which may be a problem since your OWL types are not part of or generated from your grammar) and make the cross-reference using that super type. You might have to use custom scoping to populate the local scope.

Btw: I'm completely missing the link to enum rules Wink Maybe you mean "enum-like constructs" in the DSL, rather than enum rules in the grammar?


Re: Question about enum rules [message #557697 is a reply to message #557650] Wed, 08 September 2010 14:44 Go to previous messageGo to next message
Michael Frey is currently offline Michael FreyFriend
Messages: 48
Registered: August 2010
Member
Hi,

thank you for your reply. What exactely do you mean by custom scoping" and "populate the local scope"?

Regards,
Michael

P.S.: About the enum rules - I've thought that it must be possible to define set of elements which can be assigned to a "attribute". At least I think that this is done by a common supertype of multiple elements which can be assigned to a certain type (as you stated in your post).
Re: Question about enum rules [message #557708 is a reply to message #557697] Wed, 08 September 2010 15:09 Go to previous message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
Michael, it seems as if we're using different languages here and it's not English vs. German being the problem!

Judging from your other posts, you're diving head-first into the whole Xtext ecology, trying to achieve a lot of things at the same time apparently without really having read the Xtext User Guide. As a consequence, you're a bit hard to follow since you're not completely conversant in the local Domain-Specific Language, the domain being "Xtext and its ecology". This is especially problematic as we're travelling across "meta-boundaries" all the time which makes it necessary to formulate everything quite precise to be understandable.

Now, that user guide is certainly not for the faint at heart but the core concepts are generally nearer to the beginning than to the end of the thing: custom scoping and local scope are definitely explained in the earlier chapters.

Word of advice: take it (more) slowly and try to read the User Guide, reflecting that which you know, and branching into the unknown. At the very least, it makes it easier for us to help you.


Previous Topic:Open xtext script file in my studio's editor, error emerges
Next Topic:Question about Cross-References
Goto Forum:
  


Current Time: Fri Apr 26 11:44:41 GMT 2024

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

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

Back to the top