Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Cross-referencing only if object exists(Xtext 2.0)
Cross-referencing only if object exists [message #716240] Tue, 16 August 2011 18:25 Go to next message
Lucy Sakhnenko is currently offline Lucy SakhnenkoFriend
Messages: 41
Registered: March 2011
Member
Hi, I'm having a hard time trying to do this:

Model:
	(def+=Def)+
	ref=Ref
;

Def:
	'def:' name=QualifiedName
;

QualifiedName:
	'*'ID
;

Ref:
'ref:' ref=RefVar
;

RefVar:
	crossRef=[Def|QualifiedName] | newValue=QualifiedName
;


Of course, if I try to generate the artifacts for my dsl, I will get:

Decision can match input such as "'*' RULE_ID" using multiple alternatives: 1, 2


What I am trying to do is to let the programmer do two things:

1. Define a variable and then, use it.
2. Use a variable which was never defined.

If the variable was defined, a cross-reference should be made to the definition.
If the variavle was not defined, a name '*'ID should be used without trying to resolve any cross-reference.

I have no hints at all about how to do this.

How could I achieve this?

Thanks!









Re: Cross-referencing only if object exists [message #716366 is a reply to message #716240] Wed, 17 August 2011 07:51 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

personally, I would consider that "sub-optimal" language design. Either I want a cross reference to an existing object or I want to define a new one. You even have a syntactic indicator that it *is* a reference, so why should it be possible to define something new there.

Anyway, your proposed grammar snippet will not work no matter what you do. The parser has to decide which feature is to be instantiated (cross reference or "simple" attribute). It cannot do so based on the input, in both cases it is a qualified name. It is not the parser's responsibility to do the linking (the linker will do that after the parser is done). Either you create new dummy objects during linking or you live with unresolved cross references.

As I said, I consider the latter alternative the clean solution, it correctly tells the user "the object you want to reference does not exist, define it if you want" (you could even implement a quickfix that would create a corresponding definition).

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: Cross-referencing only if object exists [message #716513 is a reply to message #716366] Wed, 17 August 2011 15:16 Go to previous messageGo to next message
Lucy Sakhnenko is currently offline Lucy SakhnenkoFriend
Messages: 41
Registered: March 2011
Member
Thanks, Alexander. I agree with you about the language design, however, it is a requierement that the dsl works that way Sad, so I have to exhaust all the possibilities before changing the language design.

I think I could use your alternative of " tells the user "the object you want to reference does not exist, define it if you want"", but I must change the message severity to "warning".


I'm extending LinkingDiagnosticMessageProvider, but I don't see which method I have to override in the RuntimeModule. I thought It would be something like bindISyntaxErrorMessageProvider, but is not.

Any ideas or further suggestions?

Thanks!






Re: Cross-referencing only if object exists [message #716524 is a reply to message #716513] Wed, 17 August 2011 15:47 Go to previous message
Lucy Sakhnenko is currently offline Lucy SakhnenkoFriend
Messages: 41
Registered: March 2011
Member
Sorry,

I saw I have to register my LinkingDiagnosticMessageProvider in the UI Module.
Previous Topic:Finding reason for IParser.NullImpl usage
Next Topic:Xtend generation File attributes
Goto Forum:
  


Current Time: Thu Mar 28 11:38:58 GMT 2024

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

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

Back to the top