Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to have both cross references and non cross references for a rule?
How to have both cross references and non cross references for a rule? [message #1850005] Thu, 10 February 2022 16:58 Go to next message
Madhangi Rathinasabapathi is currently offline Madhangi RathinasabapathiFriend
Messages: 3
Registered: February 2022
Junior Member
Hi,

I am facing this issue in my xtext grammar.

My usecase is that I need to have both references and non references as part of a single rule. Below is my grammar


Entity:
	entityName='Sample' name=INTID '{'
	(attrList+=(DefinedAttribute|NonDefinedAttribute))*
	'}');

DefinedAttribute:
	name=[ValueAttributeDefinition] ':' value=INT;

NonDefinedAttribute:
       name=ID  ':' value=INT;

ValueAttributeDefinition:
	'Attribute' name=ID '{'
	'}';



As part of this Entity I need to have attributes which are defined as part of ValueAttributeDefinition as well as Extra attributes which are not defined and not references to ValueAttributeDefinition.

But the problem is since ValueAttributeDefinition is also an ID internally, all attributes are getting parsed as DefinedAttribute. Please help in resolving this.

Sample data file below

    Attribute proper_attribute {
    }

    Sample 12234 {
         abc: 123
         proper_attribute: 456
    }


In the above data abc is also getting considered as DefinedAttribute during parsing.

Does anyone know how to resolve this?
Re: How to have both cross references and non cross references for a rule? [message #1850006 is a reply to message #1850005] Thu, 10 February 2022 19:17 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14699
Registered: July 2009
Senior Member
this is not possible. there might be workaround.
the question is: what are your requirements regarding the references.
and regarding the declaration.
do you just want to avoid getting an error for unresolved references?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to have both cross references and non cross references for a rule? [message #1850007 is a reply to message #1850006] Thu, 10 February 2022 19:26 Go to previous messageGo to next message
Madhangi Rathinasabapathi is currently offline Madhangi RathinasabapathiFriend
Messages: 3
Registered: February 2022
Junior Member
Yes the requirement is just to not throw up an error even if there are attributes with unresolved references which have not been predefined.
Re: How to have both cross references and non cross references for a rule? [message #1850010 is a reply to message #1850007] Thu, 10 February 2022 19:56 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14699
Registered: July 2009
Senior Member
then you can simply subclass and override
org.eclipse.xtext.linking.impl.LinkingDiagnosticMessageProvider.getUnresolvedProxyMessage(ILinkingDiagnosticContext)
and return null for the reference


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to have both cross references and non cross references for a rule? [message #1850018 is a reply to message #1850010] Fri, 11 February 2022 07:19 Go to previous messageGo to next message
Rubén Porras Campo is currently offline Rubén Porras CampoFriend
Messages: 67
Registered: July 2009
Member
Hi Madhangi,

if the NonDefinedAttribute can be anything, you can use the solution proposed by Christian, but it looks to me a weird grammar. Is it maybe that the NonDefinedAttribute refers to some built-in attributes? If so I would rather model those as well, as you would link to them normally because the moment you enable optional linking you cannot really tell the user if he may a mistake (e.g. a typo) or not.

Regards
Re: How to have both cross references and non cross references for a rule? [message #1850026 is a reply to message #1850018] Fri, 11 February 2022 10:30 Go to previous messageGo to next message
Madhangi Rathinasabapathi is currently offline Madhangi RathinasabapathiFriend
Messages: 3
Registered: February 2022
Junior Member
Hi Christian,

Thanks for the reply, Can you provide a sample of how to override org.eclipse.xtext.linking.impl.LinkingDiagnosticMessageProvider.getUnresolvedProxyMessage(ILinkingDiagnosticContext) or any documentation around this if possible? Also in which module should we override?

Hello Rubén Porras CampoFriend,

The NonDefinedAttribute can be anything that is not defined and I am having a requirement to support non defined attributes as well. I get this concern (you cannot really tell the user if he may a mistake (e.g. a typo) or not) but I want to try out to support NonDefined attributes as well.

[Updated on: Fri, 11 February 2022 10:37]

Report message to a moderator

Re: How to have both cross references and non cross references for a rule? [message #1850028 is a reply to message #1850026] Fri, 11 February 2022 11:11 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14699
Registered: July 2009
Senior Member
simply binding your subclass in runtime module does not work ?!??!?!?

public Class<? extends ILinkingDiagnosticMessageProvider> bindILinkingDiagnosticMessageProvider() {
		return CustomLinkingDiagnosticMessageProvider.class;
}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Xtext & Xtend Milestone 2.26.0.M3 is available now
Next Topic:Dsl runtime library
Goto Forum:
  


Current Time: Sat Jul 27 15:07:49 GMT 2024

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

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

Back to the top