Xtext The rule ‘Primary’ may be consumed without object instantiation

When working with Xtext you might hit this issue at some point. The rule ‘Primary’ may be consumed without object instantiation. Add an action to ensure object creation, e.g. ‘{Expression}’.

You will have something similar in your Xtext file:

Primary returns Expression:
	'modify'

Solution

Use explicit notation instantiate with {}

Primary returns Expression:
	{Modify}'modify'

For more information go to Xtext documentation https://www.eclipse.org/Xtext/documentation/301_grammarlanguage.html#syntax Section: Simple Actions. It will create an instance of Modify and assign it to the result of the parser rule.