Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy doesn't linking work in my Xtext-based DSL?
    text
    copied!<p>The following is the Xtext grammar for my DSL.</p> <pre><code>Model: variableTypes=VariableTypes predicateTypes=PredicateTypes variableDeclarations= VariableDeclarations rules=Rules; VariableType: name=ID; VariableTypes: 'var types' (variableTypes+=VariableType)+; PredicateTypes: 'predicate types' (predicateTypes+=PredicateType)+; PredicateType: name=ID '(' (variableTypes+=[VariableType|ID])+ ')'; VariableDeclarations: 'vars' (variableDeclarations+=VariableDeclaration)+; VariableDeclaration: name=ID ':' type=[VariableType|ID]; Rules: 'rules' (rules+=Rule)+; Rule: head=Head ':-' body=Body; Head: predicate=Predicate; Body: (predicates+=Predicate)+; Predicate: predicateType=[PredicateType|ID] '(' (terms+=Term)+ ')'; Term: variable=Variable; Variable: variableDeclaration=[VariableDeclaration|ID]; terminal WS: (' ' | '\t' | '\r' | '\n' | ',')+; </code></pre> <p>And, the following is a program in the above DSL.</p> <pre><code>var types Node predicate types Edge(Node, Node) Path(Node, Node) vars x : Node y : Node z : Node rules Path(x, y) :- Edge(x, y) Path(x, y) :- Path(x, z) Path(z, y) </code></pre> <p>The following is my subclass of the generated <code>Switch</code> class that demonstrates the <code>getPredicateType()</code> returns null on a <code>Predicate</code> node.</p> <pre><code>public class ModelPrinter extends MyDSLSwitch&lt;Object&gt; { protected Object visitChildren(EObject object) { for (EObject eobj : object.eContents()) { doSwitch(eobj); } return object; } @Override public Object casePredicate(Predicate object) { System.out.println(object.getPredicateType()); return object; } @Override public Object defaultCase(EObject object) { return visitChildren(object); } } </code></pre> <p>When I used the <code>ModelPrinter</code> class to traverse the EMF object model corresponding to the above program, I realized that the nodes are not linked together properly. For example, the <code>getPredicateType()</code> method on a <code>Predicate</code> node returns <code>null</code>. Having read the Xtext user's guide, my impression is that the Xtext default linking semantics should work for my DSL. But, for some reason, the AST nodes of my DSL don't get linked together properly. Can anyone help me in diagnosing this problem? </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload