0
votes

If I have an Xtext grammar like the one below:

grammar org.xtext.example.mydsl.ServerGeneratorLanguage with org.eclipse.xtext.common.Terminals

generate serverGeneratorLanguage "http://www.xtext.org/example/mydsl/ServerGeneratorLanguage"

Model:
  (types+=Type)*;

Type:
  Server | DomainModel;

Server:
    "SERVER" name=ID "{"
        "CONFIG" "{"
        (Configs+=Config)*
            "}"
  "}";

Config:
    rootConfig | hostNameConfig | portConfig | logConfig | sqldbConfig | resourceConfig;

rootConfig:
    "ROOTDIR" "=" name=ID;

hostNameConfig:
    "HOSTNAME" "=" name=ID;

portConfig:
    "PORT" "=" name=ID;

logConfig:
    "LOG" "=" name=ID;

sqldbConfig:
    "SQLDB" "=" name=ID;

resourceConfig:
    "RESOURCE" "=" name=ID;

DomainModel:
    "DOMAINMODEL" name=ID "{"
        "ENTITYS" "{"
            (Entitys+=Entity)*
        "}"
        "ENTITY_RELATIONSHIP" "{"
            (Relationships+=Relationship)*
        "}" 
    "}";

Entity:
    name=ID "{"
        (Attributes+=Attribute)*
    "}";

Attribute:
    StringAttribute | NumberAttribute | ImageAttribute;

StringAttribute:
    "STRING" name=ID;

NumberAttribute:
    "NUMBER" name=ID;

ImageAttribute:
    "IMAGE" name=ID;

QualifiedName:
    ID ('.' ID)*;

Relationship:
    name=[Attribute|QualifiedName] "->" refName=[Attribute|QualifiedName];

How do I access the name-ID part of each Config object from a higher level than Server. Let me explain:

I want to generate code by collecting data from Server.configs.eClass.name AS WELL AS DomainModel.blahblah.eClass.name. I assume I need to access it from Type, but I can't seem to get there in Xtend.

From Server I can access all the components Server.configs.eClass.name.

Thank you for the help.

1

1 Answers

0
votes

The automatic model inferrer of Xtext should push common features (like 'name' in your case) up the inheritance hierarchy. When it does not do this, you should check:

  • Does each Config have a name feature? Are they the same type? Check this in your grammar.

  • Do RootConfig, HostConfig etc. derive from Config? Check this in the generated classes.