Skip to main content



      Home
Home » Modeling » TMF (Xtext) » cross-reference resolution
cross-reference resolution [message #698141] Mon, 18 July 2011 17:32 Go to next message
Eclipse UserFriend
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 18:13] by Moderator

Re: cross-reference resolution [message #698259 is a reply to message #698141] Tue, 19 July 2011 02:19 Go to previous messageGo to next message
Eclipse UserFriend
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 17:05 Go to previous messageGo to next message
Eclipse UserFriend
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 17:58] by Moderator

Re: cross-reference resolution [message #699221 is a reply to message #699111] Thu, 21 July 2011 02:00 Go to previous message
Eclipse UserFriend
Hi,

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

Alex
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: Fri Jul 25 09:12:23 EDT 2025

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

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

Back to the top