Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Alternative types in cross references(How to distinguish a cross reference with different types)
Alternative types in cross references [message #1115504] Tue, 24 September 2013 07:33 Go to next message
Peter Simon is currently offline Peter SimonFriend
Messages: 3
Registered: September 2013
Junior Member
Hi all,
I got a grammar for our domain model where I need a cross reference to 2 different types.
In the parser rule ReferenceAttribute I should be able to distinguish between a Java-Type reference and a reference to another DomainObject (from another resource).
Of course it's not possible with an alternative (for the ANTLR parser it's the same thing).

What's the best (most default) way to achieve that?


Here's my simplified grammar:

grammar xy.domaindsl.DomainDSL with org.eclipse.xtext.common.Terminals
   hidden(WS, ML_COMMENT, NUM_COMMENT)

import "http://www.eclipse.org/framework/v1.0/DomainDSL" // It's of course not eclipse.org  :d 
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
import "http://www.eclipse.org/xtext/common/JavaVMTypes" as java

DomainModel:
   'package' name = QualifiedName ';'

   imports  += TypeImportDeclaration*
   elements += DomainObject*
;

TypeImportDeclaration:
   'import' importedNamespace = QualifiedName ';'
;

DomainObject:
   'bo' name = ID ('extends' superType = [BusinessObject|QualifiedName])?
   '{'
      description = MultipleSLComment?
      (attributes += Attribute)* 
   '}'
;

Attribute:
   (
      ReferenceAttribute     |
      ... other alternative attributes
   )
   description = SL_COMMENT?
;

ReferenceAttribute:
   type = ([DomainObject|QualifiedName] | [java::JvmGenericType|QualifiedName]) // That's the kind of thing I'd like to have
   name = ID
;



Thanks a lot for any help
Peter
Re: Alternative types in cross references [message #1115670 is a reply to message #1115504] Tue, 24 September 2013 12:15 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6482
Registered: July 2009
Senior Member
Hi,

this is afaik not possible. (parsing is done before linking.
you need either a common supertype or a kind of syntactic difference e.g. a prefix.
Re: Alternative types in cross references [message #1115676 is a reply to message #1115670] Tue, 24 September 2013 12:25 Go to previous messageGo to next message
Peter Simon is currently offline Peter SimonFriend
Messages: 3
Registered: September 2013
Junior Member
Hi Christian,
thanks for your reply.

As common supertype I have an ecore::EObject. In the attached grammar I just wanted to show what I'd like to have.
So actually the grammar rule looks like this:

ReferenceAttribute:
   type = [ecore::EObject|QualifiedName]
   name = ID
;


The problem is that I don't know exactly how the scoping should be implemented.

[Updated on: Tue, 24 September 2013 12:28]

Report message to a moderator

Re: Alternative types in cross references [message #1115682 is a reply to message #1115676] Tue, 24 September 2013 12:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6482
Registered: July 2009
Senior Member
Hi,


maybe something like (pseudo code)

	IScope scope_X_y(EObject ctx, EReference ref) {
		Predicate<IEObjectDescription> filter = new Predicate<IEObjectDescription>() {

			@Override
			public boolean apply(IEObjectDescription arg0) {
				return TypesPackage.Literals.JVM_GENERIC_TYPE.isSuperTypeOf(arg0.getEClass())
						|| MydslPackage.Literals.XXX_YYY.isSuperTypeOf(arg0.getEClass());
			}
		};
		return new FilteringScope(delegateGetScope(ctx, ref), filter);
	}
Re: Alternative types in cross references [message #1115701 is a reply to message #1115682] Tue, 24 September 2013 12:59 Go to previous message
Peter Simon is currently offline Peter SimonFriend
Messages: 3
Registered: September 2013
Junior Member
Thanks a lot works perfect.
Here how it looks like implemented in Xtend (DeclarativeScopeProvider).

def IScope scope_ReferenceAttribute_type (EObject context, EReference ref) {
      return new FilteringScope (delegateGetScope (context, ref)) [
         return TypesPackage.Literals.JVM_GENERIC_TYPE.isSuperTypeOf (it.EClass) 
                || DomaindslPackage.Literals.DOMAIN_OBJECT.isSuperTypeOf (it.EClass)
      ]
}

Previous Topic:Using DSL-Editor in an older Eclipse
Next Topic:Problem with Super Grammar and an Ecore based SubGrammar
Goto Forum:
  


Current Time: Fri Nov 21 19:34:57 GMT 2014

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

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