Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Access to the fields of a package (Tree structure)
Access to the fields of a package (Tree structure) [message #1809878] Thu, 25 July 2019 09:31 Go to next message
Martin BREUNEVAL is currently offline Martin BREUNEVALFriend
Messages: 17
Registered: July 2019
Junior Member
Hello xTexters,

I have a question concerning this code :

grammar org.xtext.metalist.Metalist with org.eclipse.xtext.common.Terminals

generate metalist "http://www.xtext.org/metalist/Metalist"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore


METALIST:
packages+=Package+;

Package:
	'_¡' name=packageName 
	nb=nbField '®'
	(fields+=Fields)+
	'®';
Fields:
	{Fields} numField  '¡' name=field? '¡' 
	'×'?
;

. . .

(packageName and field are simple IDs)

This is the structure of the declaration of a package and its fields. (definition dedicated DSL)

Now i'd like to have the fields parsed and content assisted according to the package they are contained in.

I'd need to use something of the form "package.field" in many statement so i created this rule in my main DSL

PackageFieldExpression:
	pack=[ML::Package|MAJID] ('.' field=[ML::Fields|MAJID])?
;

¨

I can already access to my package easily but i can' access the fields corresponding to the package, having couple of errors.

Do you know how i could achieve this ? I tried may solutions including this one : https://stackoverflow.com/questions/21306822/xtext-dsl-reference-to-attribute that seemed similar to my situation but it didn't solve it.

Thank u

[Updated on: Thu, 25 July 2019 10:12]

Report message to a moderator

Re: Access to the fields of a package (Tree structure) [message #1809883 is a reply to message #1809878] Thu, 25 July 2019 09:41 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 13158
Registered: July 2009
Senior Member
How does your scope provider look like
Is AbstractDeclarativeScopeProvider the parent class


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Access to the fields of a package (Tree structure) [message #1809887 is a reply to message #1809883] Thu, 25 July 2019 10:16 Go to previous messageGo to next message
Martin BREUNEVAL is currently offline Martin BREUNEVALFriend
Messages: 17
Registered: July 2019
Junior Member
For the moment, my ScopeProvider looks lite this :
/*

package org.xtext.itl.scoping

import org.xtext.itl.iTL.PackageFieldExpression
import org.eclipse.xtext.scoping.IScope
import org.eclipse.emf.ecore.EReference

import org.eclipse.xtext.scoping.Scopes

class ITLScopeProvider extends AbstractITLScopeProvider {
	
    def IScope scope_PackageFieldExpression_field(PackageFieldExpression dat, EReference ref) {
        return Scopes.scopeFor(dat.pack.fields)
    }
 
}

Is it ok to replace my parent class AbstractITLScopeProvider with AbstractDeclarativeScopeProvider ?
Re: Access to the fields of a package (Tree structure) [message #1809889 is a reply to message #1809887] Thu, 25 July 2019 10:27 Go to previous messageGo to next message
Martin BREUNEVAL is currently offline Martin BREUNEVALFriend
Messages: 17
Registered: July 2019
Junior Member
I works great with what you suggested thank you i missread! Modyfing this extend class won't cause any problem?
Re: Access to the fields of a package (Tree structure) [message #1809893 is a reply to message #1809889] Thu, 25 July 2019 11:08 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 13158
Registered: July 2009
Senior Member
no it wont.
but you are encoraged to implement the existing scope provider class by overriding getScope and if else on context and ereference parameters


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Access to the fields of a package (Tree structure) [message #1809902 is a reply to message #1809893] Thu, 25 July 2019 12:55 Go to previous messageGo to next message
Martin BREUNEVAL is currently offline Martin BREUNEVALFriend
Messages: 17
Registered: July 2019
Junior Member
Allright, got it, thank you.

I have another related question. Is it the same way to operate for this kind of rule ?
AddOccStatement: {AddOccStatement} ('ADDOCC') addocPack=[ML::Package] (('PARENT') parentPack=[ML::Package])? (('WITH') fieldAssignList=FieldAssignList)?;

FieldAssign  : fieldToAssign=[ML::Fields] compareOperator compare=data ;
FieldAssignSingle: => list+=FieldAssign (',' list+=FieldAssign)* ;


FieldAssignList: (list+=FieldAssignSingle)+; 


I came up to this so far :
 def IScope scope_AddOccStatement_fieldToAssign(AddOccStatement dat, EReference ref) {
        return Scopes.scopeFor(dat.addocPack.fields)
    }
    

But it doesn' seem to work out since the fields are
in an inner rule of an inner rule

[Updated on: Thu, 25 July 2019 13:00]

Report message to a moderator

Re: Access to the fields of a package (Tree structure) [message #1809909 is a reply to message #1809902] Thu, 25 July 2019 14:15 Go to previous message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 13158
Registered: July 2009
Senior Member
> But it doesn' seem to work out since the fields are
> in an inner rule of an inner rule
yes and no. there are two problems. scoping vs content assist.

for scoping scope_FieldAssign_fieldToAssign(FieldAssign ctx, EReference r) // this is cause objects are created lazy (after the assignment
but the scope provider will ask for

scope_FieldAssign_fieldToAssign(AddOccStatement ctx, EReference r) too (it will walk up the parents until it finds something


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Multiple QualifiedProviders within a DSL language
Next Topic:Model meta elements and their instances?
Goto Forum:
  


Current Time: Wed Oct 16 16:39:55 GMT 2019

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

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

Back to the top