xText - What is cross referencing?

I cannot understand what it means to cross reference something, and all examples provided give a poor explanation of what it actually does and what it means.

Can someone care to explain it?

1 answer

  • answered 2018-04-17 05:42 Christian Dietrich

    Xtext parses text files and turn these text file into a abstract syntax tree. As the word "tree" suggests you only have parent/child relationships. for many usecase this is not enhough. consider you have Entities which have members of type Other Entity.

    entity A {
    }
    
    entity B {
         myA : A
    }
    

    With an AST this would not be possible or you would have to have duplicate object all over the place. or you simply store the name (or other identifier) of the members type and lookup the correct entity manually. this is bad. what you acutally want to do:

    Entity a = ...;
    Entity b = a.getMembers().get(0).getType();
    

    so what you actually want to do is to turn your AST into a graph. Inside this graph you still have the parent/child=containment references and additionally you have cross references that point from one node in the tree to another node in the tree (or even a second file)