Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to solve multiple inheritance within a DSL(Problem to solve member collision in a C++ like approach)
How to solve multiple inheritance within a DSL [message #1733166] Tue, 24 May 2016 14:34 Go to next message
Claudenir Fonseca is currently offline Claudenir FonsecaFriend
Messages: 8
Registered: February 2016
Junior Member
Hello all,

I'm having a problem which envolves multiple inheritance/instantiation, scopping and qualified names. I've tried but I don't even know how to find a solution.

I'm developing a DSL where one can declare types and their properties, and instances and the values of properties. The grammar looks like this.

Type:
     'type' name=ID 'specializes' (superTypes+=[Type|QualifiedName])*
     ( '{'
          ( properties+=PropertyDeclaration )* 
     '}')? ';'
;

Instance:
     'instance' name=ID ':' (types+=[Type|QualifiedName])*
     ( '{'
          ( propertyAssignments+=PropertyAssignments )* 
     '}')? ';'
;

PropertyDeclaration:
     name=ID ':' type=[Type|QualifiedName]
;

PropertyAssignment:
     property=[Property] '=' value=STRING
;


An example code could be:
type String;

type Person {
     name : String
};

instance Bob : Person {
     name = "Bob Marley"
}


As you can imagine, a instance can only assign a value to a instantiated property. In case of name collision (due to multiple instantion) I want to write a code like this:

type Person {
     name : String
     age : String
};
type SystemUser {
     name : String
};

instance Bob : Person SystemUser {
     age = "30"
     Person.name = "Bob Marley"
     SystemUser.name = "bobmarley123"
}


Does anyone knows how to implement this? I don't want to force a DSL user to write a QualifiedName for every property assignment. I would like to have non-collision cases automatically resolved.
Re: How to solve multiple inheritance within a DSL [message #1733214 is a reply to message #1733166] Wed, 25 May 2016 13:06 Go to previous message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
Write a scope provider that offers the properties of all types with their qualified name and the non-ambiguous ones with their simple name.

Allow QualifiedName syntax in the PropertyAssignment.property x-ref as well:

PropertyAssignment:
     property=[Property|QualifiedName] '=' value=STRING
;


The QualifiedName should also allow simple names, e.g:

QualifiedName:
 ID ('.' ID)*;


---
Get professional support from the Xtext committers at www.typefox.io
Previous Topic:Terminal rule for any text
Next Topic:Real business benefits of Xtext
Goto Forum:
  


Current Time: Tue Nov 12 05:44:59 GMT 2019

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

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

Back to the top