Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Unresolved cross references
Unresolved cross references [message #659614] Mon, 14 March 2011 19:44 Go to next message
Andreas Deinlein is currently offline Andreas DeinleinFriend
Messages: 6
Registered: July 2009
Junior Member
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 19:57 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
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


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Mon, 14 March 2011 20:07]

Report message to a moderator

Re: Unresolved cross references [message #659856 is a reply to message #659618] Tue, 15 March 2011 19:24 Go to previous message
Andreas Deinlein is currently offline Andreas DeinleinFriend
Messages: 6
Registered: July 2009
Junior Member
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: Sat Sep 21 02:22:49 GMT 2024

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

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

Back to the top