简体   繁体   中英

Inheritance in Xtext

I am building a grammar in Xtext and what I would like to achieve is be able to inherit an element and all its attributes.

I have the following example in one file:

Country C1 {
   Forest F1 {
      Tree T1, T2, T3;
  }
}

In another file which can be in the same project or not I want to have the following:

Country C2 inherits C1 {
    Forest F2 {
      remove T1;
    }
}

While I write this new grammar, I want Xtext to actually inherit C1 and all its attributes. I know that if these files are in one project, while I write remove I will get:

 remove C1.T1;

But that is only a reference, and if I have other files in this project I will get suggestions from there too (eg, if I have the following):

 Country C3 {
    Forest F3 {
      Tree T1, T2, T3;
   }
}

When I write remove, I will get both:

 remove C3.T1 and 
 remove C1.T1, 

but I want to only inherit C1 and get only C1's attributes.

Is there any way to do that in XText? Please let me know if anything is unclear.

Thank you!

Check Xtext's Scoping , it is the mechanism you want to implement to restrict only to C1's attributes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM