Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » cross-reference resolution
cross-reference resolution [message #698141] Mon, 18 July 2011 21:32 Go to next message
amazuzu  is currently offline amazuzu Friend
Messages: 17
Registered: May 2011
Junior Member
Hi

I have following grammar

Assignments:
	Assignment ({Assign.left=current} right=Assignment)*;

Assignment:
	name=ID "=" INT ";";


here I define variables e.g a=5; b=6;

all I want is to see already defined variable in content assist while creating reassignment

a=5;
b=6;
...[show me 'a' and 'b' please in content assist]...=7;


Actually I expected following will works, but...
Assignment:
	name=[Assignment|ID] "=" INT ";";

[Updated on: Mon, 18 July 2011 22:13]

Report message to a moderator

Re: cross-reference resolution [message #698259 is a reply to message #698141] Tue, 19 July 2011 06:19 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

I don't quite understand the Assignments rule. What is the reason to use actions here? Why not simply
Assignments: assignment+=Assignment*;
Also your use case is tricky as you don't syntactically distinguish the definition of a variable (first occurrence) and reference to an existing variable (second occurrence). The parser will not know the difference between the following two lines
a=5;
a=7;
It would be easier in this way
var a=5;
a=7;
Definition: 'var' name=ID '=' value=INT';';
Reference: ref=[Definition|ID] value=INT';';

Of course if it is only about code completion and not about the semantics of a model, you would only override the corresponding content assist rule for Assignment_name and propose the variable names defined before. However, from your model snippets, I don't see a way to get the behaviour out of the box. You will have to implement it outside the grammar.

Alex
Re: cross-reference resolution [message #699111 is a reply to message #698259] Wed, 20 July 2011 21:05 Go to previous messageGo to next message
amazuzu  is currently offline amazuzu Friend
Messages: 17
Registered: May 2011
Junior Member
Hi,
thanks for your answer.

Why first mention of variable can't be treated as declaration? Ok. I followed your advice and it works.

I encounter another problem, and I feel solution will not be trivial.

In my language following statements are valid
var foo = "Hello";
log foo;
log foo.length;  //note member access
log org.company.SomeClass;  //returns someth like '[class SomeClass]'


How here I can distinguish member access from qualified class name? Yes, I know xtext has no semantic predicates. May be you have some thoughts.


Thank

[Updated on: Wed, 20 July 2011 21:58]

Report message to a moderator

Re: cross-reference resolution [message #699221 is a reply to message #699111] Thu, 21 July 2011 06:00 Go to previous message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

I guess this will be hard to implement yourself. Look at Xbase and Xtend2. Buzzwords like expressions, type inference come to mind.

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
Previous Topic:View source for org.eclipse.emf.mwe2.runtime.workflow.Workflow
Next Topic:Reuse content assist from other EMF models
Goto Forum:
  


Current Time: Sun May 09 20:11:28 GMT 2021

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

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

Back to the top