Skip to main content



      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 11:58 Go to next message
Eclipse UserFriend
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 14:17 Go to previous messageGo to next message
Eclipse UserFriend
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?
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 14:26 Go to previous messageGo to next message
Eclipse UserFriend
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 14:56 Go to previous messageGo to next message
Eclipse UserFriend
then you can simply subclass and override
org.eclipse.xtext.linking.impl.LinkingDiagnosticMessageProvider.getUnresolvedProxyMessage(ILinkingDiagnosticContext)
and return null for the reference
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 02:19 Go to previous messageGo to next message
Eclipse UserFriend
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 05:30 Go to previous messageGo to next message
Eclipse UserFriend
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 05:37] by 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 06:11 Go to previous message
Eclipse UserFriend
simply binding your subclass in runtime module does not work ?!??!?!?

public Class<? extends ILinkingDiagnosticMessageProvider> bindILinkingDiagnosticMessageProvider() {
		return CustomLinkingDiagnosticMessageProvider.class;
}
Previous Topic:Xtext & Xtend Milestone 2.26.0.M3 is available now
Next Topic:Dsl runtime library
Goto Forum:
  


Current Time: Sat Jul 05 11:07:57 EDT 2025

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

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

Back to the top