Kapil Sharma
Kapil Sharma

Reputation: 75

Issue while writing xtext grammar file

Following is part of my grammar

TestLabelBase returns ResultExpressionRhs : 'VL:' path=STRING ;
AlphabateModifier : (abc?='ABC' | def?='DEF' | ghi?='GHI') ;

When I write following rule TestLabel it works fine:

TestLabel returns ResultExpressionRhs: TestLabelBase (modifier=AlphabateModifier)?;

but when I use following rule for TestLabel it says

An unassigned rule call is not allowed, when the 'current' was already created.

TestLabel returns ResultExpressionRhs: (modifier=AlphabateModifier)? TestLabelBase ;

Can you please explain the reason behind this?

Upvotes: 0

Views: 96

Answers (1)

Steve Jones
Steve Jones

Reputation: 171

Have a read of Parsing Expressions with Xtext, specifically about Therein the first element is an unassigned rule call.

You need to change your rule to:

TestLabel returns ResultExpressionRhs
  : (modifier=AlphabateModifier)? base=TestLabelBase 
  ;  

Cheers, Steve

Upvotes: 1

Related Questions