Access to the fields of a package (Tree structure) [message #1809878] |
Thu, 25 July 2019 09:31 |
Martin BREUNEVAL 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 #1809902 is a reply to message #1809893] |
Thu, 25 July 2019 12:55 |
Martin BREUNEVAL 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 |
|
> 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
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Powered by
FUDForum. Page generated in 0.06556 seconds