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 which introduces a common set of terminal rules and defines reasonable defaults for hidden terminals.

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

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)*;

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

Note that declared terminal rules always get a higher priority then imported terminal rules.