0

Following to my question: here I am trying to customize the scoping. I want that in scope of 'Predicate' in my language some of objects will be visible in the scope, types like 'typeDef'.

Predicate:
    'predicate' name=ID ('(' params=TypedParamList ')')?
    (':' body=TemporalExpression TOK_SEMI)
    | ('{' body=TemporalExpression '}');

TypeDef:
    'type' name=ID '=' type=VarType TOK_SEMI;

Here is some example of my language:

type
  move = {left, right};

predicate stop(move m1, move m2) : 
  m1=left and m2=right;

It's not recognize left and right.(can't resolve reference)

I tried something like this:

            val allContentsCurrFile  = EcoreUtil2.eAllOfType(context,TypeDef)
            val allContentsCurrFile2  = EcoreUtil2.getAllContentsOfType(context,TypeDef)

I putted this as parameters to the Scopes.scopeFor method (in addition to the params of Predicate) and this isn't worked for me. I don't know how to do it, how to find all the instances of specific type in current file so the cross reference will work in the Predicate scope.

Thanks.

Community
  • 1
  • 1
RoG
  • 411
  • 4
  • 20
  • how does your actual cross ref look like? – Christian Dietrich Aug 08 '16 at 12:30
  • it's look like: pointer=[Referrable|QualifiedName] this is the cross ref. It's get from TemporalExpression (there are a lot of parsing rules until it's get to the reference). It's get in to the if statement `if (reference == SpectraPackage.Literals.TEMPORAL_PRIMARY_EXPR_HELPER__POINTER)` – RoG Aug 08 '16 at 12:37
  • And TypeDef is a Refferrable? – Christian Dietrich Aug 08 '16 at 12:38
  • yes. in varType there is: type=[TypeDef] – RoG Aug 08 '16 at 12:51
  • No I mean is Refferrable a super type of it. Did you try walking up in the scope provider – Christian Dietrich Aug 08 '16 at 12:55
  • Refferrable is not a super type of TypeDef. I can do it a super type. I tried doing it, but it doesn't help. – RoG Aug 08 '16 at 13:04
  • Can you please Share a complete minimal grammar testmodel and scope Provider – Christian Dietrich Aug 08 '16 at 13:06
  • This is a part of my grammar (I combined it with the Domainmodel example) if it's very long I will try to minimize it more.[link](http://pastebin.com/nyg1Cis9) and this is the ScopeProvider [link](http://pastebin.com/qzcAW5dY). This is the code `type move = {left, right}; predicate stop(move m1, move m2) : m1=left and m2=right;` In my full grammar the problem is that it's not recognize 'left' and 'right'. But, In this example it's not regocnize m1,m2 (i didn't succeed to fix the ref of m1 like in my real project) – RoG Aug 09 '16 at 10:37

1 Answers1

0

You have to walk up to the root of the from before you an walk down. EcoreUtil2.getContainerOfType(context, YourRootType) might help with this.

update:

The grammar and the example model don't fit, but that seems to be a completely different problem, so I can give only some hints.

You can only reference named elements to put those elements into the scope.

Grammar:

TypedParam:
    (module=[Import] '.')? type=[TypeDef] name=ID;

Referrable:
    TypedParam | TypeDef | TypeConstant;

Code:

val root = EcoreUtil2.getContainerOfType(context, Domainmodel)
val allContentsCurrFile  = EcoreUtil2.getAllContentsOfType(root,TypeConstant) 
Ben Holland
  • 2,309
  • 4
  • 34
  • 50
Christian Dietrich
  • 11,778
  • 4
  • 24
  • 32