Grammar Mixins

Xtext supports the reuse of existing grammars. Grammars that are created via the Xtext wizard use org.eclipse.xtext.common.Terminals by default.


 grammar org.xtext.example.MyDsl with org.eclipse.xtext.common.Terminals
 
 generate myDsl "http://www.xtext.org/example/MyDsl"
 
 ....

Mixing in another grammar makes the rules defined in that grammar referable. It is also possible to overwrite rules from the used grammar.

Example :


 grammar my.SuperGrammar
 ...
 RuleA : "a" stuff=RuleB;
 RuleB : "{" name=ID "}";

 grammar my.SubGrammar with my.SuperGrammar

 Model : (ruleAs+=RuleA)*;

 // overwrites my.SuperGrammar.RuleB
 RuleB : '[' name=ID ']';

Note that declared terminal rules always come before any imported / mixed-in terminal rules.