Problem with Darwin [message #651209] |
Fri, 28 January 2011 11:24 |
aleser 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 |
|
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.23042 seconds