Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Restrict default cross reference scope.
Restrict default cross reference scope. [message #1242440] Sun, 09 February 2014 15:10 Go to next message
George P is currently offline George PFriend
Messages: 1
Registered: February 2014
Junior Member
Hello everybody,

I have an example myDsl Xtext grammar:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "http://www.eclipse.org/example/mydsl/MyDsl"

Model:
	loops+=Loop*;

Loop:
	For
;

For:
	'for' '('(ID varName = VarName)')' 'where' typedVar = [VarName] '>' INT
;

VarName:
	name = ID
;



The above Xtext grammar uses VarName as a cross reference for being able to refer only to variable names that were defined.

Example of myDsl file:
for (Integer s) where s > 10
for (Double b)	where b > 100
for (Long d) where //when content assist is invoked all VarName references are shown


Requirements:

1. In the example above, the last "for" should give as content assist suggestion only variable d. (not all variables) - I want to reduce the scope only per "for" declaration
2. Also if my project contains multiple myDsl files, I want to get suggestions for VarNames only from current file. - disable global scope of VarNames.

Can someone suggest an easy and clean way to achieve both requirements?

I was thinking to override the content assist for the VariabileName part (no use of cross references). However, in this case the functionality already provided by Xtext would be disabled and I have then to perform additional validation for VarNames that are used but not defined.


Many thanks!

Re: Restrict default cross reference scope. [message #1242855 is a reply to message #1242440] Mon, 10 February 2014 07:20 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

i am not sure what your problem is. there are many examples, blogs,... out there

Quote:

IScope scope_<RefDeclaringEClass>_<Reference>(
<ContextType> ctx, EReference ref)

IScope scope_<TypeToReturn>(<ContextType> ctx, EReference ref)


you can restrict specific cross refs scope by

scope_For_typedVar(For ctx, EReference r)

you can restrict the scope for a specific type and context by

scope_VarName(YourRoot ctx, EReference r)

collect the valid stuff to a list and your scopes.scopefor to wrap them into a scope


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Restrict default cross reference scope. [message #1243002 is a reply to message #1242855] Mon, 10 February 2014 11:24 Go to previous message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 250
Registered: June 2013
Senior Member
perhaps a look at: http://xtextcasts.org/episodes/17-restricting-scope would be helpful.

There is a comment how to reduce scope to the DSL file only.
Previous Topic:Version of dependencies when using xtext
Next Topic:Retrieving / reverse engineering grammar file from existing JavaCC generated parser
Goto Forum:
  


Current Time: Tue Apr 23 08:25:19 GMT 2024

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

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

Back to the top