Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Restrict references scope to objects declared before (including objects from imports)
Restrict references scope to objects declared before (including objects from imports) [message #1773761] Wed, 04 October 2017 10:23 Go to next message
Erwann Traisnel is currently offline Erwann TraisnelFriend
Messages: 13
Registered: June 2017
Junior Member
Hello,

I am currently working on the validation of my DSL.

I would like to restrict references to all objects declared before in the text (both included and locally defined objects)

Here is an example grammar :
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

specification :
	includes+=include*
	definitions+=definition*
;
include :
	'#include' importURI=STRING ';'
;	
definition : 
	module | var_dcl
;
module :
	'module' name=ID '{'
		definitions+=definition*
	'}'
;
type_dcl : 
	'typedef' type=type_spec name=ID ';'
;
var_dcl : 
	type=type_spec name=ID ';'
;
type_spec :
	baseType | type_ref
;
type_ref :
	referencedType = [type_dcl | scoped_name]
;
baseType : 'double' | 'int' | 'char' ;
scoped_name: '.'? ID ('.' ID)*;

and an example model:

test2.myDSL
typedef int Int1

test.myDSL
#include "test2" ;

module myModule {
	Int1 var1; // OK, Int1 is defined before
	Int2 var2; // Wrong, Int2 is defined after	
	Int3 var3; // Wrong, Int3 is defined after
	typedef int Int2;
};
typedef int Int3;


I use the ImportURIScopingFragment in the MWE2 and I've bound an ImportURIResolver custom implementation in the RuntimeModule which resolves the include directive path against a list of base paths stored in the preferences. All references are correctly resolved.
Now, I'd like to restrict the scope to objects defined before their use as a reference.

I'm trying to cope with a custom scope provider, but I find it quite difficult...
Help welcome !

Erwann

Re: Restrict references scope to objects declared before (including objects from imports) [message #1778469 is a reply to message #1773761] Thu, 14 December 2017 15:17 Go to previous messageGo to next message
Erwann Traisnel is currently offline Erwann TraisnelFriend
Messages: 13
Registered: June 2017
Junior Member
This post is now 2 months old and I couldn't get that fixed .
Is there any solution ?

Erwann
Re: Restrict references scope to objects declared before (including objects from imports) [message #1778484 is a reply to message #1778469] Thu, 14 December 2017 18:19 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11900
Registered: July 2009
Senior Member
what es your exact problem doing that.?

unfortuantely what you shared is very few. maybe this pseudocode helps:

class MyDslScopeProvider extends AbstractMyDslScopeProvider {

override getScope(EObject context, EReference reference) {
if (reference == MyDslPackage.Literals.TYPE_REF__REFERENCED_TYPE) {
val List<EObject> scope = new ArrayList
val root =EcoreUtil2.getContainerOfType(context, specification)
// traverse model until you are at context
//scope += element found
return org.eclipse.xtext.scoping.Scopes.scopeFor(scope, delegateGetScope(context,reference))
}
super.getScope(context, reference)
}

}

your grammar naming convention is terrible btw



Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Previous Topic:UnitTest fails when running through Gradle
Next Topic:Migrating content assist tests to Xpect possible?
Goto Forum:
  


Current Time: Tue Apr 24 10:31:21 GMT 2018

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

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