Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Duplicate elements error(How to handle duplicate elements error)
Duplicate elements error [message #659612] Mon, 14 March 2011 19:39 Go to next message
Andreas Deinlein is currently offline Andreas DeinleinFriend
Messages: 6
Registered: July 2009
Junior Member
Hi,

i am a beginner in xtext. 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
}
GROUP b IF a.a1 = 2
{
	INTEGER b2 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 validation error: " Duplicate Abstract Elements 'b' " In my case, this is not right, because the two groups have a different condition ! how could i prevent the validation error ?

Could I change the grammar to prevent the duplicate entries error ?

Thanks in advance.
Re: Duplicate elements error [message #659619 is a reply to message #659612] Mon, 14 March 2011 19:59 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6499
Registered: July 2009
Senior Member
Hi,

you can disable duplicate name checks for your grammar by removing

composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"


from your languages workflow

~Christian
Re: Duplicate elements error [message #659857 is a reply to message #659619] Tue, 15 March 2011 19:27 Go to previous messageGo to next message
Andreas Deinlein is currently offline Andreas DeinleinFriend
Messages: 6
Registered: July 2009
Junior Member
Ok, thanks, now i have no errors anymore !

Could you think of a solution where I deactivate or filter the duplicate names check only for these conditional groups, because apart from that exception, the duplicate names check would really help

Andreas
Re: Duplicate elements error [message #659870 is a reply to message #659857] Tue, 15 March 2011 20:11 Go to previous message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1159
Registered: July 2009
Senior Member
Hi,

I could imagine that the following works. Extend the NamesAreUniqueValidator overriding doCheckUniqueNames. You basically copy the method body but remove from descriptions those whose type is the one you do not want to be checked before passing them on to the helper.

Alternatively bind your own implementation of NamesAreUniqueValidationHelper and make that one ignore the objects you want to be ignored.

Alex
Previous Topic:Unresolved cross references
Next Topic:Retrieving the qualified name of a reference?
Goto Forum:
  


Current Time: Thu Nov 27 19:56:19 GMT 2014

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

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