0
votes

I have the following problem. Part of my grammar looks like this

RExpr
    : SetOp
    ;

SetOp returns RExpr
    : PrimaryExpr (({Union.left=current} '+'|{Difference.left=current} '-'|{Intersection.left=current} '&') right = PrimaryExpr)*
    ;

PrimaryExpr returns RExpr
    : '(' RExpr ')'
    | (this = 'this.')? slot = [Slot | QualifiedName]  
    | (this = 'this' | ensName = [Ensemble | QualifiedName])
    | 'All'
    ;

When generating Xtext artifacts ANTLR says that due to some ambiguity it disables an option(3). The ambiguity is because of QualifiedName slot and ensemble share. How do I refactor this kind of cases? I guess syntactic predicate wont help here since it'll force only one(Slot/Ensemble) to be resolved only.

Thanks.

1

1 Answers

1
votes

Xtext can't choose between your two references slot and ensemble. You can merge these references into one reference by adding this rule to your grammar:

SlotOrEnsemble:
    Slot | Ensemble
;

Then your primaryExpr rule will be something like:

PrimaryExpr returns RExpr
    : '(' RExpr ')'
    | ((this = 'this.')? ref= [SlotOrEnsemble | QualifiedName])
    | this = 'this'
    | 'All'
    ;