Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Problem with Darwin(Implementing Darwin in Xtext problem)
icon8.gif  Problem with Darwin [message #651209] Fri, 28 January 2011 11:24 Go to next message
aleser  is currently offline aleser Friend
Messages: 2
Registered: January 2011
Junior Member
Hello!
Trying to implement Darwing DSL for students Lab work.
This is my grammar:

grammar org.xtext.example.Darwin with org.eclipse.xtext.common.Terminals

generate darwin "http://www.xtext.org/example/Darwin"

Darwin :
  (elements+=Component)*;
  
Component:
  'component' name=ID '{'
    (features+=Feature)*
'}';
  
Feature:
  Require | Provide | InstantiateSection | BindSection;
  
Require:
	'require' name=ID ';';

Provide:
	'provide' name=ID ';';	

InstantiateSection:
	'inst'
	 (insts+=Instance)*;

Instance:
	name=ID ':' type=ComponentRef ';';

BindSection:
	'bind'
	(binds+=Bind)*;

Bind:
	"bind" instance1=[Instance]
	"." port1=[Require]
	"--" instance2=[Instance]
	"." port2=[Provide] ';';
	 
	
ComponentRef:
	referenced=[Component](multi?='*')?;



Writing such a code:

component DataStore{
	provide landerValues;
}

component Calculation{
	require landerValues;
}

component Application{
	//provide landerValues;
	inst
		D : DataStore;
		C : Calculation;
	bind
		bind D.landerValues -- C.landerValues;
}


leads to errors:

Couldn't resolve reference to Require 'landerValues'.
Couldn't resolve reference to Provide 'landerValues'.
-------
Obviously landerValues are not accessible, becouse they are inside components. How do I remove these problems and also how do I make Eclipse showing in autocomplete only those 'required', which are inside DataStore component after typing D. ?

Thank you for help!

[Updated on: Fri, 28 January 2011 11:49]

Report message to a moderator

Re: Problem with Darwin [message #651217 is a reply to message #651209] Fri, 28 January 2011 12:55 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

slightly changes to the scoping should solve your problem.

public class MyDslScopeProvider extends AbstractDeclarativeScopeProvider {
	
	public IScope scope_Bind_instance1(Bind bind, EReference ref) {
		List<Instance> instances = new ArrayList<Instance>();
		for (Feature f : ((Component)bind.eContainer().eContainer()).getFeatures()) {
			if (f instanceof InstantiateSection) {
				InstantiateSection is = (InstantiateSection)f;
				instances.addAll(is.getInsts());
			}
		}
		return Scopes.scopeFor(instances);
	}
	
	public IScope scope_Bind_port1(Bind bind, EReference ref) {
		List<Require> requires = new ArrayList<Require>();
		for (Feature f : bind.getInstance1().getType().getReferenced().getFeatures()) {
			if (f instanceof Require) {
				requires.add((Require) f);
			}
		}
		return Scopes.scopeFor(requires, SimpleAttributeResolver.NAME_RESOLVER, IScope.NULLSCOPE);
	}
	
	public IScope scope_Bind_instance2(Bind bind, EReference ref) {
		List<Instance> instances = new ArrayList<Instance>();
		for (Feature f : ((Component)bind.eContainer().eContainer()).getFeatures()) {
			if (f instanceof InstantiateSection) {
				InstantiateSection is = (InstantiateSection)f;
				instances.addAll(is.getInsts());
			}
		}
		return Scopes.scopeFor(instances);
	}
	
	public IScope scope_Bind_port2(Bind bind, EReference ref) {
		List<Provide> provides = new ArrayList<Provide>();
		for (Feature f : bind.getInstance2().getType().getReferenced().getFeatures()) {
			if (f instanceof Provide) {
				provides.add((Provide) f);
			}
		}
		return Scopes.scopeFor(provides, SimpleAttributeResolver.NAME_RESOLVER, IScope.NULLSCOPE);
	}

}



btw your test model: should it not look like
component DataStore{
	provide landerValues;
}

component Calculation{
	require landerValues;
}

component Application{
	//provide landerValues;
	inst
		D : DataStore;
		C : Calculation;
	bind
		bind C.landerValues -- D.landerValues;
		
}


~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Problem with Darwin [message #651228 is a reply to message #651217] Fri, 28 January 2011 13:23 Go to previous message
aleser  is currently offline aleser Friend
Messages: 2
Registered: January 2011
Junior Member
Christian, thank you very much for fast reply! It helped! Now my students are supplied with simple Darwin tool! Smile

P.S. yes, test model was slightly incorrect

[Updated on: Fri, 28 January 2011 13:33]

Report message to a moderator

Previous Topic:Importing namespaces with syntax different from the default
Next Topic:Using other attribute than "name" for references
Goto Forum:
  


Current Time: Fri Apr 26 05:34:22 GMT 2024

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

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

Back to the top