Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Unresolved cross references
Unresolved cross references [message #659614] Mon, 14 March 2011 15:44 Go to next message
Eclipse UserFriend
Hi,

I am trying to create a grammar for my DSL.
Here is an example:
GROUP a
{
	INTEGER a1 DEFAULT 1
}
GROUP b IF a.a1 = 1
{
	INTEGER b1 DEFAULT 1
}


I created the following grammar:
grammar org.xtext.example.config.MyConfig with org.eclipse.xtext.common.Terminals

generate myConfig "http://www.xtext.org/example/config/MyConfig"

Model:
	elements+=AbstractElements*;

AbstractElements:
	Parameter | Group;

Group:
	'GROUP' name=ID ('IF' (condition+=Condition)* )?
	'{'
		(parameters+=Parameter)*
	'}';

Parameter:
	'INTEGER'  name=ID 'DEFAULT' default=INT;

Condition:
	EquationCondition;

EquationCondition:
	group=[Group|ID]'.'parameter=[Parameter|ID] '=' value=INT;


I get the following error: " Couldn't resolve reference to Parameter 'a1' " in the line with the "IF". How could I change the cross reference in the grammar to resolve the reference to 'a1' in group 'a' ?

Thanks.
Re: Unresolved cross references [message #659618 is a reply to message #659614] Mon, 14 March 2011 15:57 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

the (qualified) name of the parameters is contructed of its and its parents names. so in your case the qualified name is a.a1. you have to adapt NameProvider and Scoping

public class MyQNP extends DefaultDeclarativeQualifiedNameProvider {
	
	public String qualifiedName(Parameter p) {
		return p.getName();
	}

}


public class MyDslRuntimeModule extends org.xtext.example.mydsl.AbstractMyDslRuntimeModule {

	@Override
	public Class<? extends IQualifiedNameProvider> bindIQualifiedNameProvider() {
		return MyQNP.class;
	}
	
}


public class MyDslScopeProvider extends AbstractDeclarativeScopeProvider {
	
	public IScope scope_EquationCondition_parameter(EquationCondition ec, EReference ref) {
		return Scopes.scopeFor(ec.getGroup().getParameters());
	}

}


or you change the grammer to make use of the QualifiedNames

EquationCondition:
	parameter=[Parameter|FQN] '=' value=INT;

FQN: ID ("." ID)*;


~Christian

[Updated on: Mon, 14 March 2011 16:07] by Moderator

Re: Unresolved cross references [message #659856 is a reply to message #659618] Tue, 15 March 2011 15:24 Go to previous message
Eclipse UserFriend
Thanks !

I used the second proposal and changed my grammar. It works fine.

Andreas
Previous Topic:Xtext project from an existing ecore model : generation impossible
Next Topic:Duplicate elements error
Goto Forum:
  


Current Time: Mon Jul 14 05:43:32 EDT 2025

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

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

Back to the top