Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Another cross-referencing question
Another cross-referencing question [message #1016625] Thu, 07 March 2013 03:16
Pascal Degenne is currently offline Pascal Degenne
Messages: 5
Registered: September 2012
Junior Member
Hi everyone,

I built a DSL with XBase expressions. In order to create my own simple types, I added to the grammar something like that :
    Typedef : 'alias' name=ID type=JvmTypeReference

    Entity : 'entity' name=ID '{'
      (vardefs += EntVarDef)*
    '}';

    EntVarDef : type = [Typedef] name=ID ;

I can then write things like :
    alias text java.lang.String
    alias geom my.own.GeomClass
    
    entity Foo {
      text fooId
      geom geometry
    }

And with a JvmModelInferrer generating a class for every entity, it works great.

Now I would like to be able to reuse a declared entity as being the type for an entity internal variable. In other words, I'd like to be able to append to that model someting like this :
    entity Bar {
      text BarId
      Foo fooVar
    }

I could do that if I was allowed to write this in the grammar :
    EntVarDef : type = [Typedef] | [Entity] name=ID;

But I am not allowed to do so. I tried to subtype JvmTypeReference but I am not allowed to do so either.

I tried several other things so far, like subtyping :
    EntVarDef : type = [VarType|ID] name=ID;
    
    VarType : Typedef | Entity

Which looks to be ok for validation but I run into problems when trying to write the JvmModelInferrer (how to give a JvmReferenceType to the toField() method ?)

I also tried a solution like this :
   Typedef returns JvmTypeReference : 'alias' name=ID type=JvmTypeReference
   ...
   EntVarDef : type = JvmTypeReference name=ID ;

and it allows me to reuse a declared entity but I do not have access to my alias types any more.

Well, in your opinion, what best way should I explore further to obtain the expected behavior ?

I advance, thank you for your help.

[Updated on: Thu, 07 March 2013 04:36]

Report message to a moderator

Previous Topic:Automatic Validation ( NoViableAltException)
Next Topic:Is Xtext right for me?
Goto Forum:
  


Current Time: Thu Jul 24 23:40:42 EDT 2014

Powered by FUDForum. Page generated in 0.01542 seconds